test_cli_launcher.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from __future__ import annotations
  2. import json
  3. import subprocess
  4. import sys
  5. from pathlib import Path
  6. ROOT = Path(__file__).resolve().parents[2]
  7. VIEWER_ROOT = ROOT / "tools" / "board-viewer"
  8. sys.path.insert(0, str(VIEWER_ROOT))
  9. from board_viewer.cli import build_parser, default_generation_config, main # noqa: E402
  10. def test_cli_exposes_generate_validate_and_serve_without_host_override() -> None:
  11. parser = build_parser()
  12. assert parser.parse_args(["generate"]).command == "generate"
  13. assert parser.parse_args(["validate"]).command == "validate"
  14. serve = parser.parse_args(["serve", "--port", "9000", "--open-browser"])
  15. assert serve.command == "serve"
  16. assert serve.port == 9000
  17. assert serve.open_browser is True
  18. assert "--host" not in parser.format_help()
  19. def test_default_generation_config_targets_reviewed_product_inputs() -> None:
  20. config = default_generation_config()
  21. assert config.brd_path == ROOT / "reference/original/board/FCB_FPGA_MCU_V1.1_20260625/FCB_FPGA+MCU_V1.1_20260625.brd"
  22. assert config.inventory_path == ROOT / "config/pin_inventory.fcb_fpga_mcu0611.json"
  23. assert config.annotations_path == ROOT / "config/board_viewer_annotations.fcb_fpga_mcu0611.json"
  24. assert config.output_dir == VIEWER_ROOT / "generated"
  25. assert config.expected_counts == {"footprints": 1052, "touchpoints": 110, "pads": 472}
  26. assert config.product_regression is True
  27. def test_validate_cli_reports_current_bundle_as_json(capsys) -> None:
  28. exit_code = main(["validate", "--json"])
  29. payload = json.loads(capsys.readouterr().out)
  30. assert exit_code == 0
  31. assert payload["status"] == "pass"
  32. assert payload["counts"] == {"footprints": 1052, "touchpoints": 110, "pads": 472}
  33. def test_script_entrypoint_validate_command_runs_from_any_working_directory(tmp_path: Path) -> None:
  34. result = subprocess.run(
  35. [sys.executable, str(VIEWER_ROOT / "board_viewer.py"), "validate", "--json"],
  36. cwd=tmp_path,
  37. check=False,
  38. capture_output=True,
  39. text=True,
  40. encoding="utf-8",
  41. )
  42. assert result.returncode == 0, result.stderr
  43. assert json.loads(result.stdout)["status"] == "pass"
  44. def test_windows_launcher_is_location_independent_and_opens_loopback_server() -> None:
  45. launcher = (VIEWER_ROOT / "OPEN_BOARD_VIEWER.cmd").read_text(encoding="ascii")
  46. assert 'cd /d "%~dp0"' in launcher
  47. assert "py -3.12" in launcher
  48. assert "board_viewer.py serve --open-browser" in launcher
  49. assert "0.0.0.0" not in launcher
  50. assert "PROGRAM_" not in launcher