import datetime as dt import json from test_crossfetch_masks import _load_crossfetch def test_liturgy_pair_follows_season(monkeypatch): cf = _load_crossfetch() monkeypatch.delenv("CROSS_LITURGY", raising=False) monkeypatch.delenv("CROSS_FEAST", raising=False) cf.FORCED_FEAST = None pair = cf._liturgy_pair() assert pair is not None and len(pair) == 2 # Aug 13 2026 is Ordinary Time -> (pine, foam); today's real season may # differ if this test runs another day, so check against liturgy directly. import liturgy today = dt.date.today() f = liturgy.feast(today) expected = f.roles if f else liturgy.season(today).roles assert tuple(pair) == tuple(expected) def test_liturgy_off_disables(monkeypatch): cf = _load_crossfetch() monkeypatch.setenv("CROSS_LITURGY", "off") cf.FORCED_FEAST = None assert cf._liturgy_pair() is None def test_explicit_cross_burst_wins(monkeypatch): cf = _load_crossfetch() monkeypatch.setenv("CROSS_BURST", "love,gold") assert cf._pair() == ("love", "gold") monkeypatch.delenv("CROSS_BURST", raising=False) def test_forced_feast_wins(monkeypatch): cf = _load_crossfetch() import liturgy monkeypatch.delenv("CROSS_BURST", raising=False) cf.FORCED_FEAST = liturgy.FEAST_DEFS["pentecost"] assert cf._pair() == ("love", "gold") assert cf.daily_verse() == liturgy.FEAST_DEFS["pentecost"].verse cf.FORCED_FEAST = None def test_feast_state_roundtrip(tmp_path, monkeypatch): cf = _load_crossfetch() import liturgy monkeypatch.setattr(cf, "STATE_DIR", str(tmp_path)) f = liturgy.FEAST_DEFS["easter_day"] assert cf._feast_unseen(f) cf._mark_feast_seen(f) assert not cf._feast_unseen(f) data = json.loads((tmp_path / "shown.json").read_text()) assert f.id in data[str(dt.date.today().year)] # corrupt file must not crash (tmp_path / "shown.json").write_text("{ nope") assert cf._feast_unseen(f) def test_mark_feast_seen_survives_unwritable_state_dir(tmp_path, monkeypatch): cf = _load_crossfetch() import liturgy # STATE_DIR points below a plain FILE, so os.makedirs can never succeed # there (ENOTDIR) -> the write path must degrade silently, not raise. blocker = tmp_path / "blocker" blocker.write_text("not a directory") monkeypatch.setattr(cf, "STATE_DIR", str(blocker / "state")) f = liturgy.FEAST_DEFS["easter_day"] cf._mark_feast_seen(f) # must not raise def test_use_season_stops_changes_gradient(monkeypatch): cf = _load_crossfetch() import liturgy monkeypatch.delenv("CROSS_LITURGY", raising=False) cf.FORCED_FEAST = liturgy.FEAST_DEFS["good_friday"] before = list(cf.STOPS) cf.use_season_stops() assert cf.STOPS != before assert len(cf.STOPS) >= 4 cf.STOPS = cf.PALETTE # restore cf.FORCED_FEAST = None