mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Establishes the strict-enum pattern for Elmhurst label-to-cascade-enum
helpers: lodged-but-unrecognised labels raise `UnmappedElmhurstLabel`
instead of silently returning None and letting the cascade default to
a wrong-but-not-obviously-wrong value downstream.
Triggered by the user's observation following Slice S0380.14 ("In a
case like that, where the mapper maps to the wrong thing, is it
better to raise an exception?"). The cert 9418 "Large" cylinder miss
hid for an entire diagnostic cycle because
`_elmhurst_cylinder_size_code('Large', True)` silently returned None
→ cascade routed off the HW-with-cylinder path → 466 kWh/yr HW
under-count → Δ +2.60 SAP. Strict raising would have surfaced the
gap at the first cohort probe.
Scope-limited first pass — converts only the two cylinder helpers
(`_elmhurst_cylinder_size_code`, `_elmhurst_cylinder_insulation_code`)
to establish the pattern. Follow-up slices can extend to the other
label→enum helpers (wall_construction, wall_insulation, main_fuel,
pv_overshading, party_wall_construction, emitter_temperature,
flue_type, pump_age, …) where the source vocabulary is finite and we
control it.
Behavioural contract:
- `(label = None)` → return None (lodging genuinely absent; cert
has no cylinder, no §15.1 block, or the field is optional).
- `(label in dict)` → return mapped code (existing behaviour).
- `(label = "anything-else")` → raise UnmappedElmhurstLabel(field,
value) with a message pointing the next reader at the corresponding
mapper lookup dict.
Tests:
- `test_summary_mapper_raises_on_unmapped_cylinder_size_label` —
injects "Tiny" via dataclass mutation, asserts the public
`from_elmhurst_site_notes` propagates the raise with the right
field + value attributes.
- `test_summary_mapper_raises_on_unmapped_cylinder_insulation_label`
— mirror for the "Insulated" label dict.
- `test_all_seven_ashp_cohort_certs_extract_without_unmapped_label_raise`
— coverage forcing function: every cohort cert must extract
cleanly. New cohort certs fall under the same gate. Any future
Elmhurst-PDF variant with an unmapped cylinder label fails this
test until the dict is extended.
Tests deliberately go through `from_elmhurst_site_notes` rather than
importing the private helpers (`reportPrivateUsage` clean).
Pyright net-zero across both edited files (mapper.py 32 baseline,
test 0).
Regression suite: 689 pass + 10 fail (= handover baseline 669 + 10 +
20 new GREEN tests across S0380.2..S0380.15).
Trade-off documented in the exception's docstring: strict raising
trades graceful degradation for early detection. For the cohort-
validation workflow (this branch's purpose) early detection is the
right default. Production extraction code that needs to soft-fail on
novel Elmhurst variants can either catch `UnmappedElmhurstLabel` at
the boundary or (in a future slice) the helpers can grow a
`strict: bool = True` parameter.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
||
|---|---|---|
| .. | ||
| fixtures | ||
| __init__.py | ||
| test_elmhurst_end_to_end.py | ||
| test_elmhurst_extractor.py | ||
| test_end_to_end.py | ||
| test_extractor.py | ||
| test_pdf.py | ||
| test_summary_pdf_mapper_chain.py | ||