|
1 |
| -from copy import deepcopy |
2 |
| - |
3 | 1 | import shutil
|
| 2 | +from copy import deepcopy |
4 | 3 | from pathlib import Path
|
5 | 4 |
|
6 | 5 | import matplotlib
|
@@ -152,27 +151,36 @@ def find_mpl_stylesheet(name: str) -> Path:
|
152 | 151 | return Path(matplotlib.__path__[0]) / f"mpl-data/stylelib/{name}.mplstyle"
|
153 | 152 |
|
154 | 153 |
|
155 |
| -def test_stylesheet_in_cwd(tmpdir, make_napari_viewer, image_data): |
| 154 | +def test_custom_stylesheet(make_napari_viewer, image_data): |
156 | 155 | """
|
157 | 156 | Test that a stylesheet in the current directory is given precidence.
|
158 | 157 |
|
159 | 158 | Do this by copying over a stylesheet from matplotlib's built in styles,
|
160 | 159 | naming it correctly, and checking the colours are as expected.
|
161 | 160 | """
|
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" |
| 161 | + # Copy Solarize_Light2 as if it was a user-overriden stylesheet. |
| 162 | + style_sheet_path = ( |
| 163 | + Path(matplotlib.get_configdir()) / "napari-matplotlib.mplstyle" |
| 164 | + ) |
| 165 | + if style_sheet_path.exists(): |
| 166 | + pytest.skip("Won't ovewrite existing custom style sheet.") |
| 167 | + shutil.copy( |
| 168 | + find_mpl_stylesheet("Solarize_Light2"), |
| 169 | + style_sheet_path, |
| 170 | + ) |
| 171 | + |
| 172 | + viewer = make_napari_viewer() |
| 173 | + viewer.add_image(image_data[0], **image_data[1]) |
| 174 | + widget = HistogramWidget(viewer) |
| 175 | + assert widget.mpl_style_sheet_path == style_sheet_path |
| 176 | + ax = widget.figure.gca() |
| 177 | + |
| 178 | + # The axes should have a light brownish grey background: |
| 179 | + assert ax.get_facecolor() == to_rgba("#eee8d5") |
| 180 | + assert ax.patch.get_facecolor() == to_rgba("#eee8d5") |
| 181 | + |
| 182 | + # The figure background and axis gridlines are light yellow: |
| 183 | + assert widget.figure.patch.get_facecolor() == to_rgba("#fdf6e3") |
| 184 | + for gridline in ax.get_xgridlines() + ax.get_ygridlines(): |
| 185 | + assert gridline.get_visible() is True |
| 186 | + assert gridline.get_color() == "#fdf6e3" |
0 commit comments