Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add can_read classmethod to ZarrIO #97

Merged
merged 4 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Minor enhancements
* Updated handling of references on read to simplify future integration of file-based Zarr
stores (e.g., ZipStore or database stores) @oruebel [#62](https://github.com/hdmf-dev/hdmf-zarr/pull/62)
* Added can_read classmethod to ZarrIO. @bendichter [#97](https://github.com/hdmf-dev/hdmf-zarr/pull/97)

### Test suite enhancements
* Modularized unit tests to simplify running tests for multiple Zarr storage backends
Expand Down
8 changes: 8 additions & 0 deletions src/hdmf_zarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@

class ZarrIO(HDMFIO):

@staticmethod
def can_read(path):
try:
zarr.open(path, mode="r")
return True
except Exception:
return False

@docval({'name': 'path',
'type': (str, *SUPPORTED_ZARR_STORES),
'doc': 'the path to the Zarr file or a supported Zarr store'},
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/base_tests_zarrio.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def createReferenceCompoundBuilder(self):
'ref_dataset': dataset_ref})
return builder

def test_cannot_read(self):
assert not ZarrIO.can_read("incorrect_path")

def read_test_dataset(self):
reader = ZarrIO(self.store, manager=self.manager, mode='r')
self.root = reader.read_builder()
Expand Down Expand Up @@ -209,6 +212,7 @@ def test_write_int(self, test_data=None):
writer = ZarrIO(self.store, manager=self.manager, mode='a')
writer.write_builder(self.builder)
writer.close()
assert ZarrIO.can_read(self.store)

def test_write_compound(self, test_data=None):
"""
Expand Down