7
7
8
8
def test_valid_no_issue_number ():
9
9
assert blurb ._extract_issue_number (None ) is None
10
- res = blurb ._blurb_template_text (issue = None )
10
+ res = blurb ._blurb_template_text (issue = None , section = None )
11
11
lines = frozenset (res .splitlines ())
12
12
assert '.. gh-issue:' not in lines
13
13
assert '.. gh-issue: ' in lines
@@ -37,7 +37,7 @@ def test_valid_issue_number_12345(issue):
37
37
actual = blurb ._extract_issue_number (issue )
38
38
assert actual == 12345
39
39
40
- res = blurb ._blurb_template_text (issue = issue )
40
+ res = blurb ._blurb_template_text (issue = issue , section = None )
41
41
lines = frozenset (res .splitlines ())
42
42
assert '.. gh-issue:' not in lines
43
43
assert '.. gh-issue: ' not in lines
@@ -70,7 +70,7 @@ def test_valid_issue_number_12345(issue):
70
70
def test_invalid_issue_number (issue ):
71
71
error_message = re .escape (f'Invalid GitHub issue number: { issue } ' )
72
72
with pytest .raises (SystemExit , match = error_message ):
73
- blurb ._blurb_template_text (issue = issue )
73
+ blurb ._blurb_template_text (issue = issue , section = None )
74
74
75
75
76
76
@pytest .mark .parametrize ('invalid' , (
@@ -84,4 +84,80 @@ def test_malformed_gh_issue_line(invalid, monkeypatch):
84
84
with monkeypatch .context () as cm :
85
85
cm .setattr (blurb , 'template' , template )
86
86
with pytest .raises (SystemExit , match = error_message ):
87
- blurb ._blurb_template_text (issue = '1234' )
87
+ blurb ._blurb_template_text (issue = '1234' , section = None )
88
+
89
+
90
+ def _check_section_name (section_name , expected ):
91
+ actual = blurb ._extract_section_name (section_name )
92
+ assert actual == expected
93
+
94
+ res = blurb ._blurb_template_text (issue = None , section = section_name )
95
+ res = res .splitlines ()
96
+ for section_name in blurb .sections :
97
+ if section_name == expected :
98
+ assert f'.. section: { section_name } ' in res
99
+ else :
100
+ assert f'#.. section: { section_name } ' in res
101
+ assert f'.. section: { section_name } ' not in res
102
+
103
+
104
+ @pytest .mark .parametrize (
105
+ ('section_name' , 'expected' ),
106
+ [(name , name ) for name in blurb .sections ],
107
+ )
108
+ def test_exact_names (section_name , expected ):
109
+ _check_section_name (section_name , expected )
110
+
111
+
112
+ @pytest .mark .parametrize (
113
+ ('section_name' , 'expected' ),
114
+ [(name .lower (), name ) for name in blurb .sections ],
115
+ )
116
+ def test_exact_names_lowercase (section_name , expected ):
117
+ _check_section_name (section_name , expected )
118
+
119
+
120
+ @pytest .mark .parametrize ('section' , (
121
+ '' ,
122
+ ' ' ,
123
+ '\t ' ,
124
+ '\n ' ,
125
+ '\r \n ' ,
126
+ ' ' ,
127
+ ))
128
+ def test_empty_section_name (section ):
129
+ error_message = re .escape ('Empty section name!' )
130
+ with pytest .raises (SystemExit , match = error_message ):
131
+ blurb ._extract_section_name (section )
132
+
133
+ with pytest .raises (SystemExit , match = error_message ):
134
+ blurb ._blurb_template_text (issue = None , section = section )
135
+
136
+
137
+ @pytest .mark .parametrize ('section' , [
138
+ # Wrong capitalisation
139
+ 'C api' ,
140
+ 'c API' ,
141
+ 'LibrarY' ,
142
+ # Invalid
143
+ '_' ,
144
+ '-' ,
145
+ '/' ,
146
+ 'invalid' ,
147
+ 'Not a section' ,
148
+ # Non-special names
149
+ 'c?api' ,
150
+ 'cXapi' ,
151
+ 'C+API' ,
152
+ # Super-strings
153
+ 'Library and more' ,
154
+ 'library3' ,
155
+ 'librari' ,
156
+ ])
157
+ def test_invalid_section_name (section ):
158
+ error_message = rf"(?m)Invalid section name: '{ re .escape (section )} '\n\n.+"
159
+ with pytest .raises (SystemExit , match = error_message ):
160
+ blurb ._extract_section_name (section )
161
+
162
+ with pytest .raises (SystemExit , match = error_message ):
163
+ blurb ._blurb_template_text (issue = None , section = section )
0 commit comments