diff options
author | Raymond Hettinger <python@rcn.com> | 2003-03-09 07:05:43 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-03-09 07:05:43 (GMT) |
commit | 2c2d322884ee72077a256ec3cd0aa9ce3580eedc (patch) | |
tree | d64fac31dcecd48ed44aceb9d5fb6d8dc415e95f /Lib/test/test_shelve.py | |
parent | 42182ebaf6387371c238d2a3484e7f1e085c9d1c (diff) | |
download | cpython-2c2d322884ee72077a256ec3cd0aa9ce3580eedc.zip cpython-2c2d322884ee72077a256ec3cd0aa9ce3580eedc.tar.gz cpython-2c2d322884ee72077a256ec3cd0aa9ce3580eedc.tar.bz2 |
SF patch #667730: More DictMixin
* Adds missing pop() methods to weakref.py
* Expands test suite to broaden coverage of objects with
a mapping interface.
Contributed by Sebastien Keim.
Diffstat (limited to 'Lib/test/test_shelve.py')
-rw-r--r-- | Lib/test/test_shelve.py | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/Lib/test/test_shelve.py b/Lib/test/test_shelve.py index e69e311..e7c4b50 100644 --- a/Lib/test/test_shelve.py +++ b/Lib/test/test_shelve.py @@ -43,9 +43,54 @@ class TestCase(unittest.TestCase): self.assertEqual(len(d1), 1) self.assertNotEqual(d1, d2) -def test_main(): - test_support.run_unittest(TestCase) +from test_userdict import TestMappingProtocol +class TestShelveBase(TestMappingProtocol): + fn = "shelftemp.db" + counter = 0 + def __init__(self, *args, **kw): + self._db = [] + TestMappingProtocol.__init__(self, *args, **kw) + _tested_class = shelve.Shelf + def _reference(self): + return {"key1":"value1", "key2":2, "key3":(1,2,3)} + def _empty_mapping(self): + if self._in_mem: + x= shelve.Shelf({}, binary = self._binary) + else: + self.counter+=1 + x= shelve.open(self.fn+str(self.counter), binary=self._binary) + self._db.append(x) + return x + def tearDown(self): + for db in self._db: + db.close() + self._db = [] + if not self._in_mem: + for f in glob.glob(self.fn+"*"): + os.unlink(f) + +class TestAsciiFileShelve(TestShelveBase): + _binary = False + _in_mem = False +class TestBinaryFileShelve(TestShelveBase): + _binary = True + _in_mem = False +class TestAsciiMemShelve(TestShelveBase): + _binary = False + _in_mem = True +class TestBinaryMemShelve(TestShelveBase): + _binary = True + _in_mem = True + +def test_main(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestAsciiFileShelve)) + suite.addTest(unittest.makeSuite(TestBinaryFileShelve)) + suite.addTest(unittest.makeSuite(TestAsciiMemShelve)) + suite.addTest(unittest.makeSuite(TestBinaryMemShelve)) + suite.addTest(unittest.makeSuite(TestCase)) + test_support.run_suite(suite) if __name__ == "__main__": test_main() |