diff options
author | Ross Barnowski <rossbar@berkeley.edu> | 2020-06-30 12:53:17 -0700 |
---|---|---|
committer | Eric Larson <larson.eric.d@gmail.com> | 2020-06-30 19:27:31 -0400 |
commit | d04a1acc23bcbb03439995741febb4924b56315f (patch) | |
tree | 40a15fb4616fc029439d6fbf2c12527c68f6bdaf | |
parent | 9867198abb54daee7f8a66885e75f753df1d5da8 (diff) | |
download | numpydoc-d04a1acc23bcbb03439995741febb4924b56315f.tar.gz |
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.
-rw-r--r-- | numpydoc/tests/test_full.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/numpydoc/tests/test_full.py b/numpydoc/tests/test_full.py index 7ccb28a..852c0d2 100644 --- a/numpydoc/tests/test_full.py +++ b/numpydoc/tests/test_full.py @@ -77,25 +77,20 @@ def test_my_function(sphinx_app): assert 'glossary.html#term-iterable' in html -def test_reference(sphinx_app): +@pytest.mark.parametrize(("html_file", "expected_length"), ( + (["index.html"], 1), + (["generated", "numpydoc_test_module.my_function.html"], 1), + (["generated", "numpydoc_test_module.MyClass.html"], 1), +)) +def test_reference(sphinx_app, html_file, expected_length): """Test for bad references""" out_dir = sphinx_app.outdir - html_files = [ - ["index.html"], - ["generated", "numpydoc_test_module.my_function.html"], - ["generated", "numpydoc_test_module.MyClass.html"], - ] - expected_lengths = [1, 1, 1] - - for html_file, expected_length in zip(html_files, expected_lengths): - html_file = op.join(out_dir, *html_file) - - with open(html_file, 'r') as fid: - html = fid.read() + with open(op.join(out_dir, *html_file), 'r') as fid: + html = fid.read() - reference_list = re.findall(r'<a class="fn-backref" href="\#id\d+">(.*)<\/a>', html) + reference_list = re.findall(r'<a class="fn-backref" href="\#id\d+">(.*)<\/a>', html) - assert len(reference_list) == expected_length - for ref in reference_list: - assert '-' not in ref # Bad reference if it contains "-" e.g. R1896e33633d5-1 + assert len(reference_list) == expected_length + for ref in reference_list: + assert '-' not in ref # Bad reference if it contains "-" e.g. R1896e33633d5-1 |