File size: 2,201 Bytes
12d2e9e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
"""
Copyright 2021, Dana-Farber Cancer Institute and Weill Cornell Medicine
License: GNU GPL 2.0
"""
import numpy as np
import pytest
import pathml.core.h5managers
from pathml.core import HESlide, Masks
@pytest.fixture
def emptymasks():
slidedata = HESlide("tests/testdata/small_HE.svs")
return Masks(h5manager=pathml.core.h5managers.h5pathManager(slidedata=slidedata))
@pytest.fixture
def smallmasks():
slidedata = HESlide("tests/testdata/small_HE.svs")
shape = (224, 224, 3)
im = np.arange(np.product(shape)).reshape(shape)
testmasks = Masks(
h5manager=pathml.core.h5managers.h5pathManager(slidedata=slidedata),
masks={"mask1": im, "mask2": im},
)
return testmasks
@pytest.mark.parametrize(
"incorrect_input", ["string", True, 5, [5, 4, 3], {"dict": "testing"}]
)
def test_init_incorrect_input(incorrect_input):
slidedata = HESlide("tests/testdata/small_HE.svs")
with pytest.raises(ValueError):
Masks(
h5manager=pathml.core.h5managers.h5pathManager(slidedata=slidedata),
masks=incorrect_input,
)
@pytest.mark.parametrize(
"incorrect_input", ["string", True, [5, 4, 3], {"dict": "testing"}]
)
def test_add_get_incorrect_input(emptymasks, smallmasks, incorrect_input):
with pytest.raises(ValueError):
emptymasks.add(
incorrect_input, np.arange(np.product((224, 224, 3))).reshape((224, 224, 3))
)
emptymasks.add("newmask", incorrect_input)
with pytest.raises(KeyError):
smallmasks[incorrect_input]
@pytest.mark.parametrize(
"incorrect_input", ["string", True, [5, 4, 3], {"dict": "testing"}]
)
def test_slice(smallmasks, incorrect_input):
masks = smallmasks
slices = [slice(2, 5)]
test = masks.slice(slices)
assert test[list(test.keys())[0]].shape == (3, 224, 3)
with pytest.raises(Exception):
test = masks.slice(incorrect_input)
@pytest.mark.parametrize(
"incorrect_input", ["string", True, 5, [5, 4, 3], {"dict": "testing"}]
)
def test_remove(smallmasks, incorrect_input):
masks = smallmasks
masks.remove("mask1")
with pytest.raises(KeyError):
masks.remove(incorrect_input)
|