Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 1 | from test import support |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 2 | import unittest |
Neal Norwitz | e7629c8 | 2002-11-02 18:25:08 +0000 | [diff] [blame] | 3 | import os |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 4 | import random |
Georg Brandl | 0a7ac7d | 2008-05-26 10:29:35 +0000 | [diff] [blame] | 5 | import dbm.ndbm |
6 | from dbm.ndbm import error | ||||
Roger E. Masse | fab8ab8 | 1996-12-20 22:36:52 +0000 | [diff] [blame] | 7 | |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 8 | class DbmTestCase(unittest.TestCase): |
Roger E. Masse | 16f9fd2 | 1996-12-10 00:06:24 +0000 | [diff] [blame] | 9 | |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 10 | def setUp(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 11 | self.filename = support.TESTFN |
Georg Brandl | 0a7ac7d | 2008-05-26 10:29:35 +0000 | [diff] [blame] | 12 | self.d = dbm.ndbm.open(self.filename, 'c') |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 13 | self.d.close() |
Fred Drake | 57a4e90 | 2000-09-18 17:56:58 +0000 | [diff] [blame] | 14 | |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 15 | def tearDown(self): |
16 | for suffix in ['', '.pag', '.dir', '.db']: | ||||
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 17 | support.unlink(self.filename + suffix) |
Roger E. Masse | 16f9fd2 | 1996-12-10 00:06:24 +0000 | [diff] [blame] | 18 | |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 19 | def test_keys(self): |
Georg Brandl | 0a7ac7d | 2008-05-26 10:29:35 +0000 | [diff] [blame] | 20 | self.d = dbm.ndbm.open(self.filename, 'c') |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 21 | self.assert_(self.d.keys() == []) |
22 | self.d['a'] = 'b' | ||||
23 | self.d['12345678910'] = '019237410982340912840198242' | ||||
24 | self.d.keys() | ||||
25 | self.assert_(b'a' in self.d) | ||||
26 | self.d.close() | ||||
Neal Norwitz | e7629c8 | 2002-11-02 18:25:08 +0000 | [diff] [blame] | 27 | |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 28 | def test_modes(self): |
29 | for mode in ['r', 'rw', 'w', 'n']: | ||||
30 | try: | ||||
Georg Brandl | 0a7ac7d | 2008-05-26 10:29:35 +0000 | [diff] [blame] | 31 | self.d = dbm.ndbm.open(self.filename, mode) |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 32 | self.d.close() |
Georg Brandl | 0a7ac7d | 2008-05-26 10:29:35 +0000 | [diff] [blame] | 33 | except error: |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 34 | self.fail() |
Neal Norwitz | e7629c8 | 2002-11-02 18:25:08 +0000 | [diff] [blame] | 35 | |
Christian Heimes | 180510d | 2008-03-03 19:15:45 +0000 | [diff] [blame] | 36 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 37 | support.run_unittest(DbmTestCase) |
Christian Heimes | 180510d | 2008-03-03 19:15:45 +0000 | [diff] [blame] | 38 | |
39 | if __name__ == '__main__': | ||||
40 | test_main() |