Debian Codegraph @

tests/u/scripts/test_scan.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 import pytest
18 from pathlib import Path
19
20 from cylc.flow.scripts.scan import (
21 ScanOptions,
22 get_pipe,
23 _format_plain,
24 _construct_tree,
25 FLOW_STATES,
26 BAD_CONTACT_FILE_MSG
27 )
28
29
30 def test_no_connection():
31 """Ensure scan uses the filesystem where possible."""
32 pipe = get_pipe(ScanOptions(states=FLOW_STATES), _format_plain)
33 assert 'graphql_query' not in repr(pipe)
34
35
36 def test_ping_connection():
37 """Ensure scan always connects to the flow when requested via --ping."""
38 pipe = get_pipe(ScanOptions(states=FLOW_STATES, ping=True), _format_plain)
39 assert 'graphql_query' in repr(pipe)
40
41
42 def test_good_contact_info() -> None:
43 """Check correct reporting of workflow contact information."""
44 port = 8888
45 host = "wizard"
46 name = "blargh/run1"
47 pid = 12345
48 res = _format_plain(
49 {
50 "name": name,
51 "contact": Path(f"/path/to/{name}"),
52 "CYLC_WORKFLOW_HOST": host,
53 "CYLC_WORKFLOW_PORT": port,
54 "CYLC_WORKFLOW_PID": pid,
55 },
56 None
57 )
58 assert name in res
59 assert f"{host}:{port} {pid}" in res
60
61
62 def test_bad_contact_info(caplog: pytest.LogCaptureFixture) -> None:
63 """Check correct reporting of bad workflow contact information.
64
65 Missing contact keys should result in a warning.
66 """
67 name = "blargh/run1"
68 _format_plain(
69 {
70 "name": name,
71 "contact": Path(f"/path/to/{name}"),
72 },
73 None
74 )
75 assert BAD_CONTACT_FILE_MSG.format(flow_name=name) in caplog.text
76
77
78 def test_bad_contact_info_tree(caplog: pytest.LogCaptureFixture) -> None:
79 """Check correct reporting of bad workflow contact information.
80
81 Missing contact keys should result in a warning.
82 """
83 name = "blargh/run1"
84 flows = [{
85 "name": name,
86 "contact": Path(f"/path/to/{name}"),
87 }]
88 tree = {}
89 _construct_tree(flows, tree, _format_plain, None, None)
90
91 # Error during tree formatting: reports only the last name component.
92 assert (
93 BAD_CONTACT_FILE_MSG.format(flow_name=f"{Path(name).name}")
94 in caplog.text
95 )