Add deterministic portfolio spec composition
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from scripts.combine_belgium_building_portfolio_specs import combine_specs
|
||||
|
||||
|
||||
def write_spec(path: Path, slug: str, *, resolution: float = 0.25, status: str = "complete") -> Path:
|
||||
path.write_text(json.dumps({
|
||||
"status": status,
|
||||
"side_m": 256.0,
|
||||
"resolution_m": resolution,
|
||||
"samples": [{"sample_slug": slug}],
|
||||
}), encoding="utf-8")
|
||||
return path
|
||||
|
||||
|
||||
def test_combine_specs_records_provenance(tmp_path: Path) -> None:
|
||||
payload = combine_specs([write_spec(tmp_path / "one.json", "one"), write_spec(tmp_path / "two.json", "two")])
|
||||
assert payload["sample_count"] == 2
|
||||
assert [sample["sample_slug"] for sample in payload["samples"]] == ["one", "two"]
|
||||
assert all(len(source["sha256"]) == 64 for source in payload["source_specs"])
|
||||
|
||||
|
||||
def test_combine_specs_rejects_duplicate_slugs(tmp_path: Path) -> None:
|
||||
with pytest.raises(ValueError, match="Duplicate"):
|
||||
combine_specs([write_spec(tmp_path / "one.json", "same"), write_spec(tmp_path / "two.json", "same")])
|
||||
|
||||
|
||||
def test_combine_specs_rejects_mismatched_resolution(tmp_path: Path) -> None:
|
||||
with pytest.raises(ValueError, match="resolution"):
|
||||
combine_specs([write_spec(tmp_path / "one.json", "one"), write_spec(tmp_path / "two.json", "two", resolution=0.5)])
|
||||
|
||||
|
||||
def test_combine_specs_rejects_incomplete_source(tmp_path: Path) -> None:
|
||||
with pytest.raises(ValueError, match="not complete"):
|
||||
combine_specs([write_spec(tmp_path / "one.json", "one", status="in_progress")])
|
||||
Reference in New Issue
Block a user