From ae4656eef49f865aa556128fbc3f9cd95400ac8d Mon Sep 17 00:00:00 2001 From: "Oddvar Lia (ST MSU GEO)" Date: Tue, 3 May 2022 18:38:13 +0200 Subject: [PATCH] Extend design_kw to accept template files for xml files and only give warnings, not stop by error. Add tests for new functions that check for xml format. --- semeio/jobs/design_kw/design_kw.py | 13 ++++++ .../data/parameters_for_xml_case.txt | 16 ++++++++ .../data/template_xml_format.reference | 32 +++++++++++++++ .../design_kw/data/template_xml_format.tmpl | 32 +++++++++++++++ tests/jobs/design_kw/test_design_kw.py | 41 +++++++++++++++++-- 5 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 tests/jobs/design_kw/data/parameters_for_xml_case.txt create mode 100644 tests/jobs/design_kw/data/template_xml_format.reference create mode 100644 tests/jobs/design_kw/data/template_xml_format.tmpl diff --git a/semeio/jobs/design_kw/design_kw.py b/semeio/jobs/design_kw/design_kw.py index 0e65cbe33..ffd44557d 100644 --- a/semeio/jobs/design_kw/design_kw.py +++ b/semeio/jobs/design_kw/design_kw.py @@ -3,6 +3,8 @@ import shlex import re +from typing import List + _STATUS_FILE_NAME = "DESIGN_KW.OK" @@ -61,6 +63,13 @@ def all_matched(line, template_file_name, template): f"but this is probably a Perl file" ) ) + elif is_xml(template_file_name, template): + _logger.warning( # pylint: disable=logging-fstring-interpolation + ( + f"{unmatched} not found in design matrix, " + f"but this is probably an xml file" + ) + ) else: _logger.error( # pylint: disable=logging-fstring-interpolation f"{unmatched} not found in design matrix" @@ -73,6 +82,10 @@ def is_perl(file_name, template): return file_name.endswith(".pl") or template[0].find("perl") != -1 +def is_xml(file_name: str, template: List[str]): + return file_name.endswith(".xml") or template[0].find("?xml") != -1 + + def unmatched_templates(line): bracketpattern = re.compile("<.+?>") if bracketpattern.search(line): diff --git a/tests/jobs/design_kw/data/parameters_for_xml_case.txt b/tests/jobs/design_kw/data/parameters_for_xml_case.txt new file mode 100644 index 000000000..fa17b9fab --- /dev/null +++ b/tests/jobs/design_kw/data/parameters_for_xml_case.txt @@ -0,0 +1,16 @@ +prob_FP_FP 0.9 +prob_CH_FP 0.0 +prob_CR_FP 0.05 +prob_CO_FP 0.05 +prob_FP_CH 0.1 +prob_CH_CH 0.85 +prob_CR_CH 0.05 +prob_CO_CH 0.0 +prob_FP_CR 0.1 +prob_CH_CR 0.1 +prob_CR_CR 0.75 +prob_CO_CR 0.05 +prob_FP_CO 0.05 +prob_CH_CO 0.0 +prob_CR_CO 0.05 +prob_CO_CO 0.90 diff --git a/tests/jobs/design_kw/data/template_xml_format.reference b/tests/jobs/design_kw/data/template_xml_format.reference new file mode 100644 index 000000000..642311610 --- /dev/null +++ b/tests/jobs/design_kw/data/template_xml_format.reference @@ -0,0 +1,32 @@ + + + + geogrid + Zone + Facies_true_model + ProbTrend + 1 2 3 + 1 + + Floodplain Floodplain 0.9 + Channel Floodplain 0.0 + Crevasse Floodplain 0.05 + Coal Floodplain 0.05 + + Floodplain Channel 0.1 + Channel Channel 0.85 + Crevasse Channel 0.05 + Coal Channel 0.0 + + Floodplain Crevasse 0.1 + Channel Crevasse 0.1 + Crevasse Crevasse 0.75 + Coal Crevasse 0.05 + + Floodplain Coal 0.05 + Channel Coal 0.0 + Crevasse Coal 0.05 + Coal Coal 0.90 + + + diff --git a/tests/jobs/design_kw/data/template_xml_format.tmpl b/tests/jobs/design_kw/data/template_xml_format.tmpl new file mode 100644 index 000000000..d3388397b --- /dev/null +++ b/tests/jobs/design_kw/data/template_xml_format.tmpl @@ -0,0 +1,32 @@ + + + + geogrid + Zone + Facies_true_model + ProbTrend + 1 2 3 + 1 + + Floodplain Floodplain + Channel Floodplain + Crevasse Floodplain + Coal Floodplain + + Floodplain Channel + Channel Channel + Crevasse Channel + Coal Channel + + Floodplain Crevasse + Channel Crevasse + Crevasse Crevasse + Coal Crevasse + + Floodplain Coal + Channel Coal + Crevasse Coal + Coal Coal + + + diff --git a/tests/jobs/design_kw/test_design_kw.py b/tests/jobs/design_kw/test_design_kw.py index af0379087..844a28d5f 100644 --- a/tests/jobs/design_kw/test_design_kw.py +++ b/tests/jobs/design_kw/test_design_kw.py @@ -190,19 +190,54 @@ def test_is_perl(): assert not design_kw.is_perl(file_name, template) +def test_is_xml(): + file_name = "filename.yml" + template = ["?xml", " ECLIPSE_INIT_DATE: "] + assert design_kw.is_xml(file_name, template) + + file_name = "filename.xml" + template = ["?xml", " ECLIPSE_INIT_DATE: "] + assert design_kw.is_xml(file_name, template) + + file_name = "filename.xml" + template = [" ECLIPSE_INIT_DATE: "] + assert design_kw.is_xml(file_name, template) + + file_name = "filename.yml" + template = [" ECLIPSE_INIT_DATE: "] + assert not design_kw.is_xml(file_name, template) + + @pytest.mark.parametrize( "filenames", ( - ["template.yml.reference", "template.yml.tmpl", "template.yml"], - ["schfile.inc.reference", "schfile.inc.tmpl", "schfile.inc"], + [ + "template.yml.reference", + "template.yml.tmpl", + "template.yml", + "parameters.txt", + ], + ["schfile.inc.reference", "schfile.inc.tmpl", "schfile.inc", "parameters.txt"], + [ + "template_xml_format.reference", + "template_xml_format.tmpl", + "template_xml_format.xml", + "parameters_for_xml_case.txt", + ], ), ) def test_run(input_data, filenames): reference_filename = filenames[0] template_filename = filenames[1] result_filename = filenames[2] + parameter_filename = filenames[3] - design_kw.run(template_filename, result_filename, log_level=logging.DEBUG) + design_kw.run( + template_filename, + result_filename, + log_level=logging.DEBUG, + parameters_file_name=parameter_filename, + ) with open(result_filename, "r", encoding="utf-8") as result_file: result = result_file.read()