refactor(tests): one definition each for the copied fixtures and fakes (#2825, milestone 296 area 1)
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 8s
CI & Build / integration (push) Successful in 24s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 54s
CI & Build / Build & push image (push) Successful in 18s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 8s
CI & Build / integration (push) Successful in 24s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 54s
CI & Build / Build & push image (push) Successful in 18s
The shape ledger showed the same test scaffolding defined over and over: _bind_user x12 (byte-identical), _dispose_engine x10 in three wordings, _no_supersession x3, _make_mock_session x7 in three subsets, a get-or-create User helper x2 (+3 inlined), and fifteen hand-rolled MagicMock note factories each re-explaining the same "an auto-MagicMock attribute is truthy" hazard (note 2109). Now: conftest.py carries _bind_user / _dispose_engine / _no_supersession as opt-in fixtures (pytestmark = usefixtures(...) per module, so unit tests pay nothing), and tests/helpers.py carries make_mock_session(), ensure_user() and fake_note(**attrs) — the hazard documented once, real values on every attribute the product reads. Call sites were rewritten by AST so titles with dashes and commas survived; the three SimpleNamespace _note stand-ins that only feed a single function stay local. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,22 +8,9 @@ before this it surfaced snippets while leaving no trace anywhere.
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _no_supersession():
|
||||
"""The auto-inject menu now asks which of its lines are superseded (#278).
|
||||
|
||||
That is a real database call on a path these tests exercise without one.
|
||||
Stubbed to "nothing superseded" — the ordinary state — rather than hidden
|
||||
behind a try/except in the product, which would make the code lie about
|
||||
what it does. The label's own behaviour is covered in
|
||||
tests/test_supersession_ranking.py.
|
||||
"""
|
||||
with patch("scribe.services.plugin_context.superseded_ids",
|
||||
AsyncMock(return_value=set())):
|
||||
yield
|
||||
pytestmark = pytest.mark.usefixtures("_no_supersession")
|
||||
|
||||
|
||||
from scribe.services import note_usage
|
||||
@@ -33,19 +20,7 @@ from scribe.services.note_usage import (
|
||||
record_surfaced,
|
||||
usage_for_notes,
|
||||
)
|
||||
|
||||
|
||||
def _note(nid, title, user_id=1):
|
||||
n = MagicMock()
|
||||
n.id, n.title, n.user_id = nid, title, user_id
|
||||
n.note_type = "snippet"
|
||||
# See the same note in test_write_path_trigger: an auto-created mock on
|
||||
# `.data` is truthy and would leak into a rendered menu line (#2244).
|
||||
n.data = None
|
||||
# And on `.is_task`, which the kind marker reads FIRST — truthy there makes
|
||||
# every one of these snippets read as a task (#2246).
|
||||
n.is_task, n.task_kind = False, "work"
|
||||
return n
|
||||
from tests.helpers import fake_note
|
||||
|
||||
|
||||
# --- recording ------------------------------------------------------------
|
||||
@@ -207,7 +182,7 @@ async def test_auto_inject_records_what_survived_the_margin_gate():
|
||||
two numbers must not silently mean different things per surface."""
|
||||
from scribe.services import plugin_context
|
||||
|
||||
hits = [(0.90, _note(1, "kept")), (0.40, _note(2, "cut by the margin gate"))]
|
||||
hits = [(0.90, fake_note(id=1, title="kept", user_id=1, note_type="snippet")), (0.40, fake_note(id=2, title="cut by the margin gate", user_id=1, note_type="snippet"))]
|
||||
with (
|
||||
patch.object(
|
||||
plugin_context,
|
||||
@@ -271,13 +246,6 @@ def test_every_getter_that_can_be_surfaced_also_records_a_pull():
|
||||
# and split the chain so a failure names its half.
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def _dispose_engine():
|
||||
from scribe.models import engine
|
||||
yield
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
async def _purge(note_id: int) -> None:
|
||||
from sqlalchemy import delete
|
||||
|
||||
|
||||
Reference in New Issue
Block a user