Skip to content

Commit

Permalink
Merge pull request #52 from wxtim/fix-workflow-state-check.tests2
Browse files Browse the repository at this point in the history
Extra testing for fix-workflow-state-check
  • Loading branch information
hjoliver authored Jun 12, 2024
2 parents fa22199 + d59bc23 commit c51ff6e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
4 changes: 1 addition & 3 deletions cylc/flow/xtriggers/workflow_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def validate(args: Dict[str, Any]):
raise WorkflowConfigError(
"Full ID needed: workflow//cycle/task[:selector].")

try:
int(args["flow_num"])
except ValueError:
if not isinstance(args["flow_num"], int):
raise WorkflowConfigError("flow_num must be an integer.")


Expand Down
37 changes: 37 additions & 0 deletions tests/unit/xtriggers/test_workflow_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import pytest

from cylc.flow.dbstatecheck import output_fallback_msg
from cylc.flow.exceptions import WorkflowConfigError
from cylc.flow.rundb import CylcWorkflowDAO
from cylc.flow.workflow_files import WorkflowFiles
from cylc.flow.xtriggers.workflow_state import (
_workflow_state_backcompat,
workflow_state,
validate,
)
from cylc.flow.xtriggers.suite_state import suite_state

Expand Down Expand Up @@ -260,3 +262,38 @@ def test__workflow_state_backcompat(tmp_run_dir: 'Callable'):
assert satisfied
satisfied, _ = func(id_, 'arrakis', '2012', message='lisan al-gaib')
assert satisfied


def test_validate_ok():
"""Validate returns ok with valid args."""
validate({
'workflow_task_id': 'foo//1/bar',
'offset': 'PT1H',
'flow_num': 44,
})


@pytest.mark.parametrize(
'id_', (('foo//1'),)
)
def test_validate_fail_bad_id(id_):
"""Validation failure for bad id"""
with pytest.raises(WorkflowConfigError, match='Full ID needed'):
validate({
'workflow_task_id': id_,
'offset': 'PT1H',
'flow_num': 44,
})


@pytest.mark.parametrize(
'flow_num', ((4.25260), ('Belguim'))
)
def test_validate_fail_non_int_flow(flow_num):
"""Validate failure for non integer flow numbers."""
with pytest.raises(WorkflowConfigError, match='must be an integer'):
validate({
'workflow_task_id': 'foo//1/bar',
'offset': 'PT1H',
'flow_num': flow_num,
})

0 comments on commit c51ff6e

Please sign in to comment.