| 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 |
import pytest |
| 18 |
|
| 19 |
from cylc.flow.option_parsers import Options |
| 20 |
from cylc.flow.scripts.graph import _main, get_option_parser |
| 21 |
|
| 22 |
|
| 23 |
Opts = Options(get_option_parser()) |
| 24 |
|
| 25 |
|
| 26 |
@pytest.fixture |
| 27 |
def disable_graph_open(monkeypatch): |
| 28 |
"""Prevent "cylc graph" from trying to pop open the image.""" |
| 29 |
monkeypatch.setattr( |
| 30 |
'cylc.flow.scripts.graph.open_image', |
| 31 |
lambda *_a, **_k: None, |
| 32 |
) |
| 33 |
|
| 34 |
|
| 35 |
async def test_blank_graph(one, disable_graph_open, capsys): |
| 36 |
"""It should inform the user if there are no tasks to display.""" |
| 37 |
# graph with one task |
| 38 |
await _main(Opts(color='never'), one.tokens.id) |
| 39 |
out, err = capsys.readouterr() |
| 40 |
assert 'Graph rendered to' in out |
| 41 |
|
| 42 |
# graph with no tasks (the only task is in cycle "1") |
| 43 |
await _main(Opts(color='never'), one.tokens.id, '5') |
| 44 |
out, err = capsys.readouterr() |
| 45 |
assert 'No tasks to display' in err |
| 46 |
assert 'Try changing the start and stop values' in err |