Files
beefy-player/tests/test_theme.py
T

71 lines
2.4 KiB
Python

from __future__ import annotations
import re
from pathlib import Path
import pytest
from somafm_tui.app import SomaFMApp
from somafm_tui.widgets.header import HeaderBar
from somafm_tui.widgets.search import SearchInput
from somafm_tui.widgets.spectrum import SpectrumPanel
from somafm_tui.widgets.stage import StagePanel
from somafm_tui.widgets.station_list import StationList
from somafm_tui.widgets.status import StatusBar
PACKAGE = Path(__file__).resolve().parents[1] / "somafm_tui"
def test_no_rgb_colors_in_source() -> None:
"""The app must follow the terminal palette, not force its own RGB colours."""
pattern = re.compile(r"#[0-9a-fA-F]{6}")
offenders = [
str(path.relative_to(PACKAGE))
for path in PACKAGE.rglob("*")
if path.suffix in {".py", ".tcss"} and pattern.search(path.read_text())
]
assert not offenders, offenders
@pytest.mark.asyncio
async def test_backgrounds_use_terminal_default_and_borders_are_ansi() -> None:
app = SomaFMApp(autoplay=False, offline=True, audio=False)
async with app.run_test(size=(100, 30)) as pilot:
await pilot.pause()
assert app.theme == "terminal"
assert app.ansi_color is True
assert app.native_ansi_color is True
assert app.screen.styles.background.ansi == -1 # SGR 49, terminal default
assert app.screen.styles.color.ansi == -1
for widget_type in (
HeaderBar,
SearchInput,
StationList,
StagePanel,
SpectrumPanel,
StatusBar,
):
widget = app.query_one(widget_type)
assert widget.styles.background.ansi == -1, widget_type
assert widget.styles.color.ansi == -1, widget_type
border = app.query_one(StationList).styles.border.top
assert border[1].ansi is not None # an ANSI palette index, not RGB
await pilot.press("slash")
await pilot.pause()
search = app.query_one(SearchInput)
assert search.styles.background.ansi == -1
assert search.styles.background_tint.a == 0
assert search.styles.color.ansi == -1 # ansi_default
await pilot.press("escape")
await pilot.pause()
await pilot.press("question_mark")
await pilot.pause()
assert app.screen.styles.background.ansi == -1
assert app.screen.query_one("#help").styles.background.ansi == -1
await pilot.press("x")
await pilot.pause()