Debian Codegraph @

tests/unit/test_workflow_status.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 from types import SimpleNamespace
18
19 import pytest
20 from metomi.isodatetime.data import TimePoint
21
22 from cylc.flow.cycling.integer import IntegerPoint
23 from cylc.flow.workflow_status import (
24 WORKFLOW_STATUS_RUNNING_TO_HOLD,
25 WORKFLOW_STATUS_RUNNING_TO_STOP,
26 StopMode,
27 WorkflowStatus,
28 get_workflow_status,
29 get_workflow_status_msg,
30 )
31
32 STOP_TIME = TimePoint(year=2006).to_local_time_zone()
33
34
35 def schd(
36 final_point=None,
37 hold_point=None,
38 is_paused=False,
39 is_stalled=None,
40 stop_clock_time=None,
41 stop_mode=None,
42 stop_point=None,
43 stop_task_id=None,
44 reload_pending=False,
45 ):
46 return SimpleNamespace(
47 is_paused=is_paused,
48 is_stalled=is_stalled,
49 stop_clock_time=stop_clock_time,
50 stop_mode=stop_mode,
51 reload_pending=reload_pending,
52 pool=SimpleNamespace(
53 hold_point=hold_point,
54 stop_point=stop_point,
55 stop_task_id=stop_task_id,
56 ),
57 config=SimpleNamespace(final_point=final_point),
58 options=SimpleNamespace(utc_mode=True),
59 )
60
61
62 @pytest.mark.parametrize(
63 'kwargs, state, message',
64 [
65 # test each of the states
66 (
67 {'is_paused': True},
68 WorkflowStatus.PAUSED,
69 'paused'
70 ),
71 (
72 {'reload_pending': 'message'},
73 WorkflowStatus.PAUSED,
74 'reloading: message'
75 ),
76 (
77 {'stop_mode': StopMode.AUTO},
78 WorkflowStatus.STOPPING,
79 'stopping: waiting for active jobs to complete'
80 ),
81 (
82 {'hold_point': 2},
83 WorkflowStatus.RUNNING,
84 WORKFLOW_STATUS_RUNNING_TO_HOLD % 2
85 ),
86 (
87 {'stop_point': 4},
88 WorkflowStatus.RUNNING,
89 WORKFLOW_STATUS_RUNNING_TO_STOP % 4
90 ),
91 (
92 {'stop_clock_time': int(STOP_TIME.seconds_since_unix_epoch)},
93 WorkflowStatus.RUNNING,
94 WORKFLOW_STATUS_RUNNING_TO_STOP % str(STOP_TIME)
95 ),
96 (
97 {'stop_task_id': '6/foo'},
98 WorkflowStatus.RUNNING,
99 WORKFLOW_STATUS_RUNNING_TO_STOP % '6/foo'
100 ),
101 (
102 {'final_point': 8},
103 WorkflowStatus.RUNNING,
104 WORKFLOW_STATUS_RUNNING_TO_STOP % 8
105 ),
106 (
107 {'is_stalled': True},
108 WorkflowStatus.RUNNING,
109 'stalled'
110 ),
111 (
112 {},
113 WorkflowStatus.RUNNING,
114 'running'
115 ),
116
117 # test combinations
118 (
119 # stopping should trump stalled, paused & running
120 {
121 'stop_mode': StopMode.REQUEST_NOW,
122 'is_stalled': True,
123 'is_paused': True
124 },
125 WorkflowStatus.STOPPING,
126 'stopping: shutting down'
127 ),
128 (
129 {'is_stalled': True, 'is_paused': True},
130 WorkflowStatus.PAUSED,
131 'stalled and paused',
132 ),
133 (
134 # earliest of stop point, hold point and stop task id
135 {
136 'stop_point': IntegerPoint(4),
137 'hold_point': IntegerPoint(2),
138 'stop_task_id': '6/foo',
139 },
140 WorkflowStatus.RUNNING,
141 WORKFLOW_STATUS_RUNNING_TO_HOLD % 2,
142 ),
143 (
144 {
145 'stop_point': IntegerPoint(11),
146 'hold_point': IntegerPoint(15),
147 'stop_task_id': '9/bar',
148 },
149 WorkflowStatus.RUNNING,
150 WORKFLOW_STATUS_RUNNING_TO_STOP % '9/bar',
151 ),
152 (
153 {
154 'stop_point': IntegerPoint(3),
155 'hold_point': IntegerPoint(3),
156 },
157 WorkflowStatus.RUNNING,
158 WORKFLOW_STATUS_RUNNING_TO_STOP % 3,
159 ),
160 (
161 # stop point trumps final point
162 {
163 'stop_point': IntegerPoint(1),
164 'final_point': IntegerPoint(2),
165 },
166 WorkflowStatus.RUNNING,
167 WORKFLOW_STATUS_RUNNING_TO_STOP % 1,
168 ),
169 ]
170 )
171 def test_get_workflow_status(kwargs, state, message, set_cycling_type):
172 set_cycling_type()
173 scheduler = schd(**kwargs)
174 assert get_workflow_status(scheduler) == state
175 assert get_workflow_status_msg(scheduler) == message