From e1024d1a099a6e59426631c09e29e56ec1464193 Mon Sep 17 00:00:00 2001 From: Dobson <bdobson@ic.ac.uk> Date: Mon, 6 Jan 2025 16:45:06 +0000 Subject: [PATCH 1/3] create failing test --- tests/test_land.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_land.py b/tests/test_land.py index 7925def..ad183ff 100644 --- a/tests/test_land.py +++ b/tests/test_land.py @@ -1447,6 +1447,7 @@ def test_apply_surface_overrides(tmp_path): "name": "land1", "type_": "Land", "percolation_residence_time": 0.1, + "data_input_dict": {"fake-key": 1}, "surfaces": { "Woodland": { "area": 100, @@ -1454,6 +1455,7 @@ def test_apply_surface_overrides(tmp_path): "type_": "GrowingSurface", "ET_depletion_factor": 0.75, "surface": "Woodland", + "data_input_dict": {"fake-key": 1}, }, "Grass": { "area": 200, @@ -1461,6 +1463,7 @@ def test_apply_surface_overrides(tmp_path): "type_": "GrowingSurface", "ET_depletion_factor": 0.75, "surface": "Grass", + "data_input_dict": {"fake-key": 1}, }, }, }, From 539cdc1321b93d1c0b308c243671e943d6f97026 Mon Sep 17 00:00:00 2001 From: Dobson <bdobson@ic.ac.uk> Date: Tue, 7 Jan 2025 09:37:07 +0000 Subject: [PATCH 2/3] use real data in failing test --- tests/test_land.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_land.py b/tests/test_land.py index ad183ff..9f6d9b9 100644 --- a/tests/test_land.py +++ b/tests/test_land.py @@ -1431,6 +1431,14 @@ def test_apply_surface_overrides(tmp_path): import yaml from wsimod.orchestration.model import Model + with (tmp_path / "fake_surface_inputs.csv").open("w") as f: + f.write("node,surface,variable,time,value\n") + f.write("land1,Woodland,srp-dry,2000-01-01,1\n") + + with (tmp_path / "fake_inputs.csv").open("w") as f: + f.write("node,variable,time,value\n") + f.write("land1,et0,2000-01-01,1\n") + config = { "arcs": { "arc1": { @@ -1447,7 +1455,7 @@ def test_apply_surface_overrides(tmp_path): "name": "land1", "type_": "Land", "percolation_residence_time": 0.1, - "data_input_dict": {"fake-key": 1}, + "filename": str(tmp_path / "fake_inputs.csv"), "surfaces": { "Woodland": { "area": 100, @@ -1455,7 +1463,7 @@ def test_apply_surface_overrides(tmp_path): "type_": "GrowingSurface", "ET_depletion_factor": 0.75, "surface": "Woodland", - "data_input_dict": {"fake-key": 1}, + "filename": str(tmp_path / "fake_surface_inputs.csv"), }, "Grass": { "area": 200, @@ -1463,7 +1471,7 @@ def test_apply_surface_overrides(tmp_path): "type_": "GrowingSurface", "ET_depletion_factor": 0.75, "surface": "Grass", - "data_input_dict": {"fake-key": 1}, + "filename": str(tmp_path / "fake_surface_inputs.csv"), }, }, }, From 0c301566166a34caae7fb45a22d8d2144d147b76 Mon Sep 17 00:00:00 2001 From: Dobson <bdobson@ic.ac.uk> Date: Tue, 7 Jan 2025 09:46:52 +0000 Subject: [PATCH 3/3] fix test --- tests/test_land.py | 1 - tests/test_nodes.py | 4 ++-- wsimod/nodes/land.py | 5 +++-- wsimod/nodes/nodes.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_land.py b/tests/test_land.py index 9f6d9b9..0567390 100644 --- a/tests/test_land.py +++ b/tests/test_land.py @@ -1493,7 +1493,6 @@ def test_apply_surface_overrides(tmp_path): "surfaces": { "Woodland": { "surface": "Woodland", - "type_": "GrowingSurface", "area": 1000, "ET_depletion_factor": 0.8, } diff --git a/tests/test_nodes.py b/tests/test_nodes.py index a8a211b..dc19c61 100644 --- a/tests/test_nodes.py +++ b/tests/test_nodes.py @@ -430,7 +430,7 @@ def test_data_overrides(self): ) input_data = pd.read_csv(data_path) - overrides = {"data_input_dict": data_path} + overrides = {"filename": data_path} node = Node(name="") node.apply_overrides(overrides) node.t = list(node.data_input_dict.keys())[0][1] @@ -440,7 +440,7 @@ def test_data_overrides(self): node.get_data_input("temperature"), ) # test runtime error - self.assertRaises(RuntimeError, lambda: node.apply_overrides({})) + self.assertRaises(RuntimeError, lambda: node.apply_overrides({"filename": 123})) if __name__ == "__main__": diff --git a/wsimod/nodes/land.py b/wsimod/nodes/land.py index 0409ffa..a97c9f3 100644 --- a/wsimod/nodes/land.py +++ b/wsimod/nodes/land.py @@ -183,11 +183,12 @@ def apply_overrides(self, overrides=Dict[str, Any]): self.surface_runoff.residence_time = self.surface_residence_time self.subsurface_runoff.residence_time = self.subsurface_residence_time self.percolation.residence_time = self.percolation_residence_time - super().apply_overrides(overrides) - for surface, override in overrides.get("surfaces", {}).items(): + for surface, override in overrides.pop("surfaces", {}).items(): self.get_surface(surface).apply_overrides(override) + super().apply_overrides(overrides) + def apply_irrigation(self): """Iterate over any irrigation functions (needs further testing.. diff --git a/wsimod/nodes/nodes.py b/wsimod/nodes/nodes.py index a405917..b3d8af2 100644 --- a/wsimod/nodes/nodes.py +++ b/wsimod/nodes/nodes.py @@ -90,7 +90,7 @@ def apply_overrides(self, overrides: Dict[str, Any] = {}) -> None: # overrides data_input_dict from wsimod.orchestration.model import read_csv - content = overrides.pop("data_input_dict", self.data_input_dict) + content = overrides.pop("filename", None) if isinstance(content, str): self.data_input_dict = read_csv(content) elif not content: