Skip to content

Commit 669cdc2

Browse files
samcunliffedstansby
authored andcommitted
Test first.
A TDD test to check we can set the theme from a user-defined stylesheet. For this, just use Solarized_Light2.
1 parent d437948 commit 669cdc2

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/napari_matplotlib/tests/test_theme.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
from copy import deepcopy
22

3+
import shutil
4+
from pathlib import Path
5+
6+
import matplotlib
37
import napari
48
import numpy as np
59
import pytest
10+
from matplotlib.colors import to_rgba
611

7-
from napari_matplotlib import ScatterWidget
12+
from napari_matplotlib import HistogramWidget, ScatterWidget
813
from napari_matplotlib.base import NapariMPLWidget
914

1015

@@ -140,3 +145,34 @@ def test_custom_theme(make_napari_viewer, theme_path, brain_data):
140145
viewer.layers.selection.add(viewer.layers[1])
141146

142147
return deepcopy(widget.figure)
148+
149+
150+
def find_mpl_stylesheet(name: str) -> Path:
151+
"""Find the built-in matplotlib stylesheet."""
152+
return Path(matplotlib.__path__[0]) / f"mpl-data/stylelib/{name}.mplstyle"
153+
154+
155+
def test_stylesheet_in_cwd(tmpdir, make_napari_viewer, image_data):
156+
"""
157+
Test that a stylesheet in the current directory is given precidence.
158+
159+
Do this by copying over a stylesheet from matplotlib's built in styles,
160+
naming it correctly, and checking the colours are as expected.
161+
"""
162+
with tmpdir.as_cwd():
163+
# Copy Solarize_Light2 to current dir as if it was a user-overriden stylesheet.
164+
shutil.copy(find_mpl_stylesheet("Solarize_Light2"), "./user.mplstyle")
165+
viewer = make_napari_viewer()
166+
viewer.add_image(image_data[0], **image_data[1])
167+
widget = HistogramWidget(viewer)
168+
ax = widget.figure.gca()
169+
170+
# The axes should have a light brownish grey background:
171+
assert ax.get_facecolor() == to_rgba("#eee8d5")
172+
assert ax.patch.get_facecolor() == to_rgba("#eee8d5")
173+
174+
# The figure background and axis gridlines are light yellow:
175+
assert widget.figure.patch.get_facecolor() == to_rgba("#fdf6e3")
176+
for gridline in ax.get_xgridlines() + ax.get_ygridlines():
177+
assert gridline.get_visible() is True
178+
assert gridline.get_color() == "#fdf6e3"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy