forked from python/blurb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_blurb_add.py
More file actions
87 lines (76 loc) · 2.68 KB
/
test_blurb_add.py
File metadata and controls
87 lines (76 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import re
import pytest
from blurb import blurb
def test_valid_no_issue_number():
assert blurb._extract_issue_number(None) is None
res = blurb._blurb_template_text(issue=None)
lines = frozenset(res.splitlines())
assert '.. gh-issue:' not in lines
assert '.. gh-issue: ' in lines
@pytest.mark.parametrize('issue', (
# issue given by their number
'12345',
' 12345 ',
# issue given by their number and a 'GH-' prefix
'GH-12345',
' GH-12345 ',
# issue given by their number and a 'gh-' prefix
'gh-12345',
' gh-12345 ',
# issue given by their number and a '#' prefix
'#12345',
' #12345 ',
# issue given by their URL (no scheme)
'github.com/python/cpython/issues/12345',
' github.com/python/cpython/issues/12345 ',
# issue given by their URL (with scheme)
'https://github.com/python/cpython/issues/12345',
' https://github.com/python/cpython/issues/12345 ',
))
def test_valid_issue_number_12345(issue):
actual = blurb._extract_issue_number(issue)
assert actual == 12345
res = blurb._blurb_template_text(issue=issue)
lines = frozenset(res.splitlines())
assert '.. gh-issue:' not in lines
assert '.. gh-issue: ' not in lines
assert '.. gh-issue: 12345' in lines
@pytest.mark.parametrize('issue', (
'',
'abc',
'Gh-123',
'gh-abc',
'gh- 123',
'gh -123',
'gh-',
'bpo-',
'bpo-12345',
'github.com/python/cpython/issues',
'github.com/python/cpython/issues/',
'github.com/python/cpython/issues/abc',
'github.com/python/cpython/issues/gh-abc',
'github.com/python/cpython/issues/gh-123',
'github.com/python/cpython/issues/1234?param=1',
'https://github.com/python/cpython/issues',
'https://github.com/python/cpython/issues/',
'https://github.com/python/cpython/issues/abc',
'https://github.com/python/cpython/issues/gh-abc',
'https://github.com/python/cpython/issues/gh-123',
'https://github.com/python/cpython/issues/1234?param=1',
))
def test_invalid_issue_number(issue):
error_message = re.escape(f'Invalid GitHub issue number: {issue}')
with pytest.raises(SystemExit, match=error_message):
blurb._blurb_template_text(issue=issue)
@pytest.mark.parametrize('invalid', (
'gh-issue: ',
'gh-issue: 1',
'gh-issue',
))
def test_malformed_gh_issue_line(invalid, monkeypatch):
template = blurb.template.replace('.. gh-issue:', invalid)
error_message = re.escape("Can't find gh-issue line in the template!")
with monkeypatch.context() as cm:
cm.setattr(blurb, 'template', template)
with pytest.raises(SystemExit, match=error_message):
blurb._blurb_template_text(issue='1234')