Mirrors --add - removes AMOUNT (default: all) of a building from the copied spec. Used this to check whether BHP's HWP is still worth running after its price drop (still +19.8k-28.4k/day marginal, nowhere near a teardown call) without hand-writing two spec files. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
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_remove_drops_building_entirely_by_default():
|
|
spec = {"buildings": [{"building": "HWP", "amount": 1, "recipes": ["AL,STL,HE=>BHP"]}]}
|
|
whatif.apply_remove(spec, "HWP")
|
|
assert spec["buildings"] == []
|
|
|
|
|
|
def test_apply_remove_partial_amount():
|
|
spec = {"buildings": [{"building": "CHP", "amount": 3, "recipes": ["MG,S,CU=>IND"]}]}
|
|
whatif.apply_remove(spec, "CHP:1")
|
|
assert spec["buildings"] == [{"building": "CHP", "amount": 2, "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}
|