Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ywkure committed Feb 17, 2021
1 parent a6cb3f4 commit 06f229a
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 29 deletions.
6 changes: 5 additions & 1 deletion napari_split_dataset/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def read_directory(path):
def read_hdf5(path):
# read the image if the h5 file is an array or part of split dataset files

data = fl.load(path)
try:
data = fl.load(path)
except (OSError, RuntimeError):
return None

if not isinstance(data, (np.ndarray, dict)):
return None
elif isinstance(data, dict):
Expand Down
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
"""Unit test package for napari_split_dataset."""
from pathlib import Path

ASSETS_PATH = Path(__file__).parent / "assets"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
62 changes: 34 additions & 28 deletions tests/test_napari_split_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,57 @@

from napari_split_dataset import _reader

from . import ASSETS_PATH


@pytest.mark.parametrize(
"path",
"path, expected",
[
"fake.h5",
"fake.hdf5",
"fake.tif",
"fake",
"asset/sample_3d",
"asset/sample_4d",
"asset/empty",
"asset/array.h5",
"asset/dict_stack.h5",
"asset/dict_shift.h5",
("fake.h5", True),
("fake.hdf5", True),
("fake.tif", False),
("fake", False),
(ASSETS_PATH / "sample_3d", True),
(ASSETS_PATH / "sample_4d", True),
(ASSETS_PATH / "empty", True),
(ASSETS_PATH / "array.h5", True),
(ASSETS_PATH / "dict_stack.h5", True),
(ASSETS_PATH / "dict_shift.h5", True),
],
)
def test_reader(path):
def test_reader(path, expected):
reader = _reader.napari_get_reader(path)
assert callable(reader)
assert callable(reader) == expected


@pytest.mark.parametrize(
"path",
"path, expected",
[
"asset/sample_3d",
"asset/sample_4d",
"asset/empty",
"asset/array.h5",
(ASSETS_PATH / "sample_3d", ndarray),
(ASSETS_PATH / "sample_4d", Array),
(ASSETS_PATH / "empty", type(None)),
(ASSETS_PATH / "array.h5", type(None)),
],
)
def test_dir_reader(path):
def test_dir_reader(path, expected):
data = _reader.read_directory(path)
assert isinstance(data[0][0], (ndarray, Array))
if isinstance(data, list):
data = data[0][0]
assert isinstance(data, expected)


@pytest.mark.parametrize(
"path",
"path, expected",
[
"asset/sample_4d",
"asset/empty",
"asset/array.h5",
"asset/dict_stack.h5",
"asset/dict_shift.h5",
(ASSETS_PATH / "sample_4d", type(None)),
(ASSETS_PATH / "empty", type(None)),
(ASSETS_PATH / "array.h5", ndarray),
(ASSETS_PATH / "dict_stack.h5", ndarray),
(ASSETS_PATH / "dict_shift.h5", type(None)),
],
)
def test_h5_reader(path):
def test_h5_reader(path, expected):
data = _reader.read_hdf5(path)
assert isinstance(data[0][0], ndarray)
if isinstance(data, list):
data = data[0][0]
assert isinstance(data, expected)

0 comments on commit 06f229a

Please sign in to comment.