Skip to content

Commit 4b3a581

Browse files
committed
Add tests for issue #171. The first part seems to be passing.
1 parent 4ee470a commit 4b3a581

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

tests/test_future/test_bytes.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def test_bytes_encoding_arg(self):
2929
b = bytes(u, encoding='utf-8')
3030
self.assertEqual(b, u.encode('utf-8'))
3131

32+
nu = str(u)
33+
b = bytes(nu, encoding='utf-8')
34+
self.assertEqual(b, u.encode('utf-8'))
35+
3236
def test_bytes_encoding_arg_issue_193(self):
3337
"""
3438
This used to be True: bytes(str(u'abc'), 'utf8') == b"b'abc'"
@@ -47,6 +51,10 @@ def test_bytes_encoding_arg_non_kwarg(self):
4751
b = bytes(u, 'utf-8')
4852
self.assertEqual(b, u.encode('utf-8'))
4953

54+
nu = str(u)
55+
b = bytes(nu, 'utf-8')
56+
self.assertEqual(b, u.encode('utf-8'))
57+
5058
def test_bytes_string_no_encoding(self):
5159
with self.assertRaises(TypeError):
5260
bytes(u'ABC')
@@ -300,7 +308,7 @@ def test_endswith(self):
300308
exc = str(cm.exception)
301309
# self.assertIn('bytes', exc)
302310
# self.assertIn('tuple', exc)
303-
311+
304312
def test_decode(self):
305313
b = bytes(b'abcd')
306314
s = b.decode('utf-8')
@@ -367,7 +375,7 @@ def test_hash(self):
367375
d[s] = s
368376
self.assertEqual(len(d), 2)
369377
self.assertEqual(set(d.keys()), set([s, b]))
370-
378+
371379
@unittest.expectedFailure
372380
def test_hash_with_native_types(self):
373381
# Warning: initializing the dict with native Py2 types throws the
@@ -488,7 +496,7 @@ def test_bytes_within_range(self):
488496
ValueError
489497
...
490498
ValueError: bytes must be in range(0, 256)
491-
499+
492500
Ensure our bytes() constructor has the same behaviour
493501
"""
494502
b1 = bytes([254, 255])
@@ -684,6 +692,23 @@ def test_surrogateescape_decoding(self):
684692
self.assertTrue(isinstance(decoded, str))
685693
self.assertEqual(b, decoded.encode('utf-8', 'surrogateescape'))
686694

695+
def test_issue_171_part_a(self):
696+
b1 = str(u'abc \u0123 do re mi').encode(u'utf_8')
697+
b2 = bytes(u'abc \u0123 do re mi', u'utf_8')
698+
b3 = bytes(str(u'abc \u0123 do re mi'), u'utf_8')
699+
700+
@expectedFailurePY2
701+
def test_issue_171_part_b(self):
702+
"""
703+
Tests whether:
704+
>>> nativebytes = bytes ; nativestr = str ; from builtins import *
705+
>>> nativebytes(bytes(b'asdf'))[0] == b'a' == b'asdf'
706+
"""
707+
nativebytes = type(b'')
708+
nativestr = type('')
709+
b = nativebytes(bytes(b'asdf'))
710+
self.assertEqual(b, b'asdf')
711+
687712

688713
if __name__ == '__main__':
689714
unittest.main()

0 commit comments

Comments
 (0)