test_manifest.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from pathlib import Path
  2. import tempfile
  3. import pytest
  4. from tools.manifest_cli import create_snapshot, lint
  5. ROOT = Path(__file__).resolve().parents[1]
  6. def test_product_manifest_has_exact_repository_set() -> None:
  7. projects = lint(ROOT / "manifests/products/6400-front-rear.xml")
  8. assert {item.get("name") for item in projects} == {
  9. "engineering-manifests",
  10. "cpld-temperature-control",
  11. "hth-platform",
  12. "thermal-control-lab",
  13. }
  14. def test_legacy_manifest_is_minimal() -> None:
  15. projects = lint(ROOT / "manifests/products/legacy-door-percent.xml")
  16. assert {item.get("name") for item in projects} == {
  17. "engineering-manifests",
  18. "cpld-temperature-control",
  19. }
  20. def test_duplicate_project_is_rejected() -> None:
  21. with tempfile.TemporaryDirectory() as directory:
  22. path = Path(directory) / "bad.xml"
  23. path.write_text(
  24. '<manifest><project name="a" path="x"/><project name="a" path="y"/></manifest>',
  25. encoding="utf-8",
  26. )
  27. with pytest.raises(ValueError, match="duplicate"):
  28. lint(path)
  29. def test_floating_snapshot_is_rejected() -> None:
  30. with tempfile.TemporaryDirectory() as directory:
  31. path = Path(directory) / "bad.xml"
  32. path.write_text(
  33. '<manifest><project name="a" path="a" revision="refs/heads/dev"/></manifest>',
  34. encoding="utf-8",
  35. )
  36. with pytest.raises(ValueError, match="full SHA"):
  37. lint(path, snapshot=True)
  38. def test_snapshot_output_inside_snapshotted_repository_is_rejected() -> None:
  39. with pytest.raises(ValueError, match="outside every snapshotted repository"):
  40. create_snapshot(
  41. ROOT / "manifests/products/6400-front-rear.xml",
  42. ROOT / "manifests/snapshots/6400-front-rear/development.xml",
  43. )