2020
2121from numcodecs .tests .common import (check_config , check_repr , check_encode_decode_array ,
2222 check_backwards_compatibility , greetings )
23- from numcodecs .compat import text_type , binary_type
23+ from numcodecs .compat import text_type , binary_type , PY2
2424
2525
2626# object array with strings
3737 np .array (greetings * 100 ),
3838 np .array (greetings * 100 , dtype = object ),
3939 np .array ([b'foo' , b'bar' , b'baz' ] * 300 , dtype = object ),
40- np .array ([g .encode () for g in greetings ] * 100 , dtype = object ),
40+ np .array ([g .encode ('utf-8' ) for g in greetings ] * 100 , dtype = object ),
4141]
4242
4343
@@ -139,7 +139,6 @@ def test_bytes():
139139 codec = MsgPack ()
140140 # works for bytes array, round-trips bytes to bytes
141141 b = codec .decode (codec .encode (bytes_arr ))
142- print (type (b ), b )
143142 assert np .array_equal (bytes_arr , b )
144143 assert isinstance (b [0 ], binary_type )
145144 assert b [0 ] == b'foo'
@@ -158,7 +157,11 @@ def test_bytes():
158157 assert b [0 ] == b'foo'
159158 # broken for unicode array, round-trips unicode to bytes
160159 b = codec .decode (codec .encode (unicode_arr ))
161- assert not np .array_equal (unicode_arr , b )
160+ if PY2 :
161+ # PY2 considers b'foo' and u'foo' to be equal
162+ assert np .array_equal (unicode_arr , b )
163+ else :
164+ assert not np .array_equal (unicode_arr , b )
162165 assert isinstance (b [0 ], binary_type )
163166 assert b [0 ] == b'foo'
164167
@@ -168,7 +171,11 @@ def test_bytes():
168171 warnings .simplefilter ('ignore' , PendingDeprecationWarning )
169172 # broken for bytes array, round-trips bytes to unicode
170173 b = codec .decode (codec .encode (bytes_arr ))
171- assert not np .array_equal (bytes_arr , b )
174+ if PY2 :
175+ # PY2 considers b'foo' and u'foo' to be equal
176+ assert np .array_equal (unicode_arr , b )
177+ else :
178+ assert not np .array_equal (bytes_arr , b )
172179 assert isinstance (b [0 ], text_type )
173180 assert b [0 ] == u'foo'
174181 # works for unicode array, round-trips unicode to unicode
0 commit comments