Skip to content

Commit 7cfe04a

Browse files
committed
Parametrize tests
This eg makes it easier to spot which particular iteration breaks
1 parent 781716b commit 7cfe04a

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

tests/test_doi.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ def test_redirect(needs_cloudscraper, urls) -> None:
6868

6969

7070
@pytest.mark.net
71-
def test_validate_doi() -> None:
72-
data = [
71+
@pytest.mark.parametrize(
72+
"doi,url",
73+
[
7374
("10.1063/1.5081715",
7475
"https://pubs.aip.org/jcp/article/150/7/074102/197572/Exact-two-component-equation-of-motion-coupled"), # noqa: E501
7576
("10.1007%2FBF01451751",
@@ -83,29 +84,41 @@ def test_validate_doi() -> None:
8384
("10.1016/S0009-2614(97)04014-1",
8485
"https://linkinghub.elsevier.com/retrieve/pii/S0009261497040141"),
8586
]
86-
for doi, url in data:
87-
assert normalize_eq(url, validate_doi(doi))
87+
)
88+
def test_validate_doi(doi, url) -> None:
89+
assert normalize_eq(url, validate_doi(doi))
90+
8891

89-
for doi in ["", "asdf"]:
90-
try:
91-
validate_doi(doi)
92-
except ValueError as e:
93-
assert str(e) == "HTTP 404: DOI not found"
92+
@pytest.mark.parametrize(
93+
"doi",
94+
[
95+
"",
96+
"asdf"
97+
]
98+
)
99+
def test_validate_invalid_doi(doi) -> None:
100+
try:
101+
validate_doi(doi)
102+
except ValueError as e:
103+
assert str(e) == "HTTP 404: DOI not found"
94104

95105

96106
@pytest.mark.net
97-
def test_get_real_url_from_doi() -> None:
98-
data = [
107+
@pytest.mark.parametrize(
108+
"doi,url",
109+
[
99110
("10.1016/S0009-2614(97)04014-1",
100111
"https://www.sciencedirect.com/science/"
101112
"article/abs/pii/S0009261497040141"),
102113
]
103-
for doi, url in data:
104-
assert normalize_eq(url, get_real_url_from_doi(doi))
114+
)
115+
def test_get_real_url_from_doi(doi, url) -> None:
116+
assert normalize_eq(url, get_real_url_from_doi(doi))
105117

106118

107-
def test_find_doi_in_line() -> None:
108-
test_data = [
119+
@pytest.mark.parametrize(
120+
"url, doi",
121+
[
109122
("http://dx.doi.org/10.1063/1.881498", "10.1063/1.881498"),
110123
("http://dx.doi.org/10.1063%2F1.881498", "10.1063/1.881498"),
111124
(2 * "qer " + "var doi = '12345/12345.3'", "12345/12345.3"),
@@ -134,8 +147,9 @@ def test_find_doi_in_line() -> None:
134147
"10.1016/j.comptc.2018.10.004"),
135148
("doi(10.1038/s41535-018-0103-6;)", "10.1038/s41535-018-0103-6"),
136149
]
137-
for url, doi in test_data:
138-
assert find_doi_in_text(url) == doi
150+
)
151+
def test_find_doi_in_line(url, doi) -> None:
152+
assert find_doi_in_text(url) == doi
139153

140154

141155
def test_doi_from_pdf() -> None:

0 commit comments

Comments
 (0)