Skip to content

Commit 4655158

Browse files
committed
BUG: Make 'ert_username' actually optional
1 parent f86a0b5 commit 4655158

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/fmu/dataio/scripts/create_case_metadata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def get_parser() -> argparse.ArgumentParser:
145145
"ert_username",
146146
type=str,
147147
help="Deprecated and can safely be removed",
148+
nargs="?", # Makes it optional
149+
default=None,
148150
)
149151
parser.add_argument(
150152
"--sumo",

tests/test_ert_integration/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def fmu_snakeoil_project(
5454
"WF_CREATE_CASE_METADATA "
5555
"<SCRATCH>/<USER>/<CASE_DIR> " # ert case root
5656
"<CONFIG_PATH> " # ert config path
57-
"<CASE_DIR> " # ert case dir
58-
"<USER>", # ert username
57+
"<CASE_DIR>", # ert case dir
5958
encoding="utf-8",
6059
)
6160
pathlib.Path(

tests/test_ert_integration/test_simple_export_run.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,41 @@ def test_simple_export_ert_environment_variables(snakeoil_export_surface: Path)
6060
avg_poro = FmuResults.model_validate(avg_poro_metadata) # asserts valid
6161
assert avg_poro.root.fmu.ert.simulation_mode == ErtSimulationMode.test_run
6262
assert avg_poro.root.fmu.ert.experiment.id is not None
63+
64+
65+
def test_snakeoil_wf_case_metadata_includes_user(
66+
fmu_snakeoil_project: Path, monkeypatch: Any, mocker: Any
67+
) -> None:
68+
"""Test that if 'ert_username' argument is specified in WF_CREATE_CASE_METADATA
69+
a deprecation warning is emitted and the input is ignored.
70+
"""
71+
monkeypatch.chdir(fmu_snakeoil_project / "ert/model")
72+
73+
Path(
74+
fmu_snakeoil_project / "ert/bin/workflows/xhook_create_case_metadata"
75+
).write_text(
76+
"WF_CREATE_CASE_METADATA <SCRATCH>/<USER>/<CASE_DIR> <CONFIG_PATH> <CASE_DIR> "
77+
"<USER>", # ert user (now deprecated)
78+
encoding="utf-8",
79+
)
80+
81+
add_create_case_workflow("snakeoil.ert")
82+
83+
mocker.patch(
84+
"sys.argv",
85+
["ert", "ensemble_experiment", "snakeoil.ert", "--disable-monitoring"],
86+
)
87+
with pytest.warns(FutureWarning, match="'ert_username' is deprecated"):
88+
ert.__main__.main()
89+
90+
fmu_case_yml = (
91+
fmu_snakeoil_project / "scratch/user/snakeoil/share/metadata/fmu_case.yml"
92+
)
93+
assert fmu_case_yml.exists()
94+
95+
with open(fmu_case_yml, encoding="utf-8") as f:
96+
fmu_case = yaml.safe_load(f)
97+
98+
# check that user input is ignored
99+
assert fmu_case["fmu"]["case"]["user"]["id"] != "user"
100+
assert fmu_case["fmu"]["case"]["user"]["id"] == getpass.getuser()

0 commit comments

Comments
 (0)