Model/tests/scripts/test_reclassify_mixed_glazing.py
Khalim Conn-Kowlessar 0ebff1bcc2 Re-classify aggregate-mix glazing overrides flattened to Double onto MIXED 🟩
One-time script (dry-run default, --apply in a transaction, idempotent) reusing the
live glazing_mix_guard so the backfill and classifier cannot drift. Maps every
genuine percentage-mix override (neither type >= 90%) off a flattened single type
onto MIXED (no overlay -> the cert's per-window glazing is kept). property_overrides
TEXT updated now; the glazing pgEnum cache write for 'Mixed glazing' is deferred
until the FE adds the member. Dry-run against the audited DB reports 647 rows.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 11:09:42 +00:00

35 lines
1.3 KiB
Python

"""The mixed-glazing reclassify maps a flattened aggregate mix onto MIXED, leaves
uniform / already-correct rows alone, and is idempotent (#1376 / ADR-0042)."""
from __future__ import annotations
from scripts.reclassify_mixed_glazing import mixed_glazing_corrections
def test_flattened_mix_rows_are_corrected_to_mixed() -> None:
# Arrange — an aggregate mix flattened to Double (the bug), a near-uniform mix
# and a clean uniform row (both correctly Double), and a pure single row.
stored = [
("40% double glazing 2002 or later, 60% single glazing", "Double glazing, 2002 or later"),
("96% double glazing 2002 or later, 4% single glazing", "Double glazing, 2002 or later"),
("100% double glazing 2002 or later", "Double glazing, 2002 or later"),
("100% single glazing", "Single glazing"),
]
# Act
corrections = mixed_glazing_corrections(stored)
# Assert — only the genuine mix is re-mapped; near-uniform and uniform stay.
assert corrections == {
"40% double glazing 2002 or later, 60% single glazing": "Mixed glazing"
}
def test_already_mixed_rows_need_no_change() -> None:
# Act / Assert — idempotent.
assert (
mixed_glazing_corrections(
[("40% double glazing 2002 or later, 60% single glazing", "Mixed glazing")]
)
== {}
)