feat(grunnlag): the approved EEA assessment as a fixed table, and M7 rejects a net present value that is not a number (clarifications 136 and 139)

fra_frys takes the assessment of clarification 136 («usikker» for all
four ownership forms) and has no guard any more; it is still not called
before part 6. beste_per_trekning raises on NaN, where the best would
depend on the order of the solutions.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-11-14 06:43:45 +01:00
commit 6a51c4f4d2
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
6 changed files with 75 additions and 37 deletions

View file

@ -119,6 +119,15 @@ def test_m7_hvem_som_er_best_blant_a_b_og_c() -> None:
# ------------------------------------------------------------------ M3 and M4
def test_M7_avviser_en_netto_naaverdi_som_ikke_er_et_tall() -> None:
"""Clarification 139: with NaN the best would depend on the order of the solutions."""
with pytest.raises(ValueError, match="not a number in draw 1"):
dommer.beste_per_trekning({Losning.A: [1.0, math.nan], Losning.B: [2.0, 0.0]})
with pytest.raises(ValueError, match="not a number in draw 0"):
dommer.beste_per_trekning({Losning.B: [0.0], Losning.C: [math.nan]})
assert dommer.beste_per_trekning({Losning.A: [-math.inf], Losning.B: [None]}) == [(Losning.A,)]
def test_m3_verste_prisvirkning_i_R(oppdiktet: LagInndata) -> None:
"""One facility in R takes 3.942 TWh from the balance: 39.42 kr/MWh on a price of 600.

View file

@ -99,12 +99,22 @@ def test_faste_verdier_settes_etter_trekningen_i_filas_enhet(grunnlag: gl.Grunnl
grunnlag.med_verdier({"finnes_ikke": 1.0})
def test_grunnlaget_fra_frysen_stanser_foer_noe_leses_uten_EOS_vurderingen() -> None:
"""Clarification 127, «Mangler før del 6»: the guard comes before any file is read."""
with pytest.raises(gl.GrunnlagError, match=r"EØS-vurderingen per eierform er ikke fastsatt"):
gl.fra_frys(None, parametere=Path("/finnes/ikke.json"), data=Path("/finnes/ikke"))
with pytest.raises(gl.GrunnlagError, match=r"avklaring 127"):
gl.fra_frys(None)
def test_EOS_vurderingen_er_usikker_for_alle_fire_eierformene(grunnlag: gl.Grunnlag) -> None:
"""Clarification 136, approved 2026-11-14: no form is taken out and none is told apart."""
assert dict(gl.EOS_VURDERING) == {
"direkte": "usikker",
"heleid_selskap": "usikker",
"majoritet_boers": "usikker",
"petroleumsmodell": "usikker",
}
assert set(gl.EOS_VURDERING) == set(grunnlag.eos)
assert set(gl.EOS_VURDERING.values()) <= set(gl.EOS_VURDERINGER)
def test_grunnlaget_fra_frysen_har_ingen_sperre_og_leser_filene_det_faar() -> None:
"""The guard of clarification 127 is gone; with files that do not exist nothing is read."""
with pytest.raises(FileNotFoundError):
gl.fra_frys(parametere=Path("/finnes/ikke.json"), data=Path("/finnes/ikke"))
def test_den_frosne_sjekksummen_er_den_i_parameterkoden() -> None:

View file

@ -390,18 +390,21 @@ def test_inngangsfila_leses_strengt_og_stanser_foer_noe_regnes(
assert not ut.exists()
def test_frysen_stanser_ved_vakten(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
"""Clarification 127: until the EEA assessment is written down, --frys stops at once."""
sti = _skriv_inngang(tmp_path, {"navn": "x"})
for argumenter in (
["scenario", sti, "--frys", "--ut", str(tmp_path / "ut")],
["hovedkjoring", "--frys", "--ut", str(tmp_path / "ut")],
):
assert vt.main(argumenter) == 2
assert (
"EØS-vurderingen per eierform er ikke fastsatt (avklaring 127)"
in capsys.readouterr().err
)
def test_frysen_henter_grunnlaget_fra_frysen(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
"""--frys asks for the basis from the freeze; the freeze itself is not read before part 6."""
kalt: list[tuple[object, ...]] = []
def fra_frys(*args: object) -> gl.Grunnlag:
kalt.append(args)
msg = "ikke lest i testen"
raise gl.GrunnlagError(msg)
monkeypatch.setattr(gl, "fra_frys", fra_frys)
assert vt.main(["hovedkjoring", "--frys", "--ut", str(tmp_path / "ut")]) == 2
assert "ikke lest i testen" in capsys.readouterr().err
assert kalt == [()]
assert not (tmp_path / "ut").exists()