from pathlib import Path import json ROOT = Path(__file__).resolve().parents[1] def _validate_feature_collection(path: Path) -> None: data = json.loads(path.read_text(encoding="utf-8")) if data.get("type") != "FeatureCollection": raise SystemExit(f"{path} is not a FeatureCollection") features = data.get("features") if not isinstance(features, list): raise SystemExit(f"{path} has no feature list") for index, feature in enumerate(features): geometry = feature.get("geometry") if isinstance(feature, dict) else None if not isinstance(geometry, dict) or not geometry.get("type"): raise SystemExit(f"{path} feature {index} has no geometry") def _validate_fixture_dir(relative_path: str) -> None: fixture_dir = ROOT / relative_path if not fixture_dir.exists(): raise SystemExit(f"{relative_path} missing") for path in fixture_dir.glob("*.geojson"): _validate_feature_collection(path) _validate_fixture_dir("fixtures/geojson") _validate_fixture_dir("fixtures/golden") expected_path = ROOT / "fixtures" / "golden" / "expected_qa_metrics.json" expected = json.loads(expected_path.read_text(encoding="utf-8")) for key in ("candidate_fixture", "reference_fixture"): fixture_path = ROOT / expected[key] if not fixture_path.exists(): raise SystemExit(f"Golden QA fixture missing: {fixture_path}") print("Fixture validation OK")