From a51afc784a35c4dc16e57eb538c29ae87a3d3852 Mon Sep 17 00:00:00 2001 From: DanSava Date: Thu, 14 Nov 2024 16:17:10 +0200 Subject: [PATCH] Fix faulty validation for maintained forward model objectives. (cherry picked from commit e544ddcdc19898ef7aa6a8a198ebd4fdcf99e086) --- src/everest/config/everest_config.py | 2 +- tests/everest/test_config_validation.py | 28 ++++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/everest/config/everest_config.py b/src/everest/config/everest_config.py index 57c99db4cc0..27e963ae70c 100644 --- a/src/everest/config/everest_config.py +++ b/src/everest/config/everest_config.py @@ -438,7 +438,7 @@ def validate_maintained_forward_models(self) -> Self: @model_validator(mode="after") def validate_maintained_forward_model_write_objectives(self) -> Self: - if not self.objective_functions: + if not self.objective_functions or not self.forward_model: return self objectives = {objective.name for objective in self.objective_functions} check_forward_model_objective(self.forward_model, objectives) diff --git a/tests/everest/test_config_validation.py b/tests/everest/test_config_validation.py index 139fcb3f8ef..4415c0a48b6 100644 --- a/tests/everest/test_config_validation.py +++ b/tests/everest/test_config_validation.py @@ -952,37 +952,41 @@ def test_that_non_existing_workflow_jobs_cause_error(): @skipif_no_everest_models @pytest.mark.everest_models_test @pytest.mark.parametrize( - ["objective", "warning_msg"], + ["objective", "forward_model", "warning_msg"], [ ( ["npv", "rf"], + ["rf -s TEST -o rf"], "Warning: Forward model might not write the required output file for \\['npv'\\]", ), ( ["npv", "npv2"], + ["rf -s TEST -o rf"], "Warning: Forward model might not write the required output files for \\['npv', 'npv2'\\]", ), - (["rf"], None), + ( + ["rf"], + ["rf -s TEST -o rf"], + None, + ), + ( + ["rf"], + None, + None, + ), ], ) -def test_warning_forward_model_write_objectives(objective, warning_msg): - fm_steps = [ - "well_constraints -i files/well_readydate.json -c files/wc_config.yml -rc well_rate.json -o wc_wells.json", - "add_templates -i wc_wells.json -c files/at_config.yml -o at_wells.json", - "schmerge -s eclipse/include/schedule/schedule.tmpl -i at_wells.json -o eclipse/include/schedule/schedule.sch", - "eclipse100 TEST.DATA --version 2020.2", - "rf -s TEST -o rf", - ] +def test_warning_forward_model_write_objectives(objective, forward_model, warning_msg): if warning_msg is not None: with pytest.warns(ConfigWarning, match=warning_msg): EverestConfig.with_defaults( objective_functions=[{"name": o} for o in objective], - forward_model=fm_steps, + forward_model=forward_model, ) else: with warnings.catch_warnings(): warnings.simplefilter("error", category=ConfigWarning) EverestConfig.with_defaults( objective_functions=[{"name": o} for o in objective], - forward_model=fm_steps, + forward_model=forward_model, )