def test_dict(self): assert_equal_typed(to_str({ b'hello': b'world', 'abc': 'xyz' }), { 'hello': 'world', 'abc': 'xyz' })
def test_numpy_object(self): a = np.array([b'abc', 'def', (b'xyz', 'uvw')], dtype='O') b = np.array(['abc', 'def', ('xyz', 'uvw')], dtype='O') np.testing.assert_array_equal(to_str(a), b)
def test_numpy_str(self): a = np.array([[b'abc', b'def'], [b'ghi', b'jk']]) b = np.array([['abc', 'def'], ['ghi', 'jk']]) c = np.array([['abc', 'def'], ['ghi', 'jk']]) np.testing.assert_array_equal(to_str(a), c) np.testing.assert_array_equal(to_str(b), c)
def test_custom_dict(self): assert_equal_typed( to_str(OrderedDict([(b'hello', b'world'), ('abc', 'xyz')])), OrderedDict([('hello', 'world'), ('abc', 'xyz')]))
def test_tuple(self): assert_equal_typed(to_str((b'hello', 'world')), ('hello', 'world'))
def test_list(self): assert_equal_typed(to_str([b'hello', 'world']), ['hello', 'world'])
def test_non_ascii(self): assert_equal_typed(to_str(b'caf\xc3\xa9'), 'café') assert_equal_typed(to_str('café'), 'café')
def test_simple_str(self): assert_equal_typed(to_str(b'hello'), 'hello') assert_equal_typed(to_str('hello'), 'hello')
def test_non_str(self): assert_equal_typed(to_str(3), 3) assert_equal_typed(to_str(None), None)