Use unittest for assertions
This commit is contained in:
parent
3884690d69
commit
d29f1d2241
|
@ -78,7 +78,8 @@ class TableDBTestCase(unittest.TestCase):
|
|||
tabname, [colname], conditions={colname: None})
|
||||
|
||||
colval = pickle.loads(values[0][colname])
|
||||
assert(colval > 3.141 and colval < 3.142)
|
||||
self.assert_(colval > 3.141)
|
||||
self.assert_(colval < 3.142)
|
||||
|
||||
|
||||
def test02(self):
|
||||
|
@ -103,11 +104,11 @@ class TableDBTestCase(unittest.TestCase):
|
|||
values = self.tdb.Select(tabname, [col2],
|
||||
conditions={col0: lambda x: pickle.loads(x) >= 8})
|
||||
|
||||
assert len(values) == 2
|
||||
self.assertEqual(len(values), 2)
|
||||
if values[0]['Species'] == 'Penguin' :
|
||||
assert values[1]['Species'] == 'SR-71A Blackbird'
|
||||
self.assertEqual(values[1]['Species'], 'SR-71A Blackbird')
|
||||
elif values[0]['Species'] == 'SR-71A Blackbird' :
|
||||
assert values[1]['Species'] == 'Penguin'
|
||||
self.assertEqual(values[1]['Species'], 'Penguin')
|
||||
else :
|
||||
if verbose:
|
||||
print "values= %r" % (values,)
|
||||
|
@ -137,13 +138,13 @@ class TableDBTestCase(unittest.TestCase):
|
|||
{'a': "",
|
||||
'e': pickle.dumps([{4:5, 6:7}, 'foo'], 1),
|
||||
'f': "Zero"})
|
||||
assert 0
|
||||
self.fail('Expected an exception')
|
||||
except dbtables.TableDBError:
|
||||
pass
|
||||
|
||||
try:
|
||||
self.tdb.Select(tabname, [], conditions={'foo': '123'})
|
||||
assert 0
|
||||
self.fail('Expected an exception')
|
||||
except dbtables.TableDBError:
|
||||
pass
|
||||
|
||||
|
@ -172,20 +173,20 @@ class TableDBTestCase(unittest.TestCase):
|
|||
values = self.tdb.Select(tabname, ['b', 'a', 'd'],
|
||||
conditions={'e': re.compile('wuzzy').search,
|
||||
'a': re.compile('^[0-9]+$').match})
|
||||
assert len(values) == 2
|
||||
self.assertEqual(len(values), 2)
|
||||
|
||||
# now lets delete one of them and try again
|
||||
self.tdb.Delete(tabname, conditions={'b': dbtables.ExactCond('good')})
|
||||
values = self.tdb.Select(
|
||||
tabname, ['a', 'd', 'b'],
|
||||
conditions={'e': dbtables.PrefixCond('Fuzzy')})
|
||||
assert len(values) == 1
|
||||
assert values[0]['d'] == None
|
||||
self.assertEqual(len(values), 1)
|
||||
self.assertEqual(values[0]['d'], None)
|
||||
|
||||
values = self.tdb.Select(tabname, ['b'],
|
||||
conditions={'c': lambda c: c == 'meep'})
|
||||
assert len(values) == 1
|
||||
assert values[0]['b'] == "bad"
|
||||
self.assertEqual(len(values), 1)
|
||||
self.assertEqual(values[0]['b'], "bad")
|
||||
|
||||
|
||||
def test04_MultiCondSelect(self):
|
||||
|
@ -201,7 +202,7 @@ class TableDBTestCase(unittest.TestCase):
|
|||
{'a': "",
|
||||
'e': pickle.dumps([{4:5, 6:7}, 'foo'], 1),
|
||||
'f': "Zero"})
|
||||
assert 0
|
||||
self.fail('Expected an exception')
|
||||
except dbtables.TableDBError:
|
||||
pass
|
||||
|
||||
|
@ -225,7 +226,7 @@ class TableDBTestCase(unittest.TestCase):
|
|||
'a': dbtables.ExactCond('A'),
|
||||
'd': dbtables.PrefixCond('-')
|
||||
} )
|
||||
assert len(values) == 0, values
|
||||
self.assertEqual(len(values), 0, values)
|
||||
|
||||
|
||||
def test_CreateOrExtend(self):
|
||||
|
@ -238,7 +239,7 @@ class TableDBTestCase(unittest.TestCase):
|
|||
{'taste': 'crap',
|
||||
'filling': 'no',
|
||||
'is it Guinness?': 'no'})
|
||||
assert 0, "Insert should've failed due to bad column name"
|
||||
self.fail("Insert should've failed due to bad column name")
|
||||
except:
|
||||
pass
|
||||
self.tdb.CreateOrExtendTable(tabname,
|
||||
|
@ -272,16 +273,16 @@ class TableDBTestCase(unittest.TestCase):
|
|||
values = self.tdb.Select(
|
||||
tabname, ['p', 'e'],
|
||||
conditions={'e': dbtables.PrefixCond('the l')})
|
||||
assert len(values) == 2, values
|
||||
assert values[0]['e'] == values[1]['e'], values
|
||||
assert values[0]['p'] != values[1]['p'], values
|
||||
self.assertEqual(len(values), 2, values)
|
||||
self.assertEqual(values[0]['e'], values[1]['e'], values)
|
||||
self.assertNotEqual(values[0]['p'], values[1]['p'], values)
|
||||
|
||||
values = self.tdb.Select(
|
||||
tabname, ['d', 'a'],
|
||||
conditions={'a': dbtables.LikeCond('%aardvark%')})
|
||||
assert len(values) == 1, values
|
||||
assert values[0]['d'] == "is for dog", values
|
||||
assert values[0]['a'] == "is for aardvark", values
|
||||
self.assertEqual(len(values), 1, values)
|
||||
self.assertEqual(values[0]['d'], "is for dog", values)
|
||||
self.assertEqual(values[0]['a'], "is for aardvark", values)
|
||||
|
||||
values = self.tdb.Select(tabname, None,
|
||||
{'b': dbtables.Cond(),
|
||||
|
@ -290,9 +291,9 @@ class TableDBTestCase(unittest.TestCase):
|
|||
'd':dbtables.ExactCond('is for dog'),
|
||||
'c':dbtables.PrefixCond('is for'),
|
||||
'p':lambda s: not s})
|
||||
assert len(values) == 1, values
|
||||
assert values[0]['d'] == "is for dog", values
|
||||
assert values[0]['a'] == "is for aardvark", values
|
||||
self.assertEqual(len(values), 1, values)
|
||||
self.assertEqual(values[0]['d'], "is for dog", values)
|
||||
self.assertEqual(values[0]['a'], "is for aardvark", values)
|
||||
|
||||
def test_Delete(self):
|
||||
tabname = "test_Delete"
|
||||
|
@ -308,7 +309,7 @@ class TableDBTestCase(unittest.TestCase):
|
|||
self.tdb.Delete(tabname, conditions={'x': dbtables.PrefixCond('X')})
|
||||
values = self.tdb.Select(tabname, ['y'],
|
||||
conditions={'x': dbtables.PrefixCond('X')})
|
||||
assert len(values) == 0
|
||||
self.assertEqual(len(values), 0)
|
||||
|
||||
def test_Modify(self):
|
||||
tabname = "test_Modify"
|
||||
|
@ -354,24 +355,24 @@ class TableDBTestCase(unittest.TestCase):
|
|||
values = self.tdb.Select(
|
||||
tabname, None,
|
||||
conditions={'Type': dbtables.ExactCond('Unknown')})
|
||||
assert len(values) == 1, values
|
||||
assert values[0]['Name'] == None, values
|
||||
assert values[0]['Access'] == None, values
|
||||
self.assertEqual(len(values), 1, values)
|
||||
self.assertEqual(values[0]['Name'], None, values)
|
||||
self.assertEqual(values[0]['Access'], None, values)
|
||||
|
||||
# Modify value by select conditions
|
||||
values = self.tdb.Select(
|
||||
tabname, None,
|
||||
conditions={'Name': dbtables.ExactCond('Nifty.MP3')})
|
||||
assert len(values) == 1, values
|
||||
assert values[0]['Type'] == "MP3", values
|
||||
assert values[0]['Access'] == "2", values
|
||||
self.assertEqual(len(values), 1, values)
|
||||
self.assertEqual(values[0]['Type'], "MP3", values)
|
||||
self.assertEqual(values[0]['Access'], "2", values)
|
||||
|
||||
# Make sure change applied only to select conditions
|
||||
values = self.tdb.Select(
|
||||
tabname, None, conditions={'Name': dbtables.LikeCond('%doc%')})
|
||||
assert len(values) == 1, values
|
||||
assert values[0]['Type'] == "Word", values
|
||||
assert values[0]['Access'] == "9", values
|
||||
self.assertEqual(len(values), 1, values)
|
||||
self.assertEqual(values[0]['Type'], "Word", values)
|
||||
self.assertEqual(values[0]['Access'], "9", values)
|
||||
|
||||
|
||||
def test_suite():
|
||||
|
|
Loading…
Reference in New Issue