2008-03-17 22:50:25 -03:00
|
|
|
from test import test_support
|
|
|
|
import unittest
|
2009-03-30 20:05:48 -03:00
|
|
|
dbm = test_support.import_module('dbm')
|
1996-12-20 18:36:52 -04:00
|
|
|
|
2008-03-17 22:50:25 -03:00
|
|
|
class DbmTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.filename = test_support.TESTFN
|
|
|
|
self.d = dbm.open(self.filename, 'c')
|
|
|
|
self.d.close()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
for suffix in ['', '.pag', '.dir', '.db']:
|
|
|
|
test_support.unlink(self.filename + suffix)
|
|
|
|
|
|
|
|
def test_keys(self):
|
|
|
|
self.d = dbm.open(self.filename, 'c')
|
2008-10-07 15:10:47 -03:00
|
|
|
self.assertEqual(self.d.keys(), [])
|
|
|
|
a = [('a', 'b'), ('12345678910', '019237410982340912840198242')]
|
|
|
|
for k, v in a:
|
|
|
|
self.d[k] = v
|
|
|
|
self.assertEqual(sorted(self.d.keys()), sorted(k for (k, v) in a))
|
|
|
|
for k, v in a:
|
2010-01-23 19:04:36 -04:00
|
|
|
self.assertIn(k, self.d)
|
2008-10-07 15:10:47 -03:00
|
|
|
self.assertEqual(self.d[k], v)
|
2010-01-23 19:04:36 -04:00
|
|
|
self.assertNotIn('xxx', self.d)
|
2008-10-07 15:10:47 -03:00
|
|
|
self.assertRaises(KeyError, lambda: self.d['xxx'])
|
2008-03-17 22:50:25 -03:00
|
|
|
self.d.close()
|
|
|
|
|
|
|
|
def test_modes(self):
|
|
|
|
for mode in ['r', 'rw', 'w', 'n']:
|
|
|
|
try:
|
|
|
|
self.d = dbm.open(self.filename, mode)
|
|
|
|
self.d.close()
|
|
|
|
except dbm.error:
|
|
|
|
self.fail()
|
2002-11-02 14:25:08 -04:00
|
|
|
|
2008-03-03 00:19:29 -04:00
|
|
|
def test_main():
|
2008-03-17 22:50:25 -03:00
|
|
|
test_support.run_unittest(DbmTestCase)
|
2008-03-03 00:19:29 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|