forked from python/peps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_writer.py
More file actions
88 lines (68 loc) · 2.18 KB
/
test_writer.py
File metadata and controls
88 lines (68 loc) · 2.18 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
88
from pathlib import Path
import pytest
from pep_sphinx_extensions.pep_zero_generator import parser, writer
def test_pep_zero_writer_emit_text_newline():
pep0_writer = writer.PEPZeroWriter()
pep0_writer.emit_text("my text 1")
pep0_writer.emit_newline()
pep0_writer.emit_text("my text 2")
assert pep0_writer.output == ["my text 1", "", "my text 2"]
def test_pep_zero_writer_emit_title():
pep0_writer = writer.PEPZeroWriter()
pep0_writer.emit_title("My Title")
pep0_writer.emit_subtitle("My Subtitle")
assert pep0_writer.output == [
"My Title",
"========",
"",
"My Subtitle",
"-----------",
"",
]
@pytest.mark.parametrize(
("test_input", "expected"),
[
(
"pep-9000.rst",
{
"Francis Fussyreverend": "one@example.com",
"Javier Soulfulcommodore": "two@example.com",
},
),
(
"pep-9001.rst",
{"Francis Fussyreverend": "", "Javier Soulfulcommodore": ""},
),
],
)
def test_verify_email_addresses(test_input, expected):
# Arrange
peps = [parser.PEP(Path(f"pep_sphinx_extensions/tests/peps/{test_input}"))]
# Act
out = writer._verify_email_addresses(peps)
# Assert
assert out == expected
def test_verify_email_addresses_multiple_emails():
# Arrange
peps = [
parser.PEP(Path("pep_sphinx_extensions/tests/peps/pep-9000.rst")),
parser.PEP(Path("pep_sphinx_extensions/tests/peps/pep-9003.rst")),
]
# Act
out = writer._verify_email_addresses(peps)
# Assert: Francis has two emails combined, Javier's single email is not duplicated
assert out == {
"Francis Fussyreverend": "one@example.com, different@example.com",
"Javier Soulfulcommodore": "two@example.com",
}
def test_sort_authors():
# Arrange
authors_dict = {
"Zebra, Zoë": "zoe@example.com",
"lowercase, laurence": "laurence@example.com",
"Aardvark, Alfred": "alfred@example.com",
}
# Act
out = writer._sort_authors(authors_dict)
# Assert
assert out == ["Aardvark, Alfred", "lowercase, laurence", "Zebra, Zoë"]