Skip to content

Commit ac062d8

Browse files
Fix tests in main (#258)
* updated target image with artficat from runner * increased DPI to reduce test flakyness due to pixel precision * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * added tight layout * Regenerated images * added images from runner * attempt to force the runner to a fixed res * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * bump * added figures from runner * attempt to fix inconsistency across runners --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f442785 commit ac062d8

File tree

96 files changed

+40
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+40
-101
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ docs = [
4747
test = [
4848
"pytest",
4949
"pytest-cov",
50+
"pooch", # for scipy.datasets module
5051
]
5152
# this will be used by readthedocs and will make pip also look for pre-releases, generally installing the latest available version
5253
pre = [

pyproject.toml.rej

Lines changed: 0 additions & 63 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.
119 KB
76.5 KB
50.9 KB
52.8 KB
50.9 KB
52.8 KB
54.6 KB
28.3 KB
21.5 KB
52 KB
12.6 KB
23.6 KB
34.4 KB
5.83 KB
8.03 KB
20.8 KB
7.65 KB
8.44 KB
4.84 KB
9.79 KB
8.96 KB
8.67 KB
7.53 KB
41.6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/conftest.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from geopandas import GeoDataFrame
1515
from matplotlib.testing.compare import compare_images
1616
from multiscale_spatial_image import MultiscaleSpatialImage
17-
from numpy.random import default_rng
1817
from shapely.geometry import MultiPolygon, Polygon
1918
from spatial_image import SpatialImage
2019
from spatialdata import SpatialData
@@ -35,9 +34,9 @@
3534
EXPECTED = HERE / "_images"
3635
ACTUAL = HERE / "figures"
3736
TOL = 60
38-
DPI = 40
37+
DPI = 80
3938

40-
RNG = default_rng()
39+
RNG = np.random.default_rng(seed=42)
4140

4241

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

377+
width, height = 400, 300 # fixed dimensions so runners don't change
378+
fig = plt.gcf()
379+
fig.set_size_inches(width / DPI, height / DPI)
380+
fig.set_dpi(DPI)
381+
382+
# Apply constrained layout and save the plot
383+
fig.set_constrained_layout(True)
378384
plt.savefig(out_path, dpi=DPI)
379385
plt.close()
380386

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

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

tests/pl/test_get_extent.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
from spatialdata.models import PointsModel, ShapesModel
1212
from spatialdata.transformations import Affine, set_transformation
1313

14-
from tests.conftest import PlotTester, PlotTesterMeta
14+
from tests.conftest import DPI, PlotTester, PlotTesterMeta
1515

16+
RNG = np.random.default_rng(seed=42)
1617
sc.pl.set_rcParams_defaults()
17-
sc.set_figure_params(dpi=40, color_map="viridis")
18+
sc.set_figure_params(dpi=DPI, color_map="viridis")
1819
matplotlib.use("agg") # same as GitHub action runner
1920
_ = spatialdata_plot
21+
plt.tight_layout()
2022

2123
# WARNING:
2224
# 1. all classes must both subclass PlotTester and use metaclass=PlotTesterMeta

tests/pl/test_render_images.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import dask.array as da
22
import matplotlib
3+
import numpy as np
34
import scanpy as sc
45
import spatialdata_plot # noqa: F401
56
from spatial_image import to_spatial_image
67
from spatialdata import SpatialData
78

8-
from tests.conftest import PlotTester, PlotTesterMeta
9+
from tests.conftest import DPI, PlotTester, PlotTesterMeta
910

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

tests/pl/test_render_labels.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
from spatialdata._core.query.relational_query import _get_unique_label_values_as_index
1111
from spatialdata.models import TableModel
1212

13-
from tests.conftest import PlotTester, PlotTesterMeta
13+
from tests.conftest import DPI, PlotTester, PlotTesterMeta
1414

15+
RNG = np.random.default_rng(seed=42)
1516
sc.pl.set_rcParams_defaults()
16-
sc.set_figure_params(dpi=40, color_map="viridis")
17+
sc.set_figure_params(dpi=DPI, color_map="viridis")
1718
matplotlib.use("agg") # same as GitHub action runner
1819
_ = spatialdata_plot
1920

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

120120
def test_plot_multiscale_label_categorical_color(self, sdata_blobs: SpatialData):
121+
# recreate RNG to get same plot acorss 3.9 and 3.10 workers
122+
RNG = np.random.default_rng(seed=42)
123+
121124
n_obs = max(_get_unique_label_values_as_index(sdata_blobs["blobs_multiscale_labels"]))
122125
adata = AnnData(
123126
RNG.normal(size=(n_obs, 10)), obs=pd.DataFrame(RNG.normal(size=(n_obs, 3)), columns=["a", "b", "c"])
@@ -133,19 +136,3 @@ def test_plot_multiscale_label_categorical_color(self, sdata_blobs: SpatialData)
133136

134137
sdata_blobs["other_table"].obs["category"] = sdata_blobs["other_table"].obs["category"].astype("category")
135138
sdata_blobs.pl.render_labels("blobs_multiscale_labels", color="category").pl.show()
136-
137-
# def test_plot_multiscale_label_coercable_categorical_color(self, sdata_blobs: SpatialData):
138-
# n_obs = max(_get_unique_label_values_as_index(sdata_blobs["blobs_multiscale_labels"]))
139-
# adata = AnnData(
140-
# RNG.normal(size=(n_obs, 10)), obs=pd.DataFrame(RNG.normal(size=(n_obs, 3)), columns=["a", "b", "c"])
141-
# )
142-
# adata.obs["instance_id"] = np.arange(adata.n_obs)
143-
# adata.obs["category"] = RNG.choice(["a", "b", "c"], size=adata.n_obs)
144-
# adata.obs["instance_id"] = list(range(adata.n_obs))
145-
# adata.obs["region"] = "blobs_multiscale_labels"
146-
# table = TableModel.parse(
147-
# adata=adata, region_key="region", instance_key="instance_id", region="blobs_multiscale_labels"
148-
# )
149-
# sdata_blobs["other_table"] = table
150-
#
151-
# sdata_blobs.pl.render_labels("blobs_multiscale_labels", color="category").pl.show()

tests/pl/test_render_points.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from spatialdata import SpatialData
88
from spatialdata.models import TableModel
99

10-
from tests.conftest import PlotTester, PlotTesterMeta
10+
from tests.conftest import DPI, PlotTester, PlotTesterMeta
1111

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

tests/pl/test_render_shapes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
from spatialdata import SpatialData
1111
from spatialdata.models import ShapesModel, TableModel
1212

13-
from tests.conftest import PlotTester, PlotTesterMeta
13+
from tests.conftest import DPI, PlotTester, PlotTesterMeta
1414

15+
RNG = np.random.default_rng(seed=42)
1516
sc.pl.set_rcParams_defaults()
16-
sc.set_figure_params(dpi=40, color_map="viridis")
17+
sc.set_figure_params(dpi=DPI, color_map="viridis")
1718
matplotlib.use("agg") # same as GitHub action runner
1819
_ = spatialdata_plot
1920

20-
RNG = np.random.default_rng(seed=42)
2121
# WARNING:
2222
# 1. all classes must both subclass PlotTester and use metaclass=PlotTesterMeta
2323
# 2. tests which produce a plot must be prefixed with `test_plot_`

tests/pl/test_show.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import matplotlib
2+
import numpy as np
23
import scanpy as sc
34
import spatialdata_plot # noqa: F401
45
from spatialdata import SpatialData
56

6-
from tests.conftest import PlotTester, PlotTesterMeta
7+
from tests.conftest import DPI, PlotTester, PlotTesterMeta
78

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

tests/pl/test_upstream_plots.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import matplotlib
44
import matplotlib.pyplot as plt
5+
import numpy as np
56
import scanpy as sc
67
import spatialdata_plot # noqa: F401
78
from spatialdata import SpatialData
@@ -14,10 +15,11 @@
1415
set_transformation,
1516
)
1617

17-
from tests.conftest import PlotTester, PlotTesterMeta
18+
from tests.conftest import DPI, PlotTester, PlotTesterMeta
1819

19-
sc.pl.set_rcParams_defaults()
20-
sc.set_figure_params(dpi=40, color_map="viridis")
20+
RNG = np.random.default_rng(seed=42)
21+
# sc.pl.set_rcParams_defaults()
22+
sc.set_figure_params(dpi=DPI, color_map="viridis")
2123
matplotlib.use("agg") # same as GitHub action runner
2224
_ = spatialdata_plot
2325

0 commit comments

Comments
 (0)