Skip to content

Commit af7c9aa

Browse files
committed
Trim density test suite
Consolidate 8 single-assertion unit tests into 2 parametrized ones (rejections and warn-and-ignores) and drop 3 low-value cases (forces_datashader, chaining_composes, default_path_unchanged) that either duplicate other tests or assert tautologies. Folds the "no warnings at default" check into the combined defaults test. Drop two redundant visual tests: density_how_log (linear and eq_hist already bracket the intensity-mapping range) and density_categorical_with_groups (groups filtering shares no code with density; covered elsewhere). Down from 12 + 5 to 4 + 3 tests with the same coverage of decision points.
1 parent c8ddc3c commit af7c9aa

3 files changed

Lines changed: 27 additions & 66 deletions

File tree

-35.6 KB
Binary file not shown.
-55.1 KB
Binary file not shown.

tests/pl/test_render_points.py

Lines changed: 27 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,6 @@ def test_plot_density_plain(self, sdata_dense_points: SpatialData):
178178
def test_plot_density_categorical(self, sdata_dense_points: SpatialData):
179179
sdata_dense_points.pl.render_points("dense_points", color="gene", density=True).pl.show()
180180

181-
def test_plot_density_categorical_with_groups(self, sdata_dense_points: SpatialData):
182-
sdata_dense_points.pl.render_points(
183-
"dense_points", color="gene", groups=["gene_a", "gene_b"], density=True
184-
).pl.show()
185-
186-
def test_plot_density_how_log(self, sdata_dense_points: SpatialData):
187-
sdata_dense_points.pl.render_points("dense_points", density=True, density_how="log").pl.show()
188-
189181
def test_plot_density_how_eq_hist(self, sdata_dense_points: SpatialData):
190182
sdata_dense_points.pl.render_points("dense_points", density=True, density_how="eq_hist").pl.show()
191183

@@ -1202,68 +1194,37 @@ def test_datashader_canvas_from_empty_dataframe_does_not_crash():
12021194
# ---------------------------------------------------------------------------
12031195

12041196

1205-
def test_density_rejects_continuous_color(sdata_blobs: SpatialData):
1206-
with pytest.raises(ValueError, match="density=True is only supported"):
1207-
sdata_blobs.pl.render_points("blobs_points", color="instance_id", density=True).pl.show()
1197+
@pytest.mark.parametrize(
1198+
("kwargs", "match"),
1199+
[
1200+
({"color": "instance_id"}, "density=True is only supported"),
1201+
({"color": "red"}, "literal color is ambiguous"),
1202+
({"method": "matplotlib"}, "datashader backend"),
1203+
({"density_how": "magic"}, "density_how"),
1204+
],
1205+
)
1206+
def test_density_rejects_invalid_combinations(sdata_blobs: SpatialData, kwargs, match):
1207+
with pytest.raises(ValueError, match=match):
1208+
sdata_blobs.pl.render_points("blobs_points", density=True, **kwargs).pl.show()
12081209
plt.close("all")
12091210

12101211

1211-
def test_density_rejects_literal_color(sdata_blobs: SpatialData):
1212-
with pytest.raises(ValueError, match="literal color is ambiguous"):
1213-
sdata_blobs.pl.render_points("blobs_points", color="red", density=True)
1214-
1215-
1216-
def test_density_rejects_matplotlib_method(sdata_blobs: SpatialData):
1217-
with pytest.raises(ValueError, match="datashader backend"):
1218-
sdata_blobs.pl.render_points("blobs_points", density=True, method="matplotlib")
1219-
1220-
1221-
def test_density_rejects_invalid_density_how(sdata_blobs: SpatialData):
1222-
with pytest.raises(ValueError, match="density_how"):
1223-
sdata_blobs.pl.render_points("blobs_points", density=True, density_how="magic")
1224-
1225-
1226-
def test_density_warns_on_ignored_size(sdata_blobs: SpatialData):
1227-
with pytest.warns(UserWarning, match="size is ignored when density=True"):
1228-
sdata_blobs.pl.render_points("blobs_points", density=True, size=5.0)
1229-
1230-
1231-
def test_density_warns_on_ignored_transfunc(sdata_blobs: SpatialData):
1232-
with pytest.warns(UserWarning, match="transfunc is ignored when density=True"):
1233-
sdata_blobs.pl.render_points("blobs_points", density=True, transfunc=lambda x: x)
1234-
1235-
1236-
def test_density_warns_on_ignored_norm(sdata_blobs: SpatialData):
1237-
with pytest.warns(UserWarning, match="norm.vmin/vmax are ignored when density=True"):
1238-
sdata_blobs.pl.render_points("blobs_points", density=True, norm=Normalize(vmin=0, vmax=1))
1239-
1240-
1241-
def test_density_warns_on_ignored_datashader_reduction(sdata_blobs: SpatialData):
1242-
with pytest.warns(UserWarning, match="datashader_reduction is ignored when density=True"):
1243-
sdata_blobs.pl.render_points("blobs_points", density=True, datashader_reduction="mean")
1244-
1245-
1246-
def test_density_no_warnings_at_default_params(sdata_blobs: SpatialData, recwarn):
1247-
sdata_blobs.pl.render_points("blobs_points", density=True)
1248-
assert not any(("ignored when density=True" in str(w.message)) for w in recwarn.list)
1212+
@pytest.mark.parametrize(
1213+
("kwargs", "match"),
1214+
[
1215+
({"size": 5.0}, "size is ignored"),
1216+
({"transfunc": lambda x: x}, "transfunc is ignored"),
1217+
({"norm": Normalize(vmin=0, vmax=1)}, "norm.vmin/vmax are ignored"),
1218+
({"datashader_reduction": "mean"}, "datashader_reduction is ignored"),
1219+
],
1220+
)
1221+
def test_density_warns_on_ignored_params(sdata_blobs: SpatialData, kwargs, match):
1222+
with pytest.warns(UserWarning, match=match):
1223+
sdata_blobs.pl.render_points("blobs_points", density=True, **kwargs)
12491224

12501225

1251-
def test_density_forces_datashader_when_method_none(sdata_blobs: SpatialData):
1226+
def test_density_defaults_silent_and_force_datashader(sdata_blobs: SpatialData, recwarn):
12521227
out = sdata_blobs.pl.render_points("blobs_points", density=True)
12531228
last = list(out.plotting_tree.values())[-1]
1254-
assert last.method == "datashader"
1255-
assert last.density is True
1256-
assert last.density_how == "linear"
1257-
1258-
1259-
def test_density_chaining_composes(sdata_blobs: SpatialData):
1260-
sdata_blobs.pl.render_points("blobs_points").pl.render_points("blobs_points", density=True).pl.show()
1261-
plt.close("all")
1262-
1263-
1264-
def test_render_points_default_path_unchanged(sdata_blobs: SpatialData):
1265-
# smoke check: density=False (the default) must keep behaving as before
1266-
out = sdata_blobs.pl.render_points("blobs_points")
1267-
last = list(out.plotting_tree.values())[-1]
1268-
assert last.density is False
1269-
assert last.density_how == "linear"
1229+
assert (last.density, last.density_how, last.method) == (True, "linear", "datashader")
1230+
assert not any("ignored when density=True" in str(w.message) for w in recwarn.list)

0 commit comments

Comments
 (0)