Skip to content

Commit

Permalink
Merge pull request #97 from hdmf-dev/can_read
Browse files Browse the repository at this point in the history
add can_read classmethod to ZarrIO
  • Loading branch information
bendichter authored Jun 18, 2023
2 parents 3c2bb12 + 26cad63 commit 531296c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
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

0 comments on commit 531296c

Please sign in to comment.