Example #1
0
 def test_dict(self):
     assert_equal_typed(to_str({
         b'hello': b'world',
         'abc': 'xyz'
     }), {
         'hello': 'world',
         'abc': 'xyz'
     })
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 def test_custom_dict(self):
     assert_equal_typed(
         to_str(OrderedDict([(b'hello', b'world'), ('abc', 'xyz')])),
         OrderedDict([('hello', 'world'), ('abc', 'xyz')]))
Example #5
0
 def test_tuple(self):
     assert_equal_typed(to_str((b'hello', 'world')), ('hello', 'world'))
Example #6
0
 def test_list(self):
     assert_equal_typed(to_str([b'hello', 'world']), ['hello', 'world'])
Example #7
0
 def test_non_ascii(self):
     assert_equal_typed(to_str(b'caf\xc3\xa9'), 'café')
     assert_equal_typed(to_str('café'), 'café')
Example #8
0
 def test_simple_str(self):
     assert_equal_typed(to_str(b'hello'), 'hello')
     assert_equal_typed(to_str('hello'), 'hello')
Example #9
0
 def test_non_str(self):
     assert_equal_typed(to_str(3), 3)
     assert_equal_typed(to_str(None), None)