Skip to content

Commit

Permalink
Added extra test for too high water potentials
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobcook1995 committed Nov 27, 2023
1 parent 682131e commit 60b29fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions tests/models/soil/test_env_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ def test_calculate_water_potential_impact_on_microbes(
assert np.allclose(actual_factor, expected_factor)


def test_soil_water_potential_too_high(dummy_carbon_data, top_soil_layer_index):
"""Test that too high soil water potential results in an error."""
from virtual_rainforest.models.soil.constants import SoilConsts
from virtual_rainforest.models.soil.env_factors import (
calculate_water_potential_impact_on_microbes,
)

water_potentials = np.array([-2.0, -10.0, -250.0, -10000.0])

with pytest.raises(ValueError):
calculate_water_potential_impact_on_microbes(
water_potential=water_potentials,
water_potential_halt=SoilConsts.soil_microbe_water_potential_halt,
water_potential_opt=SoilConsts.soil_microbe_water_potential_optimum,
moisture_response_curvature=SoilConsts.moisture_response_curvature,
)


def test_calculate_pH_suitability():
"""Test that calculation of pH suitability is correct."""
from virtual_rainforest.models.soil.constants import SoilConsts
Expand Down
2 changes: 1 addition & 1 deletion virtual_rainforest/models/soil/env_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def calculate_water_potential_impact_on_microbes(

# If the water potential is greater than the optimal then the function produces NaNs
# so the simulation should be interrupted
if any(water_potential > water_potential_opt):
if np.any(water_potential > water_potential_opt):
err = ValueError("Water potential greater than minimum value")
LOGGER.critical(err)
raise err
Expand Down

0 comments on commit 60b29fc

Please sign in to comment.