8000 Add (failing) tests: are hasattr(newstr(), 'decode') and hasattr(newb… · TrendingTechnology/python-future@980bf5d · GitHub
[go: up one dir, main page]

Skip to content

Commit 980bf5d

Browse files
committed
Add (failing) tests: are hasattr(newstr(), 'decode') and hasattr(newbytes(), 'encode') False like on Py3?
1 parent 51b47e9 commit 980bf5d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

future/tests/test_bytes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,14 @@ def test_bytes_within_range(self):
464464
with self.assertRaises(ValueError):
465465
b2 = bytes([254, 255, 256])
466466

467+
def test_bytes_hasattr_encode(self):
468+
"""
469+
This test tests whether hasattr(b, 'encode') is False, like it is on Py3.
470+
"""
471+
b = bytes(b'abcd')
472+
self.assertFalse(hasattr(b, 'encode'))
473+
self.assertTrue(hasattr(b, 'decode'))
474+
467475

468476
if __name__ == '__main__':
469477
unittest.main()

future/tests/test_str.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ def test_str_is_str(self):
7878
def test_str_fromhex(self):
7979
self.assertFalse(hasattr(str, 'fromhex'))
8080

81+
def test_str_hasattr_decode(self):
82+
"""
83+
This test tests whether hasattr(s, 'decode') is False, like it is on Py3.
84+
85+
Sometimes code (such as http.client in Py3.3) checks hasattr(mystring,
86+
'decode') to determine if a string-like thing needs encoding. It would
87+
be nice to have this return False so the string can be treated on Py2
88+
like a Py3 string.
89+
"""
90+
s = str(u'abcd')
91+
self.assertFalse(hasattr(s, 'decode'))
92+
self.assertTrue(hasattr(s, 'encode'))
93+
8194
def test_isinstance_str(self):
8295
self.assertTrue(isinstance(str('blah'), str))
8396

0 commit comments

Comments
 (0)
0