Skip to content

Commit d04a1ac

Browse files
rossbarlarsoner
authored andcommitted
MAINT: Refactor - parametrize test_reference
Refactors test_full.test_reference using the parametrization facilities of pytest. In principle, improves readibility and makes it easier to extend the test.
1 parent 9867198 commit d04a1ac

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

numpydoc/tests/test_full.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,20 @@ def test_my_function(sphinx_app):
7777
assert 'glossary.html#term-iterable' in html
7878

7979

80-
def test_reference(sphinx_app):
80+
@pytest.mark.parametrize(("html_file", "expected_length"), (
81+
(["index.html"], 1),
82+
(["generated", "numpydoc_test_module.my_function.html"], 1),
83+
(["generated", "numpydoc_test_module.MyClass.html"], 1),
84+
))
85+
def test_reference(sphinx_app, html_file, expected_length):
8186
"""Test for bad references"""
8287
out_dir = sphinx_app.outdir
83-
html_files = [
84-
["index.html"],
85-
["generated", "numpydoc_test_module.my_function.html"],
86-
["generated", "numpydoc_test_module.MyClass.html"],
87-
]
8888

89-
expected_lengths = [1, 1, 1]
90-
91-
for html_file, expected_length in zip(html_files, expected_lengths):
92-
html_file = op.join(out_dir, *html_file)
93-
94-
with open(html_file, 'r') as fid:
95-
html = fid.read()
89+
with open(op.join(out_dir, *html_file), 'r') as fid:
90+
html = fid.read()
9691

97-
reference_list = re.findall(r'<a class="fn-backref" href="\#id\d+">(.*)<\/a>', html)
92+
reference_list = re.findall(r'<a class="fn-backref" href="\#id\d+">(.*)<\/a>', html)
9893

99-
assert len(reference_list) == expected_length
100-
for ref in reference_list:
101-
assert '-' not in ref # Bad reference if it contains "-" e.g. R1896e33633d5-1
94+
assert len(reference_list) == expected_length
95+
for ref in reference_list:
96+
assert '-' not in ref # Bad reference if it contains "-" e.g. R1896e33633d5-1

0 commit comments

Comments
 (0)