2 """Test script for the whichdb module
3 based on test_anydbm.py
7 import test
.test_support
14 _fname
= test
.test_support
.TESTFN
17 # we don't know the precise name the underlying database uses
18 # so we use glob to locate all names
19 for f
in glob
.glob(_fname
+ "*"):
25 class WhichDBTestCase(unittest
.TestCase
):
26 # Actual test methods are added to namespace
27 # after class definition.
28 def __init__(self
, *args
):
29 unittest
.TestCase
.__init
__(self
, *args
)
37 for name
in anydbm
._names
:
38 # we define a new test method for each
39 # candidate database module.
41 mod
= __import__(name
)
45 def test_whichdb_name(self
, name
=name
, mod
=mod
):
46 # Check whether whichdb correctly guesses module name
47 # for databases opened with module mod.
48 f
= mod
.open(_fname
, 'c')
51 self
.assertEqual(name
, whichdb
.whichdb(_fname
))
52 setattr(WhichDBTestCase
,"test_whichdb_%s" % name
, test_whichdb_name
)
56 test
.test_support
.run_unittest(WhichDBTestCase
)
60 if __name__
== "__main__":