Exemplo n.º 1
0
def test_formats_for_obj():
    arr = np.ndarray(3)

    fmt = FormatRegistry.for_obj(arr)[0]

    assert 'npz' in fmt.handled_extensions
    assert FormatRegistry.for_ext('npy')[0] is fmt

    expected_string_fmt_names = ['utf-8', 'unicode', 'json']
    found_string_fmt_names = list(f.name
                                  for f in FormatRegistry.for_obj('blah'))
    assert found_string_fmt_names == expected_string_fmt_names

    bytes_obj = fmt.serialize(arr)[0]
    assert np.array_equal(fmt.deserialize(bytes_obj, ), arr)
Exemplo n.º 2
0
def test_formats_for_ext():
    fmt = FormatRegistry.for_ext('json')[0]
    assert fmt.serialize({'blah': 'blah'})[0] == b'{"blah": "blah"}'
    assert fmt.deserialize(b'{"meow": "mix"}', ) == {'meow': 'mix'}