Skip to content

Commit

Permalink
Fix monkeypatch
Browse files Browse the repository at this point in the history
  • Loading branch information
JMGilbert committed Jun 15, 2023
1 parent 3bbdfd1 commit 172a518
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
16 changes: 12 additions & 4 deletions tests/test_input_damages.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def test_concatenate_damage_output(tmp_path, monkeypatch):
"""
Test that concatenate_damage_output correctly concatenates damages across batches and saves to a single zarr file
"""
monkeypatch.setattr(dscim.preprocessing.input_damages, "validate_damages", True)
monkeypatch.setattr(
"dscim.preprocessing.input_damages.validate_damages", lambda *args: True
)

d = os.path.join(tmp_path, "concatenate_in")
if not os.path.exists(d):
Expand Down Expand Up @@ -440,7 +442,9 @@ def test_compute_ag_damages(
Test that compute_ag_damages correctly reshapes ag estimate runs for use in integration system and saves to zarr file
"""

monkeypatch.setattr(dscim.preprocessing.input_damages, "validate_damages", True)
monkeypatch.setattr(
"dscim.preprocessing.input_damages.validate_damages", lambda *args: True
)

rcp = ["rcp45", "rcp85"]
gcm = ["ACCESS1-0", "GFDL-CM3"]
Expand Down Expand Up @@ -1015,7 +1019,9 @@ def test_prep_mortality_damages(
Test that prep_mortality_damages correctly reshapes different versions of mortality estimate runs for use in integration system and saves to zarr file
"""

monkeypatch.setattr(dscim.preprocessing.input_damages, "validate_damages", True)
monkeypatch.setattr(
"dscim.preprocessing.input_damages.validate_damages", lambda *args: True
)

for b in ["6", "9"]:
ds_in = xr.Dataset(
Expand Down Expand Up @@ -1170,7 +1176,9 @@ def test_coastal_inputs(
Test that coastal_inputs correctly reshapes different versions of coastal results for use in integration system and saves to zarr file (v0.21 and v0.22 have exactly the same structure, so testing either one should be sufficient)
"""

monkeypatch.setattr(dscim.preprocessing.input_damages, "validate_damages", True)
monkeypatch.setattr(
"dscim.preprocessing.input_damages.validate_damages", lambda *args: True
)

if version_test == "v0.21":
ds_in = xr.Dataset(
Expand Down
12 changes: 9 additions & 3 deletions tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
reduce_damages,
ce_from_chunk,
)
import dscim
from pathlib import Path
import yaml

Expand Down Expand Up @@ -294,7 +293,9 @@ def test_reduce_damages(tmp_path, recipe, eta, monkeypatch):
Test that reduce_damages returns a Zarr file with damages reduced according to the expected file structure
"""

monkeypatch.setattr(dscim.preprocessing.input_damages, "validate_damages", True)
monkeypatch.setattr(
"dscim.preprocessing.preprocessing.validate_damages", lambda *args: True
)

d = tmp_path / "reduction"
d.mkdir()
Expand Down Expand Up @@ -427,10 +428,15 @@ def test_reduce_damages(tmp_path, recipe, eta, monkeypatch):
)


def test_reduce_damages_batchsize_error(tmp_path):
def test_reduce_damages_batchsize_error(tmp_path, monkeypatch):
"""
Test that reduce_damages with batchsize not equal to 15 returns an error
"""

monkeypatch.setattr(
"dscim.preprocessing.preprocessing.validate_damages", lambda *args: True
)

d = tmp_path / "reduction"
d.mkdir()
dummy_sector1_dir = d / "dummy_sector1"
Expand Down

0 comments on commit 172a518

Please sign in to comment.