diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:25:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:25:40 +0000 |
commit | cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a (patch) | |
tree | 18dcde1a8d1f5570a77cd0c361de3b490d02c789 /tests/test_ext_extlinks.py | |
parent | Initial commit. (diff) | |
download | sphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.tar.xz sphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.zip |
Adding upstream version 7.2.6.upstream/7.2.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_ext_extlinks.py')
-rw-r--r-- | tests/test_ext_extlinks.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_ext_extlinks.py b/tests/test_ext_extlinks.py new file mode 100644 index 0000000..7634db6 --- /dev/null +++ b/tests/test_ext_extlinks.py @@ -0,0 +1,45 @@ +import pytest + + +@pytest.mark.sphinx('html', testroot='ext-extlinks-hardcoded-urls', + confoverrides={'extlinks_detect_hardcoded_links': False}) +def test_extlinks_detect_candidates(app, warning): + app.build() + assert warning.getvalue() == '' + + +@pytest.mark.sphinx('html', testroot='ext-extlinks-hardcoded-urls') +def test_replaceable_uris_emit_extlinks_warnings(app, warning): + app.build() + warning_output = warning.getvalue() + + # there should be exactly three warnings for replaceable URLs + message = ( + "index.rst:%d: WARNING: hardcoded link 'https://github.com/sphinx-doc/sphinx/issues/1' " + "could be replaced by an extlink (try using '%s' instead)" + ) + assert message % (11, ":issue:`1`") in warning_output + assert message % (13, ":issue:`inline replaceable link <1>`") in warning_output + assert message % (15, ":issue:`replaceable link <1>`") in warning_output + + +@pytest.mark.sphinx('html', testroot='ext-extlinks-hardcoded-urls-multiple-replacements') +def test_all_replacements_suggested_if_multiple_replacements_possible(app, warning): + app.build() + warning_output = warning.getvalue() + # there should be six warnings for replaceable URLs, three pairs per link + assert warning_output.count("WARNING: hardcoded link") == 6 + message = ( + "index.rst:%d: WARNING: hardcoded link 'https://github.com/octocat' " + "could be replaced by an extlink (try using '%s' instead)" + ) + assert message % (14, ":user:`octocat`") in warning_output + assert message % (16, ":user:`inline replaceable link <octocat>`") in warning_output + assert message % (18, ":user:`replaceable link <octocat>`") in warning_output + message = ( + "index.rst:%d: WARNING: hardcoded link 'https://github.com/octocat' " + "could be replaced by an extlink (try using '%s' instead)" + ) + assert message % (14, ":repo:`octocat`") in warning_output + assert message % (16, ":repo:`inline replaceable link <octocat>`") in warning_output + assert message % (18, ":repo:`replaceable link <octocat>`") in warning_output |