Files
beefy-player/tests/test_timezone.py
T
beefcarver e30ca09627 refactor!: rename somafm-tui to beefy-player
The app is now a general internet-radio player rather than a SomaFM client, so the package, console script, MPRIS identity, mpv namespaces, macOS tap names, XDG directories and docs all move to beefy-player.

Environment variables are now BEEFY_* (the old SOMAFM_* spellings are still honoured) and an existing ~/.config/somafm-tui/config.json is migrated on first run, so favourites and volume survive the rename.

The visible interface is untouched: same layout, same logo, same keys.
2026-11-03 16:10:25 -05:00

49 lines
1.5 KiB
Python

from __future__ import annotations
from datetime import datetime, timedelta, timezone
from pathlib import Path
import pytest
from beefy_player.widgets import common
BERLIN = Path("/usr/share/zoneinfo/Europe/Berlin")
UTC_FILE = Path("/usr/share/zoneinfo/UTC")
@pytest.fixture(autouse=True)
def clear_zone_cache():
common.local_zone.cache_clear()
yield
common.local_zone.cache_clear()
def _copy_zone(tmp_path: Path, source: Path) -> Path:
target = tmp_path / "localtime"
target.write_bytes(source.read_bytes())
return target
def test_build_time_tz_utc_does_not_hide_the_system_zone(tmp_path, monkeypatch) -> None:
if not BERLIN.exists():
pytest.skip("system tzdata is not installed")
monkeypatch.setattr(common, "LOCALTIME_PATH", str(_copy_zone(tmp_path, BERLIN)))
monkeypatch.setenv("TZ", "UTC")
zone = common.local_zone()
assert zone.utcoffset(datetime(2026, 1, 1)) == timedelta(hours=1)
aware = datetime(2026, 1, 1, 12, 0, tzinfo=timezone.utc)
assert common.local_time(aware) == "13:00"
def test_explicit_non_utc_tz_is_respected(tmp_path, monkeypatch) -> None:
if not BERLIN.exists() or not UTC_FILE.exists():
pytest.skip("system tzdata is not installed")
monkeypatch.setattr(common, "LOCALTIME_PATH", str(_copy_zone(tmp_path, UTC_FILE)))
monkeypatch.setenv("TZ", "Europe/Berlin")
zone = common.local_zone()
assert zone.utcoffset(datetime(2026, 1, 1)) == timedelta(hours=1)
assert common.local_time(datetime(2026, 1, 1, 12, 0, tzinfo=timezone.utc)) == "13:00"