|
| 1 | +"""End-to-end tests for :func:`in2lambda.main.runner` across the built-in filters. |
| 2 | +
|
| 3 | +Each built-in filter ships a self-contained ``example.tex`` that exercises the |
| 4 | +document structure it targets. These tests run every filter over its own example |
| 5 | +and check both the in-memory :class:`~in2lambda.api.set.Set` and the JSON/ZIP |
| 6 | +files written to disk. |
| 7 | +""" |
| 8 | + |
| 9 | +import json |
| 10 | +import os |
| 11 | + |
| 12 | +import pytest |
| 13 | + |
| 14 | +from in2lambda.api.set import Set |
| 15 | +from in2lambda.main import runner |
| 16 | + |
| 17 | +BUILTIN_FILTERS = ["PartsSepSol", "PartsOneSol", "PartPartSolSol", "PartSolPartSol"] |
| 18 | + |
| 19 | + |
| 20 | +@pytest.mark.parametrize("filter_name", BUILTIN_FILTERS) |
| 21 | +def test_runner_returns_populated_set(filter_name: str, filters_dir: str) -> None: |
| 22 | + """Every filter turns its example into a Set with at least one usable question.""" |
| 23 | + result = runner(os.path.join(filters_dir, filter_name, "example.tex"), filter_name) |
| 24 | + |
| 25 | + assert isinstance(result, Set) |
| 26 | + assert result.questions, f"{filter_name} produced no questions" |
| 27 | + for question in result.questions: |
| 28 | + # A question is only useful if it has top-level text or at least one part. |
| 29 | + assert question.main_text or question.parts |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.parametrize("filter_name", BUILTIN_FILTERS) |
| 33 | +def test_runner_writes_importable_json( |
| 34 | + filter_name: str, filters_dir: str, tmp_path |
| 35 | +) -> None: |
| 36 | + """Passing an output directory produces the Lambda Feedback set/ dir and zip.""" |
| 37 | + out_dir = tmp_path / "out" |
| 38 | + result = runner( |
| 39 | + os.path.join(filters_dir, filter_name, "example.tex"), |
| 40 | + filter_name, |
| 41 | + str(out_dir), |
| 42 | + ) |
| 43 | + |
| 44 | + set_dir = out_dir / "set" |
| 45 | + assert set_dir.is_dir() |
| 46 | + assert (out_dir / "set.zip").is_file() |
| 47 | + |
| 48 | + set_json = json.loads((set_dir / "set_set.json").read_text()) |
| 49 | + assert set_json["name"] == "set" |
| 50 | + |
| 51 | + question_files = sorted(set_dir.glob("question_*.json")) |
| 52 | + assert len(question_files) == len(result.questions) |
| 53 | + for question_file in question_files: |
| 54 | + question_json = json.loads(question_file.read_text()) |
| 55 | + assert question_json["title"] |
| 56 | + assert "masterContent" in question_json |
| 57 | + assert "parts" in question_json |
0 commit comments