Skip to content

Commit

Permalink
Test reader with path and paths
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed May 25, 2022
1 parent 3621892 commit 842c9a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
29 changes: 25 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,37 @@ def test_objects():
return [create_test_object(id=i)[0] for i in range(10)]


def write_h5_file(file_path: Path, test_objects) -> Path:
"""
Write a h5 file with test objects and return path.
"""
with btrack.dataio.HDF5FileHandler(file_path, "w") as h:
h.write_objects(test_objects)

return file_path


@pytest.fixture
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"
return write_h5_file(tmp_path / "test.h5", test_objects)

with btrack.dataio.HDF5FileHandler(fn, "w") as h:
h.write_objects(test_objects)

return fn
@pytest.fixture(params=["single", "list"])
def hdf5_file_path_or_paths(tmp_path, test_objects, request) -> Path:
"""
Create and save a btrack HDF5 file, and return the path.
Note that this only saves segmentation results, not tracking results.
"""
if request.param == "single":
return write_h5_file(tmp_path / "test.h5", test_objects)
elif request.param == "list":
return [
write_h5_file(tmp_path / "test1.h5", test_objects),
write_h5_file(tmp_path / "test2.h5", test_objects),
]
6 changes: 3 additions & 3 deletions tests/napari/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
napari_reader = pytest.importorskip("btrack.napari.reader")


def test_reader(hdf5_file_path):
reader = napari_reader.get_reader(hdf5_file_path)
def test_reader(hdf5_file_path_or_paths):
reader = napari_reader.get_reader(hdf5_file_path_or_paths)
assert reader is not None

tracks = reader(hdf5_file_path)
tracks = reader(hdf5_file_path_or_paths)
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 empty HDF5 file
Expand Down

0 comments on commit 842c9a0

Please sign in to comment.