Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Nov 18, 2024
1 parent b959246 commit 68b2ede
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/hdmf_zarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ def write_group(self, **kwargs):
if links:
for link_name, sub_builder in links.items():
# Note: sub_builder is a LinkBuilder not the builder within.
# HDMF: h5tools --> 1034
self.write_link(group, sub_builder, export_source)

attributes = builder.attributes
Expand Down Expand Up @@ -850,7 +849,6 @@ def write_link(self, **kwargs):

group_filename = self.__get_store_path(parent.store)
if export_source is not None:
# HDMF: h5tools 1081
if target_builder.source in (group_filename, export_source):
# Case 1:
# target_builder.source == export_source
Expand Down Expand Up @@ -1043,7 +1041,7 @@ def write_dataset(self, **kwargs): # noqa: C901
# and will be refactored/removed.
if self.__is_ref(dts['dtype']):
refs.append(i)
ref_tmp = self._create_ref(data[0][i], ref_link_source=self.path) # HDMF 1229
ref_tmp = self._create_ref(data[0][i], ref_link_source=self.path)
if isinstance(ref_tmp, ZarrReference):
dts_str = 'object'
else:
Expand Down
51 changes: 37 additions & 14 deletions tests/unit/base_tests_zarrio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,13 +1312,46 @@ def test_pop_linked_group(self):
with self.assertRaisesWith(OrphanContainerBuildError, msg):
export_io.export(src_io=read_io, container=read_foofile)

def test_soft_links_export(self):
def test_soft_link_data(self):
"""
Test data soft links.
"""
foo1 = Foo('foo1', [1, 2, 3, 4, 5], "I am foo1", 17, 3.14)
foobucket = FooBucket('bucket1', [foo1])
foofile = FooFile(buckets=[foobucket])

with ZarrIO(self.store[0], manager=get_foo_buildmanager(), mode='w') as write_io:
write_io.write(foofile)

with ZarrIO(self.store[0], manager=get_foo_buildmanager(), mode='r') as read_io:
read_foofile = read_io.read()

# create a foo with link to existing dataset my_data, add the foo to new foobucket
# this should make a soft link within the exported file
foo2 = Foo('foo2', read_foofile.buckets['bucket1'].foos['foo1'].my_data, "I am foo2", 17, 3.14)
foobucket2 = FooBucket('bucket2', [foo2])
read_foofile.add_bucket(foobucket2)

read_foofile.foofile_data = foo2.my_data

with ZarrIO(self.store[1], mode='w') as export_io:
export_io.export(src_io=read_io, container=read_foofile)

with ZarrIO(self.store[1], manager=get_foo_buildmanager(), mode='r') as read_io:
read_foofile2 = read_io.read()

# test new soft link to dataset in file
self.assertIs(read_foofile2.buckets['bucket1'].foos['foo1'].my_data,
read_foofile2.buckets['bucket2'].foos['foo2'].my_data)

# test new soft link to new soft link to dataset in file
self.assertIs(read_foofile2.buckets['bucket1'].foos['foo1'].my_data, read_foofile2.foofile_data)


def test_soft_links_group_after_write(self):
"""
Test that exporting a written container after adding
groups, links, and references to it works.
This tests `builder.parent.name != parent_name:` within
`if data_filename != export_source or builder.parent.name != parent_name:`.
"""
foo1 = Foo('foo1', [1, 2, 3, 4, 5], "I am foo1", 17, 3.14)
foobucket = FooBucket('bucket1', [foo1])
Expand All @@ -1339,9 +1372,6 @@ def test_soft_links_export(self):
# also add link from foofile to new foo2 container
read_foofile.foo_link = foo2

# also add link from foofile to new foo2.my_data dataset which is a link to foo1.my_data dataset
read_foofile.foofile_data = foo2.my_data

# also add reference from foofile to new foo2
read_foofile.foo_ref_attr = foo2

Expand All @@ -1351,16 +1381,9 @@ def test_soft_links_export(self):
with ZarrIO(self.store[1], manager=get_foo_buildmanager(), mode='r') as read_io:
read_foofile2 = read_io.read()

# test new soft link to dataset in file
self.assertIs(read_foofile2.buckets['bucket1'].foos['foo1'].my_data,
read_foofile2.buckets['bucket2'].foos['foo2'].my_data)

# test new soft link to group in file
self.assertIs(read_foofile2.foo_link, read_foofile2.buckets['bucket2'].foos['foo2'])

# test new soft link to new soft link to dataset in file
self.assertIs(read_foofile2.buckets['bucket1'].foos['foo1'].my_data, read_foofile2.foofile_data)

# test new attribute reference to new group in file
self.assertIs(read_foofile2.foo_ref_attr, read_foofile2.buckets['bucket2'].foos['foo2'])

Expand Down

0 comments on commit 68b2ede

Please sign in to comment.