mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-10-25 22:50:22 -05:00
Tests: adapt HTML escaping to pygments v2.21.0 change-in-behaviour (#14611)
This commit is contained in:
1 parent
e44a40eb2f
commit
b04a210129
4 files changed
+35
-11
No files matched your search
@@ -45,6 +45,11 @@ def test_html_code_role(app: SphinxTestApp) -> None:
|
||||
else:
|
||||
sp = ' '
|
||||
|
||||
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 21):
|
||||
abc = '"abc"'
|
||||
else:
|
||||
abc = '"abc"'
|
||||
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
@@ -57,7 +62,7 @@ def test_html_code_role(app: SphinxTestApp) -> None:
|
||||
'<span class="o">+</span> '
|
||||
'<span class="kc">None</span> '
|
||||
'<span class="o">+</span> '
|
||||
'<span class="s2">"abc"</span>'
|
||||
f'<span class="s2">{abc}</span>'
|
||||
'<span class="p">):</span> '
|
||||
'<span class="k">pass</span>'
|
||||
)
|
||||
|
||||
@@ -20,6 +20,11 @@ def check_viewcode_output(app: SphinxTestApp) -> str:
|
||||
else:
|
||||
sp = ' '
|
||||
|
||||
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 21):
|
||||
ds = '"""this is Class1"""'
|
||||
else:
|
||||
ds = '"""this is Class1"""'
|
||||
|
||||
warnings = re.sub(r'\\+', '/', app.warning.getvalue())
|
||||
assert re.findall(
|
||||
r"index.rst:\d+: WARNING: Object named 'func1' not found in include "
|
||||
@@ -49,10 +54,7 @@ def check_viewcode_output(app: SphinxTestApp) -> str:
|
||||
) in result
|
||||
assert '<span>@decorator</span>\n' in result
|
||||
assert f'<span>class</span>{sp}<span>Class1</span><span>:</span>\n' in result
|
||||
assert (
|
||||
'<span> </span>'
|
||||
'<span>"""this is Class1"""</span></div>\n'
|
||||
) in result
|
||||
assert f'<span> </span><span>{ds}</span></div>\n' in result
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -26,6 +26,11 @@ if tuple(map(int, pygments.__version__.split('.')[:2])) < (2, 18):
|
||||
|
||||
Formatter.__class_getitem__ = classmethod(lambda cls, name: cls) # type: ignore[attr-defined]
|
||||
|
||||
if tuple(map(int, pygments.__version__.split('.')[:2])) < (2, 21):
|
||||
hsw = '"Hello sphinx world"'
|
||||
else:
|
||||
hsw = '"Hello sphinx world"'
|
||||
|
||||
|
||||
class MyLexer(RegexLexer):
|
||||
name = 'testlexer'
|
||||
@@ -93,7 +98,7 @@ def test_default_highlight(logger: mock.Mock) -> None:
|
||||
ret = bridge.highlight_block('print "Hello sphinx world"', 'default')
|
||||
assert ret == (
|
||||
'<div class="highlight"><pre><span></span><span class="nb">print</span> '
|
||||
'<span class="s2">"Hello sphinx world"</span>\n</pre></div>\n'
|
||||
f'<span class="s2">{hsw}</span>\n</pre></div>\n'
|
||||
)
|
||||
|
||||
# default: fallbacks to none if highlighting failed
|
||||
@@ -107,7 +112,7 @@ def test_default_highlight(logger: mock.Mock) -> None:
|
||||
assert ret == (
|
||||
'<div class="highlight"><pre><span></span><span class="nb">print</span>'
|
||||
'<span class="p">(</span>'
|
||||
'<span class="s2">"Hello sphinx world"</span>'
|
||||
f'<span class="s2">{hsw}</span>'
|
||||
'<span class="p">)</span>\n</pre></div>\n'
|
||||
)
|
||||
|
||||
@@ -116,7 +121,7 @@ def test_default_highlight(logger: mock.Mock) -> None:
|
||||
assert ret == (
|
||||
'<div class="highlight"><pre><span></span><span class="nb">print</span>'
|
||||
'<span class="p">(</span>'
|
||||
'<span class="s2">"Hello sphinx world"</span>'
|
||||
f'<span class="s2">{hsw}</span>'
|
||||
'<span class="p">)</span>\n</pre></div>\n'
|
||||
)
|
||||
|
||||
|
||||
@@ -1638,6 +1638,11 @@ def test_additional_targets_should_not_be_translated(app: SphinxTestApp) -> None
|
||||
else:
|
||||
sp = ' '
|
||||
|
||||
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 21):
|
||||
res = "'result'"
|
||||
else:
|
||||
res = ''result''
|
||||
|
||||
app.build()
|
||||
# [literalblock.txt]
|
||||
result = (app.outdir / 'literalblock.html').read_text(encoding='utf8')
|
||||
@@ -1647,7 +1652,7 @@ def test_additional_targets_should_not_be_translated(app: SphinxTestApp) -> None
|
||||
assert_count(expected_expr, result, 2)
|
||||
|
||||
# ruby code block should not be translated but be highlighted
|
||||
expected_expr = """<span class="s1">'result'</span>"""
|
||||
expected_expr = f"""<span class="s1">{res}</span>"""
|
||||
assert_count(expected_expr, result, 1)
|
||||
|
||||
# C code block without lang should not be translated and *ruby* highlighted
|
||||
@@ -1726,6 +1731,13 @@ def test_additional_targets_should_be_translated(app: SphinxTestApp) -> None:
|
||||
else:
|
||||
sp = ' '
|
||||
|
||||
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 21):
|
||||
home = '"HTTPS://SPHINX-DOC.ORG"'
|
||||
res = "'RESULT'"
|
||||
else:
|
||||
home = '"HTTPS://SPHINX-DOC.ORG"'
|
||||
res = ''RESULT''
|
||||
|
||||
app.build()
|
||||
# [literalblock.txt]
|
||||
result = (app.outdir / 'literalblock.html').read_text(encoding='utf8')
|
||||
@@ -1738,7 +1750,7 @@ def test_additional_targets_should_be_translated(app: SphinxTestApp) -> None:
|
||||
assert_count(expected_expr, result, 1)
|
||||
|
||||
# literalinclude should be translated
|
||||
expected_expr = '<span class="s2">"HTTPS://SPHINX-DOC.ORG"</span>'
|
||||
expected_expr = f'<span class="s2">{home}</span>'
|
||||
assert_count(expected_expr, result, 1)
|
||||
|
||||
# title should be translated
|
||||
@@ -1746,7 +1758,7 @@ def test_additional_targets_should_be_translated(app: SphinxTestApp) -> None:
|
||||
assert_count(expected_expr, result, 2)
|
||||
|
||||
# ruby code block should be translated and be highlighted
|
||||
expected_expr = """<span class="s1">'RESULT'</span>"""
|
||||
expected_expr = f"""<span class="s1">{res}</span>"""
|
||||
assert_count(expected_expr, result, 1)
|
||||
|
||||
# C code block without lang should be translated and *ruby* highlighted
|
||||
|
||||
Reference in new issue
Block a user