Skip to content

Fix tests in main #258

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 12 commits into from
May 16, 2024
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ docs = [
test = [
"pytest",
"pytest-cov",
"pooch", # for scipy.datasets module
]
# this will be used by readthedocs and will make pip also look for pre-releases, generally installing the latest available version
pre = [
Expand Down
63 changes: 0 additions & 63 deletions pyproject.toml.rej

This file was deleted.

Binary file modified tests/_images/Extent_correct_plot_after_transformations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Extent_extent_of_img_full_canvas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Extent_extent_of_partial_canvas_on_full_canvas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Extent_extent_of_points_partial_canvas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file modified tests/_images/Images_can_do_rasterization.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_normalize_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_pass_cmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_pass_cmap_list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_pass_cmap_to_each_channel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_pass_cmap_to_single_channel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_pass_color_to_each_channel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_pass_color_to_single_channel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_pass_str_cmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_pass_str_cmap_list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_render_a_single_channel_from_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_render_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_render_multiscale_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_render_two_channels_from_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Images_can_stack_render_images.png
Binary file modified tests/_images/Images_can_stop_rasterization_with_scale_full.png
Binary file modified tests/_images/Labels_can_color_labels.png
Binary file modified tests/_images/Labels_can_color_labels_by_continuous_variable.png
Binary file modified tests/_images/Labels_can_do_rasterization.png
Binary file modified tests/_images/Labels_can_render_labels.png
Binary file modified tests/_images/Labels_can_render_multiscale_labels.png
Binary file modified tests/_images/Labels_can_stack_render_labels.png
Binary file modified tests/_images/Labels_can_stop_rasterization_with_scale_full.png
Binary file modified tests/_images/Labels_label_categorical_color.png
Binary file modified tests/_images/Labels_multiscale_label_categorical_color.png
Binary file modified tests/_images/Points_can_filter_with_groups.png
Binary file modified tests/_images/Points_can_filter_with_groups_default_palette.png
Binary file modified tests/_images/Points_can_render_points.png
Binary file modified tests/_images/Points_can_stack_render_points.png
Binary file modified tests/_images/Points_color_recognises_actual_color_as_color.png
Binary file modified tests/_images/Points_coloring_with_cmap.png
Binary file modified tests/_images/Points_coloring_with_palette.png
Binary file modified tests/_images/Points_points_categorical_color.png
Binary file modified tests/_images/Points_points_coercable_categorical_color.png
Binary file modified tests/_images/Shapes_can_color_from_geodataframe.png
Binary file modified tests/_images/Shapes_can_filter_with_groups.png
Binary file modified tests/_images/Shapes_can_plot_shapes_after_spatial_query.png
Binary file modified tests/_images/Shapes_can_render_circles.png
Binary file modified tests/_images/Shapes_can_render_circles_with_colored_outline.png
Binary file modified tests/_images/Shapes_can_render_circles_with_outline.png
Binary file modified tests/_images/Shapes_can_render_empty_geometry.png
Binary file modified tests/_images/Shapes_can_render_multipolygons.png
Binary file modified tests/_images/Shapes_can_render_polygons.png
Binary file modified tests/_images/Shapes_can_render_polygons_with_outline.png
Binary file modified tests/_images/Shapes_can_scale_shapes.png
Binary file modified tests/_images/Shapes_can_stack_render_shapes.png
Binary file modified tests/_images/Shapes_color_recognises_actual_color_as_color.png
Binary file modified tests/_images/Shapes_colorbar_can_be_normalised.png
Binary file modified tests/_images/Shapes_colorbar_respects_input_limits.png
Binary file modified tests/_images/Shapes_coloring_with_palette.png
Binary file modified tests/_images/Shapes_shapes_categorical_color.png
Binary file modified tests/_images/Shapes_shapes_coercable_categorical_color.png
Binary file modified tests/_images/Show_pad_extent_adds_padding.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
14 changes: 10 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from geopandas import GeoDataFrame
from matplotlib.testing.compare import compare_images
from multiscale_spatial_image import MultiscaleSpatialImage
from numpy.random import default_rng
from shapely.geometry import MultiPolygon, Polygon
from spatial_image import SpatialImage
from spatialdata import SpatialData
Expand All @@ -35,9 +34,9 @@
EXPECTED = HERE / "_images"
ACTUAL = HERE / "figures"
TOL = 60
DPI = 40
DPI = 80

RNG = default_rng()
RNG = np.random.default_rng(seed=42)


@pytest.fixture()
Expand Down Expand Up @@ -375,12 +374,19 @@ def compare(cls, basename: str, tolerance: Optional[float] = None):
ACTUAL.mkdir(parents=True, exist_ok=True)
out_path = ACTUAL / f"{basename}.png"

width, height = 400, 300 # fixed dimensions so runners don't change
fig = plt.gcf()
fig.set_size_inches(width / DPI, height / DPI)
fig.set_dpi(DPI)

# Apply constrained layout and save the plot
fig.set_constrained_layout(True)
plt.savefig(out_path, dpi=DPI)
plt.close()

if tolerance is None:
# see https://github.com/scverse/squidpy/pull/302
tolerance = 2 * TOL if "Napari" in str(basename) else TOL
tolerance = 2 * TOL if "Napari" in basename else TOL

res = compare_images(str(EXPECTED / f"{basename}.png"), str(out_path), tolerance)

Expand Down
6 changes: 4 additions & 2 deletions tests/pl/test_get_extent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
from spatialdata.models import PointsModel, ShapesModel
from spatialdata.transformations import Affine, set_transformation

from tests.conftest import PlotTester, PlotTesterMeta
from tests.conftest import DPI, PlotTester, PlotTesterMeta

RNG = np.random.default_rng(seed=42)
sc.pl.set_rcParams_defaults()
sc.set_figure_params(dpi=40, color_map="viridis")
sc.set_figure_params(dpi=DPI, color_map="viridis")
matplotlib.use("agg") # same as GitHub action runner
_ = spatialdata_plot
plt.tight_layout()

# WARNING:
# 1. all classes must both subclass PlotTester and use metaclass=PlotTesterMeta
Expand Down
6 changes: 4 additions & 2 deletions tests/pl/test_render_images.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import dask.array as da
import matplotlib
import numpy as np
import scanpy as sc
import spatialdata_plot # noqa: F401
from spatial_image import to_spatial_image
from spatialdata import SpatialData

from tests.conftest import PlotTester, PlotTesterMeta
from tests.conftest import DPI, PlotTester, PlotTesterMeta

RNG = np.random.default_rng(seed=42)
sc.pl.set_rcParams_defaults()
sc.set_figure_params(dpi=40, color_map="viridis")
sc.set_figure_params(dpi=DPI, color_map="viridis")
matplotlib.use("agg") # same as GitHub action runner
_ = spatialdata_plot

Expand Down
27 changes: 7 additions & 20 deletions tests/pl/test_render_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from spatialdata._core.query.relational_query import _get_unique_label_values_as_index
from spatialdata.models import TableModel

from tests.conftest import PlotTester, PlotTesterMeta
from tests.conftest import DPI, PlotTester, PlotTesterMeta

RNG = np.random.default_rng(seed=42)
sc.pl.set_rcParams_defaults()
sc.set_figure_params(dpi=40, color_map="viridis")
sc.set_figure_params(dpi=DPI, color_map="viridis")
matplotlib.use("agg") # same as GitHub action runner
_ = spatialdata_plot

RNG = np.random.default_rng(seed=42)
# WARNING:
# 1. all classes must both subclass PlotTester and use metaclass=PlotTesterMeta
# 2. tests which produce a plot must be prefixed with `test_plot_`
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_plot_can_stack_render_labels(self, sdata_blobs: SpatialData):
elements="blobs_labels", na_color="red", fill_alpha=1, outline_alpha=0, outline=False
)
.pl.render_labels(
elements="blobs_labels", na_color="blue", fill_alpha=0, outline_alpha=1, outline=True, contour_px=10
elements="blobs_labels", na_color="blue", fill_alpha=0, outline_alpha=1, outline=True, contour_px=15
)
.pl.show()
)
Expand Down Expand Up @@ -118,6 +118,9 @@ def test_plot_label_categorical_color(self, sdata_blobs: SpatialData):
sdata_blobs.pl.render_labels("blobs_labels", color="category").pl.show()

def test_plot_multiscale_label_categorical_color(self, sdata_blobs: SpatialData):
# recreate RNG to get same plot acorss 3.9 and 3.10 workers
RNG = np.random.default_rng(seed=42)

n_obs = max(_get_unique_label_values_as_index(sdata_blobs["blobs_multiscale_labels"]))
adata = AnnData(
RNG.normal(size=(n_obs, 10)), obs=pd.DataFrame(RNG.normal(size=(n_obs, 3)), columns=["a", "b", "c"])
Expand All @@ -133,19 +136,3 @@ def test_plot_multiscale_label_categorical_color(self, sdata_blobs: SpatialData)

sdata_blobs["other_table"].obs["category"] = sdata_blobs["other_table"].obs["category"].astype("category")
sdata_blobs.pl.render_labels("blobs_multiscale_labels", color="category").pl.show()

# def test_plot_multiscale_label_coercable_categorical_color(self, sdata_blobs: SpatialData):
# n_obs = max(_get_unique_label_values_as_index(sdata_blobs["blobs_multiscale_labels"]))
# adata = AnnData(
# RNG.normal(size=(n_obs, 10)), obs=pd.DataFrame(RNG.normal(size=(n_obs, 3)), columns=["a", "b", "c"])
# )
# adata.obs["instance_id"] = np.arange(adata.n_obs)
# adata.obs["category"] = RNG.choice(["a", "b", "c"], size=adata.n_obs)
# adata.obs["instance_id"] = list(range(adata.n_obs))
# adata.obs["region"] = "blobs_multiscale_labels"
# table = TableModel.parse(
# adata=adata, region_key="region", instance_key="instance_id", region="blobs_multiscale_labels"
# )
# sdata_blobs["other_table"] = table
#
# sdata_blobs.pl.render_labels("blobs_multiscale_labels", color="category").pl.show()
4 changes: 2 additions & 2 deletions tests/pl/test_render_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from spatialdata import SpatialData
from spatialdata.models import TableModel

from tests.conftest import PlotTester, PlotTesterMeta
from tests.conftest import DPI, PlotTester, PlotTesterMeta

RNG = np.random.default_rng(seed=42)
sc.pl.set_rcParams_defaults()
sc.set_figure_params(dpi=40, color_map="viridis")
sc.set_figure_params(dpi=DPI, color_map="viridis")
matplotlib.use("agg") # same as GitHub action runner
_ = spatialdata_plot

Expand Down
6 changes: 3 additions & 3 deletions tests/pl/test_render_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from spatialdata import SpatialData
from spatialdata.models import ShapesModel, TableModel

from tests.conftest import PlotTester, PlotTesterMeta
from tests.conftest import DPI, PlotTester, PlotTesterMeta

RNG = np.random.default_rng(seed=42)
sc.pl.set_rcParams_defaults()
sc.set_figure_params(dpi=40, color_map="viridis")
sc.set_figure_params(dpi=DPI, color_map="viridis")
matplotlib.use("agg") # same as GitHub action runner
_ = spatialdata_plot

RNG = np.random.default_rng(seed=42)
# WARNING:
# 1. all classes must both subclass PlotTester and use metaclass=PlotTesterMeta
# 2. tests which produce a plot must be prefixed with `test_plot_`
Expand Down
6 changes: 4 additions & 2 deletions tests/pl/test_show.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import matplotlib
import numpy as np
import scanpy as sc
import spatialdata_plot # noqa: F401
from spatialdata import SpatialData

from tests.conftest import PlotTester, PlotTesterMeta
from tests.conftest import DPI, PlotTester, PlotTesterMeta

RNG = np.random.default_rng(seed=42)
sc.pl.set_rcParams_defaults()
sc.set_figure_params(dpi=40, color_map="viridis")
sc.set_figure_params(dpi=DPI, color_map="viridis")
matplotlib.use("agg") # same as GitHub action runner
_ = spatialdata_plot

Expand Down
8 changes: 5 additions & 3 deletions tests/pl/test_upstream_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import scanpy as sc
import spatialdata_plot # noqa: F401
from spatialdata import SpatialData
Expand All @@ -14,10 +15,11 @@
set_transformation,
)

from tests.conftest import PlotTester, PlotTesterMeta
from tests.conftest import DPI, PlotTester, PlotTesterMeta

sc.pl.set_rcParams_defaults()
sc.set_figure_params(dpi=40, color_map="viridis")
RNG = np.random.default_rng(seed=42)
# sc.pl.set_rcParams_defaults()
sc.set_figure_params(dpi=DPI, color_map="viridis")
matplotlib.use("agg") # same as GitHub action runner
_ = spatialdata_plot

Expand Down
Loading