Index: Lib/test/test_dbm_ndbm.py |
=================================================================== |
--- Lib/test/test_dbm_ndbm.py (revision 88435) |
+++ Lib/test/test_dbm_ndbm.py (working copy) |
@@ -1,41 +1,27 @@ |
from test import support |
-support.import_module("dbm.ndbm") #skip if not supported |
+ndbm = support.import_module("dbm.ndbm") #skip if not supported |
import unittest |
-import os |
-import random |
-import dbm.ndbm |
-from dbm.ndbm import error |
+import test.test_dbm_base as test_dbm_base |
-class DbmTestCase(unittest.TestCase): |
- def setUp(self): |
- self.filename = support.TESTFN |
- self.d = dbm.ndbm.open(self.filename, 'c') |
- self.d.close() |
+filename = test_dbm_base.filename |
- def tearDown(self): |
- for suffix in ['', '.pag', '.dir', '.db']: |
- support.unlink(self.filename + suffix) |
- def test_keys(self): |
- self.d = dbm.ndbm.open(self.filename, 'c') |
- self.assertTrue(self.d.keys() == []) |
- self.d['a'] = 'b' |
- self.d[b'bytes'] = b'data' |
- self.d['12345678910'] = '019237410982340912840198242' |
- self.d.keys() |
- self.assertIn(b'a', self.d) |
- self.assertEqual(self.d[b'bytes'], b'data') |
- self.d.close() |
+class DbmTestCase(test_dbm_base.TestDbmBase): |
+ _module = ndbm |
+ |
def test_modes(self): |
- for mode in ['r', 'rw', 'w', 'n']: |
+ # Here the order is important, put the 'c' flags at the first make sure |
+ # that 'r' won't raise file-not-exists error. |
+ for mode in ['c', 'r', 'rw', 'w', 'n']: |
try: |
- self.d = dbm.ndbm.open(self.filename, mode) |
+ self.d = self._module.open(filename, mode) |
self.d.close() |
except error: |
self.fail() |
+ |
def test_main(): |
support.run_unittest(DbmTestCase) |