Skip to content

Commit

Permalink
Simplify test logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava authored and eivindjahren committed Nov 19, 2024
1 parent 8ebd027 commit 093c43e
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions tests/ert/unit_tests/config/test_ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import os.path
import stat
import warnings
from datetime import date
from pathlib import Path
from textwrap import dedent
Expand Down Expand Up @@ -1537,9 +1538,7 @@ def test_general_option_in_local_config_has_priority_over_site_config():


@pytest.mark.usefixtures("use_tmpdir")
def test_warning_raised_when_summary_key_and_no_simulation_job_present(caplog, recwarn):
caplog.set_level(logging.WARNING)

def test_warning_raised_when_summary_key_and_no_simulation_job_present():
with open("job_file", "w", encoding="utf-8") as fout:
fout.write("EXECUTABLE echo\nARGLIST <ECLBASE> <RUNPATH>\n")

Expand All @@ -1548,34 +1547,26 @@ def test_warning_raised_when_summary_key_and_no_simulation_job_present(caplog, r
fout.write("NUM_REALIZATIONS 1\n")
fout.write("SUMMARY *\n")
fout.write("ECLBASE RESULT_SUMMARY\n")

fout.write("INSTALL_JOB job_name job_file\n")
fout.write(
"FORWARD_MODEL job_name(<ECLBASE>=A/<ECLBASE>, <RUNPATH>=<RUNPATH>/x)\n"
)
with warnings.catch_warnings(record=True) as all_warnings:
ErtConfig.from_file("config_file.ert")

ErtConfig.from_file("config_file.ert")

# Check no warning is logged when config contains
# forward model step with <ECLBASE> and <RUNPATH> as arguments
assert not caplog.text
assert len(recwarn) == 1
assert issubclass(recwarn[0].category, ConfigWarning)
assert (
recwarn[0].message.info.message
assert any(
str(w.message)
== "Config contains a SUMMARY key but no forward model steps known to generate a summary file"
for w in all_warnings
if isinstance(w.message, ConfigWarning)
)


@pytest.mark.parametrize(
"job_name", ["eclipse", "eclipse100", "flow", "FLOW", "ECLIPSE100"]
)
@pytest.mark.usefixtures("use_tmpdir")
def test_no_warning_when_summary_key_and_simulation_job_present(
caplog, recwarn, job_name
):
caplog.set_level(logging.WARNING)

def test_no_warning_when_summary_key_and_simulation_job_present(job_name):
with open("job_file", "w", encoding="utf-8") as fout:
fout.write("EXECUTABLE echo\nARGLIST <ECLBASE> <RUNPATH>\n")

Expand All @@ -1589,9 +1580,8 @@ def test_no_warning_when_summary_key_and_simulation_job_present(
fout.write(
f"FORWARD_MODEL {job_name}(<ECLBASE>=A/<ECLBASE>, <RUNPATH>=<RUNPATH>/x)\n"
)

ErtConfig.from_file("config_file.ert")

# Check no warning is logged when config contains
# forward model step with <ECLBASE> and <RUNPATH> as arguments
assert not any(w.message for w in recwarn if issubclass(w.category, ConfigWarning))
with warnings.catch_warnings():
warnings.simplefilter("error", category=ConfigWarning)
ErtConfig.from_file("config_file.ert")

0 comments on commit 093c43e

Please sign in to comment.