PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Lib/test/test_dbm.py

http://unladen-swallow.googlecode.com/
Python | 42 lines | 39 code | 3 blank | 0 comment | 2 complexity | 114bfd1cadac765a399cbd89f1fb3520 MD5 | raw file
 1from test import test_support
 2import unittest
 3import dbm
 4
 5class DbmTestCase(unittest.TestCase):
 6
 7    def setUp(self):
 8        self.filename = test_support.TESTFN
 9        self.d = dbm.open(self.filename, 'c')
10        self.d.close()
11
12    def tearDown(self):
13        for suffix in ['', '.pag', '.dir', '.db']:
14            test_support.unlink(self.filename + suffix)
15
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.assert_(k in self.d)
25            self.assertEqual(self.d[k], v)
26        self.assert_('xxx' not in self.d)
27        self.assertRaises(KeyError, lambda: self.d['xxx'])
28        self.d.close()
29
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()
37
38def test_main():
39    test_support.run_unittest(DbmTestCase)
40
41if __name__ == '__main__':
42    test_main()