Skip to content

Commit 965768b

Browse files
committed
Fix tests for Pygments 2.14
Pygments 2.14 was released on 01/01/2023 [0] [0]: https://pygments.org/docs/changelog/#version-2-14-0
1 parent 5715abf commit 965768b

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ dependencies = [
6262
"sphinxcontrib-serializinghtml>=1.1.5",
6363
"sphinxcontrib-qthelp",
6464
"Jinja2>=3.0",
65-
"Pygments>=2.12",
65+
"Pygments>=2.13",
6666
"docutils>=0.18,<0.20",
6767
"snowballstemmer>=2.0",
6868
"babel>=2.9",

tests/test_ext_viewcode.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import re
44

5+
import pygments
56
import pytest
67

78

@@ -31,14 +32,24 @@ def test_viewcode(app, status, warning):
3132

3233
result = (app.outdir / '_modules/spam/mod1.html').read_text(encoding='utf8')
3334
result = re.sub('<span class=".*?">', '<span>', result) # filter pygments classes
34-
assert ('<div class="viewcode-block" id="Class1"><a class="viewcode-back" '
35-
'href="../../index.html#spam.Class1">[docs]</a>'
36-
'<span>@decorator</span>\n'
37-
'<span>class</span> <span>Class1</span>'
38-
'<span>(</span><span>object</span><span>):</span>\n'
39-
' <span>&quot;&quot;&quot;</span>\n'
40-
'<span> this is Class1</span>\n'
41-
'<span> &quot;&quot;&quot;</span></div>\n') in result
35+
if pygments.__version__ >= '2.14.0':
36+
assert ('<div class="viewcode-block" id="Class1"><a class="viewcode-back" '
37+
'href="../../index.html#spam.Class1">[docs]</a>'
38+
'<span>@decorator</span>\n'
39+
'<span>class</span> <span>Class1</span>'
40+
'<span>(</span><span>object</span><span>):</span>\n'
41+
'<span> </span><span>&quot;&quot;&quot;</span>\n'
42+
'<span> this is Class1</span>\n'
43+
'<span> &quot;&quot;&quot;</span></div>\n') in result
44+
else:
45+
assert ('<div class="viewcode-block" id="Class1"><a class="viewcode-back" '
46+
'href="../../index.html#spam.Class1">[docs]</a>'
47+
'<span>@decorator</span>\n'
48+
'<span>class</span> <span>Class1</span>'
49+
'<span>(</span><span>object</span><span>):</span>\n'
50+
' <span>&quot;&quot;&quot;</span>\n'
51+
'<span> this is Class1</span>\n'
52+
'<span> &quot;&quot;&quot;</span></div>\n') in result
4253

4354

4455
@pytest.mark.sphinx('epub', testroot='ext-viewcode')

tests/test_intl.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import re
88

9+
import pygments
910
import pytest
1011
from babel.messages import mofile, pofile
1112
from babel.messages.catalog import Catalog
@@ -1104,8 +1105,11 @@ def test_additional_targets_should_not_be_translated(app):
11041105
expected_expr = ("""<span class="n">literal</span>"""
11051106
"""<span class="o">-</span>"""
11061107
"""<span class="n">block</span>\n"""
1107-
"""<span class="k">in</span> """
1108+
"""<span class="k">in</span>"""
1109+
"""<span class="w"> </span>"""
11081110
"""<span class="n">list</span>""")
1111+
if pygments.__version__ < '2.14.0':
1112+
expected_expr = expected_expr.replace("""<span class="w"> </span>""", ' ')
11091113
assert_count(expected_expr, result, 1)
11101114

11111115
# doctest block should not be translated but be highlighted
@@ -1179,8 +1183,11 @@ def test_additional_targets_should_be_translated(app):
11791183
expected_expr = ("""<span class="no">LITERAL</span>"""
11801184
"""<span class="o">-</span>"""
11811185
"""<span class="no">BLOCK</span>\n"""
1182-
"""<span class="no">IN</span> """
1186+
"""<span class="no">IN</span>"""
1187+
"""<span class="w"> </span>"""
11831188
"""<span class="no">LIST</span>""")
1189+
if pygments.__version__ < '2.14.0':
1190+
expected_expr = expected_expr.replace("""<span class="w"> </span>""", ' ')
11841191
assert_count(expected_expr, result, 1)
11851192

11861193
# doctest block should not be translated but be highlighted

0 commit comments

Comments
 (0)