autoresearch-quantum/tests/test_cli.py
saymrwulf 5d0c28f939 Harden teaching layer, add notebook execution tests, fix repo hygiene
Quality fixes:
- Add deprecation warnings to 5 silent no-op legacy wrappers in assess.py
- Remove dead code in tracker.py score_by_section (unused first loop)
- Remove unused variable in assess.py _check_order
- Fix .gitignore: add progress JSONs, checkpoints, .coverage, .DS_Store, LaTeX aux
- Fix "all three plans" → "all four plans" in learning_objectives.md
- Add teaching/ package to README project tree
- Add compendium to README paper tree

Testing:
- Add 43 unit tests for teaching/assess.py and tracker.py (quiz, predict_choice,
  reflect, order, checkpoint_summary, legacy wrapper deprecation warnings,
  tracker scoring, persistence, mastery calculation)
- Add notebook execution test suite (nbclient): all 11 notebooks execute without
  errors in a fresh kernel, structural validation (valid JSON, has code cells,
  has assessments, section parameters, learning objectives document)
- Overall test count: 185 passing (was 107), coverage: 85% (was ~25% in tests)

Toolchain:
- Add pytest-cov, ruff, nbclient, nbformat to dev dependencies
- Add ruff config (E, F, W, I, UP, B, SIM rules)
- Add coverage config with term-missing output
- Fix all ruff lint issues across src/ and tests/ (import sorting, unused imports)
- Fix Plan D notebook paths (configs/rungs → ../../configs/rungs)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 15:34:37 +02:00

84 lines
2.6 KiB
Python

"""Tests for CLI parsing and override logic."""
from __future__ import annotations
import pytest
from autoresearch_quantum.cli import _parse_override, build_parser
# ── _parse_override ──────────────────────────────────────────────────────────
def test_parse_override_bool_true() -> None:
assert _parse_override("flag=true") == ("flag", True)
def test_parse_override_bool_false() -> None:
assert _parse_override("flag=false") == ("flag", False)
def test_parse_override_int() -> None:
assert _parse_override("shots=1024") == ("shots", 1024)
def test_parse_override_negative_int() -> None:
assert _parse_override("offset=-5") == ("offset", -5)
def test_parse_override_float() -> None:
key, val = _parse_override("rate=0.95")
assert key == "rate"
assert abs(val - 0.95) < 1e-9
def test_parse_override_json_list() -> None:
key, val = _parse_override("initial_layout=[0,1,2,3]")
assert key == "initial_layout"
assert val == [0, 1, 2, 3]
def test_parse_override_string() -> None:
assert _parse_override("name=hello_world") == ("name", "hello_world")
def test_parse_override_empty_value() -> None:
assert _parse_override("name=") == ("name", "")
def test_parse_override_no_equals_raises() -> None:
with pytest.raises(ValueError, match="key=value"):
_parse_override("no_equals_here")
# ── build_parser ─────────────────────────────────────────────────────────────
def test_parser_run_experiment_args() -> None:
parser = build_parser()
args = parser.parse_args(["run-experiment", "--config", "configs/rungs/rung1.yaml"])
assert args.command == "run-experiment"
assert args.config == "configs/rungs/rung1.yaml"
def test_parser_run_ratchet_multiple_configs() -> None:
parser = build_parser()
args = parser.parse_args([
"run-ratchet",
"--config", "configs/rungs/rung1.yaml",
"--config", "configs/rungs/rung2.yaml",
])
assert args.command == "run-ratchet"
assert len(args.config) == 2
def test_parser_run_transfer_with_backends() -> None:
parser = build_parser()
args = parser.parse_args([
"run-transfer",
"--config", "configs/rungs/rung1.yaml",
"--backends", "fake_brisbane", "fake_kyoto",
])
assert args.backends == ["fake_brisbane", "fake_kyoto"]
def test_parser_requires_command() -> None:
parser = build_parser()
with pytest.raises(SystemExit):
parser.parse_args([])