Skip to content

Commit

Permalink
notify_on normalized (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeltrankyl authored Dec 16, 2024
1 parent 1bb4631 commit 3685a43
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.75
1.0.76
16 changes: 16 additions & 0 deletions autosubmitconfigparser/config/configcommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
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:
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():
if "DEPENDENCIES" in job_data or must_exists:
Expand All @@ -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:
"""
Expand Down
88 changes: 88 additions & 0 deletions test/unit/test_normalize_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3685a43

Please sign in to comment.