Skip to content

Commit 437190e

Browse files
committed
Test the automatic figuring out if a background is light.
... using the pydantic.Color HSL.
1 parent 7bf5db1 commit 437190e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/napari_matplotlib/tests/test_theme.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import napari
12
import pytest
23

34
from napari_matplotlib.base import NapariMPLWidget
@@ -18,3 +19,31 @@ def test_theme_mpl_toolbar_icons(
1819
assert (
1920
path_to_icons.stem == expected_icons
2021
), "The theme is selecting unexpected icons."
22+
23+
24+
def _mock_up_theme() -> None:
25+
"""Mock up a new color theme based on dark mode but with a tasteful blue background.
26+
27+
Based on:
28+
https://napari.org/stable/gallery/new_theme.html
29+
"""
30+
blue_theme = napari.utils.theme.get_theme("dark", False)
31+
blue_theme.name = "blue"
32+
blue_theme.background = "#4169e1" # my favourite shade of blue
33+
napari.utils.theme.register_theme("blue", blue_theme)
34+
35+
36+
def test_theme_background_check(make_napari_viewer):
37+
"""Check that the hue, saturation, lightness can distinguish dark and light backgrounds."""
38+
viewer = make_napari_viewer()
39+
widget = NapariMPLWidget(viewer)
40+
41+
viewer.theme = "dark"
42+
assert widget._theme_has_light_bg() is False
43+
44+
viewer.theme = "light"
45+
assert widget._theme_has_light_bg() is True
46+
47+
_mock_up_theme()
48+
viewer.theme = "blue"
49+
assert widget._theme_has_light_bg() is True

0 commit comments

Comments
 (0)