Debian Codegraph @

reno/tests/test_exts.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 import textwrap
16
17 from reno._exts import show_reno_config
18 from reno import config
19 from reno.tests import base
20
21
22 class TestMultiLineString(base.TestCase):
23
24 def test_no_indent(self):
25 input = textwrap.dedent("""\
26 The notes subdirectory within the relnotesdir where the
27 notes live.
28 """)
29 expected = '\n'.join([
30 'The notes subdirectory within the relnotesdir where the',
31 'notes live.',
32 ])
33 actual = '\n'.join(show_reno_config._multi_line_string(input))
34 self.assertEqual(expected, actual)
35
36 def test_with_indent(self):
37 input = textwrap.dedent("""\
38 The notes subdirectory within the relnotesdir where the
39 notes live.
40 """)
41 expected = '\n'.join([
42 ' The notes subdirectory within the relnotesdir where the',
43 ' notes live.',
44 ])
45 actual = '\n'.join(show_reno_config._multi_line_string(input, ' '))
46 self.assertEqual(expected, actual)
47
48 def test_first_line_blank(self):
49 input = textwrap.dedent("""
50 The notes subdirectory within the relnotesdir where the
51 notes live.
52 """)
53 expected = '\n'.join([
54 ' The notes subdirectory within the relnotesdir where the',
55 ' notes live.',
56 ])
57 actual = '\n'.join(show_reno_config._multi_line_string(input, ' '))
58 self.assertEqual(expected, actual)
59
60
61 class TestFormatOptionHelp(base.TestCase):
62
63 def test_simple_default(self):
64 opt = config.Opt(
65 'notesdir', 'path/to/notes',
66 textwrap.dedent("""\
67 The notes subdirectory within the relnotesdir where the
68 notes live.
69 """),
70 )
71 actual = '\n'.join(show_reno_config._format_option_help([opt]))
72 expected = textwrap.dedent("""\
73 ``notesdir``
74 The notes subdirectory within the relnotesdir where the
75 notes live.
76
77 Defaults to ``'path/to/notes'``
78 """)
79 self.assertEqual(expected, actual)
80
81 def test_bool_default(self):
82 opt = config.Opt(
83 'collapse_pre_releases', True,
84 textwrap.dedent("""\
85 Should pre-release versions be merged into the final release
86 of the same number (1.0.0.0a1 notes appear under 1.0.0).
87 """),
88 )
89 actual = '\n'.join(show_reno_config._format_option_help([opt]))
90 expected = textwrap.dedent("""\
91 ``collapse_pre_releases``
92 Should pre-release versions be merged into the final release
93 of the same number (1.0.0.0a1 notes appear under 1.0.0).
94
95 Defaults to ``True``
96 """)
97 self.assertEqual(expected, actual)
98
99 def test_multiline_default(self):
100 opt = config.Opt(
101 'release_tag_re',
102 textwrap.dedent('''\
103 ((?:[\\d.ab]|rc)+) # digits, a, b, and rc cover regular and
104 # pre-releases
105 '''),
106 textwrap.dedent("""\
107 The regex pattern used to match the repo tags representing a
108 valid release version. The pattern is compiled with the
109 verbose and unicode flags enabled.
110 """),
111 )
112 actual = '\n'.join(show_reno_config._format_option_help([opt]))
113 expected = textwrap.dedent("""\
114 ``release_tag_re``
115 The regex pattern used to match the repo tags representing a
116 valid release version. The pattern is compiled with the
117 verbose and unicode flags enabled.
118
119 Defaults to
120
121 ::
122
123 ((?:[\\d.ab]|rc)+) # digits, a, b, and rc cover regular and
124 # pre-releases
125 """)
126 self.assertEqual(expected, actual)