Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aede1f8

Browse filesBrowse 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 d5a6213 commit aede1f8
Copy full SHA for aede1f8

File tree

2 files changed

+30
-0
lines changed
Filter options

2 files changed

+30
-0
lines changed
Loading

‎src/napari_matplotlib/tests/test_theme.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/tests/test_theme.py
+30Lines changed: 30 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.