summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2001-11-13 20:16:52 (GMT)
committerBarry Warsaw <barry@python.org>2001-11-13 20:16:52 (GMT)
commit3ca656f1be84cd03852cc44958caacdb71f3b9ec (patch)
tree81eaee8a94973c82794ffa6311bf80366a1846d6
parent88d21319ba824b4bd05ce1f9d26a80e3c2f388f6 (diff)
downloadcpython-3ca656f1be84cd03852cc44958caacdb71f3b9ec.zip
cpython-3ca656f1be84cd03852cc44958caacdb71f3b9ec.tar.gz
cpython-3ca656f1be84cd03852cc44958caacdb71f3b9ec.tar.bz2
Committing the second part of patch #480902, an improved test suite
for dumbdbm.py, by Skip Montanaro. The first half of Skip's patch has been postponed until Py2.3 since it adds new features.
-rw-r--r--Lib/test/test_dumbdbm.py97
1 files changed, 66 insertions, 31 deletions
diff --git a/Lib/test/test_dumbdbm.py b/Lib/test/test_dumbdbm.py
index 3c6a5c5..51b6217 100644
--- a/Lib/test/test_dumbdbm.py
+++ b/Lib/test/test_dumbdbm.py
@@ -3,35 +3,70 @@
Original by Roger E. Masse
"""
-# XXX This test is a disgrace. It doesn't test that it works.
-
-import dumbdbm as dbm
-from dumbdbm import error
-from test_support import verbose, TESTFN as filename
-
-d = dbm.open(filename, 'c')
-d['a'] = 'b'
-d['12345678910'] = '019237410982340912840198242'
-d.keys()
-if d.has_key('a'):
- if verbose:
- print 'Test dbm keys: ', d.keys()
-
-d.close()
-d = dbm.open(filename, 'r')
-d.close()
-d = dbm.open(filename, 'w')
-d.close()
-d = dbm.open(filename, 'n')
-d.close()
-
import os
-def rm(fn):
- try:
- os.unlink(fn)
- except os.error:
- pass
-
-rm(filename + '.dir')
-rm(filename + '.dat')
-rm(filename + '.bak')
+import test_support
+import unittest
+import dumbdbm
+import tempfile
+
+class DumbDBMTestCase(unittest.TestCase):
+ _fname = tempfile.mktemp()
+ _dict = {'0': '',
+ 'a': 'Python:',
+ 'b': 'Programming',
+ 'c': 'the',
+ 'd': 'way',
+ 'f': 'Guido',
+ 'g': 'intended'
+ }
+
+ def __init__(self, *args):
+ unittest.TestCase.__init__(self, *args)
+ self._dkeys = self._dict.keys()
+ self._dkeys.sort()
+
+ def test_dumbdbm_creation(self):
+ for ext in [".dir", ".dat", ".bak"]:
+ try: os.unlink(self._fname+ext)
+ except OSError: pass
+
+ f = dumbdbm.open(self._fname, 'c')
+ self.assertEqual(f.keys(), [])
+ for key in self._dict:
+ f[key] = self._dict[key]
+ self.read_helper(f)
+ f.close()
+
+ def test_dumbdbm_modification(self):
+ f = dumbdbm.open(self._fname, 'w')
+ self._dict['g'] = f['g'] = "indented"
+ self.read_helper(f)
+ f.close()
+
+ def test_dumbdbm_read(self):
+ f = dumbdbm.open(self._fname, 'r')
+ self.read_helper(f)
+ f.close()
+
+ def test_dumbdbm_keys(self):
+ f = dumbdbm.open(self._fname)
+ keys = self.keys_helper(f)
+ f.close()
+
+ def read_helper(self, f):
+ keys = self.keys_helper(f)
+ for key in self._dict:
+ self.assertEqual(self._dict[key], f[key])
+
+ def keys_helper(self, f):
+ keys = f.keys()
+ keys.sort()
+ self.assertEqual(keys, self._dkeys)
+ return keys
+
+def test_main():
+ test_support.run_unittest(DumbDBMTestCase)
+
+
+if __name__ == "__main__":
+ test_main()