summaryrefslogtreecommitdiff
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-12-28 11:54:53 +0000
committerGeorg Brandl <georg@python.org>2008-12-28 11:54:53 +0000
commit6425a2fa8f354e755f876f2dea708697e42cc9fd (patch)
tree45f306eac9c148cc56fe9aeef40fbbabc2a25067 /Lib/test/test_bytes.py
parente7d1e7e5d43e369db602bab35a6d5a47b6e5569e (diff)
downloadcpython-git-6425a2fa8f354e755f876f2dea708697e42cc9fd.tar.gz
Backport r67974:
#4759: allow None as first argument of bytearray.translate(), for consistency with bytes.translate(). Also fix segfault for bytearray.translate(x, None) -- will backport this part to 3.0 and 2.6.
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 36defb8a84..8ac8898394 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -872,11 +872,21 @@ class AssortedBytesTest(unittest.TestCase):
def test_translate(self):
b = b'hello'
+ ba = bytearray(b)
rosetta = bytearray(range(0, 256))
rosetta[ord('o')] = ord('e')
c = b.translate(rosetta, b'l')
self.assertEqual(b, b'hello')
self.assertEqual(c, b'hee')
+ c = ba.translate(rosetta, b'l')
+ self.assertEqual(ba, b'hello')
+ self.assertEqual(c, b'hee')
+ c = b.translate(None, b'e')
+ self.assertEqual(c, b'hllo')
+ c = ba.translate(None, b'e')
+ self.assertEqual(c, b'hllo')
+ self.assertRaises(TypeError, b.translate, None, None)
+ self.assertRaises(TypeError, ba.translate, None, None)
def test_split_bytearray(self):
self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b'])