Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra testing for fix-workflow-state-check #52

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 failur for non integer flow numbers."""
hjoliver marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(WorkflowConfigError, match='must be an integer'):
validate({
'workflow_task_id': 'foo//1/bar',
'offset': 'PT1H',
'flow_num': flow_num,
})
Loading