Add pytest suite with 40 unit and integration tests
Coverage: - test_model: SimpleNet forward (parametrized over batch sizes and both unsqueezed and flat input shapes), layer dimensions, differentiability, and ONNX round-trip - test_inference: load_model resolution order (bundled, cwd override, explicit path, missing path), and predict shape/dtype/determinism plus endpoint sanity across 8 cardinal/diagonal targets - test_train: _load_csv parsing, TrajectoryDataset indexing, full train() pipeline producing a single-file ONNX, plus a smoke test against the real data shipped under data/ - test_cli: --help for the three console scripts and a real run of mouse-visualize via both the entry point and python -m Wire up pytest via dependency-groups and tool.pytest.ini_options.
This commit is contained in:
49
tests/test_cli.py
Normal file
49
tests/test_cli.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
CLI_COMMANDS = ["mouse-collect", "mouse-train", "mouse-visualize"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("command", CLI_COMMANDS)
|
||||
def test_cli_help(command: str) -> None:
|
||||
"""Every CLI must respond to --help with exit 0 and an argparse usage line."""
|
||||
result = subprocess.run(
|
||||
[command, "--help"], capture_output=True, text=True, check=False,
|
||||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert "usage:" in result.stdout
|
||||
|
||||
|
||||
def test_visualize_no_show_produces_png(tmp_path: Path) -> None:
|
||||
save_path = tmp_path / "out.png"
|
||||
result = subprocess.run(
|
||||
[
|
||||
"mouse-visualize", "--no-show", "--seed", "1",
|
||||
"--n-trajectories", "3", "--n-interp", "20",
|
||||
"--save", str(save_path),
|
||||
],
|
||||
capture_output=True, text=True, check=False,
|
||||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert save_path.exists()
|
||||
assert save_path.stat().st_size > 1000
|
||||
|
||||
|
||||
def test_visualize_module_invocation(tmp_path: Path) -> None:
|
||||
"""The module is also runnable via `python -m mouse_control.visualize`."""
|
||||
save_path = tmp_path / "out.png"
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable, "-m", "mouse_control.visualize",
|
||||
"--no-show", "--seed", "2", "--n-trajectories", "2",
|
||||
"--save", str(save_path),
|
||||
],
|
||||
capture_output=True, text=True, check=False,
|
||||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert save_path.exists()
|
||||
Reference in New Issue
Block a user