2 """Test script for the anydbm module
3 based on testdumbdbm.py
10 from test
import test_support
12 _fname
= test_support
.TESTFN
15 # we don't know the precise name the underlying database uses
16 # so we use glob to locate all names
17 for f
in glob
.glob(_fname
+ "*"):
23 class AnyDBMTestCase(unittest
.TestCase
):
33 def __init__(self
, *args
):
34 unittest
.TestCase
.__init
__(self
, *args
)
36 def test_anydbm_creation(self
):
37 f
= anydbm
.open(_fname
, 'c')
38 self
.assertEqual(f
.keys(), [])
39 for key
in self
._dict
:
40 f
[key
] = self
._dict
[key
]
44 def test_anydbm_modification(self
):
46 f
= anydbm
.open(_fname
, 'c')
47 self
._dict
['g'] = f
['g'] = "indented"
51 def test_anydbm_read(self
):
53 f
= anydbm
.open(_fname
, 'r')
57 def test_anydbm_keys(self
):
59 f
= anydbm
.open(_fname
, 'r')
60 keys
= self
.keys_helper(f
)
63 def read_helper(self
, f
):
64 keys
= self
.keys_helper(f
)
65 for key
in self
._dict
:
66 self
.assertEqual(self
._dict
[key
], f
[key
])
69 f
= anydbm
.open(_fname
, 'n')
74 def keys_helper(self
, f
):
77 dkeys
= self
._dict
.keys()
79 self
.assertEqual(keys
, dkeys
)
90 test_support
.run_unittest(AnyDBMTestCase
)
94 if __name__
== "__main__":