Debian Codegraph @

tests/unit/test_task_message.py

raw
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 from socket import gaierror
18
19 import pytest
20
21 from cylc.flow.task_message import send_messages
22
23
24 def test_send_messages_err(
25 monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
26 ):
27 """If an error occurs while initializing the client, it should be printed.
28 """
29 exc_msg = 'Relic malfunction detected'
30
31 def mock_get_client(*a, **k):
32 raise gaierror(-2, exc_msg)
33
34 monkeypatch.setattr('cylc.flow.task_message.get_client', mock_get_client)
35 send_messages(
36 'arasaka', '1/v/01', [['INFO', 'silverhand']], '2077-01-01T00:00:00Z'
37 )
38 assert f"gaierror: [Errno -2] {exc_msg}" in capsys.readouterr().err