summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-10-14 18:40:37 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-10-14 18:40:37 (GMT)
commitd29f1d2241f3ad30fffc7086b690d8d6515bc6db (patch)
tree290fea3e0be4dbc3ebc2815d11530b410bc78984 /Lib/bsddb
parent3884690d69291b627b317e0f7d8d0b009df5a564 (diff)
downloadcpython-d29f1d2241f3ad30fffc7086b690d8d6515bc6db.zip
cpython-d29f1d2241f3ad30fffc7086b690d8d6515bc6db.tar.gz
cpython-d29f1d2241f3ad30fffc7086b690d8d6515bc6db.tar.bz2
Use unittest for assertions
Diffstat (limited to 'Lib/bsddb')
-rw-r--r--Lib/bsddb/test/test_dbtables.py67
1 files changed, 34 insertions, 33 deletions
diff --git a/Lib/bsddb/test/test_dbtables.py b/Lib/bsddb/test/test_dbtables.py
index 1debb89..959565c 100644
--- a/Lib/bsddb/test/test_dbtables.py
+++ b/Lib/bsddb/test/test_dbtables.py
@@ -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():