From c126067f4ea1c70d37f4e04979c4afa9f508058b Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Mon, 16 Jul 2018 23:17:44 +0200 Subject: [PATCH 1/4] #4886 add tests to better cover the current link check ignore configuration behavior --- tests/roots/test-linkcheck/links.txt | 2 ++ tests/test_build_linkcheck.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/roots/test-linkcheck/links.txt b/tests/roots/test-linkcheck/links.txt index 36376bef4..d5057e08e 100644 --- a/tests/roots/test-linkcheck/links.txt +++ b/tests/roots/test-linkcheck/links.txt @@ -9,3 +9,5 @@ Some additional anchors to exercise ignore code * `Example Bar invalid `_ * `Example Bar invalid `_ tests that default ignore anchor of #! does not need to be prefixed with / * `Example Bar invalid `_ +* `Example anchor invalid `_ +* `Complete nonsense `_ diff --git a/tests/test_build_linkcheck.py b/tests/test_build_linkcheck.py index 839a15628..560eb2499 100644 --- a/tests/test_build_linkcheck.py +++ b/tests/test_build_linkcheck.py @@ -21,14 +21,21 @@ def test_defaults(app, status, warning): content = (app.outdir / 'output.txt').text() print(content) - # looking for #top should fail + # looking for '#top' and 'does-not-exist' not found should fail assert "Anchor 'top' not found" in content - assert len(content.splitlines()) == 1 + assert "Anchor 'does-not-exist' not found" in content + # looking for non-existent URL should fail + assert " Max retries exceeded with url: /doesnotexist" in content + assert len(content.splitlines()) == 3 @pytest.mark.sphinx( 'linkcheck', testroot='linkcheck', freshenv=True, - confoverrides={'linkcheck_anchors_ignore': ["^!", "^top$"]}) + confoverrides={'linkcheck_anchors_ignore': ["^!", "^top$"], + 'linkcheck_ignore': [ + 'https://localhost:7777/doesnotexist', + 'http://www.sphinx-doc.org/en/1.7/intro.html#*'] + }) def test_anchors_ignored(app, status, warning): app.builder.build_all() From 537a69e5180f3380490592204022ff30f4a7556e Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Mon, 16 Jul 2018 23:22:26 +0200 Subject: [PATCH 2/4] #4886 adjust documentation to match actual link check behavior --- doc/usage/configuration.rst | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 8db606515..288290a27 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -2485,12 +2485,20 @@ Options for the linkcheck builder .. confval:: linkcheck_anchors_ignore - A list of regular expressions that match URIs that should skip checking - the validity of anchors in links. This allows skipping entire sites, where - anchors are used to control dynamic pages, or just specific anchors within - a page, where JavaScript is used to add anchors dynamically, or use the - fragment as part of to trigger an internal REST request. Default is - ``["/#!"]``. + A list of regular expressions that match anchors Sphinx should skip when + checking the validity of anchors in links. This allows skipping anchors that + a website's JavaScript adds to control dynamic pages or when triggering an + internal REST request. Default is ``["^!"]``. + + .. note:: + + If you want to ignore anchors of a specific page or of pages that match a + specific pattern, use :confval:`linkcheck_ignore` instead, for example as + follows:: + + linkcheck_ignore = [ + 'http://www.sphinx-doc.org/en/1.7/intro.html#*' + ] .. versionadded:: 1.5 From f605012617d4e1005cab02393fb0cf4ea9cd435f Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Tue, 17 Jul 2018 20:40:49 +0200 Subject: [PATCH 3/4] #4886 remove obsolete `*` --- doc/usage/configuration.rst | 2 +- tests/test_build_linkcheck.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 288290a27..288b95ae4 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -2497,7 +2497,7 @@ Options for the linkcheck builder follows:: linkcheck_ignore = [ - 'http://www.sphinx-doc.org/en/1.7/intro.html#*' + 'http://www.sphinx-doc.org/en/1.7/intro.html#' ] .. versionadded:: 1.5 diff --git a/tests/test_build_linkcheck.py b/tests/test_build_linkcheck.py index 560eb2499..1716a0c42 100644 --- a/tests/test_build_linkcheck.py +++ b/tests/test_build_linkcheck.py @@ -34,7 +34,7 @@ def test_defaults(app, status, warning): confoverrides={'linkcheck_anchors_ignore': ["^!", "^top$"], 'linkcheck_ignore': [ 'https://localhost:7777/doesnotexist', - 'http://www.sphinx-doc.org/en/1.7/intro.html#*'] + 'http://www.sphinx-doc.org/en/1.7/intro.html#'] }) def test_anchors_ignored(app, status, warning): app.builder.build_all() From 8066d36e3cba5eabc09ed95dc2f9055d4badc2ca Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Wed, 18 Jul 2018 19:40:22 +0200 Subject: [PATCH 4/4] #4886 clarify example/note --- doc/usage/configuration.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 288b95ae4..22d0966b4 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -2493,8 +2493,9 @@ Options for the linkcheck builder .. note:: If you want to ignore anchors of a specific page or of pages that match a - specific pattern, use :confval:`linkcheck_ignore` instead, for example as - follows:: + specific pattern (but still check occurrences of the same page(s) that + don't have anchors), use :confval:`linkcheck_ignore` instead, for example + as follows:: linkcheck_ignore = [ 'http://www.sphinx-doc.org/en/1.7/intro.html#'