Skip to content

Commit 99a2e97

Browse files
committed
Test to guard against re-introducing #64.
1 parent 1385b5d commit 99a2e97

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Loading

src/napari_matplotlib/tests/test_theme.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from copy import deepcopy
2+
13
import napari
24
import numpy as np
35
import pytest
@@ -88,3 +90,31 @@ def test_titles_respect_theme(
8890

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

0 commit comments

Comments
 (0)