Download tests/test_cli_card.py from tailot/codex-python: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/datasets/tailot/codex-python/resolve/main/tests/test_cli_card.py
- Command line
-
hf download hf://datasets/tailot/codex-python/tests/test_cli_card.py
-
curl -L -o test_cli_card.py https://huggingface.co/datasets/tailot/codex-python/resolve/main/tests/test_cli_card.py
2.19 kB
| """Tests for the gate that keeps the printed commands of the card runnable.""" | |
| from __future__ import annotations | |
| import importlib.util | |
| from pathlib import Path | |
| _ROOT = Path(__file__).resolve().parent.parent | |
| # The kernel bundle carries a tools/run_gates.py of its own, so this file loads | |
| # the bundle runner by path instead of by package name. | |
| _spec = importlib.util.spec_from_file_location( | |
| "codex_python_gates_runner_card", _ROOT / "tools" / "run_gates.py" | |
| ) | |
| assert _spec is not None and _spec.loader is not None | |
| _run_gates = importlib.util.module_from_spec(_spec) | |
| _spec.loader.exec_module(_run_gates) | |
| _card_commands = _run_gates._card_commands | |
| _card_command_problems = _run_gates._card_command_problems | |
| _parser_surface = _run_gates._parser_surface | |
| gate_cli_card_agreement = _run_gates.gate_cli_card_agreement | |
| from lingologos_python.cli import _build_parser | |
| def test_the_card_agreement_gate_confirms_the_real_pair() -> None: | |
| res = gate_cli_card_agreement() | |
| assert res.verdict == "CONFIRMED" | |
| assert "agree with" in res.note | |
| def test_a_wrapped_example_is_still_one_command() -> None: | |
| card = ( | |
| "text\n\n" | |
| "```bash\n" | |
| "$ python -B -m lingologos_python edit --workspace w \\\n" | |
| " --file f.py --search a --replace b --json\n" | |
| "```\n" | |
| ) | |
| commands = _card_commands(card) | |
| assert commands == [("edit", ["--workspace", "--file", "--search", "--replace", "--json"])] | |
| def test_the_parser_surface_carries_the_flags_a_reader_copies_today() -> None: | |
| top, verbs = _parser_surface(_build_parser()) | |
| assert "--version" in top | |
| assert "--search-file" in verbs["edit"] and "--replace-file" in verbs["edit"] | |
| for verb in ("create", "delete", "patterns"): | |
| assert "--allow-single-prover" in verbs[verb] | |
| def test_a_flag_invented_in_the_card_is_reported_as_not_carried() -> None: | |
| card = ( | |
| "python -B -m lingologos_python edit --workspace w --file f.py --invented-flag x\n" | |
| "python -B -m lingologos_python frobnicate --workspace w\n" | |
| ) | |
| problems = _card_command_problems(card, _build_parser()) | |
| assert "edit --invented-flag" in problems | |
| assert "verb frobnicate" in problems | |