2 """Test script for the anydbm module
3 based on testdumbdbm.py
9 from test
import test_support
11 _fname
= test_support
.TESTFN
13 # Silence Py3k warning
14 anydbm
= test_support
.import_module('anydbm', deprecated
=True)
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 AnyDBMTestCase(unittest
.TestCase
):
35 def __init__(self
, *args
):
36 unittest
.TestCase
.__init
__(self
, *args
)
38 def test_anydbm_creation(self
):
39 f
= anydbm
.open(_fname
, 'c')
40 self
.assertEqual(f
.keys(), [])
41 for key
in self
._dict
:
42 f
[key
] = self
._dict
[key
]
46 def test_anydbm_modification(self
):
48 f
= anydbm
.open(_fname
, 'c')
49 self
._dict
['g'] = f
['g'] = "indented"
53 def test_anydbm_read(self
):
55 f
= anydbm
.open(_fname
, 'r')
59 def test_anydbm_keys(self
):
61 f
= anydbm
.open(_fname
, 'r')
62 keys
= self
.keys_helper(f
)
65 def read_helper(self
, f
):
66 keys
= self
.keys_helper(f
)
67 for key
in self
._dict
:
68 self
.assertEqual(self
._dict
[key
], f
[key
])
71 f
= anydbm
.open(_fname
, 'n')
76 def keys_helper(self
, f
):
79 dkeys
= self
._dict
.keys()
81 self
.assertEqual(keys
, dkeys
)
92 test_support
.run_unittest(AnyDBMTestCase
)
96 if __name__
== "__main__":