Skip to content

Commit 6af9ce0

Browse files
committed
Test to guard against re-introducing #64.
Use plt.subplots for safety. And no longer need copy.deepcopy. Save eyes and make a lovely histogram.
1 parent 3d50618 commit 6af9ce0

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Loading

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

+30
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,33 @@ def test_titles_respect_theme(
8888

8989
assert ax.xaxis.label.get_color() == expected_text_colour
9090
assert ax.yaxis.label.get_color() == expected_text_colour
91+
92+
93+
@pytest.mark.mpl_image_compare
94+
def test_no_theme_side_effects(make_napari_viewer):
95+
"""Ensure that napari-matplotlib doesn't pollute the globally set style.
96+
97+
A MWE to guard aganst issue matplotlib/#64. Should always reproduce a plot
98+
with the default matplotlib style.
99+
"""
100+
import matplotlib.pyplot as plt
101+
102+
np.random.seed(12345)
103+
104+
# should not affect global matplotlib plot style
105+
viewer = make_napari_viewer()
106+
viewer.theme = "dark"
107+
NapariMPLWidget(viewer)
108+
109+
# some plotting unrelated to napari-matplotlib
110+
normal_dist = np.random.normal(size=1000)
111+
unrelated_figure, ax = plt.subplots()
112+
ax.hist(normal_dist, bins=100)
113+
ax.set_xlabel("something unrelated to napari (x)")
114+
ax.set_ylabel("something unrelated to napari (y)")
115+
ax.set_title(
116+
"this plot style should not change with napari styles or themes"
117+
)
118+
unrelated_figure.tight_layout()
119+
120+
return unrelated_figure

0 commit comments

Comments
 (0)