summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_anydbm.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_anydbm.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_anydbm.py')
-rw-r--r--Lib/test/test_anydbm.py46
1 files changed, 41 insertions, 5 deletions
diff --git a/Lib/test/test_anydbm.py b/Lib/test/test_anydbm.py
index 367360f..9399d71 100644
--- a/Lib/test/test_anydbm.py
+++ b/Lib/test/test_anydbm.py
@@ -11,7 +11,33 @@ from test import test_support
_fname = test_support.TESTFN
-def _delete_files():
+_all_modules = []
+
+for _name in anydbm._names:
+ try:
+ _module = __import__(_name)
+ except ImportError:
+ continue
+ _all_modules.append(_module)
+
+
+#
+# Iterates over every database module supported by anydbm
+# currently available, setting anydbm to use each in turn,
+# and yielding that module
+#
+def dbm_iterator():
+ old_default = anydbm._defaultmod
+ for module in _all_modules:
+ anydbm._defaultmod = module
+ yield module
+ anydbm._defaultmod = old_default
+
+#
+# Clean up all scratch databases we might have created
+# during testing
+#
+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 + "*"):
@@ -60,6 +86,14 @@ class AnyDBMTestCase(unittest.TestCase):
keys = self.keys_helper(f)
f.close()
+ def test_anydbm_access(self):
+ self.init_db()
+ f = anydbm.open(_fname, 'r')
+ key = "a".encode("ascii")
+ assert(key in f)
+ assert(f[key] == b"Python:")
+ f.close()
+
def read_helper(self, f):
keys = self.keys_helper(f)
for key in self._dict:
@@ -78,16 +112,18 @@ class AnyDBMTestCase(unittest.TestCase):
return keys
def tearDown(self):
- _delete_files()
+ delete_files()
def setUp(self):
- _delete_files()
+ delete_files()
+
def test_main():
try:
- test_support.run_unittest(AnyDBMTestCase)
+ for module in dbm_iterator():
+ test_support.run_unittest(AnyDBMTestCase)
finally:
- _delete_files()
+ delete_files()
if __name__ == "__main__":
test_main()