Skip to content

Commit

Permalink
Add test for napari reader
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Apr 21, 2022
1 parent 47198fc commit 2ff84f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion btrack/napari/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def reader_function(path: PathLike) -> List[LayerDataTuple]:
to layer_type=="image" if not provided
"""
# handle both a string and a list of strings
paths = [path] if isinstance(path, str) else path
paths = [path] if not isinstance(path, list) else path

# store the layers to be generated
layers = []
Expand All @@ -66,6 +66,7 @@ def reader_function(path: PathLike) -> List[LayerDataTuple]:
with HDF5FileHandler(_path, "r") as hdf:

# get the segmentation if there is one
import pdb; pdb.set_trace()
if "segmentation" in hdf._hdf:
segmentation = hdf.segmentation
layers.append((segmentation, {}, "labels"))
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def test_objects():
def hdf5_file_path(tmp_path, test_objects) -> Path:
"""
Create and save a btrack HDF5 file, and return the path.
Note that this only saves segmentation results, not tracking results.
"""
fn = Path(tmp_path) / "test.h5"

Expand Down
11 changes: 9 additions & 2 deletions tests/napari/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
napari_reader = pytest.importorskip("btrack.napari.reader")


def test_get_reader_pass():
reader = napari_reader.get_reader("fake.file")
def test_reader(hdf5_file_path):
reader = napari_reader.get_reader(hdf5_file_path)
assert reader is not None

tracks = reader(hdf5_file_path)
assert isinstance(tracks, list)
# TODO: update the HDF file so that it has some tracks that can be read.
# For now this just checks that the reader can read an emtpy HDF5 file
# with no tracks in it
assert len(tracks) == 0

0 comments on commit 2ff84f1

Please sign in to comment.