Skip to content

Commit

Permalink
add tests for workflow state xtrigger validation function
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Jun 12, 2024
1 parent fa22199 commit b1b0424
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 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,35 @@ 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 inputs."""
with pytest.raises(WorkflowConfigError, match='Full ID needed'):
validate({
'workflow_task_id': id_,
'offset': 'PT1H',
'flow_num': 44,
})


def test_validate_fail_non_int_flow():
"""Validate returns ok with valid args."""
with pytest.raises(ValueError, match='must be an integer'):
validate({
'workflow_task_id': 'foo//1/bar',
'offset': 'PT1H',
'flow_num': 3.14159,
})

0 comments on commit b1b0424

Please sign in to comment.