Skip to content

Commit a1dc63d

Browse files
committed
fixup! Validate workflow job args against hook runtime fixtures
address review
1 parent b157fcc commit a1dc63d

File tree

1 file changed

+12
-57
lines changed

1 file changed

+12
-57
lines changed

tests/ert/unit_tests/config/test_ert_config.py

+12-57
Original file line numberDiff line numberDiff line change
@@ -1995,8 +1995,8 @@ def run(self, *args):
19951995
assert ert_config.substitutions["<FOO2>"] == "ertconfig_foo2"
19961996

19971997

1998-
@pytest.mark.usefixtures("use_tmpdir")
1999-
def test_ert_script_hook_pre_experiment_but_asks_for_storage():
1998+
@pytest.fixture
1999+
def setup_workflow_file():
20002000
workflow_file_path = os.path.join(os.getcwd(), "workflow")
20012001
with open(workflow_file_path, mode="w", encoding="utf-8") as fh:
20022002
fh.write("TEST_SCRIPT")
@@ -2005,14 +2005,17 @@ def test_ert_script_hook_pre_experiment_but_asks_for_storage():
20052005
fh.write(
20062006
dedent(
20072007
f"""
2008-
NUM_REALIZATIONS 1
2008+
NUM_REALIZATIONS 1
20092009
2010-
LOAD_WORKFLOW {workflow_file_path} workflow_alias
2011-
HOOK_WORKFLOW workflow_alias PRE_EXPERIMENT
2012-
"""
2010+
LOAD_WORKFLOW {workflow_file_path} workflow_alias
2011+
HOOK_WORKFLOW workflow_alias PRE_EXPERIMENT
2012+
"""
20132013
)
20142014
)
20152015

2016+
2017+
@pytest.mark.usefixtures("use_tmpdir", "setup_workflow_file")
2018+
def test_ert_script_hook_pre_experiment_but_asks_for_storage():
20162019
class SomeScript(ErtScript):
20172020
def run(self, storage: Storage):
20182021
pass
@@ -2031,24 +2034,8 @@ def run(self, storage: Storage):
20312034
ErtConfig.from_file("config.ert")
20322035

20332036

2034-
@pytest.mark.usefixtures("use_tmpdir")
2037+
@pytest.mark.usefixtures("use_tmpdir", "setup_workflow_file")
20352038
def test_ert_script_hook_pre_experiment_but_asks_for_ensemble():
2036-
workflow_file_path = os.path.join(os.getcwd(), "workflow")
2037-
with open(workflow_file_path, mode="w", encoding="utf-8") as fh:
2038-
fh.write("TEST_SCRIPT")
2039-
2040-
with open("config.ert", mode="w", encoding="utf-8") as fh:
2041-
fh.write(
2042-
dedent(
2043-
f"""
2044-
NUM_REALIZATIONS 1
2045-
2046-
LOAD_WORKFLOW {workflow_file_path} workflow_alias
2047-
HOOK_WORKFLOW workflow_alias PRE_EXPERIMENT
2048-
"""
2049-
)
2050-
)
2051-
20522039
class SomeScript(ErtScript):
20532040
def run(self, ensemble: LocalEnsemble):
20542041
pass
@@ -2067,24 +2054,8 @@ def run(self, ensemble: LocalEnsemble):
20672054
ErtConfig.from_file("config.ert")
20682055

20692056

2070-
@pytest.mark.usefixtures("use_tmpdir")
2057+
@pytest.mark.usefixtures("use_tmpdir", "setup_workflow_file")
20712058
def test_ert_script_hook_pre_experiment_but_asks_for_random_seed():
2072-
workflow_file_path = os.path.join(os.getcwd(), "workflow")
2073-
with open(workflow_file_path, mode="w", encoding="utf-8") as fh:
2074-
fh.write("TEST_SCRIPT")
2075-
2076-
with open("config.ert", mode="w", encoding="utf-8") as fh:
2077-
fh.write(
2078-
dedent(
2079-
f"""
2080-
NUM_REALIZATIONS 1
2081-
2082-
LOAD_WORKFLOW {workflow_file_path} workflow_alias
2083-
HOOK_WORKFLOW workflow_alias PRE_EXPERIMENT
2084-
"""
2085-
)
2086-
)
2087-
20882059
class SomeScript(ErtScript):
20892060
def run(self, random_seed: int):
20902061
pass
@@ -2098,24 +2069,8 @@ def run(self, random_seed: int):
20982069
ErtConfig.from_file("config.ert")
20992070

21002071

2101-
@pytest.mark.usefixtures("use_tmpdir")
2072+
@pytest.mark.usefixtures("use_tmpdir", "setup_workflow_file")
21022073
def test_ert_script_hook_pre_experiment_essettings_fails():
2103-
workflow_file_path = os.path.join(os.getcwd(), "workflow")
2104-
with open(workflow_file_path, mode="w", encoding="utf-8") as fh:
2105-
fh.write("TEST_SCRIPT")
2106-
2107-
with open("config.ert", mode="w", encoding="utf-8") as fh:
2108-
fh.write(
2109-
dedent(
2110-
f"""
2111-
NUM_REALIZATIONS 1
2112-
2113-
LOAD_WORKFLOW {workflow_file_path} workflow_alias
2114-
HOOK_WORKFLOW workflow_alias PRE_EXPERIMENT
2115-
"""
2116-
)
2117-
)
2118-
21192074
class SomeScript(ErtScript):
21202075
def run(self, es_settings: ESSettings):
21212076
pass

0 commit comments

Comments
 (0)