Copy the committed lab 1 sources as-is: src/, student-tests/, bench/, Dockerfile, docker-compose.yml, pyproject.toml, uv.lock, .python-version, config_example.toml, AGENTS.md, CLAUDE.md, .claude/, openspec/, .graphifyignore and KNOWN_ISSUES.md. Lab 1 evidence stays in the lab 1 repository. Merge the new skeleton files with own sections: Makefile (lab 2 targets plus own run, docker, bench and common targets), .gitignore, .dockerignore and .env.example. Rename the image to mtusi-messenger:lab2 and point AGENTS.md at lab 2. The application is still the in-memory lab 1 implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
3.2 KiB
Python
97 lines
3.2 KiB
Python
"""У каждого сценария основных спеков есть тест или исключение."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from spec_coverage import (
|
|
CAPABILITIES,
|
|
COLLECTED,
|
|
EXCLUDED,
|
|
Exclusion,
|
|
Scenario,
|
|
all_scenarios,
|
|
coverage_problems,
|
|
spec_scenarios,
|
|
)
|
|
|
|
TESTS_DIR = Path(__file__).parent
|
|
|
|
|
|
def complete_marks(scenarios: set[Scenario]) -> dict[Scenario, list[str]]:
|
|
"""Маркеры, при которых покрыто всё, кроме исключений."""
|
|
return {scenario: ["test_x"] for scenario in scenarios - EXCLUDED.keys()}
|
|
|
|
|
|
def test_every_scenario_is_covered(request: pytest.FixtureRequest) -> None:
|
|
collected = request.config.stash[COLLECTED]
|
|
modules = {path.name for path in TESTS_DIR.glob("test_*.py")}
|
|
if not modules <= collected.modules:
|
|
pytest.skip(
|
|
"coverage is checked only when the whole suite is collected: "
|
|
"make student_test",
|
|
)
|
|
scenarios = all_scenarios()
|
|
problems = coverage_problems(scenarios, collected.marks, EXCLUDED)
|
|
tested = len(scenarios & collected.marks.keys())
|
|
print(
|
|
f"coverage: {len(scenarios)} scenarios in "
|
|
f"{len(CAPABILITIES)} specs, {tested} tested, "
|
|
f"{len(EXCLUDED)} excluded",
|
|
)
|
|
assert not problems, "\n".join(problems)
|
|
|
|
|
|
def test_every_spec_has_scenarios() -> None:
|
|
for capability in CAPABILITIES:
|
|
assert spec_scenarios(capability), f"no scenarios in {capability}"
|
|
|
|
|
|
def test_exclusions_explain_reason_and_check() -> None:
|
|
for (capability, scenario), exclusion in EXCLUDED.items():
|
|
assert exclusion.reason.strip(), f"{capability} / {scenario}"
|
|
assert exclusion.check.strip(), f"{capability} / {scenario}"
|
|
|
|
|
|
def test_scenario_parser(tmp_path: Path) -> None:
|
|
spec = tmp_path / "demo" / "spec.md"
|
|
spec.parent.mkdir()
|
|
spec.write_text(
|
|
"### Requirement: R\n\n#### Scenario: Первый\n\n- **WHEN** x\n\n"
|
|
"#### Scenario: Второй \n",
|
|
encoding="utf-8",
|
|
)
|
|
assert spec_scenarios("demo", tmp_path) == ["Первый", "Второй"]
|
|
|
|
|
|
def test_new_scenario_without_test_fails() -> None:
|
|
scenarios = all_scenarios()
|
|
marks = complete_marks(scenarios)
|
|
assert coverage_problems(scenarios, marks, EXCLUDED) == []
|
|
|
|
grown = scenarios | {("users", "Новый сценарий")}
|
|
assert coverage_problems(grown, marks, EXCLUDED) == [
|
|
"no test and no exclusion: users / Новый сценарий",
|
|
]
|
|
|
|
|
|
def test_marker_typo_fails() -> None:
|
|
scenarios = all_scenarios()
|
|
marks = complete_marks(scenarios)
|
|
marks[("users", "Повтор usernme")] = ["test_typo"]
|
|
assert coverage_problems(scenarios, marks, EXCLUDED) == [
|
|
"marker points to unknown scenario users / Повтор usernme: test_typo",
|
|
]
|
|
|
|
|
|
def test_stale_exclusion_fails() -> None:
|
|
scenarios = all_scenarios()
|
|
marks = complete_marks(scenarios)
|
|
excluded = {
|
|
**EXCLUDED,
|
|
("health", "Удалённый сценарий"): Exclusion(reason="r", check="c"),
|
|
}
|
|
assert coverage_problems(scenarios, marks, excluded) == [
|
|
"exclusion points to unknown scenario: health / Удалённый сценарий",
|
|
]
|