Skip to content

Merged tests from broken PR #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ def sdata_blobs() -> SpatialData:
@pytest.fixture
def test_sdata_single_image():
"""Creates a simple sdata object."""
images = {"data1": sd.models.Image2DModel.parse(np.zeros((1, 10, 10)), dims=("c", "y", "x"))}
images = {
"data1_image": sd.models.Image2DModel.parse(
np.zeros((1, 10, 10)), dims=("c", "y", "x"), transformations={"data1": sd.transformations.Identity()}
)
}
sdata = sd.SpatialData(images=images)
return sdata

Expand All @@ -77,9 +81,15 @@ def test_sdata_single_image_with_label():
def test_sdata_multiple_images():
"""Creates an sdata object with multiple images."""
images = {
"data1": sd.models.Image2DModel.parse(np.zeros((1, 10, 10)), dims=("c", "y", "x")),
"data2": sd.models.Image2DModel.parse(np.zeros((1, 10, 10)), dims=("c", "y", "x")),
"data3": sd.models.Image2DModel.parse(np.zeros((1, 10, 10)), dims=("c", "y", "x")),
"data1_image": sd.models.Image2DModel.parse(
np.zeros((1, 10, 10)), dims=("c", "y", "x"), transformations={"data1": sd.transformations.Identity()}
),
"data2_image": sd.models.Image2DModel.parse(
np.zeros((1, 10, 10)), dims=("c", "y", "x"), transformations={"data1": sd.transformations.Identity()}
),
"data3_image": sd.models.Image2DModel.parse(
np.zeros((1, 10, 10)), dims=("c", "y", "x"), transformations={"data1": sd.transformations.Identity()}
),
}
sdata = sd.SpatialData(images=images)
return sdata
Expand Down
36 changes: 36 additions & 0 deletions tests/pl/test_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import matplotlib.pyplot as plt
import pytest


def test_render_images_can_plot_one_cyx_image(request):
sdata = request.getfixturevalue("test_sdata_single_image")

_, ax = plt.subplots(1, 1)

sdata.pl.render_images().pl.show(ax=ax)

assert ax.get_title() == sdata.coordinate_systems[0]


@pytest.mark.parametrize(
"share_coordinate_system",
[
"all",
"two",
"none",
],
)
def test_render_images_can_plot_multiple_cyx_images(share_coordinate_system: str, request):
fun = request.getfixturevalue("get_sdata_with_multiple_images")
sdata = fun(share_coordinate_system)
sdata.pl.render_images().pl.show()
axs = plt.gcf().get_axes()

if share_coordinate_system == "all":
assert len(axs) == 1

elif share_coordinate_system == "two":
assert len(axs) == 2

elif share_coordinate_system == "none":
assert len(axs) == 3
19 changes: 8 additions & 11 deletions tests/pp/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
@pytest.mark.parametrize(
"sdata, keys ",
[
("test_sdata_multiple_images", 0),
("test_sdata_multiple_images", {"a": 0}),
("test_sdata_multiple_images", None),
("test_sdata_multiple_images", ["my_key", 0]),
("get_sdata_with_multiple_images", 0),
("get_sdata_with_multiple_images", {"a": 0}),
("get_sdata_with_multiple_images", None),
("get_sdata_with_multiple_images", ["my_key", 0]),
],
)
def test_typerror_when_key_is_invalid(sdata, keys, request):
"""Tests wether the images inside sdata can be clipped to a bounding box."""

sdata = request.getfixturevalue(sdata)
sdata = request.getfixturevalue(sdata)(share_coordinate_system="all")

with pytest.raises(TypeError):
sdata.pp.get_elements(keys)
Expand All @@ -22,14 +21,12 @@ def test_typerror_when_key_is_invalid(sdata, keys, request):
@pytest.mark.parametrize(
"sdata, keys ",
[
("test_sdata_multiple_images", "data4"),
("test_sdata_multiple_images", ["data1", "data4"]),
("get_sdata_with_multiple_images", "data4"),
("get_sdata_with_multiple_images", ["data1", "data4"]),
],
)
def test_valuerror_when_key_is_of_correct_type_but_not_in_sdata(sdata, keys, request):
"""Tests wether the images inside sdata can be clipped to a bounding box."""

sdata = request.getfixturevalue(sdata)
sdata = request.getfixturevalue(sdata)(share_coordinate_system="all")

with pytest.raises(ValueError):
sdata.pp.get_elements(keys)
Expand Down
85 changes: 1 addition & 84 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,87 +12,4 @@
def test_sdata_fixture(sdata, request):
"""Tests the sdata fixture."""
sdata = request.getfixturevalue(sdata)
assert sdata.images["data1"].shape == (1, 10, 10)


# @pytest.mark.parametrize(
# "sdata",
# [
# "test_sdata_single_image",
# "test_sdata_multiple_images",
# "test_sdata_multiple_images_dims"
# ],
# )
# def test_image_accessor_correct_image_key_string(sdata, request):
# """Tests the image accessor with a correct image key string."""
# sdata = request.getfixturevalue(sdata)
# sdata.im['data1']

# assert sdata.im.i == 'data1'


# @pytest.mark.parametrize(
# "sdata, query",
# [
# ("test_sdata_single_image", ["data1"]),
# ("test_sdata_multiple_images", ["data1"]),
# ("test_sdata_multiple_images", ["data1", "data2"]),
# ("test_sdata_multiple_images", ["data1", "data3"]),
# ("test_sdata_multiple_images_dims", ['data1']),
# ("test_sdata_multiple_images_dims", ['data1', 'data2']),
# ],
# )
# def test_image_accessor_correct_image_key_list(sdata, query, request):
# """Tests the image accessor with a correct image key list."""
# sdata = request.getfixturevalue(sdata)
# sdata.im[query]
# assert sdata.im.i == query


# @pytest.mark.parametrize(
# "sdata",
# [
# "test_sdata_single_image",
# "test_sdata_multiple_images",
# "test_sdata_multiple_images_dims"
# ],
# )
# def test_image_accessor_wrong_correct_image_key_string(sdata, request):
# """Tests the image accessor with a wrong image key string."""
# sdata = request.getfixturevalue(sdata)
# with pytest.raises(AssertionError):
# sdata.im['wrong']


# @pytest.mark.parametrize(
# "sdata",
# [
# "test_sdata_single_image",
# "test_sdata_multiple_images",
# "test_sdata_multiple_images_dims"
# ],
# )
# def test_image_accessor_correct_channel(sdata, request):
# """Tests the image accessor with a wrong image key string."""
# sdata = request.getfixturevalue(sdata)
# sdata.im[0]

# assert isinstance(sdata.im.i, list)
# assert sdata.im.c == 0


# @pytest.mark.parametrize(
# "sdata",
# [
# "test_sdata_single_image",
# "test_sdata_multiple_images",
# "test_sdata_multiple_images_dims"
# ],
# )
# def test_image_accessor_correct_image_key_and_channel(sdata, request):
# """Tests the image accessor with a wrong image key string."""
# sdata = request.getfixturevalue(sdata)
# sdata.im['data1', 0]

# assert isinstance(sdata.im.i, str)
# assert sdata.im.c == 0
assert sdata.images["data1_image"].shape == (1, 10, 10)
8 changes: 4 additions & 4 deletions tests/test_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
@pytest.mark.parametrize(
"sdata, keys",
[
("test_sdata_multiple_images", "data1"),
("test_sdata_multiple_images", ["data1"]),
("test_sdata_multiple_images", ["data1", "data2"]),
("get_sdata_with_multiple_images", "data1"),
("get_sdata_with_multiple_images", ["data1"]),
("get_sdata_with_multiple_images", ["data1", "data2"]),
],
)
def test_can_subset_to_one_or_more_images(sdata, keys, request):
"""Tests whether a subset of images can be selected from the sdata object."""

sdata = request.getfixturevalue(sdata)
sdata = request.getfixturevalue(sdata)(share_coordinate_system="all")

clipped_sdata = sdata.pp.get_elements(keys)

Expand Down