From 7fedb738cb8282e5ee1134b0b720e787849ff561 Mon Sep 17 00:00:00 2001 From: dbeltran Date: Wed, 11 Dec 2024 15:25:37 +0100 Subject: [PATCH 1/2] notify_on normalized --- autosubmitconfigparser/config/configcommon.py | 16 ++++ test/unit/test_normalize_variables.py | 88 +++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/autosubmitconfigparser/config/configcommon.py b/autosubmitconfigparser/config/configcommon.py index 22a4f66..26ad0d1 100644 --- a/autosubmitconfigparser/config/configcommon.py +++ b/autosubmitconfigparser/config/configcommon.py @@ -552,6 +552,20 @@ def _normalize_wrappers_section(data_fixed: dict) -> None: data_fixed["WRAPPERS"][wrapper]["JOBS_IN_WRAPPER"] = jobs_in_wrapper.upper() data_fixed["WRAPPERS"][wrapper]["TYPE"] = str(wrapper_data.get("TYPE", "vertical")).lower() + @staticmethod + def _normalize_notify_on(data_fixed: dict, job_section) -> None: + """ + Normalize the NOTIFY_ON section to a consistent format. + """ + if "NOTIFY_ON" in data_fixed["JOBS"][job_section]: + if type(data_fixed["JOBS"][job_section]["NOTIFY_ON"]) is str: + if "," in data_fixed["JOBS"][job_section]["NOTIFY_ON"]: + data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"].split(",")] + else: + data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"].split()] + else: + data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"]] + def _normalize_jobs_section(self, data_fixed: dict, must_exists: bool ) -> None: for job, job_data in data_fixed.get("JOBS", {}).items(): if "DEPENDENCIES" in job_data or must_exists: @@ -575,6 +589,8 @@ def _normalize_jobs_section(self, data_fixed: dict, must_exists: bool ) -> None: if "ADDITIONAL_FILES" not in data_fixed["JOBS"][job] and must_exists: data_fixed["JOBS"][job]["ADDITIONAL_FILES"] = [] + self._normalize_notify_on(data_fixed, job) + @staticmethod def _normalize_dependencies(dependencies: Union[str, dict]) -> dict: """ diff --git a/test/unit/test_normalize_variables.py b/test/unit/test_normalize_variables.py index 8528782..84a5bd8 100644 --- a/test/unit/test_normalize_variables.py +++ b/test/unit/test_normalize_variables.py @@ -282,6 +282,94 @@ True, id="dependencies_status" ), + pytest.param( + { + "JOBS": { + "job1": { + "FILE": "FILE1", + "NOTIFY_ON": ["running", "COmpLETED"] + } + } + }, + { + 'JOBS': { + 'JOB1': { + 'FILE': 'FILE1', + 'ADDITIONAL_FILES': [], + 'DEPENDENCIES': {}, + 'NOTIFY_ON': ['RUNNING', 'COMPLETED'], + }, + } + }, + True, + id="notify_on_list" + ), + pytest.param( + { + "JOBS": { + "job1": { + "FILE": "FILE1", + "NOTIFY_ON": "running, COmpLETED" + } + } + }, + { + 'JOBS': { + 'JOB1': { + 'FILE': 'FILE1', + 'ADDITIONAL_FILES': [], + 'DEPENDENCIES': {}, + 'NOTIFY_ON': ['RUNNING', 'COMPLETED'], + }, + } + }, + True, + id="notify_on_string_with_," + ), + pytest.param( + { + "JOBS": { + "job1": { + "FILE": "FILE1", + "NOTIFY_ON": "running COmpLETED" + } + } + }, + { + 'JOBS': { + 'JOB1': { + 'FILE': 'FILE1', + 'ADDITIONAL_FILES': [], + 'DEPENDENCIES': {}, + 'NOTIFY_ON': ['RUNNING', 'COMPLETED'], + }, + } + }, + True, + id="notify_on_string_without_," + ), + pytest.param( + { + "JOBS": { + "job1": { + "FILE": "FILE1", + "NOTIFY_ON": "running" + } + } + }, + { + 'JOBS': { + 'JOB1': { + 'FILE': 'FILE1', + 'ADDITIONAL_FILES': [], + 'DEPENDENCIES': {}, + 'NOTIFY_ON': ['RUNNING'], + }, + } + }, + True, + id="notify_on_string_single" + ), ]) def test_normalize_variables(autosubmit_config, data, expected_data, must_exists): as_conf = autosubmit_config(expid='t000', experiment_data=data) From e5804ca13563c3945c3d0388d315ddfee3131d78 Mon Sep 17 00:00:00 2001 From: dbeltran Date: Mon, 16 Dec 2024 14:58:49 +0100 Subject: [PATCH 2/2] Address feedback --- VERSION | 2 +- autosubmitconfigparser/config/configcommon.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/VERSION b/VERSION index e9acec7..e7468c7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.75 +1.0.76 diff --git a/autosubmitconfigparser/config/configcommon.py b/autosubmitconfigparser/config/configcommon.py index 26ad0d1..5c5126d 100644 --- a/autosubmitconfigparser/config/configcommon.py +++ b/autosubmitconfigparser/config/configcommon.py @@ -557,14 +557,14 @@ def _normalize_notify_on(data_fixed: dict, job_section) -> None: """ Normalize the NOTIFY_ON section to a consistent format. """ - if "NOTIFY_ON" in data_fixed["JOBS"][job_section]: - if type(data_fixed["JOBS"][job_section]["NOTIFY_ON"]) is str: - if "," in data_fixed["JOBS"][job_section]["NOTIFY_ON"]: - data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"].split(",")] + notify_on = data_fixed["JOBS"][job_section].get("NOTIFY_ON", "") + if notify_on: + if type(notify_on) is str: + if "," in notify_on: + notify_on = notify_on.split(",") else: - data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"].split()] - else: - data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in data_fixed["JOBS"][job_section]["NOTIFY_ON"]] + notify_on = notify_on.split() + data_fixed["JOBS"][job_section]["NOTIFY_ON"] = [status.strip(" ").upper() for status in notify_on] def _normalize_jobs_section(self, data_fixed: dict, must_exists: bool ) -> None: for job, job_data in data_fixed.get("JOBS", {}).items():