Make gdbm and dumbdbm use byte strings. Updated their tests.
diff --git a/Lib/test/test_anydbm.py b/Lib/test/test_anydbm.py
index f980354..f5eae42 100644
--- a/Lib/test/test_anydbm.py
+++ b/Lib/test/test_anydbm.py
@@ -21,13 +21,13 @@
pass
class AnyDBMTestCase(unittest.TestCase):
- _dict = {'0': '',
- 'a': 'Python:',
- 'b': 'Programming',
- 'c': 'the',
- 'd': 'way',
- 'f': 'Guido',
- 'g': 'intended'
+ _dict = {'0': b'',
+ 'a': b'Python:',
+ 'b': b'Programming',
+ 'c': b'the',
+ 'd': b'way',
+ 'f': b'Guido',
+ 'g': b'intended',
}
def __init__(self, *args):
@@ -44,7 +44,7 @@
def test_anydbm_modification(self):
self.init_db()
f = anydbm.open(_fname, 'c')
- self._dict['g'] = f['g'] = "indented"
+ self._dict['g'] = f['g'] = b"indented"
self.read_helper(f)
f.close()
diff --git a/Lib/test/test_dumbdbm.py b/Lib/test/test_dumbdbm.py
index ba94d98..c7d29ec 100644
--- a/Lib/test/test_dumbdbm.py
+++ b/Lib/test/test_dumbdbm.py
@@ -3,6 +3,7 @@
Original by Roger E. Masse
"""
+import io
import os
import unittest
import dumbdbm
@@ -18,13 +19,13 @@
pass
class DumbDBMTestCase(unittest.TestCase):
- _dict = {'0': '',
- 'a': 'Python:',
- 'b': 'Programming',
- 'c': 'the',
- 'd': 'way',
- 'f': 'Guido',
- 'g': 'intended'
+ _dict = {'0': b'',
+ 'a': b'Python:',
+ 'b': b'Programming',
+ 'c': b'the',
+ 'd': b'way',
+ 'f': b'Guido',
+ 'g': b'intended',
}
def __init__(self, *args):
@@ -64,15 +65,15 @@
def test_close_twice(self):
f = dumbdbm.open(_fname)
- f['a'] = 'b'
- self.assertEqual(f['a'], 'b')
+ f['a'] = b'b'
+ self.assertEqual(f['a'], b'b')
f.close()
f.close()
def test_dumbdbm_modification(self):
self.init_db()
f = dumbdbm.open(_fname, 'w')
- self._dict['g'] = f['g'] = "indented"
+ self._dict['g'] = f['g'] = b"indented"
self.read_helper(f)
f.close()
@@ -91,29 +92,29 @@
def test_write_write_read(self):
# test for bug #482460
f = dumbdbm.open(_fname)
- f['1'] = 'hello'
- f['1'] = 'hello2'
+ f['1'] = b'hello'
+ f['1'] = b'hello2'
f.close()
f = dumbdbm.open(_fname)
- self.assertEqual(f['1'], 'hello2')
+ self.assertEqual(f['1'], b'hello2')
f.close()
def test_line_endings(self):
# test for bug #1172763: dumbdbm would die if the line endings
# weren't what was expected.
f = dumbdbm.open(_fname)
- f['1'] = 'hello'
- f['2'] = 'hello2'
+ f['1'] = b'hello'
+ f['2'] = b'hello2'
f.close()
# Mangle the file by adding \r before each newline
- data = open(_fname + '.dir').read()
- data = data.replace('\n', '\r\n')
- open(_fname + '.dir', 'wb').write(data)
+ data = io.open(_fname + '.dir', 'rb').read()
+ data = data.replace(b'\n', b'\r\n')
+ io.open(_fname + '.dir', 'wb').write(data)
f = dumbdbm.open(_fname)
- self.assertEqual(f['1'], 'hello')
- self.assertEqual(f['2'], 'hello2')
+ self.assertEqual(f['1'], b'hello')
+ self.assertEqual(f['2'], b'hello2')
def read_helper(self, f):
@@ -147,7 +148,7 @@
del d[k]
del f[k]
else:
- v = random.choice('abc') * random.randrange(10000)
+ v = random.choice((b'a', b'b', b'c')) * random.randrange(10000)
d[k] = v
f[k] = v
self.assertEqual(f[k], v)
diff --git a/Lib/test/test_gdbm.py b/Lib/test/test_gdbm.py
index ae76e39..4daca61 100755
--- a/Lib/test/test_gdbm.py
+++ b/Lib/test/test_gdbm.py
@@ -12,7 +12,7 @@
g = gdbm.open(filename, 'c')
verify(g.keys() == [])
g['a'] = 'b'
-g['12345678910'] = '019237410982340912840198242'
+g['12345678910'] = b'019237410982340912840198242'
a = g.keys()
if verbose:
print('Test gdbm file keys: ', a)
diff --git a/Lib/test/test_whichdb.py b/Lib/test/test_whichdb.py
index f2652c1..6cb5e4f 100644
--- a/Lib/test/test_whichdb.py
+++ b/Lib/test/test_whichdb.py
@@ -51,7 +51,7 @@
self.assertEqual(name, whichdb.whichdb(_fname))
# Now add a key
f = mod.open(_fname, 'w')
- f["1"] = "1"
+ f["1"] = b"1"
f.close()
self.assertEqual(name, whichdb.whichdb(_fname))
setattr(WhichDBTestCase,"test_whichdb_%s" % name, test_whichdb_name)