| 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 |
from unittest.mock import Mock |
| 17 |
|
| 18 |
import pytest |
| 19 |
|
| 20 |
from cylc.flow.exceptions import CylcError |
| 21 |
from cylc.flow.main_loop.health_check import ( |
| 22 |
_check_workflow_run_dir, |
| 23 |
_check_contact_file |
| 24 |
) |
| 25 |
|
| 26 |
|
| 27 |
def test_check_workflow_run_dir(): |
| 28 |
"""Ensure a missing workflow run dir raises an CylcError.""" |
| 29 |
sched = Mock(workflow_run_dir='/a/b/c/d/e') |
| 30 |
with pytest.raises(CylcError): |
| 31 |
_check_workflow_run_dir(sched) |
| 32 |
|
| 33 |
|
| 34 |
def test_check_contact_file_data(monkeypatch): |
| 35 |
"""Ensure differing contact file data raises CylcError.""" |
| 36 |
contact_data = { |
| 37 |
'a': 'beef', |
| 38 |
'b': 2 |
| 39 |
} |
| 40 |
sched = Mock( |
| 41 |
workflow='foo', |
| 42 |
contact_data=dict(contact_data) |
| 43 |
) |
| 44 |
monkeypatch.setattr( |
| 45 |
'cylc.flow.main_loop.health_check.workflow_files.load_contact_file', |
| 46 |
lambda x: dict(contact_data) |
| 47 |
) |
| 48 |
# pass |
| 49 |
_check_contact_file(sched) |
| 50 |
|
| 51 |
# fail |
| 52 |
contact_data['a'] = 'wellington' |
| 53 |
with pytest.raises(CylcError): |
| 54 |
_check_contact_file(sched) |
| 55 |
|
| 56 |
|
| 57 |
def test_check_contact_file_io(monkeypatch): |
| 58 |
"""Ensure IOError retrieving the contact file raises CylcError.""" |
| 59 |
sched = Mock(workflow='foo') |
| 60 |
|
| 61 |
def whoopsie(*_): |
| 62 |
raise IOError('') |
| 63 |
|
| 64 |
monkeypatch.setattr( |
| 65 |
'cylc.flow.main_loop.health_check.workflow_files.load_contact_file', |
| 66 |
whoopsie |
| 67 |
) |
| 68 |
with pytest.raises(CylcError): |
| 69 |
_check_contact_file(sched) |