forked from cylc/cylc-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for xtrigger validation, which provides simple …
…examples for each of the built in xtriggers. - Xrandom validate function - Init test xrandom validate function - Add unit tests for validation of built in xtriggers
- Loading branch information
Showing
7 changed files
with
301 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. | ||
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from cylc.flow.exceptions import WorkflowConfigError | ||
from cylc.flow.xtriggers.echo import validate | ||
import pytest | ||
from pytest import param | ||
|
||
|
||
def test_validate_good_path(): | ||
assert validate( | ||
[], {'succeed': False, 'egg': 'fried', 'potato': 'baked'}, 'succeed' | ||
) is None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'args, kwargs', ( | ||
param([False], {}, id='no-kwarg'), | ||
param([], {'spud': 'mashed'}, id='no-succeed-kwarg'), | ||
) | ||
) | ||
def test_validate_exceptions(args, kwargs): | ||
with pytest.raises(WorkflowConfigError, match='^Requires'): | ||
validate(args, kwargs, 'blah') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. | ||
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from cylc.flow.exceptions import WorkflowConfigError | ||
from cylc.flow.xtriggers.wall_clock import validate | ||
from metomi.isodatetime.parsers import DurationParser | ||
import pytest | ||
from pytest import param | ||
|
||
|
||
@pytest.fixture | ||
def monkeypatch_interval_parser(monkeypatch): | ||
"""Interval parse only works normally if a WorkflowSpecifics | ||
object identify the parser to be used. | ||
""" | ||
monkeypatch.setattr( | ||
'cylc.flow.xtriggers.wall_clock.interval_parse', | ||
DurationParser().parse | ||
) | ||
|
||
|
||
def test_validate_good_path(monkeypatch_interval_parser): | ||
assert validate([], {}, 'Alles Gut') is None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'args, kwargs, err', ( | ||
param([1, 2], {}, "^Too", id='too-many-args'), | ||
param([], {'egg': 12}, "^Illegal", id='illegal-arg'), | ||
param([1], {}, "^Invalid", id='invalid-offset-int'), | ||
param([], {'offset': 'Zaphod'}, "^Invalid", id='invalid-offset-str'), | ||
) | ||
) | ||
def test_validate_exceptions( | ||
monkeypatch_interval_parser, args, kwargs, err | ||
): | ||
with pytest.raises(WorkflowConfigError, match=err): | ||
validate(args, kwargs, 'Alles Gut') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. | ||
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import pytest | ||
from pytest import param | ||
|
||
from cylc.flow.xtriggers.xrandom import validate | ||
from cylc.flow.exceptions import WorkflowConfigError | ||
|
||
|
||
def test_validate_good_path(): | ||
assert validate([1], {'secs': 0, '_': 'HelloWorld'}, 'good_path') is None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'args, kwargs, err', ( | ||
param([100], {'f': 1.1, 'b': 1, 'x': 2}, 'Too', id='too-many-args'), | ||
param([], {}, 'Wrong number', id='too-few-args'), | ||
param(['foo'], {}, '\'percent', id='percent-not-numeric'), | ||
param([101], {}, '\'percent', id='percent>100'), | ||
param([-1], {}, '\'percent', id='percent<0'), | ||
param([100], {'egg': 1}, 'Illegal', id='invalid-kwarg'), | ||
param([100], {'secs': 1.1}, "'secs'", id='secs-not-int'), | ||
) | ||
) | ||
def test_validate_exceptions(args, kwargs, err): | ||
"""Illegal args and kwargs cause a WorkflowConfigError raised.""" | ||
with pytest.raises(WorkflowConfigError, match=f'^{err}'): | ||
validate(args, kwargs, 'blah') |