The silencing of DeprecationWarning was not taking -3 into consideration. Since
[python.git] / Lib / test / test_dbm.py
blob43f8a5b93045997d54276938ef07fd9fa3bbe32e
1 from test import test_support
2 import unittest
3 dbm = test_support.import_module('dbm')
5 class DbmTestCase(unittest.TestCase):
7 def setUp(self):
8 self.filename = test_support.TESTFN
9 self.d = dbm.open(self.filename, 'c')
10 self.d.close()
12 def tearDown(self):
13 for suffix in ['', '.pag', '.dir', '.db']:
14 test_support.unlink(self.filename + suffix)
16 def test_keys(self):
17 self.d = dbm.open(self.filename, 'c')
18 self.assertEqual(self.d.keys(), [])
19 a = [('a', 'b'), ('12345678910', '019237410982340912840198242')]
20 for k, v in a:
21 self.d[k] = v
22 self.assertEqual(sorted(self.d.keys()), sorted(k for (k, v) in a))
23 for k, v in a:
24 self.assertTrue(k in self.d)
25 self.assertEqual(self.d[k], v)
26 self.assertTrue('xxx' not in self.d)
27 self.assertRaises(KeyError, lambda: self.d['xxx'])
28 self.d.close()
30 def test_modes(self):
31 for mode in ['r', 'rw', 'w', 'n']:
32 try:
33 self.d = dbm.open(self.filename, mode)
34 self.d.close()
35 except dbm.error:
36 self.fail()
38 def test_main():
39 test_support.run_unittest(DbmTestCase)
41 if __name__ == '__main__':
42 test_main()