Debian Codegraph @

tests/i/scripts/test_completion_server.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 """Integration tests for the "cylc completion-server command.
18
19 See also the more extensive unit tests for this module.
20 """
21
22 from cylc.flow.scripts.completion_server import complete_cylc
23
24
25 def setify(coro):
26 """Cast returned lists to sets for coroutines.
27
28 Convenience function to use when you want to test output not order.
29 """
30 async def _coro(*args, **kwargs):
31 ret = await coro(*args, **kwargs)
32 if isinstance(ret, list):
33 return set(ret)
34 return ret
35 return _coro
36
37
38 async def test_list_prereqs_and_outputs(flow, scheduler, start):
39 """Test the success cases for listing task prereqs/outputs.
40
41 The error cases are tested in a unit test (doesn't require a running
42 scheduler).
43 """
44 _complete_cylc = setify(complete_cylc) # Note: results are un-ordered
45
46 id_ = flow({
47 'scheduler': {
48 'allow implicit tasks': 'True',
49 },
50 'scheduling': {
51 'initial cycle point': '1',
52 'cycling mode': 'integer',
53 'graph': {
54 'P1': '''
55 a => b
56 c => d
57 b[-P1] => b
58 '''
59 },
60 },
61 'runtime': {
62 'a': {},
63 'b': {
64 'outputs': {
65 'foo': 'abc def ghi',
66 }
67 }
68 }
69 })
70 schd = scheduler(id_)
71 async with start(schd):
72 await schd.update_data_structure()
73 b1 = schd.tokens.duplicate(cycle='1', task='b')
74 d1 = schd.tokens.duplicate(cycle='1', task='d')
75 e1 = schd.tokens.duplicate(cycle='1', task='e') # does not exist
76
77 # list prereqs (b1)
78 assert await _complete_cylc('cylc', 'set', b1.id, '--pre', '') == {
79 # keywords
80 'all',
81 # intra-cycle dependency
82 '1/a:succeeded',
83 # inter-cycle dependency
84 '0/b:succeeded',
85 }
86
87 # list outputs (b1)
88 assert await _complete_cylc('cylc', 'set', b1.id, '--out', '') == {
89 # regular task outputs
90 'expired',
91 'failed',
92 'started',
93 'submit-failed',
94 'submitted',
95 'succeeded',
96 # custom task outputs
97 'foo',
98 }
99
100 # list prereqs (d1)
101 assert await _complete_cylc('cylc', 'set', d1.id, '--pre', '') == {
102 # keywords
103 'all',
104 # d1 prereqs
105 '1/c:succeeded',
106 }
107
108 # list prereqs for multiple (b1, d1)
109 assert await _complete_cylc(
110 'cylc',
111 'set',
112 b1.id,
113 d1.id,
114 '--pre',
115 '',
116 ) == {
117 # keywords
118 'all',
119 # b1 prereqs
120 '1/a:succeeded',
121 '0/b:succeeded',
122 # d1 prereqs
123 '1/c:succeeded',
124 }
125
126 # list prereqs for multiple (b1, d1) - alternative format
127 assert await _complete_cylc(
128 'cylc',
129 'set',
130 f'{schd.id}//',
131 f'//{b1.relative_id}',
132 f'//{d1.relative_id}',
133 '--pre',
134 '',
135 ) == {
136 # keywords
137 'all',
138 # b1 prereqs
139 '1/a:succeeded',
140 '0/b:succeeded',
141 # d1 prereqs
142 '1/c:succeeded',
143 }
144
145 # list outputs for a non-existant task
146 assert await _complete_cylc('cylc', 'set', e1.id, '--out', '') == set()
147
148 # list outputs for a non-existant workflow
149 assert await _complete_cylc(
150 'cylc',
151 'set',
152 # this invalid workflow shouldn't prevent it from returning values
153 # for the valid one
154 'no-such-workflow//',
155 f'{schd.id}//',
156 f'//{b1.relative_id}',
157 f'//{d1.relative_id}',
158 '--pre',
159 '',
160 ) == {
161 # keywords
162 'all',
163 # b1 prereqs
164 '1/a:succeeded',
165 '0/b:succeeded',
166 # d1 prereqs
167 '1/c:succeeded',
168 }
169
170 # start a second workflow to test multi-workflow functionality
171 id2 = flow({
172 'scheduling': {
173 'graph': {
174 'R1': '''
175 x => z
176 '''
177 }
178 },
179 'runtime': {'x': {}, 'z': {}},
180 })
181 schd2 = scheduler(id2)
182 async with start(schd2):
183 await schd2.update_data_structure()
184 z1 = schd2.tokens.duplicate(cycle='1', task='z')
185
186 # list prereqs for multiple tasks in multiple workflows
187 # (it should combine the results from both workflows)
188 assert await _complete_cylc(
189 'cylc',
190 'set',
191 b1.id,
192 z1.id,
193 '--pre',
194 '',
195 ) == {
196 # keywords
197 'all',
198 # workflow1//1/b prereqs
199 '0/b:succeeded',
200 '1/a:succeeded',
201 # workflow2//1/z prereqs
202 '1/x:succeeded'
203 }