diff options
author | Skip Montanaro <skip@pobox.com> | 2002-08-02 17:10:10 (GMT) |
---|---|---|
committer | Skip Montanaro <skip@pobox.com> | 2002-08-02 17:10:10 (GMT) |
commit | 13a5678a5152b019300baeb5dcfe5bbc780e84d9 (patch) | |
tree | 0cc4ea68a314c3b6187e9f6afd58593bdfe57597 /Lib/test | |
parent | 37c3b2788be1b3eea69fac9a8517459478afb6fd (diff) | |
download | cpython-13a5678a5152b019300baeb5dcfe5bbc780e84d9.zip cpython-13a5678a5152b019300baeb5dcfe5bbc780e84d9.tar.gz cpython-13a5678a5152b019300baeb5dcfe5bbc780e84d9.tar.bz2 |
regression test for the whichdb module
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_whichdb.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Lib/test/test_whichdb.py b/Lib/test/test_whichdb.py new file mode 100644 index 0000000..8f63862 --- /dev/null +++ b/Lib/test/test_whichdb.py @@ -0,0 +1,63 @@ +#! /usr/bin/env python +"""Test script for the whichdb module + based on test_anydbm.py +""" + +import os +import test.test_support +import unittest +import whichdb +import anydbm +import tempfile +import glob + +_fname = tempfile.mktemp() + +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 tearDown(self): + _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 + + def test_whichdb_name(self,name=name,mod=mod): + """Check whether whichdb correctly guesses module name + for databases opened with module mod. + """ + f = mod.open(_fname, 'c') + f["1"] = "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() + +if __name__ == "__main__": + test_main() + |