| 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 |
"""Test the "cylc dump" command.""" |
| 18 |
|
| 19 |
import pytest |
| 20 |
|
| 21 |
from cylc.flow.option_parsers import ( |
| 22 |
Options, |
| 23 |
) |
| 24 |
from cylc.flow.scripts.dump import ( |
| 25 |
dump, |
| 26 |
get_option_parser, |
| 27 |
) |
| 28 |
|
| 29 |
DumpOptions = Options(get_option_parser()) |
| 30 |
|
| 31 |
|
| 32 |
async def test_dump_tasks(flow, scheduler, start): |
| 33 |
"""It should show n=0 tasks. |
| 34 |
|
| 35 |
See: https://github.com/cylc/cylc-flow/pull/5600 |
| 36 |
""" |
| 37 |
id_ = flow({ |
| 38 |
'scheduler': { |
| 39 |
'allow implicit tasks': 'true', |
| 40 |
}, |
| 41 |
'scheduling': { |
| 42 |
'graph': { |
| 43 |
'R1': 'a => b => c', |
| 44 |
}, |
| 45 |
}, |
| 46 |
}) |
| 47 |
schd = scheduler(id_) |
| 48 |
async with start(schd): |
| 49 |
# schd.release_tasks_to_run() |
| 50 |
await schd.update_data_structure() |
| 51 |
ret = [] |
| 52 |
await dump( |
| 53 |
id_, |
| 54 |
DumpOptions(disp_form='tasks', legacy_format=True), |
| 55 |
write=ret.append |
| 56 |
) |
| 57 |
assert ret == ['a, 1, waiting, not-held, queued, not-runahead'] |
| 58 |
|
| 59 |
|
| 60 |
@pytest.mark.parametrize( |
| 61 |
'attributes_bool, flow_nums, dump_str', |
| 62 |
[ |
| 63 |
pytest.param( |
| 64 |
True, |
| 65 |
[1, 2], |
| 66 |
'1/a:waiting (held,queued,runahead) flows=[1,2]', |
| 67 |
id='1' |
| 68 |
), |
| 69 |
pytest.param( |
| 70 |
False, |
| 71 |
[1, 2], |
| 72 |
'1/a:waiting', |
| 73 |
id='2' |
| 74 |
) |
| 75 |
] |
| 76 |
) |
| 77 |
async def test_dump_format( |
| 78 |
flow, scheduler, start, attributes_bool, flow_nums, dump_str |
| 79 |
): |
| 80 |
"""Check the new "cylc dump" output format, i.e. task IDs. |
| 81 |
|
| 82 |
See: https://github.com/cylc/cylc-flow/pull/6440 |
| 83 |
""" |
| 84 |
id_ = flow({ |
| 85 |
'scheduler': { |
| 86 |
'allow implicit tasks': 'true', |
| 87 |
}, |
| 88 |
'scheduling': { |
| 89 |
'graph': { |
| 90 |
'R1': 'a', |
| 91 |
}, |
| 92 |
}, |
| 93 |
}) |
| 94 |
schd = scheduler(id_) |
| 95 |
async with start(schd): |
| 96 |
[itask] = schd.pool.get_tasks() |
| 97 |
|
| 98 |
itask.state_reset( |
| 99 |
is_held=attributes_bool, |
| 100 |
is_runahead=attributes_bool, |
| 101 |
is_queued=attributes_bool |
| 102 |
) |
| 103 |
itask.flow_nums = set(flow_nums) |
| 104 |
|
| 105 |
schd.pool.data_store_mgr.delta_task_held( |
| 106 |
itask.tdef.name, itask.point, itask.state.is_held) |
| 107 |
schd.pool.data_store_mgr.delta_task_state(itask) |
| 108 |
schd.pool.data_store_mgr.delta_task_flow_nums(itask) |
| 109 |
await schd.update_data_structure() |
| 110 |
|
| 111 |
ret = [] |
| 112 |
await dump( |
| 113 |
id_, |
| 114 |
DumpOptions(disp_form='tasks', show_flows=attributes_bool), |
| 115 |
write=ret.append |
| 116 |
) |
| 117 |
assert ret == [dump_str] |