testsAndMisc/python_pkg/code_tutor/tests/conftest.py
Krzysztof kuhy Rudnicki e3214c813c
Some checks are pending
Pre-commit checks / pre-commit (push) Waiting to run
Python tests / test (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Clear the seven over-cap code_tutor test modules
Partitioned at the section banners each file already used, into ten new
modules named for what they cover. python_pkg/code_tutor is now entirely
under the cap, from thirteen violations.

The splitter copies the whole original header into each new file and
lets ruff's F401 pass prune it - 59 imports removed correctly, versus a
hand-written import block failing on every earlier test split today.
That does not cover module-level helpers: _make_verifier sat between two
banners and was left behind by its callers, so it moved to conftest.py,
taking test_verifier.py's shadowing copy of _make_live_mock with it.

No patch string changed. Pass count is 217 before and after.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
2026-08-16 18:06:38 +02:00

65 lines
1.8 KiB
Python

"""Shared factory helpers for the ``_challenge`` / ``_challenge_support`` tests.
Kept in ``conftest.py`` (a single, import-safe location) so the split test
modules (``test_challenge``, ``test_challenge_part2``, ``test_challenge_part3``)
reuse one definition instead of duplicating the factories, which would trip
pylint's ``duplicate-code`` check.
"""
from __future__ import annotations
from unittest.mock import MagicMock
from python_pkg.code_tutor._analyzer import CodeItem
from python_pkg.code_tutor._verifier import Verifier
def _item(
file: str = "mod.py",
name: str = "fn",
start: int = 1,
end: int = 3,
class_name: str = "",
) -> CodeItem:
"""Build a ``CodeItem`` with sensible defaults for tests.
Args:
file: Relative source-file path for the item.
name: Function name.
start: 1-based start line of the item.
end: 1-based end line of the item.
class_name: Owning class name, or empty for module-level functions.
Returns:
A populated ``CodeItem`` instance.
"""
return CodeItem(
id=f"{file}.{name}",
file=file,
type="function",
name=name,
start_line=start,
end_line=end,
class_name=class_name,
)
def _make_live_mock() -> MagicMock:
"""Return a ``MagicMock`` that behaves like a ``rich.live.Live`` context.
Returns:
A mock whose ``__enter__`` yields itself and whose ``__exit__``
returns ``False`` so exceptions propagate normally.
"""
live = MagicMock()
live.__enter__ = MagicMock(return_value=live)
live.__exit__ = MagicMock(return_value=False)
return live
def _make_verifier() -> tuple[Verifier, MagicMock, MagicMock]:
mock_backend = MagicMock()
mock_console = MagicMock()
verifier = Verifier(mock_backend, mock_console)
return verifier, mock_backend, mock_console