File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -464,6 +464,14 @@ def test_bytes_within_range(self):
464
464
with self .assertRaises (ValueError ):
465
465
b2 = bytes ([254 , 255 , 256 ])
466
466
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
+
467
475
468
476
if __name__ == '__main__' :
469
477
unittest .main ()
Original file line number Diff line number Diff line change @@ -78,6 +78,19 @@ def test_str_is_str(self):
78
78
def test_str_fromhex (self ):
79
79
self .assertFalse (hasattr (str , 'fromhex' ))
80
80
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
+
81
94
def test_isinstance_str (self ):
82
95
self .assertTrue (isinstance (str ('blah' ), str ))
83
96
You can’t perform that action at this time.
0 commit comments