Skip to content

Commit 9ca9302

Browse files
committed
Failing test that demonstrates #142
1 parent 76dd23b commit 9ca9302

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Diff for: src/napari_matplotlib/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def apply_napari_colorscheme(self, ax: Axes) -> None:
8888

8989
ax.xaxis.label.set_color(text_colour)
9090
ax.yaxis.label.set_color(text_colour)
91+
# ax.set_xlabel(ax.get_xlabel, color=text_colour)
9192

9293
# changing colors of axes labels
9394
ax.tick_params(axis="x", colors=text_colour)

Diff for: src/napari_matplotlib/tests/test_theme.py

+36
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import napari
2+
import numpy as np
23
import pytest
34

5+
from napari_matplotlib import ScatterWidget
46
from napari_matplotlib.base import NapariMPLWidget
57

68

@@ -49,3 +51,37 @@ def test_theme_background_check(make_napari_viewer):
4951
_mock_up_theme()
5052
viewer.theme = "blue"
5153
assert widget._theme_has_light_bg() is True
54+
55+
56+
@pytest.mark.parametrize(
57+
"theme_name, expected_text_colour",
58+
[("dark", "white"), ("light", "black")],
59+
)
60+
def test_titles_respect_theme(
61+
make_napari_viewer, theme_name, expected_text_colour
62+
):
63+
"""
64+
Test that the axis labels and titles are the correct color for the napari theme.
65+
"""
66+
viewer = make_napari_viewer()
67+
widget = ScatterWidget(viewer)
68+
viewer.theme = theme_name
69+
70+
# make a scatter plot of two random layers
71+
viewer.add_image(np.random.random((10, 10)), name="first test image")
72+
viewer.add_image(np.random.random((10, 10)), name="second test image")
73+
viewer.layers.selection.clear()
74+
viewer.layers.selection.add(viewer.layers[0])
75+
viewer.layers.selection.add(viewer.layers[1])
76+
77+
ax = widget.figure.gca()
78+
79+
# sanity test to make sure we've got the correct image names
80+
assert ax.xaxis.label.get_text() == "first test image"
81+
assert ax.yaxis.label.get_text() == "second test image"
82+
83+
# print(dir(ax.yaxis.label))
84+
# TODO: put checks of the axis tick labels here
85+
86+
assert ax.xaxis.label.get_color() == expected_text_colour
87+
assert ax.yaxis.label.get_color() == expected_text_colour

0 commit comments

Comments
 (0)