Skip to content
Merged
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
31 changes: 31 additions & 0 deletions src/napari_matplotlib/tests/test_theme.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import napari
import pytest

from napari_matplotlib.base import NapariMPLWidget
Expand All @@ -18,3 +19,33 @@ def test_theme_mpl_toolbar_icons(
assert (
path_to_icons.stem == expected_icons
), "The theme is selecting unexpected icons."


def _mock_up_theme() -> None:
"""Mock up a new color theme based on dark mode but with a tasteful blue background.

Based on:
https://napari.org/stable/gallery/new_theme.html
"""
blue_theme = napari.utils.theme.get_theme("dark", False)
blue_theme.name = "blue"
blue_theme.background = "#4169e1" # my favourite shade of blue
napari.utils.theme.register_theme("blue", blue_theme)


def test_theme_background_check(make_napari_viewer):
"""
Check that the hue saturation lightness can distinguish dark and light backgrounds.
"""
viewer = make_napari_viewer()
widget = NapariMPLWidget(viewer)

viewer.theme = "dark"
assert widget._theme_has_light_bg() is False

viewer.theme = "light"
assert widget._theme_has_light_bg() is True

_mock_up_theme()
viewer.theme = "blue"
assert widget._theme_has_light_bg() is True