mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 22:47:02 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Docker mysql:8.0.33 container, judge-style output grading, 12 original drills with live-verified references kept in tests only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZewj4WS5X6AZyjWDp
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
"""Drill discovery and rendering over the bundled drills."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from python_pkg.sql_drills import _drills
|
|
|
|
SOLUTIONS = Path(__file__).parent / "solutions"
|
|
|
|
|
|
def test_drills_are_listed_in_priority_order() -> None:
|
|
ids = [d.id for d in _drills.list_drills()]
|
|
assert ids == sorted(ids)
|
|
assert len(ids) >= 10
|
|
|
|
|
|
def test_every_drill_has_all_parts_and_a_reference() -> None:
|
|
for d in _drills.list_drills():
|
|
assert d.schema.read_text().strip(), d.id
|
|
assert d.task.read_text().strip(), d.id
|
|
assert d.expected.read_text().strip(), d.id
|
|
assert (SOLUTIONS / f"{d.id}.sql").is_file(), d.id
|
|
|
|
|
|
def test_get_by_full_id_and_by_number_prefix() -> None:
|
|
first = _drills.list_drills()[0]
|
|
assert _drills.get_drill(first.id) == first
|
|
assert _drills.get_drill(first.id.split("_")[0]) == first
|
|
|
|
|
|
def test_unknown_drill_raises() -> None:
|
|
with pytest.raises(_drills.UnknownDrillError):
|
|
_drills.get_drill("nope")
|
|
|
|
|
|
def test_show_has_task_schema_and_sample_but_no_solution() -> None:
|
|
d = _drills.list_drills()[0]
|
|
text = _drills.render_show(d)
|
|
assert d.task.read_text().strip() in text
|
|
assert "CREATE TABLE" in text
|
|
first_expected = d.expected.read_text().splitlines()[0]
|
|
assert first_expected in text
|
|
assert (SOLUTIONS / f"{d.id}.sql").read_text().strip() not in text
|
|
|
|
|
|
def test_show_truncates_long_expected_output(tmp_path: Path) -> None:
|
|
exp = tmp_path / "expected.txt"
|
|
exp.write_text("\n".join(f"row{i}" for i in range(20)) + "\n")
|
|
task = tmp_path / "DOCS-task.md"
|
|
task.write_text("T")
|
|
schema = tmp_path / "schema.sql"
|
|
schema.write_text("S")
|
|
text = _drills.render_show(_drills.Drill("x", task, schema, exp))
|
|
assert "row0" in text
|
|
assert "row19" not in text
|
|
assert "20 rows in total" in text
|
|
|
|
|
|
def test_title_is_first_heading() -> None:
|
|
d = _drills.list_drills()[0]
|
|
assert _drills.title_of(d) == d.task.read_text().splitlines()[0].lstrip("# ")
|
|
|
|
|
|
def test_missing_drills_dir_lists_nothing(tmp_path: Path) -> None:
|
|
assert _drills.list_drills(tmp_path / "absent") == []
|