Skip to content

Tests for background lightness checking. #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2023
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