Debian Codegraph @

tests/unit/cycling/test_cycling.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
19 from cylc.flow.cycling import (
20 SequenceBase,
21 IntervalBase,
22 PointBase,
23 parse_exclusion,
24 )
25
26
27 def test_simple_abstract_class_test():
28 """Cannot instantiate abstract classes, they must be defined in
29 the subclasses"""
30 with pytest.raises(TypeError):
31 SequenceBase('sequence-string', 'context_string')
32 with pytest.raises(TypeError):
33 IntervalBase('value')
34 with pytest.raises(TypeError):
35 PointBase('value')
36
37
38 def test_parse_exclusion_simple():
39 """Tests the simple case of exclusion parsing"""
40 expression = "PT1H!20000101T02Z"
41 sequence, exclusion = parse_exclusion(expression)
42 assert sequence == "PT1H"
43 assert exclusion == ['20000101T02Z']
44
45
46 def test_parse_exclusions_list():
47 """Tests the simple case of exclusion parsing"""
48 expression = "PT1H!(T03, T06, T09)"
49 sequence, exclusion = parse_exclusion(expression)
50 assert sequence == "PT1H"
51 assert exclusion == ['T03', 'T06', 'T09']
52
53
54 def test_parse_exclusions_list_spaces():
55 """Tests the simple case of exclusion parsing"""
56 expression = "PT1H! (T03, T06, T09) "
57 sequence, exclusion = parse_exclusion(expression)
58 assert sequence == "PT1H"
59 assert exclusion == ['T03', 'T06', 'T09']
60
61
62 @pytest.mark.parametrize(
63 'expression',
64 [
65 'T01/PT1H!(T06, T09), PT5M',
66 'T01/PT1H!T03, PT17H, (T06, T09), PT5M',
67 'T01/PT1H! PT8H, (T06, T09)',
68 'T01/PT1H! T03, T06, T09',
69 'T01/PT1H !T03 !T06',
70 ],
71 )
72 def test_parse_bad_exclusion(expression):
73 """Tests incorrectly formatted exclusions"""
74 with pytest.raises(Exception):
75 parse_exclusion(expression)