Skip to content

Commit

Permalink
TST: Change to correct model argument format in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tnatt committed Apr 9, 2024
1 parent ea7dc66 commit 43e37ba
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/fmu/dataio/dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def _check_process_object(self, obj: types.Inferrable) -> None:
def _get_fmu_provider(self) -> FmuProvider:
assert isinstance(self.fmu_context, FmuContext)
return FmuProvider(
model=self.config.get("model", None),
model=self.config.get("model"),
fmu_context=self.fmu_context,
casepath_proposed=self.casepath or "",
include_ertjobs=self.include_ertjobs,
Expand Down
2 changes: 1 addition & 1 deletion src/fmu/dataio/providers/_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class FmuProvider:
workflow: Descriptive work flow info
"""

model: str = ""
model: dict | None = field(default_factory=dict)
fmu_context: FmuContext = FmuContext.REALIZATION
include_ertjobs: bool = True
casepath_proposed: str | Path = ""
Expand Down
52 changes: 40 additions & 12 deletions tests/test_units/test_fmuprovider_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

FOLDERTREE = "/scratch/myfield/case/realization-13/iter-2/"

GLOBAL_CONFIG_MODEL = {"name": "Model2", "revision": "22.1.0"}


def test_get_folderlist_from_path():
"""Test static method on getting folders from a path"""
Expand All @@ -38,7 +40,7 @@ def test_fmuprovider_no_provider():
"""Testing the FmuProvider where no ERT context is found from env variables."""

myfmu = FmuProvider(
model="Model2",
model=GLOBAL_CONFIG_MODEL,
fmu_context=FmuContext.REALIZATION,
casepath_proposed="",
include_ertjobs=False,
Expand All @@ -48,6 +50,26 @@ def test_fmuprovider_no_provider():
assert myfmu.get_provider() is None


def test_fmuprovider_model_info_in_metadata(fmurun_w_casemetadata):
"""Test that the model info is stored and preserved in the metadata."""

myfmu = FmuProvider(
model=GLOBAL_CONFIG_MODEL,
fmu_context=FmuContext.REALIZATION,
workflow="some work flow",
)

assert "model" in myfmu._metadata
assert myfmu._metadata["model"] == GLOBAL_CONFIG_MODEL

myfmu = FmuProvider(
model=None,
fmu_context=FmuContext.REALIZATION,
workflow="some work flow",
)
assert not myfmu._metadata["model"]


def test_fmuprovider_ert_provider_guess_casemeta_path(fmurun):
"""The casepath input is empty, but try guess from ERT RUNPATH without success.
Expand All @@ -56,7 +78,7 @@ def test_fmuprovider_ert_provider_guess_casemeta_path(fmurun):
os.chdir(fmurun)
with pytest.warns(UserWarning, match="Case metadata does not exist"):
myfmu = FmuProvider(
model="Model2",
model=GLOBAL_CONFIG_MODEL,
fmu_context=FmuContext.REALIZATION,
casepath_proposed="", # if casepath is undef, try deduce from, _ERT_RUNPATH
include_ertjobs=False,
Expand All @@ -82,7 +104,7 @@ def test_fmuprovider_ert_provider_missing_parameter_txt(

with pytest.warns(UserWarning, match="parameters.txt file was not found"):
myfmu = FmuProvider(
model="Model2",
model=GLOBAL_CONFIG_MODEL,
fmu_context=FmuContext.REALIZATION,
include_ertjobs=True,
workflow="some work flow",
Expand All @@ -97,7 +119,7 @@ def test_fmuprovider_arbitrary_iter_name(fmurun_w_casemetadata_pred):

os.chdir(fmurun_w_casemetadata_pred)
myfmu = FmuProvider(
model="Model2",
model=GLOBAL_CONFIG_MODEL,
fmu_context=FmuContext.REALIZATION,
include_ertjobs=True,
workflow="some work flow",
Expand Down Expand Up @@ -145,7 +167,7 @@ def test_fmuprovider_prehook_case(tmp_path, globalconfig2, fmurun_prehook):
os.chdir(fmurun_prehook)
logger.debug("Case root proposed is: %s", caseroot)
myfmu = FmuProvider(
model="Model567",
model=GLOBAL_CONFIG_MODEL,
fmu_context=FmuContext.CASE,
include_ertjobs=False,
workflow="some work flow",
Expand All @@ -165,7 +187,7 @@ def test_fmuprovider_detect_no_case_metadata(fmurun):

with pytest.warns(UserWarning):
myfmu = FmuProvider(
model="Model567",
model=GLOBAL_CONFIG_MODEL,
fmu_context=FmuContext.REALIZATION,
)
assert myfmu._case_name == "ertrun1"
Expand All @@ -181,13 +203,15 @@ def test_fmuprovider_valid_restart_env(monkeypatch, fmurun_w_casemetadata, fmuru
"""
os.chdir(fmurun_w_casemetadata)
fmu_restart_from = FmuProvider(
model="Model with restart", fmu_context=FmuContext.REALIZATION
model=GLOBAL_CONFIG_MODEL, fmu_context=FmuContext.REALIZATION
)

monkeypatch.setenv(RESTART_PATH_ENVNAME, str(fmurun_w_casemetadata))

os.chdir(fmurun_pred)
fmu_restart = FmuProvider(model="Modelrun", fmu_context=FmuContext.REALIZATION)
fmu_restart = FmuProvider(
model=GLOBAL_CONFIG_MODEL, fmu_context=FmuContext.REALIZATION
)

assert (
fmu_restart._metadata["iteration"]["restart_from"]
Expand All @@ -204,12 +228,14 @@ def test_fmuprovider_invalid_restart_env(
"""
os.chdir(fmurun_w_casemetadata)

_ = FmuProvider(model="Model with restart", fmu_context=FmuContext.REALIZATION)
_ = FmuProvider(model=GLOBAL_CONFIG_MODEL, fmu_context=FmuContext.REALIZATION)

monkeypatch.setenv(RESTART_PATH_ENVNAME, "/path/to/somewhere/invalid")

os.chdir(fmurun_pred)
fmu_restart = FmuProvider(model="Modelrun", fmu_context=FmuContext.REALIZATION)
fmu_restart = FmuProvider(
model=GLOBAL_CONFIG_MODEL, fmu_context=FmuContext.REALIZATION
)
assert "restart_from" not in fmu_restart._metadata["iteration"]


Expand All @@ -220,13 +246,15 @@ def test_fmuprovider_no_restart_env(monkeypatch, fmurun_w_casemetadata, fmurun_p
"""
os.chdir(fmurun_w_casemetadata)

_ = FmuProvider(model="Model with restart", fmu_context=FmuContext.REALIZATION)
_ = FmuProvider(model=GLOBAL_CONFIG_MODEL, fmu_context=FmuContext.REALIZATION)

monkeypatch.setenv(RESTART_PATH_ENVNAME, "/path/to/somewhere/invalid")
monkeypatch.delenv(RESTART_PATH_ENVNAME)

os.chdir(fmurun_pred)
fmu_restart = FmuProvider(model="Modelrun", fmu_context=FmuContext.REALIZATION)
fmu_restart = FmuProvider(
model=GLOBAL_CONFIG_MODEL, fmu_context=FmuContext.REALIZATION
)
assert "restart_from" not in fmu_restart._metadata["iteration"]


Expand Down

0 comments on commit 43e37ba

Please sign in to comment.