2 """Test script for the whichdb module
3 based on test_anydbm.py
7 import test
.test_support
12 _fname
= test
.test_support
.TESTFN
14 # Silence Py3k warning
15 anydbm
= test
.test_support
.import_module('anydbm', deprecated
=True)
18 # we don't know the precise name the underlying database uses
19 # so we use glob to locate all names
20 for f
in glob
.glob(_fname
+ "*"):
26 class WhichDBTestCase(unittest
.TestCase
):
27 # Actual test methods are added to namespace
28 # after class definition.
29 def __init__(self
, *args
):
30 unittest
.TestCase
.__init
__(self
, *args
)
38 for name
in anydbm
._names
:
39 # we define a new test method for each
40 # candidate database module.
42 # Silence Py3k warning
43 mod
= test
.test_support
.import_module(name
, deprecated
=True)
44 except unittest
.SkipTest
:
47 def test_whichdb_name(self
, name
=name
, mod
=mod
):
48 # Check whether whichdb correctly guesses module name
49 # for databases opened with module mod.
50 # Try with empty files first
51 f
= mod
.open(_fname
, 'c')
53 self
.assertEqual(name
, whichdb
.whichdb(_fname
))
55 f
= mod
.open(_fname
, 'w')
58 self
.assertEqual(name
, whichdb
.whichdb(_fname
))
59 setattr(WhichDBTestCase
,"test_whichdb_%s" % name
, test_whichdb_name
)
63 test
.test_support
.run_unittest(WhichDBTestCase
)
67 if __name__
== "__main__":