mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-11 18:53:48 +01:00
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Has been cancelled
Tests / test (push) Has been cancelled
Tests / web-coverage (push) Has been cancelled
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
"""Autouse isolation of the reading earner from the host's book-guard ledger.
|
|
|
|
``resolve_budget`` asks :mod:`steam_backlog_enforcer._reading_bonus` whether a
|
|
reading session was credited today, which reads the real integrity key and the
|
|
real ``~/.local/share/book_guard/ledger.json``. Unstubbed, every test that
|
|
resolves a budget would answer differently depending on whether the machine's
|
|
owner has read a book today -- the same morning/evening flake the workout stub
|
|
exists to prevent.
|
|
|
|
Two layers: the consumer binding answers a plain "no reading" unless a test
|
|
overrides it, and the module's key path points at a file that does not exist,
|
|
so even a direct call without the test's own key fixture can never reach the
|
|
real ledger. The module memo is cleared around every test.
|
|
|
|
Split out of ``conftest.py`` to keep every file inside the 250-line cap;
|
|
``conftest`` imports the fixture by name, which is what registers it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from steam_backlog_enforcer import _reading_bonus
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Iterator
|
|
from pathlib import Path
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _isolate_reading(tmp_path: Path) -> Iterator[None]:
|
|
"""Answer "no reading" and hide the real signing key for one test.
|
|
|
|
Args:
|
|
tmp_path: pytest's temporary directory.
|
|
|
|
Yields:
|
|
None, with the reading earner isolated for the whole test.
|
|
"""
|
|
_reading_bonus.reset_cache()
|
|
with (
|
|
patch(
|
|
"steam_backlog_enforcer._budget_resolve.read_today",
|
|
return_value=False,
|
|
),
|
|
patch.object(_reading_bonus, "HMAC_KEY_FILE", tmp_path / "no-reading-hmac.key"),
|
|
):
|
|
yield
|
|
_reading_bonus.reset_cache()
|