# Path: ifcb/data/io.py
# def open_raw(*files):
#     """
#     Open raw IFCB data.
# 
#     Takes one or more raw data filenames (only one is required)
#     which should all be in the same directory and differ
#     only by extension.
# 
#     Typically, just pass the pathname of the ADC file.
#     """
#     from .files import Fileset, FilesetBin
#     basepath = os.path.commonprefix(files)
#     basepath, _ = os.path.splitext(basepath)
#     fs = Fileset(basepath)
#     return FilesetBin(fs)
# 
# def open_hdf(hdf_path, group=None):
#     """
#     Open IFCB data from an HDF file.
#     """
#     from .hdf import HdfBin
#     return HdfBin(hdf_path, group=group)
# 
# def open_zip(zip_path):
#     from .zip import ZipBin
#     return ZipBin(zip_path)
# 
# def open_mat(mat_path):
#     from .matlab import MatBin
#     return MatBin(mat_path)
# 
# Path: ifcb/tests/utils.py
# def withfile(method):
#     """decorator that adds a named temporary file argument"""
#     @wraps(method)
#     def wrapper(*args, **kw):
#         with test_file() as f:
#             args = args + (f,)
#             return method(*args, **kw)
#     return wrapper
# 
# Path: ifcb/tests/data/fileset_info.py
# def list_test_bins():
#     return list(_dd())
# 
# Path: ifcb/tests/data/bins.py
# def assert_bin_equals(in_bin, out_bin):
#     # test keys
#     assert set(in_bin) == set(out_bin)
#     for k in in_bin.keys():
#         assert k in in_bin, 'inconsistent dict behavior'
#         assert k in out_bin, 'key membership does not match'
#     assert 0 not in in_bin, 'zero-based index'
#     assert 0 not in out_bin, 'zero-based index'
#     # test ADC data
#     for k in in_bin.keys():
#         for a, b in zip(in_bin[k], out_bin[k]):
#             assert np.isclose(a, b, equal_nan=True)
#     # pid
#     assert in_bin.pid == out_bin.pid, 'pid mismatch'
#     assert in_bin.lid == out_bin.lid, 'lid mismatch'
#     # timestamp
#     assert in_bin.timestamp == out_bin.timestamp, 'timestamp mismatch'
#     # schema
#     assert in_bin.schema == out_bin.schema, 'schema mismatch'
#     # headers
#     assert set(in_bin.headers) == set(out_bin.headers), 'header keys mismatch'
#     for k in in_bin.headers.keys():
#         # headers should all have same names and values
#         assert in_bin.headers[k] == out_bin.headers[k], 'header values mismatch'
#     # images
#     assert set(in_bin.images) == set(out_bin.images), 'image target numbers mismatch'
#     for k in in_bin.images:
#         assert np.all(in_bin.images[k] == out_bin.images[k]), 'image data mismatch'


import unittest
from ifcb.data.io import open_raw, open_hdf, open_zip, open_mat
from ifcb.tests.utils import withfile
from .fileset_info import list_test_bins
from .bins import assert_bin_equals




class TestFormatConversionAPI(unittest.TestCase):
    @withfile
    def test_hdf_roundtrip(self, path):
        for out_bin in list_test_bins():
            with out_bin:
                out_bin.to_hdf(path)
                with open_hdf(path) as in_bin:
                    assert_bin_equals(in_bin, out_bin)
    @withfile
    def test_zip_roundtrip(self, path):
        for out_bin in list_test_bins():
            with out_bin:
                out_bin.to_zip(path)
                with open_zip(path) as in_bin:
                    assert_bin_equals(in_bin, out_bin)

# Path: ifcb/data/io.py
# def open_raw(*files):
#     """
#     Open raw IFCB data.
# 
#     Takes one or more raw data filenames (only one is required)
#     which should all be in the same directory and differ
#     only by extension.
# 
#     Typically, just pass the pathname of the ADC file.
#     """
#     from .files import Fileset, FilesetBin
#     basepath = os.path.commonprefix(files)
#     basepath, _ = os.path.splitext(basepath)
#     fs = Fileset(basepath)
#     return FilesetBin(fs)
# 
# def open_hdf(hdf_path, group=None):
#     """
#     Open IFCB data from an HDF file.
#     """
#     from .hdf import HdfBin
#     return HdfBin(hdf_path, group=group)
# 
# def open_zip(zip_path):
#     from .zip import ZipBin
#     return ZipBin(zip_path)
# 
# def open_mat(mat_path):
#     from .matlab import MatBin
#     return MatBin(mat_path)
# 
# Path: ifcb/tests/utils.py
# def withfile(method):
#     """decorator that adds a named temporary file argument"""
#     @wraps(method)
#     def wrapper(*args, **kw):
#         with test_file() as f:
#             args = args + (f,)
#             return method(*args, **kw)
#     return wrapper
# 
# Path: ifcb/tests/data/fileset_info.py
# def list_test_bins():
#     return list(_dd())
# 
# Path: ifcb/tests/data/bins.py
# def assert_bin_equals(in_bin, out_bin):
#     # test keys
#     assert set(in_bin) == set(out_bin)
#     for k in in_bin.keys():
#         assert k in in_bin, 'inconsistent dict behavior'
#         assert k in out_bin, 'key membership does not match'
#     assert 0 not in in_bin, 'zero-based index'
#     assert 0 not in out_bin, 'zero-based index'
#     # test ADC data
#     for k in in_bin.keys():
#         for a, b in zip(in_bin[k], out_bin[k]):
#             assert np.isclose(a, b, equal_nan=True)
#     # pid
#     assert in_bin.pid == out_bin.pid, 'pid mismatch'
#     assert in_bin.lid == out_bin.lid, 'lid mismatch'
#     # timestamp
#     assert in_bin.timestamp == out_bin.timestamp, 'timestamp mismatch'
#     # schema
#     assert in_bin.schema == out_bin.schema, 'schema mismatch'
#     # headers
#     assert set(in_bin.headers) == set(out_bin.headers), 'header keys mismatch'
#     for k in in_bin.headers.keys():
#         # headers should all have same names and values
#         assert in_bin.headers[k] == out_bin.headers[k], 'header values mismatch'
#     # images
#     assert set(in_bin.images) == set(out_bin.images), 'image target numbers mismatch'
#     for k in in_bin.images:
#         assert np.all(in_bin.images[k] == out_bin.images[k]), 'image data mismatch'


# Path: ifcb/tests/data/test_io.py
import unittest
from ifcb.data.io import open_raw, open_hdf, open_zip, open_mat
from ifcb.tests.utils import withfile
from .fileset_info import list_test_bins
from .bins import assert_bin_equals





class TestFormatConversionAPI(unittest.TestCase):
    @withfile
    def test_hdf_roundtrip(self, path):
        for out_bin in list_test_bins():
            with out_bin:
                out_bin.to_hdf(path)
                with open_hdf(path) as in_bin:
                    assert_bin_equals(in_bin, out_bin)
    @withfile
    def test_zip_roundtrip(self, path):
        for out_bin in list_test_bins():
            with out_bin:
                out_bin.to_zip(path)
                with open_zip(path) as in_bin:
                    assert_bin_equals(in_bin, out_bin)

    @withfile