Debian Codegraph @

tests/u/run_modes/test_simulation_units.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 """Tests for utilities supporting simulation and skip modes
17 """
18 import pytest
19 from pytest import param
20
21 from cylc.flow.cycling.integer import IntegerPoint
22 from cylc.flow.cycling.iso8601 import ISO8601Point
23 from cylc.flow.run_modes.simulation import (
24 disable_platforms,
25 get_simulated_run_len,
26 parse_fail_cycle_points,
27 sim_task_failed,
28 )
29
30
31 @pytest.mark.parametrize(
32 'execution_time_limit, speedup_factor, default_run_length',
33 (
34 param(None, None, 'PT1H', id='default-run-length'),
35 param(None, 10, 'PT1H', id='speedup-factor-alone'),
36 param('PT1H', None, 'PT1H', id='execution-time-limit-alone'),
37 param('P1D', 24, 'PT1M', id='speed-up-and-execution-tl'),
38 )
39 )
40 def test_get_simulated_run_len(
41 execution_time_limit, speedup_factor, default_run_length
42 ):
43 """Test the logic of the presence or absence of config items.
44
45 Avoid testing the correct workign of DurationParser.
46 """
47 rtc = {
48 'execution time limit': execution_time_limit,
49 'simulation': {
50 'speedup factor': speedup_factor,
51 'default run length': default_run_length,
52 'time limit buffer': 'PT0S',
53 }
54 }
55 assert get_simulated_run_len(rtc) == 3600
56
57
58 @pytest.mark.parametrize(
59 'rtc, expect', (
60 ({'platform': 'skarloey'}, 'localhost'),
61 ({'remote': {'host': 'rheneas'}}, 'localhost'),
62 ({'job': {'batch system': 'loaf'}}, 'localhost'),
63 )
64 )
65 def test_disable_platforms(rtc, expect):
66 """A sampling of items FORBIDDEN_WITH_PLATFORMS are removed from a
67 config passed to this method.
68 """
69 disable_platforms(rtc)
70 assert rtc['platform'] == expect
71 subdicts = [v for v in rtc.values() if isinstance(v, dict)]
72 for subdict in subdicts:
73 for k, val in subdict.items():
74 if k != 'platform':
75 assert val is None
76
77
78 @pytest.mark.parametrize(
79 'args, cycling, fallback',
80 (
81 param((['2', '4'], ['']), 'integer', False, id='int.valid'),
82 param((['garbage'], []), 'integer', True, id='int.invalid'),
83 param((['20200101T0000Z'], []), 'iso8601', False, id='iso.valid'),
84 param((['garbage'], []), 'iso8601', True, id='iso.invalid'),
85 ),
86 )
87 def test_parse_fail_cycle_points(
88 caplog, set_cycling_type, args, cycling, fallback
89 ):
90 """Tests for parse_fail_cycle points.
91 """
92 set_cycling_type(cycling)
93 if fallback:
94 expect = args[1]
95 check_log = True
96 else:
97 expect = args[0]
98 check_log = False
99
100 if cycling == 'integer':
101 assert parse_fail_cycle_points(*args) == [
102 IntegerPoint(i) for i in expect
103 ]
104 else:
105 assert parse_fail_cycle_points(*args) == [
106 ISO8601Point(i) for i in expect
107 ]
108 if check_log:
109 assert "Incompatible" in caplog.messages[0]
110 assert cycling in caplog.messages[0].lower()
111
112
113 @pytest.mark.parametrize(
114 'conf, point, try_, expect',
115 (
116 param(
117 {'fail cycle points': [], 'fail try 1 only': True},
118 ISO8601Point('1'),
119 1,
120 False,
121 id='defaults'
122 ),
123 param(
124 {'fail cycle points': None, 'fail try 1 only': False},
125 ISO8601Point('1066'),
126 1,
127 True,
128 id='fail-all'
129 ),
130 param(
131 {
132 'fail cycle points': [
133 ISO8601Point('1066'), ISO8601Point('1067')],
134 'fail try 1 only': False
135 },
136 ISO8601Point('1067'),
137 1,
138 True,
139 id='point-in-failCP'
140 ),
141 param(
142 {
143 'fail cycle points': [
144 ISO8601Point('1066'), ISO8601Point('1067')],
145 'fail try 1 only': True
146 },
147 ISO8601Point('1000'),
148 1,
149 False,
150 id='point-notin-failCP'
151 ),
152 param(
153 {'fail cycle points': None, 'fail try 1 only': True},
154 ISO8601Point('1066'),
155 2,
156 False,
157 id='succeed-attempt2'
158 ),
159 param(
160 {'fail cycle points': None, 'fail try 1 only': False},
161 ISO8601Point('1066'),
162 7,
163 True,
164 id='fail-attempt7'
165 ),
166 )
167 )
168 def test_sim_task_failed(
169 conf, point, try_, expect, set_cycling_type
170 ):
171 set_cycling_type('iso8601')
172 assert sim_task_failed(conf, point, try_) == expect