1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Integration tests for the "cylc completion-server command.
See also the more extensive unit tests for this module.
"""
from cylc.flow.scripts.completion_server import complete_cylc
def setify(coro):
"""Cast returned lists to sets for coroutines.
Convenience function to use when you want to test output not order.
"""
async def _coro(*args, **kwargs):
ret = await coro(*args, **kwargs)
if isinstance(ret, list):
return set(ret)
return ret
return _coro
async def test_list_prereqs_and_outputs(flow, scheduler, start):
"""Test the success cases for listing task prereqs/outputs.
The error cases are tested in a unit test (doesn't require a running
scheduler).
"""
_complete_cylc = setify(complete_cylc) # Note: results are un-ordered
id_ = flow({
'scheduler': {
'allow implicit tasks': 'True',
},
'scheduling': {
'initial cycle point': '1',
'cycling mode': 'integer',
'graph': {
'P1': '''
a => b
c => d
b[-P1] => b
'''
},
},
'runtime': {
'a': {},
'b': {
'outputs': {
'foo': 'abc def ghi',
}
}
}
})
schd = scheduler(id_)
async with start(schd):
await schd.update_data_structure()
b1 = schd.tokens.duplicate(cycle='1', task='b')
d1 = schd.tokens.duplicate(cycle='1', task='d')
e1 = schd.tokens.duplicate(cycle='1', task='e') # does not exist
# list prereqs (b1)
assert await _complete_cylc('cylc', 'set', b1.id, '--pre', '') == {
# keywords
'all',
# intra-cycle dependency
'1/a:succeeded',
# inter-cycle dependency
'0/b:succeeded',
}
# list outputs (b1)
assert await _complete_cylc('cylc', 'set', b1.id, '--out', '') == {
# regular task outputs
'expired',
'failed',
'started',
'submit-failed',
'submitted',
'succeeded',
# custom task outputs
'foo',
}
# list prereqs (d1)
assert await _complete_cylc('cylc', 'set', d1.id, '--pre', '') == {
# keywords
'all',
# d1 prereqs
'1/c:succeeded',
}
# list prereqs for multiple (b1, d1)
assert await _complete_cylc(
'cylc',
'set',
b1.id,
d1.id,
'--pre',
'',
) == {
# keywords
'all',
# b1 prereqs
'1/a:succeeded',
'0/b:succeeded',
# d1 prereqs
'1/c:succeeded',
}
# list prereqs for multiple (b1, d1) - alternative format
assert await _complete_cylc(
'cylc',
'set',
f'{schd.id}//',
f'//{b1.relative_id}',
f'//{d1.relative_id}',
'--pre',
'',
) == {
# keywords
'all',
# b1 prereqs
'1/a:succeeded',
'0/b:succeeded',
# d1 prereqs
'1/c:succeeded',
}
# list outputs for a non-existant task
assert await _complete_cylc('cylc', 'set', e1.id, '--out', '') == set()
# list outputs for a non-existant workflow
assert await _complete_cylc(
'cylc',
'set',
# this invalid workflow shouldn't prevent it from returning values
# for the valid one
'no-such-workflow//',
f'{schd.id}//',
f'//{b1.relative_id}',
f'//{d1.relative_id}',
'--pre',
'',
) == {
# keywords
'all',
# b1 prereqs
'1/a:succeeded',
'0/b:succeeded',
# d1 prereqs
'1/c:succeeded',
}
# start a second workflow to test multi-workflow functionality
id2 = flow({
'scheduling': {
'graph': {
'R1': '''
x => z
'''
}
},
'runtime': {'x': {}, 'z': {}},
})
schd2 = scheduler(id2)
async with start(schd2):
await schd2.update_data_structure()
z1 = schd2.tokens.duplicate(cycle='1', task='z')
# list prereqs for multiple tasks in multiple workflows
# (it should combine the results from both workflows)
assert await _complete_cylc(
'cylc',
'set',
b1.id,
z1.id,
'--pre',
'',
) == {
# keywords
'all',
# workflow1//1/b prereqs
'0/b:succeeded',
'1/a:succeeded',
# workflow2//1/z prereqs
'1/x:succeeded'
}
|