# Path: numcodecs/tests/common.py
# def check_encode_decode_array(arr, codec):
# 
#     enc = codec.encode(arr)
#     dec = codec.decode(enc)
#     assert_array_items_equal(arr, dec)
# 
#     out = np.empty_like(arr)
#     codec.decode(enc, out=out)
#     assert_array_items_equal(arr, out)
# 
#     enc = codec.encode(arr)
#     dec = codec.decode(ensure_ndarray(enc))
#     assert_array_items_equal(arr, dec)
# 
# def check_config(codec):
#     config = codec.get_config()
#     # round-trip through JSON to check serialization
#     config = _json.loads(_json.dumps(config))
#     assert codec == get_codec(config)
# 
# def check_repr(stmt):
#     # check repr matches instantiation statement
#     codec = eval(stmt)
#     actual = repr(codec)
#     assert stmt == actual
# 
# def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, prefix=None):
# 
#     # setup directory to hold data fixture
#     if prefix:
#         fixture_dir = os.path.join('fixture', codec_id, prefix)
#     else:
#         fixture_dir = os.path.join('fixture', codec_id)
#     if not os.path.exists(fixture_dir):  # pragma: no cover
#         os.makedirs(fixture_dir)
# 
#     # save fixture data
#     for i, arr in enumerate(arrays):
#         arr_fn = os.path.join(fixture_dir, 'array.{:02d}.npy'.format(i))
#         if not os.path.exists(arr_fn):  # pragma: no cover
#             np.save(arr_fn, arr)
# 
#     # load fixture data
#     for arr_fn in glob(os.path.join(fixture_dir, 'array.*.npy')):
# 
#         # setup
#         i = int(arr_fn.split('.')[-2])
#         arr = np.load(arr_fn, allow_pickle=True)
#         arr_bytes = arr.tobytes(order='A')
#         if arr.flags.f_contiguous:
#             order = 'F'
#         else:
#             order = 'C'
# 
#         for j, codec in enumerate(codecs):
# 
#             if codec is None:
#                 pytest.skip("codec has been removed")
# 
#             # setup a directory to hold encoded data
#             codec_dir = os.path.join(fixture_dir, 'codec.{:02d}'.format(j))
#             if not os.path.exists(codec_dir):  # pragma: no cover
#                 os.makedirs(codec_dir)
# 
#             # file with codec configuration information
#             codec_fn = os.path.join(codec_dir, 'config.json')
#             # one time save config
#             if not os.path.exists(codec_fn):  # pragma: no cover
#                 with open(codec_fn, mode='w') as cf:
#                     _json.dump(codec.get_config(), cf, sort_keys=True, indent=4)
#             # load config and compare with expectation
#             with open(codec_fn, mode='r') as cf:
#                 config = _json.load(cf)
#                 assert codec == get_codec(config)
# 
#             enc_fn = os.path.join(codec_dir, 'encoded.{:02d}.dat'.format(i))
# 
#             # one time encode and save array
#             if not os.path.exists(enc_fn):  # pragma: no cover
#                 enc = codec.encode(arr)
#                 enc = ensure_bytes(enc)
#                 with open(enc_fn, mode='wb') as ef:
#                     ef.write(enc)
# 
#             # load and decode data
#             with open(enc_fn, mode='rb') as ef:
#                 enc = ef.read()
#                 dec = codec.decode(enc)
#                 dec_arr = ensure_ndarray(dec).reshape(-1, order='A')
#                 dec_arr = dec_arr.view(dtype=arr.dtype).reshape(arr.shape, order=order)
#                 if precision and precision[j] is not None:
#                     assert_array_almost_equal(arr, dec_arr, decimal=precision[j])
#                 elif arr.dtype == 'object':
#                     assert_array_items_equal(arr, dec_arr)
#                 else:
#                     assert_array_equal(arr, dec_arr)
#                     assert arr_bytes == ensure_bytes(dec)
# 
# def check_err_decode_object_buffer(compressor):
#     # cannot decode directly into object array, leads to segfaults
#     a = np.arange(10)
#     enc = compressor.encode(a)
#     out = np.empty(10, dtype=object)
#     with pytest.raises(TypeError):
#         compressor.decode(enc, out=out)
# 
# def check_err_encode_object_buffer(compressor):
#     # compressors cannot encode object array
#     a = np.array(['foo', 'bar', 'baz'], dtype=object)
#     with pytest.raises(TypeError):
#         compressor.encode(a)


import pytest
import numpy as np
    from numcodecs.zfpy import ZFPY, _zfpy
from numcodecs.tests.common import (
    check_encode_decode_array,
    check_config,
    check_repr,
    check_backwards_compatibility,
    check_err_decode_object_buffer,
    check_err_encode_object_buffer,
)
        10, 10, 10
    ),
]


def test_encode_decode():
    for arr in arrays:
        if arr.dtype == np.int32 or arr.dtype == np.int64:
            codec = [codecs[-1]]
        else:
            codec = codecs
        for code in codec:
            check_encode_decode_array(arr, code)


def test_config():
    for codec in codecs:
        check_config(codec)


def test_repr():
    check_repr("ZFPY(mode=4, tolerance=0.001, rate=-1, precision=-1)")


def test_backwards_compatibility():
    for code in codecs:
        if code.mode == _zfpy.mode_fixed_rate:
            codec = [code]
            check_backwards_compatibility(ZFPY.codec_id, arrays, codec)
        else:

# Path: numcodecs/tests/common.py
# def check_encode_decode_array(arr, codec):
# 
#     enc = codec.encode(arr)
#     dec = codec.decode(enc)
#     assert_array_items_equal(arr, dec)
# 
#     out = np.empty_like(arr)
#     codec.decode(enc, out=out)
#     assert_array_items_equal(arr, out)
# 
#     enc = codec.encode(arr)
#     dec = codec.decode(ensure_ndarray(enc))
#     assert_array_items_equal(arr, dec)
# 
# def check_config(codec):
#     config = codec.get_config()
#     # round-trip through JSON to check serialization
#     config = _json.loads(_json.dumps(config))
#     assert codec == get_codec(config)
# 
# def check_repr(stmt):
#     # check repr matches instantiation statement
#     codec = eval(stmt)
#     actual = repr(codec)
#     assert stmt == actual
# 
# def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, prefix=None):
# 
#     # setup directory to hold data fixture
#     if prefix:
#         fixture_dir = os.path.join('fixture', codec_id, prefix)
#     else:
#         fixture_dir = os.path.join('fixture', codec_id)
#     if not os.path.exists(fixture_dir):  # pragma: no cover
#         os.makedirs(fixture_dir)
# 
#     # save fixture data
#     for i, arr in enumerate(arrays):
#         arr_fn = os.path.join(fixture_dir, 'array.{:02d}.npy'.format(i))
#         if not os.path.exists(arr_fn):  # pragma: no cover
#             np.save(arr_fn, arr)
# 
#     # load fixture data
#     for arr_fn in glob(os.path.join(fixture_dir, 'array.*.npy')):
# 
#         # setup
#         i = int(arr_fn.split('.')[-2])
#         arr = np.load(arr_fn, allow_pickle=True)
#         arr_bytes = arr.tobytes(order='A')
#         if arr.flags.f_contiguous:
#             order = 'F'
#         else:
#             order = 'C'
# 
#         for j, codec in enumerate(codecs):
# 
#             if codec is None:
#                 pytest.skip("codec has been removed")
# 
#             # setup a directory to hold encoded data
#             codec_dir = os.path.join(fixture_dir, 'codec.{:02d}'.format(j))
#             if not os.path.exists(codec_dir):  # pragma: no cover
#                 os.makedirs(codec_dir)
# 
#             # file with codec configuration information
#             codec_fn = os.path.join(codec_dir, 'config.json')
#             # one time save config
#             if not os.path.exists(codec_fn):  # pragma: no cover
#                 with open(codec_fn, mode='w') as cf:
#                     _json.dump(codec.get_config(), cf, sort_keys=True, indent=4)
#             # load config and compare with expectation
#             with open(codec_fn, mode='r') as cf:
#                 config = _json.load(cf)
#                 assert codec == get_codec(config)
# 
#             enc_fn = os.path.join(codec_dir, 'encoded.{:02d}.dat'.format(i))
# 
#             # one time encode and save array
#             if not os.path.exists(enc_fn):  # pragma: no cover
#                 enc = codec.encode(arr)
#                 enc = ensure_bytes(enc)
#                 with open(enc_fn, mode='wb') as ef:
#                     ef.write(enc)
# 
#             # load and decode data
#             with open(enc_fn, mode='rb') as ef:
#                 enc = ef.read()
#                 dec = codec.decode(enc)
#                 dec_arr = ensure_ndarray(dec).reshape(-1, order='A')
#                 dec_arr = dec_arr.view(dtype=arr.dtype).reshape(arr.shape, order=order)
#                 if precision and precision[j] is not None:
#                     assert_array_almost_equal(arr, dec_arr, decimal=precision[j])
#                 elif arr.dtype == 'object':
#                     assert_array_items_equal(arr, dec_arr)
#                 else:
#                     assert_array_equal(arr, dec_arr)
#                     assert arr_bytes == ensure_bytes(dec)
# 
# def check_err_decode_object_buffer(compressor):
#     # cannot decode directly into object array, leads to segfaults
#     a = np.arange(10)
#     enc = compressor.encode(a)
#     out = np.empty(10, dtype=object)
#     with pytest.raises(TypeError):
#         compressor.decode(enc, out=out)
# 
# def check_err_encode_object_buffer(compressor):
#     # compressors cannot encode object array
#     a = np.array(['foo', 'bar', 'baz'], dtype=object)
#     with pytest.raises(TypeError):
#         compressor.encode(a)


# Path: numcodecs/tests/test_zfpy.py
import pytest
import numpy as np
    from numcodecs.zfpy import ZFPY, _zfpy
from numcodecs.tests.common import (
    check_encode_decode_array,
    check_config,
    check_repr,
    check_backwards_compatibility,
    check_err_decode_object_buffer,
    check_err_encode_object_buffer,
)

        10, 10, 10
    ),
]


def test_encode_decode():
    for arr in arrays:
        if arr.dtype == np.int32 or arr.dtype == np.int64:
            codec = [codecs[-1]]
        else:
            codec = codecs
        for code in codec:
            check_encode_decode_array(arr, code)


def test_config():
    for codec in codecs:
        check_config(codec)


def test_repr():
    check_repr("ZFPY(mode=4, tolerance=0.001, rate=-1, precision=-1)")


def test_backwards_compatibility():
    for code in codecs:
        if code.mode == _zfpy.mode_fixed_rate:
            codec = [code]
            check_backwards_compatibility(ZFPY.codec_id, arrays, codec)
        else:

            check_backwards_compatibility(