from pathlib import Path import sys sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "tools")) import whatif def test_apply_add_reuses_existing_recipe(): spec = {"buildings": [{"building": "POL", "amount": 1, "recipes": ["EPO,PG=>DEC"]}]} whatif.apply_add(spec, "POL:1") assert spec["buildings"] == [{"building": "POL", "amount": 2, "recipes": ["EPO,PG=>DEC"]}] def test_apply_add_new_building_needs_explicit_recipe(): spec = {"buildings": []} import pytest with pytest.raises(SystemExit): whatif.apply_add(spec, "CHP:1") def test_apply_add_appends_new_building_with_recipe(): spec = {"buildings": []} whatif.apply_add(spec, "CHP:1:MG,S,CU=>IND") assert spec["buildings"] == [{"building": "CHP", "amount": 1, "recipes": ["MG,S,CU=>IND"]}] def test_apply_infra_adds_delta(): spec = {"infrastructure": {"HB1": 4}} whatif.apply_infra(spec, "HB1:+1,HB2:+2") assert spec["infrastructure"] == {"HB1": 5, "HB2": 2}