"""Test script for the whichdb module
_fname
= test
.test_support
.TESTFN
# 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
+ "*"):
class WhichDBTestCase(unittest
.TestCase
):
# Actual test methods are added to namespace
# after class definition.
def __init__(self
, *args
):
unittest
.TestCase
.__init
__(self
, *args
)
for name
in anydbm
._names
:
# we define a new test method for each
# candidate database module.
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')
self
.assertEqual(name
, whichdb
.whichdb(_fname
))
f
= mod
.open(_fname
, 'w')
self
.assertEqual(name
, whichdb
.whichdb(_fname
))
setattr(WhichDBTestCase
,"test_whichdb_%s" % name
, test_whichdb_name
)
test
.test_support
.run_unittest(WhichDBTestCase
)
if __name__
== "__main__":