restructure a bit to not rely on test case execution ordering
add test case for bug #482460
This commit is contained in:
parent
03d3e33af9
commit
c08fe82b32
|
@ -30,11 +30,8 @@ class DumbDBMTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
unittest.TestCase.__init__(self, *args)
|
unittest.TestCase.__init__(self, *args)
|
||||||
self._dkeys = self._dict.keys()
|
|
||||||
self._dkeys.sort()
|
|
||||||
|
|
||||||
def test_dumbdbm_creation(self):
|
def test_dumbdbm_creation(self):
|
||||||
_delete_files()
|
|
||||||
f = dumbdbm.open(_fname, 'c')
|
f = dumbdbm.open(_fname, 'c')
|
||||||
self.assertEqual(f.keys(), [])
|
self.assertEqual(f.keys(), [])
|
||||||
for key in self._dict:
|
for key in self._dict:
|
||||||
|
@ -43,32 +40,59 @@ class DumbDBMTestCase(unittest.TestCase):
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def test_dumbdbm_modification(self):
|
def test_dumbdbm_modification(self):
|
||||||
|
self.init_db()
|
||||||
f = dumbdbm.open(_fname, 'w')
|
f = dumbdbm.open(_fname, 'w')
|
||||||
self._dict['g'] = f['g'] = "indented"
|
self._dict['g'] = f['g'] = "indented"
|
||||||
self.read_helper(f)
|
self.read_helper(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def test_dumbdbm_read(self):
|
def test_dumbdbm_read(self):
|
||||||
|
self.init_db()
|
||||||
f = dumbdbm.open(_fname, 'r')
|
f = dumbdbm.open(_fname, 'r')
|
||||||
self.read_helper(f)
|
self.read_helper(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def test_dumbdbm_keys(self):
|
def test_dumbdbm_keys(self):
|
||||||
|
self.init_db()
|
||||||
f = dumbdbm.open(_fname)
|
f = dumbdbm.open(_fname)
|
||||||
keys = self.keys_helper(f)
|
keys = self.keys_helper(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def test_write_write_read(self):
|
||||||
|
# test for bug #482460
|
||||||
|
f = dumbdbm.open(_fname)
|
||||||
|
f['1'] = 'hello'
|
||||||
|
f['1'] = 'hello2'
|
||||||
|
f.close()
|
||||||
|
f = dumbdbm.open(_fname)
|
||||||
|
self.assertEqual(f['1'], 'hello2')
|
||||||
|
f.close()
|
||||||
|
|
||||||
def read_helper(self, f):
|
def read_helper(self, f):
|
||||||
keys = self.keys_helper(f)
|
keys = self.keys_helper(f)
|
||||||
for key in self._dict:
|
for key in self._dict:
|
||||||
self.assertEqual(self._dict[key], f[key])
|
self.assertEqual(self._dict[key], f[key])
|
||||||
|
|
||||||
|
def init_db(self):
|
||||||
|
f = dumbdbm.open(_fname, 'w')
|
||||||
|
for k in self._dict:
|
||||||
|
f[k] = self._dict[k]
|
||||||
|
f.close()
|
||||||
|
|
||||||
def keys_helper(self, f):
|
def keys_helper(self, f):
|
||||||
keys = f.keys()
|
keys = f.keys()
|
||||||
keys.sort()
|
keys.sort()
|
||||||
self.assertEqual(keys, self._dkeys)
|
dkeys = self._dict.keys()
|
||||||
|
dkeys.sort()
|
||||||
|
self.assertEqual(keys, dkeys)
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
_delete_files()
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
_delete_files()
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
try:
|
try:
|
||||||
test_support.run_unittest(DumbDBMTestCase)
|
test_support.run_unittest(DumbDBMTestCase)
|
||||||
|
|
Loading…
Reference in New Issue