Skip to content

Commit 8e5f3c9

Browse files
committed
Parametrize tests
This eg makes it easier to spot which particular iteration breaks
1 parent ca6dcf0 commit 8e5f3c9

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
@@ -67,8 +67,9 @@ def test_redirect(needs_cloudscraper, urls) -> None:
6767

6868

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

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

94104

95105
@pytest.mark.net
96-
def test_get_real_url_from_doi() -> None:
97-
data = [
106+
@pytest.mark.parametrize(
107+
"doi,url",
108+
[
98109
("10.1016/S0009-2614(97)04014-1",
99110
"https://www.sciencedirect.com/science/"
100111
"article/abs/pii/S0009261497040141"),
101112
]
102-
for doi, url in data:
103-
assert normalize_eq(url, get_real_url_from_doi(doi))
113+
)
114+
def test_get_real_url_from_doi(doi, url) -> None:
115+
assert normalize_eq(url, get_real_url_from_doi(doi))
104116

105117

106-
def test_find_doi_in_line() -> None:
107-
test_data = [
118+
@pytest.mark.parametrize(
119+
"url, doi",
120+
[
108121
("http://dx.doi.org/10.1063/1.881498", "10.1063/1.881498"),
109122
("http://dx.doi.org/10.1063%2F1.881498", "10.1063/1.881498"),
110123
(2 * "qer " + "var doi = '12345/12345.3'", "12345/12345.3"),
@@ -133,8 +146,9 @@ def test_find_doi_in_line() -> None:
133146
"10.1016/j.comptc.2018.10.004"),
134147
("doi(10.1038/s41535-018-0103-6;)", "10.1038/s41535-018-0103-6"),
135148
]
136-
for url, doi in test_data:
137-
assert find_doi_in_text(url) == doi
149+
)
150+
def test_find_doi_in_line(url, doi) -> None:
151+
assert find_doi_in_text(url) == doi
138152

139153

140154
def test_doi_from_pdf() -> None:

0 commit comments

Comments
 (0)