Debian Codegraph @

tests/u/xtriggers/test_xrandom.py

raw
1 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
2 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 import pytest
18 from pytest import param
19
20 from cylc.flow.xtriggers.xrandom import validate
21 from cylc.flow.exceptions import WorkflowConfigError
22
23
24 def test_validate_good():
25 validate({'percent': 1, 'secs': 0, '_': 'HelloWorld'})
26
27
28 @pytest.mark.parametrize(
29 'args, err', (
30 param({'percent': 'foo'}, r"'percent", id='percent-not-numeric'),
31 param({'percent': 101}, r"'percent", id='percent>100'),
32 param({'percent': -1}, r"'percent", id='percent<0'),
33 param({'percent': 100, 'secs': 1.1}, r"'secs'", id='secs-not-int'),
34 )
35 )
36 def test_validate_exceptions(args, err):
37 """Illegal args and kwargs cause a WorkflowConfigError raised."""
38 with pytest.raises(WorkflowConfigError, match=f'^{err}'):
39 validate(args)