summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_whichdb.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2007-08-24 21:59:45 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2007-08-24 21:59:45 (GMT)
commit178fefb9b5de5aa7db33e691ce2760c54097718b (patch)
tree99e249eba9f1691cf92e13e63879f0e993f075f1 /Lib/test/test_whichdb.py
parent41cfce9c2bcfe6153ee2b42e05ff1d782d1d3b91 (diff)
downloadcpython-178fefb9b5de5aa7db33e691ce2760c54097718b.zip
cpython-178fefb9b5de5aa7db33e691ce2760c54097718b.tar.gz
cpython-178fefb9b5de5aa7db33e691ce2760c54097718b.tar.bz2
applies the better dbm and shelve related unittests. bug 1007 from larryhastings
Diffstat (limited to 'Lib/test/test_whichdb.py')
-rw-r--r--Lib/test/test_whichdb.py58
1 files changed, 25 insertions, 33 deletions
diff --git a/Lib/test/test_whichdb.py b/Lib/test/test_whichdb.py
index 675507a..d3eda84 100644
--- a/Lib/test/test_whichdb.py
+++ b/Lib/test/test_whichdb.py
@@ -10,57 +10,49 @@ import whichdb
import anydbm
import tempfile
import glob
+from test.test_anydbm import delete_files, dbm_iterator
_fname = test.test_support.TESTFN
-def _delete_files():
- # we don't know the precise name the underlying database uses
- # so we use glob to locate all names
- for f in glob.glob(_fname + "*"):
- try:
- os.unlink(f)
- except OSError:
- pass
-
class WhichDBTestCase(unittest.TestCase):
# Actual test methods are added to namespace
# after class definition.
def __init__(self, *args):
unittest.TestCase.__init__(self, *args)
+ def test_whichdb(self):
+ for module in dbm_iterator():
+ # Check whether whichdb correctly guesses module name
+ # for databases opened with "module" module.
+ # Try with empty files first
+ name = module.__name__
+ if name == 'dumbdbm':
+ continue # whichdb can't support dumbdbm
+ f = module.open(_fname, 'c')
+ f.close()
+ self.assertEqual(name, whichdb.whichdb(_fname))
+ # Now add a key
+ f = module.open(_fname, 'w')
+ f[b"1"] = b"1"
+ # and test that we can find it
+ assert b"1" in f
+ # and read it
+ assert f[b"1"] == b"1"
+ f.close()
+ self.assertEqual(name, whichdb.whichdb(_fname))
+
def tearDown(self):
- _delete_files()
+ delete_files()
def setUp(self):
- _delete_files()
-
-for name in anydbm._names:
- # we define a new test method for each
- # candidate database module.
- try:
- mod = __import__(name)
- except ImportError:
- continue
+ delete_files()
- def test_whichdb_name(self, name=name, mod=mod):
- # Check whether whichdb correctly guesses module name
- # for databases opened with module mod.
- # Try with empty files first
- f = mod.open(_fname, 'c')
- f.close()
- self.assertEqual(name, whichdb.whichdb(_fname))
- # Now add a key
- f = mod.open(_fname, 'w')
- f[b"1"] = b"1"
- f.close()
- self.assertEqual(name, whichdb.whichdb(_fname))
- setattr(WhichDBTestCase,"test_whichdb_%s" % name, test_whichdb_name)
def test_main():
try:
test.test_support.run_unittest(WhichDBTestCase)
finally:
- _delete_files()
+ delete_files()
if __name__ == "__main__":
test_main()