Debian Codegraph @

tests/i/utils/test_flow_writer.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 """Tests to ensure the tests are working - very meta.
17
18 https://github.com/cylc/cylc-flow/pull/2740#discussion_r206086008
19
20 And yes, these are unit-tests inside a functional test framework thinggy.
21
22 """
23
24 from textwrap import dedent
25
26 from .flow_writer import (
27 _write_header,
28 _write_setting,
29 _write_section,
30 flow_config_str
31 )
32
33
34 def test_write_header():
35 """It should write out cylc configuration headings."""
36 assert _write_header('foo', 1) == '[foo]'
37 assert _write_header('foo', 2) == ' [[foo]]'
38
39
40 def test_write_setting_singleline():
41 """It should write out cylc configuration settings."""
42 assert _write_setting('key', 'value', 1) == [
43 'key = value'
44 ]
45 assert _write_setting('key', 'value', 2) == [
46 ' key = value'
47 ]
48
49
50 def test_write_setting_script():
51 """It should preserve indentation for script items."""
52 assert _write_setting('script', 'a\nb\nc', 2) == [
53 ' script = """',
54 'a',
55 'b',
56 'c',
57 ' """'
58 ]
59
60
61 def test_write_setting_multiline():
62 """It should write out cylc configuration settings over multiple lines."""
63 assert _write_setting('key', 'foo\nbar', 1) == [
64 'key = """',
65 ' foo',
66 ' bar',
67 '"""'
68 ]
69 assert _write_setting('key', 'foo\nbar', 2) == [
70 ' key = """',
71 ' foo',
72 ' bar',
73 ' """'
74 ]
75
76
77 def test_write_section():
78 """It should write out entire cylc configuraitons."""
79 assert _write_section(
80 'foo',
81 {
82 'bar': {
83 'pub': 'beer'
84 },
85 'baz': 42
86 },
87 1
88 ) == [
89 '[foo]',
90 ' baz = 42',
91 ' [[bar]]',
92 ' pub = beer'
93 ]
94
95
96 def test_flow_config_str():
97 """It should write out entire cylc configuration files."""
98 assert flow_config_str(
99 {
100 '#!JiNjA2': None,
101 'foo': {
102 'bar': {
103 'pub': 'beer'
104 },
105 'baz': 42
106 },
107 'qux': 'asdf'
108 }
109 ) == dedent('''
110 #!jinja2
111 qux = asdf
112 [foo]
113 baz = 42
114 [[bar]]
115 pub = beer
116 ''').strip() + '\n'