Skip to content

Commit

Permalink
Add url test (see issue #258).
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmtroffaes committed Jul 28, 2021
1 parent 42cadb9 commit 724897e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/roots/test-bibliography_url/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extensions = ['sphinxcontrib.bibtex']
exclude_patterns = ['_build']
bibtex_bibfiles = ['test.bib']
2 changes: 2 additions & 0 deletions test/roots/test-bibliography_url/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. bibliography::
:all:
23 changes: 23 additions & 0 deletions test/roots/test-bibliography_url/test.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@Misc{one,
title = {One},
author = {A. Een},
note = {\url{https://github.com/}}
}

@Misc{two,
title = {Two},
author = {B. Twee},
note = {aaa\url{https://google.com/}bbb}
}

@Misc{three,
title = {Three},
author = {C. Drie},
howpublished = {\url{https://youtube.com/}}
}

@Misc{four,
title = {Four},
author = {D. Vier},
url = {https://wikipedia.org/}
}
24 changes: 24 additions & 0 deletions test/test_bibliography.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,27 @@ def test_bibliography_content(app, warning) -> None:
def test_bibliography_bad_key(app, warning) -> None:
app.build()
assert 'could not find bibtex key "badkey"' in warning.getvalue()


def url(link: str) -> str:
return f'<a class="reference external" href="{link}">{link}</a>'


@pytest.mark.sphinx('html', testroot='bibliography_url')
def test_bibliography_url(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text(encoding='utf-8')
match1 = html_citations(label='Een').search(output)
match2 = html_citations(label='Twe').search(output)
match3 = html_citations(label='Dri').search(output)
match4 = html_citations(label='Vie').search(output)
assert match1 is not None
assert match2 is not None
assert match3 is not None
assert match4 is not None
# TODO these are not yet supported
# assert url('https://github.com/') in match1.group('text')
# assert url('https://google.com/') in match2.group('text')
# assert url('https://youtube.com/') in match3.group('text')
assert url('https://wikipedia.org/') in match4.group('text')

0 comments on commit 724897e

Please sign in to comment.