Commit aba16e10 authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

fix warnings in tests

parent 97a732873fbd
......@@ -43,7 +43,7 @@
def add(self, subject, predicate, object):
self._kb.append( (subject, predicate, object) )
return 'added %s to the knowledge base' % ((subject, predicate, object),)
def search(self, subject, predicate, object):
assert (subject, predicate, object) is not (None, None, None)
for triple in self._kb:
......@@ -52,6 +52,6 @@
and (predicate is None or predicate == _pred) \
and (object is None or object == _obj):
yield triple
def echo(self, arg):
return arg
......@@ -56,6 +56,6 @@
def echo(self, arg):
return arg
class ReadTC(TestCase):
......@@ -91,7 +91,7 @@
def test_read(self):
lines = [(cmd, rgx.pattern, next)
for cmd, rgx, next in ail.read_from_string(self.RULES)]
self.assertListEquals(self.PATTERNS, lines)
self.assertListEqual(self.PATTERNS, lines)
def test_malformatted(self):
gen = ail.read_from_string('bla bla bla')
......@@ -102,8 +102,8 @@
lines = [(cmd, rgx.pattern, next)
for cmd, rgx, next in ail.read_from_string(self.ENV_RULES,
env_context = self.ENV_VARS)]
self.assertListEquals(lines, self.ENV_PATTERNS)
self.assertListEqual(lines, self.ENV_PATTERNS)
def test_include(self):
lines = [(cmd, rgx.pattern, next)
for cmd, rgx, next in ail.read_from_string('include data/test2.ail')]
......@@ -107,7 +107,7 @@
def test_include(self):
lines = [(cmd, rgx.pattern, next)
for cmd, rgx, next in ail.read_from_string('include data/test2.ail')]
self.assertEquals(lines, [('TERMINAL', '(<\\?XML.*<RDF:RDF.*)$', "echo '%(0)s'")])
self.assertEqual(lines, [('TERMINAL', '(<\\?XML.*<RDF:RDF.*)$', "echo '%(0)s'")])
class ThinkTC(TestCase):
RULES = r'''
......@@ -130,5 +130,5 @@
def test_rewrite(self):
rwrt = self.brain._rewrite('alf works for logilab.')
self.assertEquals(rwrt, ('REWRITE', 'alf WORKS_FOR logilab.'))
self.assertEqual(rwrt, ('REWRITE', 'alf WORKS_FOR logilab.'))
rwrt = self.brain._rewrite(rwrt[1])
......@@ -134,5 +134,5 @@
rwrt = self.brain._rewrite(rwrt[1])
self.assertEquals(rwrt, ('TERMINAL', "add 'alf' 'WORKS_FOR' 'logilab'"))
self.assertEqual(rwrt, ('TERMINAL', "add 'alf' 'WORKS_FOR' 'logilab'"))
def test_think_add(self):
res = self.brain.think('alf works for logilab.')
......@@ -136,8 +136,8 @@
def test_think_add(self):
res = self.brain.think('alf works for logilab.')
self.assertEquals(res, "added ('alf', 'WORKS_FOR', 'logilab') to the knowledge base")
self.assertEquals(self.kb._kb, [('alf', 'WORKS_FOR', 'logilab')])
self.assertEqual(res, "added ('alf', 'WORKS_FOR', 'logilab') to the knowledge base")
self.assertEqual(self.kb._kb, [('alf', 'WORKS_FOR', 'logilab')])
def test_quote(self):
self.brain.think("alf works for l'ogilab.")
......@@ -141,5 +141,5 @@
def test_quote(self):
self.brain.think("alf works for l'ogilab.")
self.assertEquals(self.kb._kb, [('alf', 'WORKS_FOR', "l'ogilab")])
self.assertEqual(self.kb._kb, [('alf', 'WORKS_FOR', "l'ogilab")])
self.brain.think("I'm away for 10 minutes")
......@@ -145,6 +145,6 @@
self.brain.think("I'm away for 10 minutes")
self.assertEquals(self.kb._kb, [('alf', 'WORKS_FOR', "l'ogilab"),
self.assertEqual(self.kb._kb, [('alf', 'WORKS_FOR', "l'ogilab"),
('MASTER', 'AWAY_FOR', 10)])
def test_quote2(self):
self.brain.think("alf works for l'og'ilab.")
......@@ -147,8 +147,8 @@
('MASTER', 'AWAY_FOR', 10)])
def test_quote2(self):
self.brain.think("alf works for l'og'ilab.")
self.assertEquals(self.kb._kb, [('alf', 'WORKS_FOR', "l'og'ilab")])
self.assertEqual(self.kb._kb, [('alf', 'WORKS_FOR', "l'og'ilab")])
def test_no_rewrite(self):
self.assertRaises(ail.NoRewriteError, self.brain.think, "no entry")
......@@ -159,7 +159,7 @@
def test_empty_regexp_groups(self):
"""tests empty regexp groups"""
self.brain.load_string('DO IT\s*(\!|\.)? :: add adim said doit')
self.assertEquals(self.kb._kb, [])
self.assertEqual(self.kb._kb, [])
# -> match.groups() will return (None,) because '!' and '.' are
# optionals => make sure None won't make our brain crash
self.brain.think('do it ')
......@@ -163,8 +163,8 @@
# -> match.groups() will return (None,) because '!' and '.' are
# optionals => make sure None won't make our brain crash
self.brain.think('do it ')
self.assertListEquals(self.kb._kb, [('adim', 'said', 'doit')])
self.assertListEqual(self.kb._kb, [('adim', 'said', 'doit')])
def test_think_search(self):
self.brain.think('alf works for logilab.')
res = list(self.brain.think('who works for logilab?'))
......@@ -168,8 +168,8 @@
def test_think_search(self):
self.brain.think('alf works for logilab.')
res = list(self.brain.think('who works for logilab?'))
self.assertEquals(res, [('alf', 'WORKS_FOR', 'logilab')])
self.assertEqual(res, [('alf', 'WORKS_FOR', 'logilab')])
def test_think_search_multiline(self):
self.assert_(re.match(MATCH_EXPR, STMT_XML))
res = self.brain.think(STMT_XML)
......@@ -172,8 +172,8 @@
def test_think_search_multiline(self):
self.assert_(re.match(MATCH_EXPR, STMT_XML))
res = self.brain.think(STMT_XML)
self.assertEquals(res, "rdf-import")
self.assertEqual(res, "rdf-import")
def test_think_search_xml_single(self):
res = self.brain.think(STMT_XML_single)
......@@ -177,7 +177,7 @@
def test_think_search_xml_single(self):
res = self.brain.think(STMT_XML_single)
self.assertEquals(res, "rdf-import")
self.assertEqual(res, "rdf-import")
def test_think_blank(self):
self.assertRaises(ail.NoRewriteError, self.brain.think, "Nonesense".upper())
......@@ -185,7 +185,7 @@
def test_think_unused_group(self):
self.brain.load_string(r"(\d([.,]\d\d?)?|[.,]\d\d?)\s+(.+) :: add yo \1 \3")
self.brain.think('1 narval')
self.assertListEquals(self.kb._kb, [('yo', 1, 'narval')])
self.assertListEqual(self.kb._kb, [('yo', 1, 'narval')])
def test_rev_think(self):
......@@ -190,10 +190,10 @@
def test_rev_think(self):
self.assertEquals(list(self.brain.rev_think('whatever')), [])
self.assertEquals(list(self.brain.rev_think('add')), ['(.*) WORKS_FOR (.*)\.$', "I\\'M AWAY FOR (\\d+) MINUTES$"])
self.assertEquals(list(self.brain.rev_think('search')), ['WHO WORKS_FOR (.*)\?$'])
self.assertEquals(list(self.brain.rev_think('search', 'None')), ['WHO WORKS_FOR (.*)\?$'])
self.assertEquals(list(self.brain.rev_think('search', 'whatever')), [])
self.assertEqual(list(self.brain.rev_think('whatever')), [])
self.assertEqual(list(self.brain.rev_think('add')), ['(.*) WORKS_FOR (.*)\.$', "I\\'M AWAY FOR (\\d+) MINUTES$"])
self.assertEqual(list(self.brain.rev_think('search')), ['WHO WORKS_FOR (.*)\?$'])
self.assertEqual(list(self.brain.rev_think('search', 'None')), ['WHO WORKS_FOR (.*)\?$'])
self.assertEqual(list(self.brain.rev_think('search', 'whatever')), [])
class LongThinkTC(TestCase):
......@@ -210,8 +210,8 @@
from_file = f_pointer.read()
f_pointer.close()
res = self.brain.think(from_file)
self.assertListEquals(res.split(), ail.normalize(from_file).split())
self.assertListEqual(res.split(), ail.normalize(from_file).split())
class LoopThinkTC(TestCase):
......@@ -239,8 +239,8 @@
class SplitTC(TestCase):
def test_1(self):
brain = ail.Brain(None)
self.assertEquals(brain.split('a +1 -2'), ['a', '+1', '-2'])
self.assertEquals(brain.split('a "+1 -2"'), ['a', '+1 -2'])
brain = ail.Brain(None)
self.assertEqual(brain.split('a +1 -2'), ['a', '+1', '-2'])
self.assertEqual(brain.split('a "+1 -2"'), ['a', '+1 -2'])
def test_2(self):
......@@ -246,7 +246,7 @@
def test_2(self):
brain = ail.Brain(None)
self.assertEquals(brain.split(r'a "+1 \" -2"'), ['a', r'+1 " -2'])
self.assertEquals(brain.split(r"a '+1 \' -2'"), ['a', r"+1 ' -2"])
brain = ail.Brain(None)
self.assertEqual(brain.split(r'a "+1 \" -2"'), ['a', r'+1 " -2'])
self.assertEqual(brain.split(r"a '+1 \' -2'"), ['a', r"+1 ' -2"])
EMPTY_RULEFILE = "# This comment is here to please CVS\n"
......@@ -269,6 +269,6 @@
fp = file(self.reload_file, 'a')
fp.write(rule + '\n')
fp.close()
def test_brain_properties(self):
"""tests basic load properties"""
......@@ -273,7 +273,7 @@
def test_brain_properties(self):
"""tests basic load properties"""
self.assertEquals(self.brain.source_files, [self.reload_file])
self.assertEquals(self.brain._patterns, [])
self.assertEqual(self.brain.source_files, [self.reload_file])
self.assertEqual(self.brain._patterns, [])
def test_reload_properties(self):
"""tests source reloading"""
......@@ -281,6 +281,6 @@
self._add_rule_for_reload("(.*) WORKS_FOR (.*)\. :: add '\1' 'WORKS_FOR' '\2'")
self.brain.reload()
# we added only one rule
self.assertEquals(len(self.brain._patterns), 1)
self.assertEqual(len(self.brain._patterns), 1)
# new source list should be equal to the previous one, but it
# should have been rebuilt (=> not the same ID)
......@@ -285,7 +285,7 @@
# new source list should be equal to the previous one, but it
# should have been rebuilt (=> not the same ID)
self.assertNotEquals(old_sourcelist_id, id(self.brain.source_files))
self.assertEquals(self.brain.source_files, [self.reload_file])
self.assertNotEqual(old_sourcelist_id, id(self.brain.source_files))
self.assertEqual(self.brain.source_files, [self.reload_file])
def test_think_after_reload(self):
"""make sure the brain is more clever after adding rules"""
......@@ -290,7 +290,7 @@
def test_think_after_reload(self):
"""make sure the brain is more clever after adding rules"""
self.assertEquals(self.kb._kb, [])
self.assertEqual(self.kb._kb, [])
self._add_rule_for_reload("(\S+) WORKS_FOR (\S+)\. :: add '\\1' 'WORKS_FOR' '\\2'")
self.assertRaises(ail.NoRewriteError, self.brain.think, "adim works_for Logilab.")
self.brain.reload()
self.brain.think("adim WORKS_FOR Logilab.")
......@@ -293,8 +293,8 @@
self._add_rule_for_reload("(\S+) WORKS_FOR (\S+)\. :: add '\\1' 'WORKS_FOR' '\\2'")
self.assertRaises(ail.NoRewriteError, self.brain.think, "adim works_for Logilab.")
self.brain.reload()
self.brain.think("adim WORKS_FOR Logilab.")
self.assertEquals(self.kb._kb, [('adim', 'WORKS_FOR', 'Logilab')])
self.assertEqual(self.kb._kb, [('adim', 'WORKS_FOR', 'Logilab')])
class TestRun(TestCase):
......@@ -310,9 +310,9 @@
context = {}
#exec "import ail" in context
#exec "ail.run(['data/tests.ail', 'data/input_question'])" in context
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment