From b32358f1ca0f7e02d0e233255b872dcf5d39a7d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20C=2E=20Riven=C3=A6s?= Date: Fri, 28 Oct 2022 12:24:59 +0200 Subject: [PATCH] Fix issue when parameters.txt is missing, cf. #258 --- src/fmu/dataio/_fmu_provider.py | 4 +++- tests/test_units/test_fmuprovider_class.py | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/fmu/dataio/_fmu_provider.py b/src/fmu/dataio/_fmu_provider.py index 02128336d..3bc891e7e 100644 --- a/src/fmu/dataio/_fmu_provider.py +++ b/src/fmu/dataio/_fmu_provider.py @@ -196,7 +196,9 @@ def get_ert2_information(self): nested_params = _utils.nested_parameters_dict(params) self.ert2["params"] = nested_params logger.debug("parameters.txt parsed.") - logger.debug("parameters.txt was not found") + else: + self.ert2["params"] = None + logger.debug("parameters.txt was not found") # store jobs.json if required! if self.dataio.include_ert2jobs: diff --git a/tests/test_units/test_fmuprovider_class.py b/tests/test_units/test_fmuprovider_class.py index c0c359e00..00251483c 100644 --- a/tests/test_units/test_fmuprovider_class.py +++ b/tests/test_units/test_fmuprovider_class.py @@ -44,6 +44,22 @@ def test_fmuprovider_ert2_provider(fmurun, globalconfig1): assert myfmu.real_id == 0 +def test_fmuprovider_ert2_provider_missing_parameter_txt(fmurun, globalconfig1): + """Test for an ERT2 case, when missing file parameter.txt (e.g. pred. run)""" + + os.chdir(fmurun) + (fmurun / "parameters.txt").unlink() + + ex = dio.ExportData(fmu_context="realization", config=globalconfig1) + ex._rootpath = fmurun + + myfmu = _FmuProvider(ex) + myfmu.detect_provider() + assert myfmu.case_name == "ertrun1" + assert myfmu.real_name == "realization-0" + assert myfmu.real_id == 0 + + def test_fmuprovider_prehook_case(globalconfig2, tmp_path): """The fmu run case metadata is initialized with Initialize case; then fet provider. @@ -59,7 +75,6 @@ def test_fmuprovider_prehook_case(globalconfig2, tmp_path): caseroot.mkdir(parents=True) os.chdir(caseroot) - print("XXXX", caseroot) exp = icase.export( rootfolder=caseroot, @@ -70,7 +85,6 @@ def test_fmuprovider_prehook_case(globalconfig2, tmp_path): casemetafile = caseroot / "share/metadata/fmu_case.yml" assert casemetafile.is_file() assert exp == str(casemetafile.resolve()) - print("Case metafile", casemetafile) eobj = dio.ExportData( config=globalconfig2, @@ -82,10 +96,6 @@ def test_fmuprovider_prehook_case(globalconfig2, tmp_path): casepath=caseroot, ) - print(eobj._rootpath) - print(eobj._pwd) - print(eobj._inside_rms) - myfmu = _FmuProvider(eobj, verbosity="INFO") myfmu.detect_provider() assert myfmu.case_name == "prehook"