Skip to content

Commit 255d115

Browse files
authored
Validate gh-issue is int before checking range, and that gh-issue or bpo exists (#35)
2 parents 2a19feb + 60f10af commit 255d115

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

src/blurb/blurb.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,21 +482,24 @@ def finish_entry():
482482
# we'll complain about the *first* error
483483
# we see in the blurb file, which is a
484484
# better user experience.
485-
if key == "gh-issue" and int(value) < lowest_possible_gh_issue_number:
486-
throw(f"The gh-issue number must be {lowest_possible_gh_issue_number} or above, not a PR number.")
487-
488485
if key in issue_keys:
489486
try:
490487
int(value)
491488
except (TypeError, ValueError):
492-
throw(f"Invalid {issue_keys[key]} issue number! ({value!r})")
489+
throw(f"Invalid {issue_keys[key]} number: {value!r}")
490+
491+
if key == "gh-issue" and int(value) < lowest_possible_gh_issue_number:
492+
throw(f"Invalid gh-issue number: {value!r} (must be >= {lowest_possible_gh_issue_number})")
493493

494494
if key == "section":
495495
if no_changes:
496496
continue
497497
if value not in sections:
498498
throw(f"Invalid section {value!r}! You must use one of the predefined sections.")
499499

500+
if "gh-issue" not in metadata and "bpo" not in metadata:
501+
throw("'gh-issue:' or 'bpo:' must be specified in the metadata!")
502+
500503
if not 'section' in metadata:
501504
throw("No 'section' specified. You must provide one!")
502505

tests/test_blurb.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
from pyfakefs.fake_filesystem import FakeFilesystem
32

43
from blurb import blurb
54

@@ -188,3 +187,68 @@ def test_version(capfd):
188187
# Assert
189188
captured = capfd.readouterr()
190189
assert captured.out.startswith("blurb version ")
190+
191+
192+
def test_parse():
193+
# Arrange
194+
contents = ".. gh-issue: 123456\n.. section: IDLE\nHello world!"
195+
blurbs = blurb.Blurbs()
196+
197+
# Act
198+
blurbs.parse(contents)
199+
200+
# Assert
201+
metadata, body = blurbs[0]
202+
assert metadata["gh-issue"] == "123456"
203+
assert metadata["section"] == "IDLE"
204+
assert body == "Hello world!\n"
205+
206+
207+
@pytest.mark.parametrize(
208+
"contents, expected_error",
209+
(
210+
(
211+
"",
212+
r"Blurb 'body' text must not be empty!",
213+
),
214+
(
215+
"gh-issue: Hello world!",
216+
r"Blurb 'body' can't start with 'gh-'!",
217+
),
218+
(
219+
".. gh-issue: 1\n.. section: IDLE\nHello world!",
220+
r"Invalid gh-issue number: '1' \(must be >= 32426\)",
221+
),
222+
(
223+
".. bpo: one-two\n.. section: IDLE\nHello world!",
224+
r"Invalid bpo number: 'one-two'",
225+
),
226+
(
227+
".. gh-issue: one-two\n.. section: IDLE\nHello world!",
228+
r"Invalid GitHub number: 'one-two'",
229+
),
230+
(
231+
".. gh-issue: 123456\n.. section: Funky Kong\nHello world!",
232+
r"Invalid section 'Funky Kong'! You must use one of the predefined sections",
233+
),
234+
(
235+
".. gh-issue: 123456\nHello world!",
236+
r"No 'section' specified. You must provide one!",
237+
),
238+
(
239+
".. gh-issue: 123456\n.. section: IDLE\n.. section: IDLE\nHello world!",
240+
r"Blurb metadata sets 'section' twice!",
241+
),
242+
(
243+
".. section: IDLE\nHello world!",
244+
r"'gh-issue:' or 'bpo:' must be specified in the metadata!",
245+
),
246+
),
247+
)
248+
def test_parse_no_body(contents, expected_error):
249+
# Arrange
250+
blurbs = blurb.Blurbs()
251+
252+
# Act / Assert
253+
with pytest.raises(blurb.BlurbError, match=expected_error):
254+
blurbs.parse(contents)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy