Skip to content

Test to guard against styling side-effects. #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions src/napari_matplotlib/tests/test_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,33 @@ def test_titles_respect_theme(

assert ax.xaxis.label.get_color() == expected_text_colour
assert ax.yaxis.label.get_color() == expected_text_colour


@pytest.mark.mpl_image_compare
def test_no_theme_side_effects(make_napari_viewer):
"""Ensure that napari-matplotlib doesn't pollute the globally set style.

A MWE to guard aganst issue matplotlib/#64. Should always reproduce a plot
with the default matplotlib style.
"""
import matplotlib.pyplot as plt

np.random.seed(12345)

# should not affect global matplotlib plot style
viewer = make_napari_viewer()
viewer.theme = "dark"
NapariMPLWidget(viewer)

# some plotting unrelated to napari-matplotlib
normal_dist = np.random.normal(size=1000)
unrelated_figure, ax = plt.subplots()
ax.hist(normal_dist, bins=100)
ax.set_xlabel("something unrelated to napari (x)")
ax.set_ylabel("something unrelated to napari (y)")
ax.set_title(
"this plot style should not change with napari styles or themes"
)
unrelated_figure.tight_layout()

return unrelated_figure