Files
geointel/tests/test_accuracy_phase1_baseline.py
T

73 lines
2.9 KiB
Python

from __future__ import annotations
import importlib.util
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SCRIPT = ROOT / "scripts" / "run_accuracy_phase1_baseline.py"
SPEC = importlib.util.spec_from_file_location("accuracy_phase1_baseline", SCRIPT)
assert SPEC and SPEC.loader
MODULE = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(MODULE)
INFERENCE_SCRIPT = ROOT / "scripts" / "collect_accuracy_phase1_inference_smoke.py"
INFERENCE_SPEC = importlib.util.spec_from_file_location("accuracy_phase1_inference", INFERENCE_SCRIPT)
assert INFERENCE_SPEC and INFERENCE_SPEC.loader
INFERENCE_MODULE = importlib.util.module_from_spec(INFERENCE_SPEC)
INFERENCE_SPEC.loader.exec_module(INFERENCE_MODULE)
def test_sha256_file_is_stable(tmp_path: Path) -> None:
artifact = tmp_path / "manifest.json"
artifact.write_bytes(b'{"version":1}\n')
assert MODULE.sha256_file(artifact) == "50208d78350a7a160dec59a82df1499b6ca7da33e54c5eb11c97e342118e68bb"
def test_mirror_inventory_distinguishes_identical_and_drifted_files(tmp_path: Path) -> None:
(tmp_path / "geointel").mkdir()
(tmp_path / "same.txt").write_text("same", encoding="utf-8")
(tmp_path / "geointel" / "same.txt").write_text("same", encoding="utf-8")
(tmp_path / "drift.txt").write_text("root", encoding="utf-8")
(tmp_path / "geointel" / "drift.txt").write_text("mirror", encoding="utf-8")
tracked = {"same.txt", "drift.txt", "geointel/same.txt", "geointel/drift.txt"}
report = MODULE.mirror_inventory(tmp_path, tracked)
assert report["tracked_mirror_file_count"] == 2
assert report["paired_identical_file_count"] == 1
assert report["paired_different_file_count"] == 1
assert report["different_files"][0]["path"] == "drift.txt"
def test_artifact_roles_do_not_claim_images_are_models() -> None:
assert MODULE.artifact_role(Path("candidate.pt")) == "model_checkpoint"
assert MODULE.artifact_role(Path("split-manifest.json")) == "manifest"
assert MODULE.artifact_role(Path("contact_sheet_001.png")) == "visual_review"
assert MODULE.artifact_role(Path("orthophoto.tif")) == "raster"
def test_inference_summary_is_explicit_for_empty_and_non_empty_outputs() -> None:
assert INFERENCE_MODULE._summarize_detections([]) == {
"count": 0,
"class_counts": {},
"confidence": {"minimum": None, "maximum": None, "mean": None},
"sample": [],
}
detections = [
{"class_name": "building", "confidence": 0.8, "bbox": [1, 2, 3, 4]},
{"class_name": "building", "confidence": 0.4, "bbox": [5, 6, 7, 8]},
{"class_name": "shed", "confidence": 0.6, "bbox": [9, 10, 11, 12]},
]
summary = INFERENCE_MODULE._summarize_detections(detections)
assert summary["count"] == 3
assert summary["class_counts"] == {"building": 2, "shed": 1}
assert summary["confidence"] == {
"minimum": 0.4,
"maximum": 0.8,
"mean": 0.6,
}
assert summary["sample"] == detections