# Path: ifcb/data/files.py
# class DataDirectory(object):
#     """
#     Represents a directory containing IFCB raw data.
# 
#     Provides a dict-like interface allowing access to FilesetBins by LID.
#     """
#     def __init__(self, path='.', whitelist=DEFAULT_WHITELIST, blacklist=DEFAULT_BLACKLIST, filter=lambda x: True):
#         """
#         :param path: the path of the data directory
#         :param whitelist: a list of directory names to allow
#         :param blacklist: a list of directory names to disallow
#         """
#         self.path = path
#         self.whitelist = whitelist
#         self.blacklist = blacklist
#         self.filter = filter
#     def list_filesets(self):
#         """
#         Yield all filesets.
#         """
#         for dirpath, basename in list_filesets(self.path, whitelist=self.whitelist, blacklist=self.blacklist):
#             basepath = os.path.join(dirpath, basename)
#             fs = Fileset(basepath)
#             if self.filter(fs):
#                 yield fs
#     def find_fileset(self, lid):
#         """
#         Locate a fileset by LID. Returns None if it is not found.
# 
#         :param lid: the LID to search for
#         :type lid: str
#         :returns Fileset: the fileset, or None if not found
#         """
#         fs = find_fileset(self.path, lid, whitelist=self.whitelist, blacklist=self.blacklist)
#         if fs is None:
#             return None
#         elif self.filter(fs):
#             return fs
#     def __iter__(self):
#         # yield from list_filesets called with no keyword args
#         for fs in self.list_filesets():
#             yield FilesetBin(fs)
#     def has_key(self, lid):
#         # fast contains method that avoids iteration
#         return self.find_fileset(lid) is not None
#     def __getitem__(self, lid):
#         fs = self.find_fileset(lid)
#         if fs is None:
#             raise KeyError('No fileset for %s found at or under %s' % (lid, self.path))
#         return FilesetBin(fs)
#     def __len__(self):
#         """warning: for large datasets, this is very slow"""
#         return sum(1 for _ in self)
#     # subdirectories
#     def list_descendants(self, **kw):
#         """
#         Find all 'leaf' data directories and yield ``DataDirectory``
#         objects for each one. Note that this enforces blacklisting
#         but not whitelisting (no fileset path validation is done).
#         Accepts ``list_data_dirs`` keywords, except ``blacklist`` which
#         takes on the value given in the constructor.
#         """
#         for dd in list_data_dirs(self.path, blacklist=self.blacklist, **kw):
#             yield DataDirectory(dd)
#     def __repr__(self):
#         return '<DataDirectory %s>' % self.path
#     def __str__(self):
#         return self.path
# 
# Path: ifcb/tests/data/fileset_info.py
# def list_test_bins():
#     return list(_dd())
# 
# TEST_FILES = {
#     'D20130526T095207_IFCB013': {
#         'n_rois': 19,
#         'n_targets': 118,
#         'roi_numbers': [7, 11, 13, 21, 32, 33, 47, 49, 54, 61, 66, 68, 73, 78, 80, 92, 99, 102, 114],
#         'roi_number': 99,
#         'roi_shape': (34, 64),
#         'roi_slice_coords': [slice(0,5), slice(0,5)],
#         'roi_slice': np.array([[172, 168, 172, 166, 171],
#                                [168, 170, 172, 171, 170],
#                                [167, 174, 171, 175, 168],
#                                [173, 171, 173, 170, 171],
#                                [176, 169, 176, 173, 172]], dtype=np.uint8),
#         'sizes': {
#             'roi': 98472,
#             'hdr': 2885,
#             'adc': 19395
#         },
#         'headers': {
#             'KloehnPort': 'COM3',
#             'laserMotorSmallStep_ms': 1000,
#             'blobXgrowAmount': 20
#         }
#     },
#     'IFCB5_2012_028_081515': {
#         'n_rois': 6,
#         'n_targets': 7,
#         'roi_numbers': [1, 2, 3, 4, 5, 6],
#         'roi_number': 1,
#         'roi_shape': (45, 96),
#         'roi_slice_coords': [slice(0,5), slice(0,5)],
#         'roi_slice': np.array([[208, 207, 206, 206, 207],
#                                [206, 206, 206, 207, 206],
#                                [206, 207, 205, 206, 208],
#                                [208, 208, 208, 208, 209],
#                                [206, 206, 205, 207, 207]], dtype=np.uint8),
#         'stitched_roi_number': 3,
#         'roi_numbers_stitched': [1, 2, 3, 5, 6],
#         'stitched_roi_shape': (86, 263),
#         'stitched_roi_coords': [slice(23,27), slice(177,183)],
#         'stitched_roi_slice': np.array([[205, 204, 205, 0, 0, 0],
#                                         [202, 203, 206, 0, 0, 0],
#                                         [205, 206, 205, 204, 202, 202],
#                                         [204, 202, 205, 203, 202, 204]], dtype=np.uint8),
#         'stitched_corners': {1: [208, 204, 205, 205],
#                              2: [205, 199, 203, 197],
#                              3: [210, 203, 207, 203],
#                              5: [210, 209, 212, 209],
#                              6: [212, 206, 209, 208]},
#         'sizes': {
#             'roi': 71083,
#             'hdr': 301,
#             'adc': 1004
#         },
#         'headers': {
#             'binarizeThreshold': 30,
#             'fluorescencePhotomultiplierSetting': 0.6,
#         }
#     }
# }


import unittest
from ifcb.data.files import DataDirectory
from .fileset_info import list_test_bins, TEST_FILES


class TestHdr(unittest.TestCase):
	def test_hdr(self):
		for b in list_test_bins():
			h = b.headers
			eh = TEST_FILES[b.lid]['headers']

# Path: ifcb/data/files.py
# class DataDirectory(object):
#     """
#     Represents a directory containing IFCB raw data.
# 
#     Provides a dict-like interface allowing access to FilesetBins by LID.
#     """
#     def __init__(self, path='.', whitelist=DEFAULT_WHITELIST, blacklist=DEFAULT_BLACKLIST, filter=lambda x: True):
#         """
#         :param path: the path of the data directory
#         :param whitelist: a list of directory names to allow
#         :param blacklist: a list of directory names to disallow
#         """
#         self.path = path
#         self.whitelist = whitelist
#         self.blacklist = blacklist
#         self.filter = filter
#     def list_filesets(self):
#         """
#         Yield all filesets.
#         """
#         for dirpath, basename in list_filesets(self.path, whitelist=self.whitelist, blacklist=self.blacklist):
#             basepath = os.path.join(dirpath, basename)
#             fs = Fileset(basepath)
#             if self.filter(fs):
#                 yield fs
#     def find_fileset(self, lid):
#         """
#         Locate a fileset by LID. Returns None if it is not found.
# 
#         :param lid: the LID to search for
#         :type lid: str
#         :returns Fileset: the fileset, or None if not found
#         """
#         fs = find_fileset(self.path, lid, whitelist=self.whitelist, blacklist=self.blacklist)
#         if fs is None:
#             return None
#         elif self.filter(fs):
#             return fs
#     def __iter__(self):
#         # yield from list_filesets called with no keyword args
#         for fs in self.list_filesets():
#             yield FilesetBin(fs)
#     def has_key(self, lid):
#         # fast contains method that avoids iteration
#         return self.find_fileset(lid) is not None
#     def __getitem__(self, lid):
#         fs = self.find_fileset(lid)
#         if fs is None:
#             raise KeyError('No fileset for %s found at or under %s' % (lid, self.path))
#         return FilesetBin(fs)
#     def __len__(self):
#         """warning: for large datasets, this is very slow"""
#         return sum(1 for _ in self)
#     # subdirectories
#     def list_descendants(self, **kw):
#         """
#         Find all 'leaf' data directories and yield ``DataDirectory``
#         objects for each one. Note that this enforces blacklisting
#         but not whitelisting (no fileset path validation is done).
#         Accepts ``list_data_dirs`` keywords, except ``blacklist`` which
#         takes on the value given in the constructor.
#         """
#         for dd in list_data_dirs(self.path, blacklist=self.blacklist, **kw):
#             yield DataDirectory(dd)
#     def __repr__(self):
#         return '<DataDirectory %s>' % self.path
#     def __str__(self):
#         return self.path
# 
# Path: ifcb/tests/data/fileset_info.py
# def list_test_bins():
#     return list(_dd())
# 
# TEST_FILES = {
#     'D20130526T095207_IFCB013': {
#         'n_rois': 19,
#         'n_targets': 118,
#         'roi_numbers': [7, 11, 13, 21, 32, 33, 47, 49, 54, 61, 66, 68, 73, 78, 80, 92, 99, 102, 114],
#         'roi_number': 99,
#         'roi_shape': (34, 64),
#         'roi_slice_coords': [slice(0,5), slice(0,5)],
#         'roi_slice': np.array([[172, 168, 172, 166, 171],
#                                [168, 170, 172, 171, 170],
#                                [167, 174, 171, 175, 168],
#                                [173, 171, 173, 170, 171],
#                                [176, 169, 176, 173, 172]], dtype=np.uint8),
#         'sizes': {
#             'roi': 98472,
#             'hdr': 2885,
#             'adc': 19395
#         },
#         'headers': {
#             'KloehnPort': 'COM3',
#             'laserMotorSmallStep_ms': 1000,
#             'blobXgrowAmount': 20
#         }
#     },
#     'IFCB5_2012_028_081515': {
#         'n_rois': 6,
#         'n_targets': 7,
#         'roi_numbers': [1, 2, 3, 4, 5, 6],
#         'roi_number': 1,
#         'roi_shape': (45, 96),
#         'roi_slice_coords': [slice(0,5), slice(0,5)],
#         'roi_slice': np.array([[208, 207, 206, 206, 207],
#                                [206, 206, 206, 207, 206],
#                                [206, 207, 205, 206, 208],
#                                [208, 208, 208, 208, 209],
#                                [206, 206, 205, 207, 207]], dtype=np.uint8),
#         'stitched_roi_number': 3,
#         'roi_numbers_stitched': [1, 2, 3, 5, 6],
#         'stitched_roi_shape': (86, 263),
#         'stitched_roi_coords': [slice(23,27), slice(177,183)],
#         'stitched_roi_slice': np.array([[205, 204, 205, 0, 0, 0],
#                                         [202, 203, 206, 0, 0, 0],
#                                         [205, 206, 205, 204, 202, 202],
#                                         [204, 202, 205, 203, 202, 204]], dtype=np.uint8),
#         'stitched_corners': {1: [208, 204, 205, 205],
#                              2: [205, 199, 203, 197],
#                              3: [210, 203, 207, 203],
#                              5: [210, 209, 212, 209],
#                              6: [212, 206, 209, 208]},
#         'sizes': {
#             'roi': 71083,
#             'hdr': 301,
#             'adc': 1004
#         },
#         'headers': {
#             'binarizeThreshold': 30,
#             'fluorescencePhotomultiplierSetting': 0.6,
#         }
#     }
# }


# Path: ifcb/tests/data/test_hdr.py
import unittest
from ifcb.data.files import DataDirectory
from .fileset_info import list_test_bins, TEST_FILES



class TestHdr(unittest.TestCase):
	def test_hdr(self):
		for b in list_test_bins():
			h = b.headers
			eh = TEST_FILES[b.lid]['headers']

			for k,v in eh.items():