mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-15 02:50:57 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
earned_time pre-commit / pre-commit (push) Waiting to run
earned_time tests / test (push) Waiting to run
file length / file-length (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
Contract C6 of the leisure rollout (leisure-watch TODO-leisure-rollout.md). leisure_from(path=LEISURE_FROM_PATH) -> date reads the switch file afresh on every call (O_RDONLY|O_NONBLOCK|O_NOFOLLOW, fstat S_ISREG, <= 64 bytes, strict YYYY-MM-DD with one optional newline); any failure is the parked LEISURE_FROM. Never raises. leisure_active(day, path=...) = day >= leisure_from() is the one way consumers ask "is Phase 2 on?". gaming_base_minutes_for / gaming_ceiling_minutes_for / base_for / resolve use it; leisure=True still forces (now a boolean, so a file date later than 2027-01-01 cannot drop the shadow budget back to 5 h). resolve reads the file once, so base and cap never disagree mid-call. Tests redirect the path via an autouse fixture and never touch the real /etc file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dsh4Znwh2KnC7q6vbGpX1N
30 lines
819 B
Python
30 lines
819 B
Python
# Copyright (c) 2026 Krzysztof Rudnicki
|
|
"""Shared fixtures: the HMAC key file the maturity rows are signed with."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
import pytest
|
|
|
|
from earned_time.tests._maturity_rows import KEY
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _no_real_switch_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""Point the leisure switch file at a missing path, never the real /etc one."""
|
|
monkeypatch.setattr(
|
|
"earned_time._leisure.LEISURE_FROM_PATH", tmp_path / "no_leisure_from"
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def key_file(tmp_path: Path) -> Path:
|
|
"""The test HMAC key, written where a test can point ``maturity`` at it."""
|
|
path = tmp_path / "hmac.key"
|
|
path.write_bytes(KEY)
|
|
return path
|