2021-10-30 10:57:17 -05:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2024-08-11 08:58:56 -05:00
|
|
|
@pytest.mark.sphinx(
|
|
|
|
'html',
|
|
|
|
testroot='ext-extlinks-hardcoded-urls',
|
|
|
|
confoverrides={'extlinks_detect_hardcoded_links': False},
|
|
|
|
)
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_extlinks_detect_candidates(app):
|
2022-01-21 20:59:09 -06:00
|
|
|
app.build()
|
2024-07-23 09:35:55 -05:00
|
|
|
assert app.warning.getvalue() == ''
|
2022-01-21 20:59:09 -06:00
|
|
|
|
|
|
|
|
2021-10-30 10:57:17 -05:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-extlinks-hardcoded-urls')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_replaceable_uris_emit_extlinks_warnings(app):
|
2021-10-30 10:57:17 -05:00
|
|
|
app.build()
|
2024-07-23 09:35:55 -05:00
|
|
|
warning_output = app.warning.getvalue()
|
2022-01-23 05:09:47 -06:00
|
|
|
|
2021-10-30 10:57:17 -05:00
|
|
|
# there should be exactly three warnings for replaceable URLs
|
|
|
|
message = (
|
2022-01-23 05:09:47 -06:00
|
|
|
"index.rst:%d: WARNING: hardcoded link 'https://github.com/sphinx-doc/sphinx/issues/1' "
|
|
|
|
"could be replaced by an extlink (try using '%s' instead)"
|
2021-10-30 10:57:17 -05:00
|
|
|
)
|
2024-08-11 08:58:56 -05:00
|
|
|
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
|
2021-10-30 10:57:17 -05:00
|
|
|
|
|
|
|
|
2024-08-11 08:58:56 -05:00
|
|
|
@pytest.mark.sphinx(
|
|
|
|
'html',
|
|
|
|
testroot='ext-extlinks-hardcoded-urls-multiple-replacements',
|
|
|
|
)
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_all_replacements_suggested_if_multiple_replacements_possible(app):
|
2021-10-30 10:57:17 -05:00
|
|
|
app.build()
|
2024-07-23 09:35:55 -05:00
|
|
|
warning_output = app.warning.getvalue()
|
2021-10-30 10:57:17 -05:00
|
|
|
# there should be six warnings for replaceable URLs, three pairs per link
|
2024-08-11 08:58:56 -05:00
|
|
|
assert warning_output.count('WARNING: hardcoded link') == 6
|
2021-10-30 10:57:17 -05:00
|
|
|
message = (
|
2022-01-23 05:09:47 -06:00
|
|
|
"index.rst:%d: WARNING: hardcoded link 'https://github.com/octocat' "
|
|
|
|
"could be replaced by an extlink (try using '%s' instead)"
|
2021-10-30 10:57:17 -05:00
|
|
|
)
|
2024-08-11 08:58:56 -05:00
|
|
|
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
|
2021-10-30 10:57:17 -05:00
|
|
|
message = (
|
2022-01-23 05:09:47 -06:00
|
|
|
"index.rst:%d: WARNING: hardcoded link 'https://github.com/octocat' "
|
|
|
|
"could be replaced by an extlink (try using '%s' instead)"
|
2021-10-30 10:57:17 -05:00
|
|
|
)
|
2024-08-11 08:58:56 -05:00
|
|
|
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
|