Fix dumbdbm and test_dumbdbm to work with dict views. Bug in dumbdbm was from

dict views not being iterators but just iterables.
This commit is contained in:
Brett Cannon 2007-02-22 05:04:32 +00:00
parent f0c82f9842
commit c1b22a07c3
2 changed files with 6 additions and 10 deletions

View File

@ -202,7 +202,7 @@ class _Database(UserDict.DictMixin):
return key in self._index
def iterkeys(self):
return self._index.keys()
return iter(self._index.keys())
__iter__ = iterkeys
def __len__(self):

View File

@ -32,7 +32,7 @@ class DumbDBMTestCase(unittest.TestCase):
def test_dumbdbm_creation(self):
f = dumbdbm.open(_fname, 'c')
self.assertEqual(f.keys(), [])
self.assertEqual(list(f.keys()), [])
for key in self._dict:
f[key] = self._dict[key]
self.read_helper(f)
@ -128,10 +128,8 @@ class DumbDBMTestCase(unittest.TestCase):
f.close()
def keys_helper(self, f):
keys = f.keys()
keys.sort()
dkeys = self._dict.keys()
dkeys.sort()
keys = sorted(f.keys())
dkeys = sorted(self._dict.keys())
self.assertEqual(keys, dkeys)
return keys
@ -156,10 +154,8 @@ class DumbDBMTestCase(unittest.TestCase):
f.close()
f = dumbdbm.open(_fname)
expected = d.items()
expected.sort()
got = f.items()
got.sort()
expected = sorted(d.items())
got = sorted(f.items())
self.assertEqual(expected, got)
f.close()