Skip to content

Commit d66d51a

Browse files
jayaddisonpicnixz
andauthored
test_build_linkcheck: test_defaults: fix line-number assertion when using docutils 0.21b+ (#11818)
Co-authored-by: Bénédikt Tran <[email protected]>
1 parent e1bbe88 commit d66d51a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

tests/test_build_linkcheck.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from queue import Queue
1515
from unittest import mock
1616

17+
import docutils
1718
import pytest
1819
from urllib3.poolmanager import PoolManager
1920

@@ -142,14 +143,19 @@ def test_defaults(app):
142143
'uri': 'http://localhost:7777#!bar',
143144
'info': '',
144145
}
145-
assert rowsby['http://localhost:7777/image2.png'] == {
146-
'filename': 'links.rst',
147-
'lineno': 13,
148-
'status': 'broken',
149-
'code': 0,
150-
'uri': 'http://localhost:7777/image2.png',
151-
'info': '404 Client Error: Not Found for url: http://localhost:7777/image2.png',
152-
}
146+
147+
def _missing_resource(filename: str, lineno: int):
148+
return {
149+
'filename': 'links.rst',
150+
'lineno': lineno,
151+
'status': 'broken',
152+
'code': 0,
153+
'uri': f'http://localhost:7777/{filename}',
154+
'info': f'404 Client Error: Not Found for url: http://localhost:7777/{filename}',
155+
}
156+
accurate_linenumbers = docutils.__version_info__[:2] >= (0, 21)
157+
image2_lineno = 12 if accurate_linenumbers else 13
158+
assert rowsby['http://localhost:7777/image2.png'] == _missing_resource("image2.png", image2_lineno)
153159
# looking for '#top' and '#does-not-exist' not found should fail
154160
assert rowsby["http://localhost:7777/#top"]["info"] == "Anchor 'top' not found"
155161
assert rowsby["http://localhost:7777/#top"]["status"] == "broken"

0 commit comments

Comments
 (0)