Skip to content

Commit b5e8003

Browse files
committed
refactor(tests): Parameterize group_cmaps tests
1 parent d7e4276 commit b5e8003

File tree

1 file changed

+92
-40
lines changed

1 file changed

+92
-40
lines changed

tests/test_plotting.py

Lines changed: 92 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,16 +1823,92 @@ def test_violin_scale_warning(monkeypatch):
18231823
sc.pl.StackedViolin(adata, adata.var_names[:3], groupby="louvain")
18241824

18251825

1826-
def test_dotplot_group_cmaps(image_comparer):
1826+
# def test_dotplot_group_cmaps(image_comparer):
1827+
# """Check group_cmaps parameter with custom color maps per group."""
1828+
# save_and_compare_images = partial(image_comparer, ROOT, tol=15)
1829+
1830+
# adata = pbmc68k_reduced()
1831+
1832+
# # Use markers with a good range of expression values to check color gradients
1833+
# markers = ["SERPINB1", "IGFBP7", "GNLY", "IFITM1", "IMP3", "UBALD2", "LTB", "CLPP"]
1834+
1835+
# # Define a complete set of colormaps for all groups that will be plotted
1836+
# group_cmaps = {
1837+
# "CD14+ Monocyte": "Greys",
1838+
# "Dendritic": "Purples",
1839+
# "CD8+ Cytotoxic T": "Reds",
1840+
# "CD8+/CD45RA+ Naive Cytotoxic": "Greens",
1841+
# "CD4+/CD45RA+/CD25- Naive T": "Oranges",
1842+
# "CD4+/CD25 T Reg": "Blues",
1843+
# "CD4+/CD45RO+ Memory": "hot",
1844+
# "CD19+ B": "cool",
1845+
# "CD56+ NK": "winter",
1846+
# "CD34+": "copper",
1847+
# }
1848+
1849+
# # Call dotplot with new parameter
1850+
# sc.pl.dotplot(
1851+
# adata,
1852+
# markers,
1853+
# groupby="bulk_labels",
1854+
# group_cmaps=group_cmaps, # Define custom color maps for each group from 'groupby'
1855+
# dendrogram=True, # Test with dendrogram reordering
1856+
# show=False,
1857+
# )
1858+
1859+
# # This will try to save the plot and compare it to a reference
1860+
# save_and_compare_images("dotplot_group_cmaps")
1861+
1862+
1863+
# def test_dotplot_group_cmaps_swap_axes(image_comparer):
1864+
# """Check that group_cmaps works with swapped axes."""
1865+
# save_and_compare_images = partial(image_comparer, ROOT, tol=15)
1866+
1867+
# adata = pbmc68k_reduced()
1868+
1869+
# # Use markers with a good range of expression values to check color gradients
1870+
# markers = ["SERPINB1", "IGFBP7", "GNLY", "IFITM1", "IMP3", "UBALD2", "LTB", "CLPP"]
1871+
1872+
# # Define a complete set of colormaps for all groups that will be plotted
1873+
# group_cmaps = {
1874+
# "CD14+ Monocyte": "Greys",
1875+
# "Dendritic": "Purples",
1876+
# "CD8+ Cytotoxic T": "Reds",
1877+
# "CD8+/CD45RA+ Naive Cytotoxic": "Greens",
1878+
# "CD4+/CD45RA+/CD25- Naive T": "Oranges",
1879+
# "CD4+/CD25 T Reg": "Blues",
1880+
# "CD4+/CD45RO+ Memory": "hot",
1881+
# "CD19+ B": "cool",
1882+
# "CD56+ NK": "winter",
1883+
# "CD34+": "copper",
1884+
# }
1885+
1886+
# sc.pl.dotplot(
1887+
# adata,
1888+
# markers,
1889+
# groupby="bulk_labels",
1890+
# group_cmaps=group_cmaps,
1891+
# dendrogram=True,
1892+
# swap_axes=True, # Check that group_cmaps works with swapped axes
1893+
# show=False,
1894+
# )
1895+
# save_and_compare_images("dotplot_group_cmaps_swap_axes")
1896+
1897+
params_dotplot_group_cmaps = [
1898+
pytest.param("dotplot_group_cmaps", False, id="default"),
1899+
pytest.param("dotplot_group_cmaps_swap_axes", True, id="swap_axes"),
1900+
]
1901+
1902+
1903+
@pytest.mark.parametrize(("name", "swap_axes"), params_dotplot_group_cmaps)
1904+
def test_dotplot_group_cmaps(image_comparer, name, swap_axes):
18271905
"""Check group_cmaps parameter with custom color maps per group."""
18281906
save_and_compare_images = partial(image_comparer, ROOT, tol=15)
18291907

18301908
adata = pbmc68k_reduced()
18311909

1832-
# Use markers with a good range of expression values to check color gradients
18331910
markers = ["SERPINB1", "IGFBP7", "GNLY", "IFITM1", "IMP3", "UBALD2", "LTB", "CLPP"]
18341911

1835-
# Define a complete set of colormaps for all groups that will be plotted
18361912
group_cmaps = {
18371913
"CD14+ Monocyte": "Greys",
18381914
"Dendritic": "Purples",
@@ -1846,50 +1922,26 @@ def test_dotplot_group_cmaps(image_comparer):
18461922
"CD34+": "copper",
18471923
}
18481924

1849-
# Call dotplot with new parameter
18501925
sc.pl.dotplot(
18511926
adata,
18521927
markers,
18531928
groupby="bulk_labels",
1854-
group_cmaps=group_cmaps, # Define custom color maps for each group from 'groupby'
1855-
dendrogram=True, # Test with dendrogram reordering
1929+
group_cmaps=group_cmaps,
1930+
dendrogram=True,
1931+
swap_axes=swap_axes,
18561932
show=False,
18571933
)
1934+
save_and_compare_images(name)
18581935

1859-
# This will try to save the plot and compare it to a reference
1860-
save_and_compare_images("dotplot_group_cmaps")
1861-
1862-
1863-
def test_dotplot_group_cmaps_swap_axes(image_comparer):
1864-
"""Check that group_cmaps works with swapped axes."""
1865-
save_and_compare_images = partial(image_comparer, ROOT, tol=15)
18661936

1937+
def test_dotplot_group_cmaps_raises_error():
1938+
"""Check that a ValueError is raised for missing groups in group_cmaps."""
18671939
adata = pbmc68k_reduced()
1940+
markers = ["CD79A"]
1941+
# Intentionally incomplete dictionary to trigger the error
1942+
group_cmaps = {"CD19+ B": "Blues"}
18681943

1869-
# Use markers with a good range of expression values to check color gradients
1870-
markers = ["SERPINB1", "IGFBP7", "GNLY", "IFITM1", "IMP3", "UBALD2", "LTB", "CLPP"]
1871-
1872-
# Define a complete set of colormaps for all groups that will be plotted
1873-
group_cmaps = {
1874-
"CD14+ Monocyte": "Greys",
1875-
"Dendritic": "Purples",
1876-
"CD8+ Cytotoxic T": "Reds",
1877-
"CD8+/CD45RA+ Naive Cytotoxic": "Greens",
1878-
"CD4+/CD45RA+/CD25- Naive T": "Oranges",
1879-
"CD4+/CD25 T Reg": "Blues",
1880-
"CD4+/CD45RO+ Memory": "hot",
1881-
"CD19+ B": "cool",
1882-
"CD56+ NK": "winter",
1883-
"CD34+": "copper",
1884-
}
1885-
1886-
sc.pl.dotplot(
1887-
adata,
1888-
markers,
1889-
groupby="bulk_labels",
1890-
group_cmaps=group_cmaps,
1891-
dendrogram=True,
1892-
swap_axes=True, # Check that group_cmaps works with swapped axes
1893-
show=False,
1894-
)
1895-
save_and_compare_images("dotplot_group_cmaps_swap_axes")
1944+
with pytest.raises(ValueError, match="missing from the `group_cmaps` dictionary"):
1945+
sc.pl.dotplot(
1946+
adata, markers, groupby="bulk_labels", group_cmaps=group_cmaps, show=False
1947+
)

0 commit comments

Comments
 (0)