feat(semantics): version scene edits and refine paint geometry
This commit is contained in:
@@ -220,3 +220,86 @@ def test_height_callback_cannot_move_xy():
|
||||
assert [[p[:2] for p in ring] for ring in after["geometry"]["coordinates"]] == (
|
||||
before["geometry"]["coordinates"]
|
||||
)
|
||||
|
||||
|
||||
def test_partial_admission_preserves_deferred_and_valid_holes():
|
||||
labels = np.zeros((7, 14), dtype=np.uint8)
|
||||
labels[1:6, 1:6] = 1
|
||||
labels[3, 3] = 0
|
||||
labels[1:6, 9:13] = 1
|
||||
p = proposal(labels)
|
||||
before = copy.deepcopy(p)
|
||||
|
||||
def heights(xy):
|
||||
return np.where(xy[:, 0] > 8, np.nan, 2.)
|
||||
|
||||
with pytest.raises(ValueError, match="height"):
|
||||
geometry.editor_features(p, height_at=heights, height_source="synthetic-support")
|
||||
result = geometry.editor_components(p, height_at=heights, height_source="synthetic-support")
|
||||
assert p == before
|
||||
assert not result["complete"]
|
||||
assert len(result["features"]) == len(result["deferred"]) == 1
|
||||
admitted = result["features"][0]
|
||||
assert len(admitted["geometry"]["coordinates"]) == 2
|
||||
deferred = result["deferred"][0]
|
||||
assert "height" in deferred["reason"]
|
||||
original = {f["id"]: f for f in p["features"]}
|
||||
assert deferred["feature"] == original[deferred["feature"]["id"]]
|
||||
assert set(original) == {admitted["id"], deferred["feature"]["id"]}
|
||||
assert [[v[:2] for v in ring] for ring in admitted["geometry"]["coordinates"]] == (
|
||||
original[admitted["id"]]["geometry"]["coordinates"]
|
||||
)
|
||||
assert "subtype" not in admitted["properties"]
|
||||
assert result["proposal_sha256"] == p["proposal_sha256"]
|
||||
|
||||
|
||||
def test_partial_admission_does_not_hide_touching_hole():
|
||||
p = proposal([[1, 1, 1, 0, 1], [1, 0, 1, 0, 1], [1, 1, 0, 0, 1]])
|
||||
result = geometry.editor_components(
|
||||
p, height_at=lambda xy: np.ones(len(xy)), height_source="synthetic-plane"
|
||||
)
|
||||
assert len(result["features"]) == len(result["deferred"]) == 1
|
||||
assert shape(result["deferred"][0]["feature"]["geometry"]).area == 7
|
||||
assert shape(result["features"][0]["geometry"]).area == 3
|
||||
|
||||
|
||||
def test_partial_admission_keeps_atomic_integrity_and_batch_budget(monkeypatch):
|
||||
p = proposal([[1, 0, 1]])
|
||||
|
||||
def forbidden(xy):
|
||||
raise AssertionError("Must reject entire batch before callback")
|
||||
|
||||
changed = copy.deepcopy(p)
|
||||
changed["features"][0]["geometry"]["coordinates"][0][0][0] += 1
|
||||
with pytest.raises(ValueError, match="Changed"):
|
||||
geometry.editor_components(changed, height_at=forbidden, height_source="test")
|
||||
duplicate = copy.deepcopy(p)
|
||||
duplicate["features"][1]["id"] = duplicate["features"][0]["id"]
|
||||
duplicate.pop("proposal_sha256")
|
||||
duplicate["proposal_sha256"] = geometry.digest(duplicate)
|
||||
with pytest.raises(ValueError, match="identity"):
|
||||
geometry.editor_components(duplicate, height_at=forbidden, height_source="test")
|
||||
monkeypatch.setattr(geometry, "MAX_EDITOR_WORK", 20)
|
||||
with pytest.raises(ValueError, match="work budget"):
|
||||
geometry.editor_components(p, height_at=forbidden, height_source="test")
|
||||
|
||||
|
||||
def test_partial_all_valid_equals_strict_and_propagates_programming_error():
|
||||
p = proposal([[1, 0, 1]])
|
||||
result = geometry.editor_components(
|
||||
p, height_at=lambda xy: np.ones(len(xy)), height_source="test"
|
||||
)
|
||||
assert result["complete"] and result["deferred"] == []
|
||||
assert result["features"] == geometry.editor_features(
|
||||
p, height_at=lambda xy: np.ones(len(xy)), height_source="test"
|
||||
)
|
||||
|
||||
for error_type in (ValueError, RuntimeError):
|
||||
def broken(xy, error_type=error_type):
|
||||
raise error_type("Unexpected sampler implementation failure")
|
||||
|
||||
with pytest.raises(error_type, match="Unexpected"):
|
||||
geometry.editor_components(p, height_at=broken, height_source="test")
|
||||
|
||||
with pytest.raises(ValueError, match="invalid shape"):
|
||||
geometry.editor_components(p, height_at=lambda xy: 3., height_source="test")
|
||||
|
||||
Reference in New Issue
Block a user