| 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.exceptions import NoHostsError |
| 20 |
from cylc.flow.scripts.check_versions import check_versions |
| 21 |
|
| 22 |
|
| 23 |
@pytest.fixture |
| 24 |
def break_host_selection(monkeypatch): |
| 25 |
"""Make host selection for any platform fail with NoHostsError.""" |
| 26 |
def _get_host_from_platform(platform, *args, **kwargs): |
| 27 |
raise NoHostsError(platform) |
| 28 |
|
| 29 |
monkeypatch.setattr( |
| 30 |
'cylc.flow.scripts.check_versions.get_host_from_platform', |
| 31 |
_get_host_from_platform, |
| 32 |
) |
| 33 |
|
| 34 |
def _get_platform(platform_name, *args, **kwargs): |
| 35 |
return {'name': platform_name} |
| 36 |
|
| 37 |
monkeypatch.setattr( |
| 38 |
'cylc.flow.scripts.check_versions.get_platform', |
| 39 |
_get_platform, |
| 40 |
) |
| 41 |
|
| 42 |
|
| 43 |
def test_no_hosts_error(break_host_selection, capsys): |
| 44 |
"""It should handle NoHostsError events.""" |
| 45 |
versions = check_versions(['buggered'], True) |
| 46 |
# the broken platform should be skipped (so no returned versions) |
| 47 |
assert not versions |
| 48 |
# a warning should have been logged to stderr |
| 49 |
out, err = capsys.readouterr() |
| 50 |
assert 'Could not connect to buggered' in err |