17
17
from types import SimpleNamespace
18
18
19
19
import pytest
20
+ from metomi .isodatetime .data import TimePoint
20
21
22
+ from cylc .flow .cycling .integer import IntegerPoint
21
23
from cylc .flow .workflow_status import (
22
- StopMode ,
23
- WorkflowStatus ,
24
24
WORKFLOW_STATUS_RUNNING_TO_HOLD ,
25
25
WORKFLOW_STATUS_RUNNING_TO_STOP ,
26
+ StopMode ,
27
+ WorkflowStatus ,
26
28
get_workflow_status ,
29
+ get_workflow_status_msg ,
27
30
)
28
31
32
+ STOP_TIME = TimePoint (year = 2006 ).to_local_time_zone ()
33
+
29
34
30
35
def schd (
31
36
final_point = None ,
@@ -50,6 +55,7 @@ def schd(
50
55
stop_task_id = stop_task_id ,
51
56
),
52
57
config = SimpleNamespace (final_point = final_point ),
58
+ options = SimpleNamespace (utc_mode = True ),
53
59
)
54
60
55
61
@@ -73,29 +79,29 @@ def schd(
73
79
'stopping: waiting for active jobs to complete'
74
80
),
75
81
(
76
- {'hold_point' : 'point' },
82
+ {'hold_point' : 2 },
77
83
WorkflowStatus .RUNNING ,
78
- WORKFLOW_STATUS_RUNNING_TO_HOLD % 'point'
84
+ WORKFLOW_STATUS_RUNNING_TO_HOLD % 2
79
85
),
80
86
(
81
- {'stop_point' : 'point' },
87
+ {'stop_point' : 4 },
82
88
WorkflowStatus .RUNNING ,
83
- WORKFLOW_STATUS_RUNNING_TO_STOP % 'point'
89
+ WORKFLOW_STATUS_RUNNING_TO_STOP % 4
84
90
),
85
91
(
86
- {'stop_clock_time' : 1234 },
92
+ {'stop_clock_time' : int ( STOP_TIME . seconds_since_unix_epoch ) },
87
93
WorkflowStatus .RUNNING ,
88
- WORKFLOW_STATUS_RUNNING_TO_STOP % ''
94
+ WORKFLOW_STATUS_RUNNING_TO_STOP % str ( STOP_TIME )
89
95
),
90
96
(
91
- {'stop_task_id' : 'foo' },
97
+ {'stop_task_id' : '6/ foo' },
92
98
WorkflowStatus .RUNNING ,
93
- WORKFLOW_STATUS_RUNNING_TO_STOP % 'foo'
99
+ WORKFLOW_STATUS_RUNNING_TO_STOP % '6/ foo'
94
100
),
95
101
(
96
- {'final_point' : 'point' },
102
+ {'final_point' : 8 },
97
103
WorkflowStatus .RUNNING ,
98
- WORKFLOW_STATUS_RUNNING_TO_STOP % 'point'
104
+ WORKFLOW_STATUS_RUNNING_TO_STOP % 8
99
105
),
100
106
(
101
107
{'is_stalled' : True },
@@ -112,22 +118,58 @@ def schd(
112
118
(
113
119
# stopping should trump stalled, paused & running
114
120
{
115
- 'stop_mode' : StopMode .AUTO ,
121
+ 'stop_mode' : StopMode .REQUEST_NOW ,
116
122
'is_stalled' : True ,
117
123
'is_paused' : True
118
124
},
119
125
WorkflowStatus .STOPPING ,
120
- 'stopping'
126
+ 'stopping: shutting down '
121
127
),
122
128
(
123
- # stalled should trump paused & running
124
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
+ },
125
140
WorkflowStatus .RUNNING ,
126
- 'stalled'
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 ,
127
168
),
128
169
]
129
170
)
130
- def test_get_workflow_status (kwargs , state , message ):
131
- state_ , message_ = get_workflow_status (schd (** kwargs ))
132
- assert state_ == state .value
133
- assert message in message_
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
0 commit comments