|
1 | | -import os |
2 | | -import shutil |
3 | | -from copy import deepcopy |
4 | | -from pathlib import Path |
5 | 1 |
|
6 | | -import matplotlib |
7 | 2 | import napari |
8 | 3 | import numpy as np |
9 | 4 | import pytest |
10 | | -from matplotlib.colors import to_rgba |
11 | 5 |
|
12 | | -from napari_matplotlib import HistogramWidget, ScatterWidget |
| 6 | +from napari_matplotlib import ScatterWidget |
13 | 7 | from napari_matplotlib.base import NapariMPLWidget |
14 | 8 |
|
15 | 9 |
|
@@ -127,66 +121,3 @@ def test_no_theme_side_effects(make_napari_viewer): |
127 | 121 | unrelated_figure.tight_layout() |
128 | 122 |
|
129 | 123 | return unrelated_figure |
130 | | - |
131 | | - |
132 | | -@pytest.mark.mpl_image_compare |
133 | | -def test_custom_theme(make_napari_viewer, theme_path, brain_data): |
134 | | - viewer = make_napari_viewer() |
135 | | - viewer.theme = "dark" |
136 | | - |
137 | | - widget = ScatterWidget(viewer) |
138 | | - widget.mpl_style_sheet_path = theme_path |
139 | | - |
140 | | - viewer.add_image(brain_data[0], **brain_data[1], name="brain") |
141 | | - viewer.add_image( |
142 | | - brain_data[0] * -1, **brain_data[1], name="brain_reversed" |
143 | | - ) |
144 | | - |
145 | | - viewer.layers.selection.clear() |
146 | | - viewer.layers.selection.add(viewer.layers[0]) |
147 | | - viewer.layers.selection.add(viewer.layers[1]) |
148 | | - |
149 | | - return deepcopy(widget.figure) |
150 | | - |
151 | | - |
152 | | -def find_mpl_stylesheet(name: str) -> Path: |
153 | | - """Find the built-in matplotlib stylesheet.""" |
154 | | - return Path(matplotlib.__path__[0]) / f"mpl-data/stylelib/{name}.mplstyle" |
155 | | - |
156 | | - |
157 | | -def test_custom_stylesheet(make_napari_viewer, image_data): |
158 | | - """ |
159 | | - Test that a stylesheet in the current directory is given precidence. |
160 | | -
|
161 | | - Do this by copying over a stylesheet from matplotlib's built in styles, |
162 | | - naming it correctly, and checking the colours are as expected. |
163 | | - """ |
164 | | - # Copy Solarize_Light2 as if it was a user-overriden stylesheet. |
165 | | - style_sheet_path = ( |
166 | | - Path(matplotlib.get_configdir()) / "napari-matplotlib.mplstyle" |
167 | | - ) |
168 | | - if style_sheet_path.exists(): |
169 | | - pytest.skip("Won't ovewrite existing custom style sheet.") |
170 | | - shutil.copy( |
171 | | - find_mpl_stylesheet("Solarize_Light2"), |
172 | | - style_sheet_path, |
173 | | - ) |
174 | | - |
175 | | - try: |
176 | | - viewer = make_napari_viewer() |
177 | | - viewer.add_image(image_data[0], **image_data[1]) |
178 | | - widget = HistogramWidget(viewer) |
179 | | - assert widget.mpl_style_sheet_path == style_sheet_path |
180 | | - ax = widget.figure.gca() |
181 | | - |
182 | | - # The axes should have a light brownish grey background: |
183 | | - assert ax.get_facecolor() == to_rgba("#eee8d5") |
184 | | - assert ax.patch.get_facecolor() == to_rgba("#eee8d5") |
185 | | - |
186 | | - # The figure background and axis gridlines are light yellow: |
187 | | - assert widget.figure.patch.get_facecolor() == to_rgba("#fdf6e3") |
188 | | - for gridline in ax.get_xgridlines() + ax.get_ygridlines(): |
189 | | - assert gridline.get_visible() is True |
190 | | - assert gridline.get_color() == "#b0b0b0" |
191 | | - finally: |
192 | | - os.remove(style_sheet_path) |
0 commit comments