LEFT | RIGHT |
1 #! /usr/bin/env python3 | 1 #! /usr/bin/env python3 |
2 """Test script for the dbm.open function based on testdumbdbm.py""" | 2 """Test script for the dbm.open function based on testdumbdbm.py""" |
3 | 3 |
4 import os | 4 import os |
5 import unittest | 5 import unittest |
6 import glob | 6 import glob |
7 import test.support | 7 import test.support |
8 | 8 |
9 # Skip tests if dbm module doesn't exist. | 9 # Skip tests if dbm module doesn't exist. |
10 dbm = test.support.import_module('dbm') | 10 dbm = test.support.import_module('dbm') |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return keys | 57 return keys |
58 | 58 |
59 def test_error(self): | 59 def test_error(self): |
60 self.assertTrue(issubclass(self.module.error, IOError)) | 60 self.assertTrue(issubclass(self.module.error, IOError)) |
61 | 61 |
62 def test_anydbm_not_existing(self): | 62 def test_anydbm_not_existing(self): |
63 self.assertRaises(dbm.error, dbm.open, _fname) | 63 self.assertRaises(dbm.error, dbm.open, _fname) |
64 | 64 |
65 def test_anydbm_creation(self): | 65 def test_anydbm_creation(self): |
66 f = dbm.open(_fname, 'c') | 66 f = dbm.open(_fname, 'c') |
67 self.assertEqual(f.keys(), set()) | 67 self.assertEqual(f.keys(), set()) |
68 for key in self._dict: | 68 for key in self._dict: |
69 f[key.encode("ascii")] = self._dict[key] | 69 f[key.encode("ascii")] = self._dict[key] |
70 self.read_helper(f) | 70 self.read_helper(f) |
71 f.close() | 71 f.close() |
72 | 72 |
73 def test_anydbm_modification(self): | 73 def test_anydbm_modification(self): |
74 self.init_db() | 74 self.init_db() |
75 f = dbm.open(_fname, 'c') | 75 f = dbm.open(_fname, 'c') |
76 self._dict['g'] = f[b'g'] = b"indented" | 76 self._dict['g'] = f[b'g'] = b"indented" |
77 self.read_helper(f) | 77 self.read_helper(f) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 unittest.TestCase.__init__(self, *args) | 116 unittest.TestCase.__init__(self, *args) |
117 | 117 |
118 def test_whichdb(self): | 118 def test_whichdb(self): |
119 for module in dbm_iterator(): | 119 for module in dbm_iterator(): |
120 # Check whether whichdb correctly guesses module name | 120 # Check whether whichdb correctly guesses module name |
121 # for databases opened with "module" module. | 121 # for databases opened with "module" module. |
122 # Try with empty files first | 122 # Try with empty files first |
123 name = module.__name__ | 123 name = module.__name__ |
124 if name == 'dbm.dumb': | 124 if name == 'dbm.dumb': |
125 continue # whichdb can't support dbm.dumb | 125 continue # whichdb can't support dbm.dumb |
126 test.support.unlink(_fname) | 126 delete_files() |
127 f = module.open(_fname, 'c') | 127 f = module.open(_fname, 'c') |
128 f.close() | 128 f.close() |
129 self.assertEqual(name, dbm.whichdb(_fname)) | 129 self.assertEqual(name, dbm.whichdb(_fname)) |
130 # Now add a key | 130 # Now add a key |
131 f = module.open(_fname, 'w') | 131 f = module.open(_fname, 'w') |
132 f[b"1"] = b"1" | 132 f[b"1"] = b"1" |
133 # and test that we can find it | 133 # and test that we can find it |
134 self.assertIn(b"1", f) | 134 self.assertIn(b"1", f) |
135 # and read it | 135 # and read it |
136 self.assertTrue(f[b"1"] == b"1") | 136 self.assertTrue(f[b"1"] == b"1") |
(...skipping 26 matching lines...) Expand all Loading... |
163 | 163 |
164 def test_main(): | 164 def test_main(): |
165 classes = [WhichDBTestCase] | 165 classes = [WhichDBTestCase] |
166 for mod in dbm_iterator(): | 166 for mod in dbm_iterator(): |
167 classes.append(type("TestCase-" + mod.__name__, (AnyDBMTestCase,), | 167 classes.append(type("TestCase-" + mod.__name__, (AnyDBMTestCase,), |
168 {'module': mod})) | 168 {'module': mod})) |
169 test.support.run_unittest(*classes) | 169 test.support.run_unittest(*classes) |
170 | 170 |
171 if __name__ == "__main__": | 171 if __name__ == "__main__": |
172 test_main() | 172 test_main() |
LEFT | RIGHT |