Skip to content

Commit

Permalink
added test for linkcheck_documents_exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
croth1 committed Dec 6, 2021
1 parent d51bd98 commit 370fbae
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sphinx/builders/linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def __init__(self, env: BuildEnvironment, config: Config, rqueue: Queue,
self.anchors_ignore = [re.compile(x)
for x in self.config.linkcheck_anchors_ignore]
self.documents_exclude = [re.compile(doc)
for doc in self.config.linkcheck_documents_exclude]
for doc in self.config.linkcheck_documents_exclude]
self.auth = [(re.compile(pattern), auth_info) for pattern, auth_info
in self.config.linkcheck_auth]

Expand Down
5 changes: 5 additions & 0 deletions tests/roots/test-linkcheck-documents_exclude/br0ken_link.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Broken link
===========

Some links are `broken <https://www.sphinx-doc.org/this-is-another-broken-link>`__
but sometimes not worrying about some broken links is a valid strategy.
5 changes: 5 additions & 0 deletions tests/roots/test-linkcheck-documents_exclude/broken_link.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Broken link
===========

Some links are `broken <https://www.sphinx-doc.org/this-is-a-broken-link>`__
but sometimes not worrying about some broken links is a valid strategy.
5 changes: 5 additions & 0 deletions tests/roots/test-linkcheck-documents_exclude/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exclude_patterns = ['_build']
linkcheck_documents_exclude = [
'^broken_link$',
'br[0-9]ken_link',
]
3 changes: 3 additions & 0 deletions tests/roots/test-linkcheck-documents_exclude/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. toctree::
broken_link
br0ken_link
11 changes: 11 additions & 0 deletions tests/test_build_linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,14 @@ def test_get_after_head_raises_connection_error(app):
"uri": "http://localhost:7777/",
"info": "",
}


@pytest.mark.sphinx('linkcheck', testroot='linkcheck-documents_exclude', freshenv=True)
def test_linkcheck_documents_exclude(app):
with http_server(make_redirect_handler(support_head=False)):
app.build()

with open(app.outdir / 'output.json') as fp:
for record in fp:
content = json.loads(record)
assert content['status'] == 'unchecked'

0 comments on commit 370fbae

Please sign in to comment.