From 82b7664876cd5c35d7034724f26a18beb0de8b83 Mon Sep 17 00:00:00 2001 From: mavaylon1 Date: Mon, 25 Sep 2023 14:59:58 -0700 Subject: [PATCH] clean up --- src/hdmf_zarr/backend.py | 3 +++ tests/unit/test_io_convert.py | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/hdmf_zarr/backend.py b/src/hdmf_zarr/backend.py index ea4427a2..402e5146 100644 --- a/src/hdmf_zarr/backend.py +++ b/src/hdmf_zarr/backend.py @@ -529,6 +529,8 @@ def resolve_ref(self, zarr_ref): try: target_zarr_obj = target_zarr_obj[object_path] except Exception: + # TODO: Find why the reference includes the root object. + # This is a fix to allow the target object to be found try: object_path = pathlib.Path(object_path) rel_obj_path = object_path.relative_to(*object_path.parts[:2]) @@ -1078,6 +1080,7 @@ def __read_group(self, zarr_obj, name=None): for sub_name, sub_group in zarr_obj.groups(): sub_builder = self.__read_group(sub_group, sub_name) ret.set_group(sub_builder) + # read sub datasets for sub_name, sub_array in zarr_obj.arrays(): sub_builder = self.__read_dataset(sub_array, sub_name) diff --git a/tests/unit/test_io_convert.py b/tests/unit/test_io_convert.py index 326a642b..2b8879d3 100644 --- a/tests/unit/test_io_convert.py +++ b/tests/unit/test_io_convert.py @@ -184,6 +184,7 @@ def test_export_roundtrip(self): self.assertEqual(exported_container.baz_data.data.__class__.__name__, 'ContainerZarrReferenceDataset') self.assertIs(exported_container.baz_data.data[i], exported_container.bazs[baz_name]) + # assert that the roundtrip worked correctly message = "Using: write_path=%s, export_path=%s" % (str(write_path), str(export_path)) self.assertIsNotNone(str(container), message) # added as a test to make sure printing works @@ -199,7 +200,6 @@ def test_export_roundtrip(self): ignore_string_to_byte=self.IGNORE_STRING_TO_BYTE, message=message) self.close_files_and_ios() - # TODO: May need to add further asserts here ########################################################## @@ -225,6 +225,7 @@ def get_manager(self): def roundtripExportContainer(self, container, write_path, export_path): with HDF5IO(write_path, manager=self.get_manager(), mode='w') as write_io: write_io.write(container, cache_spec=True) + with HDF5IO(write_path, manager=self.get_manager(), mode='r') as read_io: with ZarrIO(export_path, mode='w') as export_io: export_io.export(src_io=read_io, write_args={'link_data': False}) @@ -255,6 +256,7 @@ def get_manager(self): def roundtripExportContainer(self, container, write_path, export_path): with ZarrIO(write_path, manager=self.get_manager(), mode='w') as write_io: write_io.write(container) + with ZarrIO(write_path, manager=self.get_manager(), mode='r') as read_io: with HDF5IO(export_path, mode='w') as export_io: export_io.export(src_io=read_io, write_args={'link_data': False}) @@ -288,6 +290,7 @@ def get_manager(self): def roundtripExportContainer(self, container, write_path, export_path): with ZarrIO(write_path, manager=self.get_manager(), mode='w') as write_io: write_io.write(container, cache_spec=True) + with ZarrIO(write_path, manager=self.get_manager(), mode='r') as read_io: with ZarrIO(export_path, mode='w') as export_io: export_io.export(src_io=read_io, write_args={'link_data': False}) @@ -646,8 +649,8 @@ class TestZarrToHDF5Baz1(MixinTestBaz1, MixinTestCaseConvert, TestCase): """ - Test the conversion of a simple Foo container with two buckets of datasets from Zarr to HDF5 - See MixinTestFoo.setUpContainer for the container spec used. + Test the conversion of a BazBucket containing a dataset of references from Zarr to HDF5 + See MixinTestBaz1.setUpContainer for the container spec used. """ IGNORE_NAME = True IGNORE_HDMF_ATTRS = True @@ -660,7 +663,8 @@ class TestHDF5toZarrBaz1(MixinTestBaz1, MixinTestCaseConvert, TestCase): """ - + Test the conversion of a BazBucket containing a dataset of references from HDF5 to Zarr + See MixinTestBaz1.setUpContainer for the container spec used. """ IGNORE_NAME = True IGNORE_HDMF_ATTRS = True @@ -673,7 +677,8 @@ class TestZarrtoZarrBaz1(MixinTestBaz1, MixinTestCaseConvert, TestCase): """ - + Test the conversion of a BazBucket containing a dataset of references from Zarr to Zarr + See MixinTestBaz1.setUpContainer for the container spec used. """ IGNORE_NAME = True IGNORE_HDMF_ATTRS = True