GeoIntel release gates / Compile, test, contracts and builds (push) Successful in 1m49s
GeoIntel release gates / Python and npm vulnerability policy (push) Successful in 21s
GeoIntel release gates / Production AI image, SBOM and container scan (push) Successful in 5m39s
GeoIntel release gates / Deploy exact gated revision to Unraid (push) Failing after 58m43s
61 lines
2.7 KiB
Python
61 lines
2.7 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "build_regional_yolo_dataset.py"
|
|
SPEC = importlib.util.spec_from_file_location("build_regional_yolo_dataset", SCRIPT)
|
|
assert SPEC and SPEC.loader
|
|
module = importlib.util.module_from_spec(SPEC)
|
|
SPEC.loader.exec_module(module)
|
|
|
|
|
|
def test_regional_dataset_balances_contexts_and_keeps_validation_closed() -> None:
|
|
manifest = {"samples": [
|
|
{"sample_slug": "f-train", "region": "flanders", "split": "train", "context": "ribbon"},
|
|
{"sample_slug": "f-val", "region": "flanders", "split": "val", "context": "mixed"},
|
|
{"sample_slug": "w-train", "region": "wallonia", "split": "train", "context": "ribbon"},
|
|
]}
|
|
summary = {"tiles": [
|
|
{"sample_slug": "f-train", "split": "train", "image_path": "/f-pos.png", "kept": True},
|
|
{"sample_slug": "f-train", "split": "train", "image_path": "/f-neg.png", "is_negative": True},
|
|
{"sample_slug": "f-val", "split": "val", "image_path": "/f-val.png"},
|
|
{"sample_slug": "w-train", "split": "train", "image_path": "/w.png"},
|
|
]}
|
|
train, val, evidence = module.build(
|
|
summary=summary, manifest=manifest, region="flanders",
|
|
priority_contexts={"ribbon"}, priority_repeat=3, negative_repeat=2,
|
|
)
|
|
assert train == ["/f-pos.png"] * 3 + ["/f-neg.png"] * 2
|
|
assert val == ["/f-val.png"]
|
|
assert evidence["negative_train_entry_count"] == 2
|
|
assert evidence["protected_samples_in_training"] == []
|
|
|
|
|
|
@pytest.mark.parametrize("protected_split", ["calibration", "test", "background-test", "challenge"])
|
|
def test_regional_dataset_rejects_protected_tiles(protected_split: str) -> None:
|
|
manifest = {"samples": [
|
|
{"sample_slug": "f-cal", "region": "flanders", "split": protected_split, "context": "ribbon"},
|
|
]}
|
|
summary = {"tiles": [{"sample_slug": "f-cal", "split": protected_split, "image_path": "/cal.png"}]}
|
|
with pytest.raises(ValueError, match="protected"):
|
|
module.build(
|
|
summary=summary, manifest=manifest, region="flanders",
|
|
priority_contexts=set(), priority_repeat=1, negative_repeat=1,
|
|
)
|
|
|
|
|
|
def test_regional_dataset_rejects_manifest_protection_hidden_by_tile_split() -> None:
|
|
manifest = {"samples": [
|
|
{"sample_slug": "f-cal", "region": "flanders", "split": "calibration", "context": "ribbon"},
|
|
]}
|
|
summary = {"tiles": [{"sample_slug": "f-cal", "split": "train", "image_path": "/cal.png"}]}
|
|
with pytest.raises(ValueError, match="protected"):
|
|
module.build(
|
|
summary=summary, manifest=manifest, region="flanders",
|
|
priority_contexts=set(), priority_repeat=1, negative_repeat=1,
|
|
)
|