Debian Codegraph @

tests/unit/cfgspec/test_workflow.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 logging
18 import pytest
19 from typing import Any, Dict, Optional
20
21 from cylc.flow import CYLC_LOG
22 from cylc.flow.cfgspec.workflow import warn_about_depr_platform
23 from cylc.flow.exceptions import PlatformLookupError
24
25
26 @pytest.mark.parametrize(
27 'runtime_cfg, fail_expected, expected_warning',
28 [
29 pytest.param(
30 {
31 'foo': {'script': 'true'}
32 },
33 False, None,
34 id="No platform setting"
35 ),
36 pytest.param(
37 {
38 'foo': {'platform': 'fine'}
39 },
40 False, None,
41 id="Valid platform"
42 ),
43 pytest.param(
44 {
45 'foo': {'platform': 'fine'},
46 'bar': {'platform': '`not good`'}
47 },
48 True, None,
49 id="Invalid subshell notation"
50 ),
51 pytest.param(
52 {
53 'foo': {'platform': 'fine'},
54 'bar': {
55 'platform': '$(fine)',
56 'job': {'batch system': 'pbs'}
57 }
58 },
59 True, None,
60 id="Platform/host conflict"
61 ),
62 pytest.param(
63 {
64 'foo': {'platform': 'fine'},
65 'bar': {
66 'job': {'batch system': 'pbs'}
67 }
68 },
69 False, "please replace with [runtime][bar]platform",
70 id="Deprecated settings"
71 )
72 ]
73 )
74 def test_warn_about_depr_platform(
75 runtime_cfg: Dict[str, Any], fail_expected: bool,
76 expected_warning: Optional[str],
77 caplog: pytest.LogCaptureFixture):
78 """Test warn_about_depr_platform()"""
79 caplog.set_level(logging.WARNING, CYLC_LOG)
80 cfg = {'runtime': runtime_cfg}
81 if fail_expected:
82 with pytest.raises(PlatformLookupError):
83 warn_about_depr_platform(cfg)
84 else:
85 warn_about_depr_platform(cfg)
86 if expected_warning:
87 assert expected_warning in caplog.text
88 else:
89 assert caplog.record_tuples == []