summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-20 16:46:19 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-20 16:46:19 +0200
commit74a49ac3f5ac3c7a09c691db4888c981a0cb3232 (patch)
treefda01f4cbce74bb51529a4d05d0b954988607932 /Lib/test
parentd83b7c2df4439b678bf7e372f8c9bbaff2907689 (diff)
downloadcpython-git-74a49ac3f5ac3c7a09c691db4888c981a0cb3232.tar.gz
Issue #23681: Fixed Python 2 to 3 poring bugs.
Indexing bytes retiurns an integer, not bytes.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_buffer.py8
-rw-r--r--Lib/test/test_tokenize.py7
2 files changed, 8 insertions, 7 deletions
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py
index e84f3e4e26..aa153779ae 100644
--- a/Lib/test/test_buffer.py
+++ b/Lib/test/test_buffer.py
@@ -149,15 +149,15 @@ def randrange_fmt(mode, char, obj):
format character."""
x = randrange(*fmtdict[mode][char])
if char == 'c':
- x = bytes(chr(x), 'latin1')
+ x = bytes([x])
+ if obj == 'numpy' and x == b'\x00':
+ # http://projects.scipy.org/numpy/ticket/1925
+ x = b'\x01'
if char == '?':
x = bool(x)
if char == 'f' or char == 'd':
x = struct.pack(char, x)
x = struct.unpack(char, x)[0]
- if obj == 'numpy' and x == b'\x00':
- # http://projects.scipy.org/numpy/ticket/1925
- x = b'\x01'
return x
def gen_item(fmt, obj):
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
index 38611a79ee..4a8be3be5a 100644
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -1066,7 +1066,7 @@ class TestTokenize(TestCase):
encoding = object()
encoding_used = None
def mock_detect_encoding(readline):
- return encoding, ['first', 'second']
+ return encoding, [b'first', b'second']
def mock__tokenize(readline, encoding):
nonlocal encoding_used
@@ -1085,7 +1085,7 @@ class TestTokenize(TestCase):
counter += 1
if counter == 5:
return b''
- return counter
+ return str(counter).encode()
orig_detect_encoding = tokenize_module.detect_encoding
orig__tokenize = tokenize_module._tokenize
@@ -1093,7 +1093,8 @@ class TestTokenize(TestCase):
tokenize_module._tokenize = mock__tokenize
try:
results = tokenize(mock_readline)
- self.assertEqual(list(results), ['first', 'second', 1, 2, 3, 4])
+ self.assertEqual(list(results),
+ [b'first', b'second', b'1', b'2', b'3', b'4'])
finally:
tokenize_module.detect_encoding = orig_detect_encoding
tokenize_module._tokenize = orig__tokenize