Skip to content
Closed
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
16 changes: 5 additions & 11 deletions ome_zarr/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def __init_metadata(self) -> None:
if "ome" in self.zgroup:
self.zgroup = self.zgroup["ome"]
self.__metadata = self.zgroup
except (ValueError, FileNotFoundError):
except (ValueError, FileNotFoundError) as e:
LOGGER.error("Failed to initialize metadata: %s", e)
# group doesn't exist. If we are in "w" mode, we need to create it.
if self.__mode == "w":
# If we are creating a new group, we need to specify the zarr_format.
Expand All @@ -97,7 +98,7 @@ def __init_metadata(self) -> None:
store=self.__store, path="/", mode="w", zarr_format=zarr_format
)
else:
self.__exists = False
raise e

def __repr__(self) -> str:
"""Print the path as well as whether this is a group or an array."""
Expand Down Expand Up @@ -219,13 +220,6 @@ def parse_url(
:param fmt: Version of the OME-NGFF spec to open path with.

:return: `ZarrLocation`.
If mode is 'r', and the path does not exist returns None.
If there is an error opening the path, also returns None.

>>> parse_url('does-not-exist')
If mode is 'r', and the path does not exist, raises exception
"""
loc = ZarrLocation(path, mode=mode, fmt=fmt)
if "r" in mode and not loc.exists():
return None
else:
return loc
return ZarrLocation(path, mode=mode, fmt=fmt)
6 changes: 6 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def test_invalid_version(self):
assert len(list(reader())) == 2
assert str(exe.value) == "Version invalid not recognized"

def test_not_found(self):
with pytest.raises(FileNotFoundError) as exe:
reader = Reader(parse_url(str(self.path / "not_found")))
assert len(list(reader())) == 0
assert "Unable to find group" in str(exe.value)


class TestHCSReader:
@pytest.fixture(autouse=True)
Expand Down
Loading