mirror of https://github.com/python/cpython
Fix test case by converting dbm keys to bytes.
This commit is contained in:
parent
f9b95d4dda
commit
ca8dd9182e
|
@ -21,13 +21,13 @@ def _delete_files():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class AnyDBMTestCase(unittest.TestCase):
|
class AnyDBMTestCase(unittest.TestCase):
|
||||||
_dict = {str8('0'): b'',
|
_dict = {'0': b'',
|
||||||
str8('a'): b'Python:',
|
'a': b'Python:',
|
||||||
str8('b'): b'Programming',
|
'b': b'Programming',
|
||||||
str8('c'): b'the',
|
'c': b'the',
|
||||||
str8('d'): b'way',
|
'd': b'way',
|
||||||
str8('f'): b'Guido',
|
'f': b'Guido',
|
||||||
str8('g'): b'intended',
|
'g': b'intended',
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
|
@ -37,14 +37,14 @@ class AnyDBMTestCase(unittest.TestCase):
|
||||||
f = anydbm.open(_fname, 'c')
|
f = anydbm.open(_fname, 'c')
|
||||||
self.assertEqual(list(f.keys()), [])
|
self.assertEqual(list(f.keys()), [])
|
||||||
for key in self._dict:
|
for key in self._dict:
|
||||||
f[key] = self._dict[key]
|
f[key.encode("ascii")] = self._dict[key]
|
||||||
self.read_helper(f)
|
self.read_helper(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def test_anydbm_modification(self):
|
def test_anydbm_modification(self):
|
||||||
self.init_db()
|
self.init_db()
|
||||||
f = anydbm.open(_fname, 'c')
|
f = anydbm.open(_fname, 'c')
|
||||||
self._dict[str8('g')] = f[str8('g')] = b"indented"
|
self._dict['g'] = f[b'g'] = b"indented"
|
||||||
self.read_helper(f)
|
self.read_helper(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
@ -63,16 +63,16 @@ class AnyDBMTestCase(unittest.TestCase):
|
||||||
def read_helper(self, f):
|
def read_helper(self, f):
|
||||||
keys = self.keys_helper(f)
|
keys = self.keys_helper(f)
|
||||||
for key in self._dict:
|
for key in self._dict:
|
||||||
self.assertEqual(self._dict[key], f[key])
|
self.assertEqual(self._dict[key], f[key.encode("ascii")])
|
||||||
|
|
||||||
def init_db(self):
|
def init_db(self):
|
||||||
f = anydbm.open(_fname, 'n')
|
f = anydbm.open(_fname, 'n')
|
||||||
for k in self._dict:
|
for k in self._dict:
|
||||||
f[k] = self._dict[k]
|
f[k.encode("ascii")] = self._dict[k]
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def keys_helper(self, f):
|
def keys_helper(self, f):
|
||||||
keys = sorted(f.keys())
|
keys = sorted(k.decode("ascii") for k in f.keys())
|
||||||
dkeys = sorted(self._dict.keys())
|
dkeys = sorted(self._dict.keys())
|
||||||
self.assertEqual(keys, dkeys)
|
self.assertEqual(keys, dkeys)
|
||||||
return keys
|
return keys
|
||||||
|
|
Loading…
Reference in New Issue