Skip to content

Commit a6bf994

Browse files
Merged tests from broken PR (#59)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c3e5bee commit a6bf994

File tree

5 files changed

+63
-103
lines changed

5 files changed

+63
-103
lines changed

tests/conftest.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ def sdata_blobs() -> SpatialData:
5959
@pytest.fixture
6060
def test_sdata_single_image():
6161
"""Creates a simple sdata object."""
62-
images = {"data1": sd.models.Image2DModel.parse(np.zeros((1, 10, 10)), dims=("c", "y", "x"))}
62+
images = {
63+
"data1_image": sd.models.Image2DModel.parse(
64+
np.zeros((1, 10, 10)), dims=("c", "y", "x"), transformations={"data1": sd.transformations.Identity()}
65+
)
66+
}
6367
sdata = sd.SpatialData(images=images)
6468
return sdata
6569

@@ -77,9 +81,15 @@ def test_sdata_single_image_with_label():
7781
def test_sdata_multiple_images():
7882
"""Creates an sdata object with multiple images."""
7983
images = {
80-
"data1": sd.models.Image2DModel.parse(np.zeros((1, 10, 10)), dims=("c", "y", "x")),
81-
"data2": sd.models.Image2DModel.parse(np.zeros((1, 10, 10)), dims=("c", "y", "x")),
82-
"data3": sd.models.Image2DModel.parse(np.zeros((1, 10, 10)), dims=("c", "y", "x")),
84+
"data1_image": sd.models.Image2DModel.parse(
85+
np.zeros((1, 10, 10)), dims=("c", "y", "x"), transformations={"data1": sd.transformations.Identity()}
86+
),
87+
"data2_image": sd.models.Image2DModel.parse(
88+
np.zeros((1, 10, 10)), dims=("c", "y", "x"), transformations={"data1": sd.transformations.Identity()}
89+
),
90+
"data3_image": sd.models.Image2DModel.parse(
91+
np.zeros((1, 10, 10)), dims=("c", "y", "x"), transformations={"data1": sd.transformations.Identity()}
92+
),
8393
}
8494
sdata = sd.SpatialData(images=images)
8595
return sdata

tests/pl/test_render.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import matplotlib.pyplot as plt
2+
import pytest
3+
4+
5+
def test_render_images_can_plot_one_cyx_image(request):
6+
sdata = request.getfixturevalue("test_sdata_single_image")
7+
8+
_, ax = plt.subplots(1, 1)
9+
10+
sdata.pl.render_images().pl.show(ax=ax)
11+
12+
assert ax.get_title() == sdata.coordinate_systems[0]
13+
14+
15+
@pytest.mark.parametrize(
16+
"share_coordinate_system",
17+
[
18+
"all",
19+
"two",
20+
"none",
21+
],
22+
)
23+
def test_render_images_can_plot_multiple_cyx_images(share_coordinate_system: str, request):
24+
fun = request.getfixturevalue("get_sdata_with_multiple_images")
25+
sdata = fun(share_coordinate_system)
26+
sdata.pl.render_images().pl.show()
27+
axs = plt.gcf().get_axes()
28+
29+
if share_coordinate_system == "all":
30+
assert len(axs) == 1
31+
32+
elif share_coordinate_system == "two":
33+
assert len(axs) == 2
34+
35+
elif share_coordinate_system == "none":
36+
assert len(axs) == 3

tests/pp/test_basic.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
@pytest.mark.parametrize(
55
"sdata, keys ",
66
[
7-
("test_sdata_multiple_images", 0),
8-
("test_sdata_multiple_images", {"a": 0}),
9-
("test_sdata_multiple_images", None),
10-
("test_sdata_multiple_images", ["my_key", 0]),
7+
("get_sdata_with_multiple_images", 0),
8+
("get_sdata_with_multiple_images", {"a": 0}),
9+
("get_sdata_with_multiple_images", None),
10+
("get_sdata_with_multiple_images", ["my_key", 0]),
1111
],
1212
)
1313
def test_typerror_when_key_is_invalid(sdata, keys, request):
1414
"""Tests wether the images inside sdata can be clipped to a bounding box."""
15-
16-
sdata = request.getfixturevalue(sdata)
15+
sdata = request.getfixturevalue(sdata)(share_coordinate_system="all")
1716

1817
with pytest.raises(TypeError):
1918
sdata.pp.get_elements(keys)
@@ -22,14 +21,12 @@ def test_typerror_when_key_is_invalid(sdata, keys, request):
2221
@pytest.mark.parametrize(
2322
"sdata, keys ",
2423
[
25-
("test_sdata_multiple_images", "data4"),
26-
("test_sdata_multiple_images", ["data1", "data4"]),
24+
("get_sdata_with_multiple_images", "data4"),
25+
("get_sdata_with_multiple_images", ["data1", "data4"]),
2726
],
2827
)
2928
def test_valuerror_when_key_is_of_correct_type_but_not_in_sdata(sdata, keys, request):
30-
"""Tests wether the images inside sdata can be clipped to a bounding box."""
31-
32-
sdata = request.getfixturevalue(sdata)
29+
sdata = request.getfixturevalue(sdata)(share_coordinate_system="all")
3330

3431
with pytest.raises(ValueError):
3532
sdata.pp.get_elements(keys)

tests/test_image.py

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -12,87 +12,4 @@
1212
def test_sdata_fixture(sdata, request):
1313
"""Tests the sdata fixture."""
1414
sdata = request.getfixturevalue(sdata)
15-
assert sdata.images["data1"].shape == (1, 10, 10)
16-
17-
18-
# @pytest.mark.parametrize(
19-
# "sdata",
20-
# [
21-
# "test_sdata_single_image",
22-
# "test_sdata_multiple_images",
23-
# "test_sdata_multiple_images_dims"
24-
# ],
25-
# )
26-
# def test_image_accessor_correct_image_key_string(sdata, request):
27-
# """Tests the image accessor with a correct image key string."""
28-
# sdata = request.getfixturevalue(sdata)
29-
# sdata.im['data1']
30-
31-
# assert sdata.im.i == 'data1'
32-
33-
34-
# @pytest.mark.parametrize(
35-
# "sdata, query",
36-
# [
37-
# ("test_sdata_single_image", ["data1"]),
38-
# ("test_sdata_multiple_images", ["data1"]),
39-
# ("test_sdata_multiple_images", ["data1", "data2"]),
40-
# ("test_sdata_multiple_images", ["data1", "data3"]),
41-
# ("test_sdata_multiple_images_dims", ['data1']),
42-
# ("test_sdata_multiple_images_dims", ['data1', 'data2']),
43-
# ],
44-
# )
45-
# def test_image_accessor_correct_image_key_list(sdata, query, request):
46-
# """Tests the image accessor with a correct image key list."""
47-
# sdata = request.getfixturevalue(sdata)
48-
# sdata.im[query]
49-
# assert sdata.im.i == query
50-
51-
52-
# @pytest.mark.parametrize(
53-
# "sdata",
54-
# [
55-
# "test_sdata_single_image",
56-
# "test_sdata_multiple_images",
57-
# "test_sdata_multiple_images_dims"
58-
# ],
59-
# )
60-
# def test_image_accessor_wrong_correct_image_key_string(sdata, request):
61-
# """Tests the image accessor with a wrong image key string."""
62-
# sdata = request.getfixturevalue(sdata)
63-
# with pytest.raises(AssertionError):
64-
# sdata.im['wrong']
65-
66-
67-
# @pytest.mark.parametrize(
68-
# "sdata",
69-
# [
70-
# "test_sdata_single_image",
71-
# "test_sdata_multiple_images",
72-
# "test_sdata_multiple_images_dims"
73-
# ],
74-
# )
75-
# def test_image_accessor_correct_channel(sdata, request):
76-
# """Tests the image accessor with a wrong image key string."""
77-
# sdata = request.getfixturevalue(sdata)
78-
# sdata.im[0]
79-
80-
# assert isinstance(sdata.im.i, list)
81-
# assert sdata.im.c == 0
82-
83-
84-
# @pytest.mark.parametrize(
85-
# "sdata",
86-
# [
87-
# "test_sdata_single_image",
88-
# "test_sdata_multiple_images",
89-
# "test_sdata_multiple_images_dims"
90-
# ],
91-
# )
92-
# def test_image_accessor_correct_image_key_and_channel(sdata, request):
93-
# """Tests the image accessor with a wrong image key string."""
94-
# sdata = request.getfixturevalue(sdata)
95-
# sdata.im['data1', 0]
96-
97-
# assert isinstance(sdata.im.i, str)
98-
# assert sdata.im.c == 0
15+
assert sdata.images["data1_image"].shape == (1, 10, 10)

tests/test_pp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
@pytest.mark.parametrize(
55
"sdata, keys",
66
[
7-
("test_sdata_multiple_images", "data1"),
8-
("test_sdata_multiple_images", ["data1"]),
9-
("test_sdata_multiple_images", ["data1", "data2"]),
7+
("get_sdata_with_multiple_images", "data1"),
8+
("get_sdata_with_multiple_images", ["data1"]),
9+
("get_sdata_with_multiple_images", ["data1", "data2"]),
1010
],
1111
)
1212
def test_can_subset_to_one_or_more_images(sdata, keys, request):
1313
"""Tests whether a subset of images can be selected from the sdata object."""
1414

15-
sdata = request.getfixturevalue(sdata)
15+
sdata = request.getfixturevalue(sdata)(share_coordinate_system="all")
1616

1717
clipped_sdata = sdata.pp.get_elements(keys)
1818

0 commit comments

Comments
 (0)