Added PersistentDictionary.flush.

This commit is contained in:
Jeremy Fincher 2003-10-24 09:57:54 +00:00
parent b9434a23a6
commit 7d960ca4c6
2 changed files with 15 additions and 1 deletions

View File

@ -368,3 +368,5 @@ class PersistentDictionary(dict):
fd = file(self.filename, 'w') fd = file(self.filename, 'w')
fd.write(repr(self)) fd.write(repr(self))
fd.close() fd.close()
flush = close

View File

@ -582,11 +582,23 @@ class PersistentDictionaryTestCase(unittest.TestCase):
d['foo'] = 'bar' d['foo'] = 'bar'
d[1] = 2 d[1] = 2
d.close() d.close()
d1 = PersistentDictionary('test.dict') d2 = PersistentDictionary('test.dict')
self.failUnless('foo' in d) self.failUnless('foo' in d)
self.assertEqual(d['foo'], 'bar') self.assertEqual(d['foo'], 'bar')
self.failUnless(1 in d) self.failUnless(1 in d)
self.assertEqual(d[1], 2) self.assertEqual(d[1], 2)
self.failUnless('foo' in d2)
self.assertEqual(d2['foo'], 'bar')
self.failUnless(1 in d2)
self.assertEqual(d2[1], 2)
def testFlush(self):
d = PersistentDictionary('test.dict')
d[1] = 2
d.flush()
d2 = PersistentDictionary('test.dict')
self.failUnless(1 in d2)
self.assertEqual(d2[1], 2)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: