mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Adapt tests for Pygments 2.19
This commit is contained in:
parent
d59084a1fa
commit
5ff3740063
@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pygments
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@ -34,11 +35,16 @@ def test_html_codeblock_linenos_style_inline(app):
|
|||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='reST-code-role')
|
@pytest.mark.sphinx('html', testroot='reST-code-role')
|
||||||
def test_html_code_role(app):
|
def test_html_code_role(app):
|
||||||
|
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
|
||||||
|
sp = '<span class="w"> </span>'
|
||||||
|
else:
|
||||||
|
sp = ' '
|
||||||
|
|
||||||
app.build()
|
app.build()
|
||||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||||
|
|
||||||
common_content = (
|
common_content = (
|
||||||
'<span class="k">def</span> <span class="nf">foo</span>'
|
f'<span class="k">def</span>{sp}<span class="nf">foo</span>'
|
||||||
'<span class="p">(</span>'
|
'<span class="p">(</span>'
|
||||||
'<span class="mi">1</span> '
|
'<span class="mi">1</span> '
|
||||||
'<span class="o">+</span> '
|
'<span class="o">+</span> '
|
||||||
|
@ -11,6 +11,7 @@ from pathlib import Path
|
|||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
|
|
||||||
|
import pygments
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from sphinx.builders.latex import default_latex_documents
|
from sphinx.builders.latex import default_latex_documents
|
||||||
@ -2115,12 +2116,16 @@ def test_latex_container(app):
|
|||||||
|
|
||||||
@pytest.mark.sphinx('latex', testroot='reST-code-role')
|
@pytest.mark.sphinx('latex', testroot='reST-code-role')
|
||||||
def test_latex_code_role(app):
|
def test_latex_code_role(app):
|
||||||
|
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
|
||||||
|
sp = r'\PYG{+w}{ }'
|
||||||
|
else:
|
||||||
|
sp = ' '
|
||||||
|
|
||||||
app.build()
|
app.build()
|
||||||
content = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
|
content = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
|
||||||
|
|
||||||
common_content = (
|
common_content = (
|
||||||
r'\PYG{k}{def} '
|
r'\PYG{k}{def}' + sp + r'\PYG{n+nf}{foo}'
|
||||||
r'\PYG{n+nf}{foo}'
|
|
||||||
r'\PYG{p}{(}'
|
r'\PYG{p}{(}'
|
||||||
r'\PYG{l+m+mi}{1} '
|
r'\PYG{l+m+mi}{1} '
|
||||||
r'\PYG{o}{+} '
|
r'\PYG{o}{+} '
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pygments
|
||||||
import pytest
|
import pytest
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
|
|
||||||
@ -394,6 +395,11 @@ def test_literal_include_block_start_with_comment_or_brank(app):
|
|||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='directive-code')
|
@pytest.mark.sphinx('html', testroot='directive-code')
|
||||||
def test_literal_include_linenos(app):
|
def test_literal_include_linenos(app):
|
||||||
|
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
|
||||||
|
sp = '<span class="w"> </span>'
|
||||||
|
else:
|
||||||
|
sp = ' '
|
||||||
|
|
||||||
app.build(filenames=[app.srcdir / 'linenos.rst'])
|
app.build(filenames=[app.srcdir / 'linenos.rst'])
|
||||||
html = (app.outdir / 'linenos.html').read_text(encoding='utf8')
|
html = (app.outdir / 'linenos.html').read_text(encoding='utf8')
|
||||||
|
|
||||||
@ -411,7 +417,7 @@ def test_literal_include_linenos(app):
|
|||||||
|
|
||||||
# :lines: 5-9
|
# :lines: 5-9
|
||||||
assert (
|
assert (
|
||||||
'<span class="linenos">5</span><span class="k">class</span> '
|
f'<span class="linenos">5</span><span class="k">class</span>{sp}'
|
||||||
'<span class="nc">Foo</span><span class="p">:</span>'
|
'<span class="nc">Foo</span><span class="p">:</span>'
|
||||||
) in html
|
) in html
|
||||||
|
|
||||||
@ -556,12 +562,17 @@ def test_code_block_highlighted(app):
|
|||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='directive-code')
|
@pytest.mark.sphinx('html', testroot='directive-code')
|
||||||
def test_linenothreshold(app):
|
def test_linenothreshold(app):
|
||||||
|
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
|
||||||
|
sp = '<span class="w"> </span>'
|
||||||
|
else:
|
||||||
|
sp = ' '
|
||||||
|
|
||||||
app.build(filenames=[app.srcdir / 'linenothreshold.rst'])
|
app.build(filenames=[app.srcdir / 'linenothreshold.rst'])
|
||||||
html = (app.outdir / 'linenothreshold.html').read_text(encoding='utf8')
|
html = (app.outdir / 'linenothreshold.html').read_text(encoding='utf8')
|
||||||
|
|
||||||
# code-block using linenothreshold
|
# code-block using linenothreshold
|
||||||
assert (
|
assert (
|
||||||
'<span class="linenos">1</span><span class="k">class</span> '
|
f'<span class="linenos">1</span><span class="k">class</span>{sp}'
|
||||||
'<span class="nc">Foo</span><span class="p">:</span>'
|
'<span class="nc">Foo</span><span class="p">:</span>'
|
||||||
) in html
|
) in html
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import pygments
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -13,6 +14,11 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
def check_viewcode_output(app: SphinxTestApp) -> str:
|
def check_viewcode_output(app: SphinxTestApp) -> str:
|
||||||
|
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
|
||||||
|
sp = '<span> </span>'
|
||||||
|
else:
|
||||||
|
sp = ' '
|
||||||
|
|
||||||
warnings = re.sub(r'\\+', '/', app.warning.getvalue())
|
warnings = re.sub(r'\\+', '/', app.warning.getvalue())
|
||||||
assert re.findall(
|
assert re.findall(
|
||||||
r"index.rst:\d+: WARNING: Object named 'func1' not found in include "
|
r"index.rst:\d+: WARNING: Object named 'func1' not found in include "
|
||||||
@ -41,7 +47,7 @@ def check_viewcode_output(app: SphinxTestApp) -> str:
|
|||||||
'<a class="viewcode-back" href="../../index.html#spam.Class1">[docs]</a>\n'
|
'<a class="viewcode-back" href="../../index.html#spam.Class1">[docs]</a>\n'
|
||||||
) in result
|
) in result
|
||||||
assert '<span>@decorator</span>\n' in result
|
assert '<span>@decorator</span>\n' in result
|
||||||
assert '<span>class</span> <span>Class1</span><span>:</span>\n' in result
|
assert f'<span>class</span>{sp}<span>Class1</span><span>:</span>\n' in result
|
||||||
assert '<span> </span><span>"""</span>\n' in result
|
assert '<span> </span><span>"""</span>\n' in result
|
||||||
assert '<span> this is Class1</span>\n' in result
|
assert '<span> this is Class1</span>\n' in result
|
||||||
assert '<span> """</span>\n' in result
|
assert '<span> """</span>\n' in result
|
||||||
|
@ -12,7 +12,7 @@ from pygments.token import Name, Text
|
|||||||
|
|
||||||
from sphinx.highlighting import PygmentsBridge
|
from sphinx.highlighting import PygmentsBridge
|
||||||
|
|
||||||
if tuple(map(int, pygments.__version__.split('.')[:2]))[:2] < (2, 18):
|
if tuple(map(int, pygments.__version__.split('.')[:2])) < (2, 18):
|
||||||
from pygments.formatter import Formatter
|
from pygments.formatter import Formatter
|
||||||
|
|
||||||
Formatter.__class_getitem__ = classmethod(lambda cls, name: cls) # type: ignore[attr-defined]
|
Formatter.__class_getitem__ = classmethod(lambda cls, name: cls) # type: ignore[attr-defined]
|
||||||
|
@ -11,6 +11,7 @@ import shutil
|
|||||||
import time
|
import time
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import pygments
|
||||||
import pytest
|
import pytest
|
||||||
from babel.messages import mofile, pofile
|
from babel.messages import mofile, pofile
|
||||||
from babel.messages.catalog import Catalog
|
from babel.messages.catalog import Catalog
|
||||||
@ -1487,6 +1488,11 @@ def test_xml_strange_markup(app):
|
|||||||
@pytest.mark.sphinx('html', testroot='intl')
|
@pytest.mark.sphinx('html', testroot='intl')
|
||||||
@pytest.mark.test_params(shared_result='test_intl_basic')
|
@pytest.mark.test_params(shared_result='test_intl_basic')
|
||||||
def test_additional_targets_should_not_be_translated(app):
|
def test_additional_targets_should_not_be_translated(app):
|
||||||
|
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
|
||||||
|
sp = '<span class="w"> </span>'
|
||||||
|
else:
|
||||||
|
sp = ' '
|
||||||
|
|
||||||
app.build()
|
app.build()
|
||||||
# [literalblock.txt]
|
# [literalblock.txt]
|
||||||
result = (app.outdir / 'literalblock.html').read_text(encoding='utf8')
|
result = (app.outdir / 'literalblock.html').read_text(encoding='utf8')
|
||||||
@ -1525,7 +1531,7 @@ def test_additional_targets_should_not_be_translated(app):
|
|||||||
# doctest block should not be translated but be highlighted
|
# doctest block should not be translated but be highlighted
|
||||||
expected_expr = (
|
expected_expr = (
|
||||||
"""<span class="gp">>>> </span>"""
|
"""<span class="gp">>>> </span>"""
|
||||||
"""<span class="kn">import</span> <span class="nn">sys</span> """
|
f"""<span class="kn">import</span>{sp}<span class="nn">sys</span> """
|
||||||
"""<span class="c1"># sys importing</span>"""
|
"""<span class="c1"># sys importing</span>"""
|
||||||
)
|
)
|
||||||
assert_count(expected_expr, result, 1)
|
assert_count(expected_expr, result, 1)
|
||||||
@ -1570,6 +1576,11 @@ def test_additional_targets_should_not_be_translated(app):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
def test_additional_targets_should_be_translated(app):
|
def test_additional_targets_should_be_translated(app):
|
||||||
|
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
|
||||||
|
sp = '<span class="w"> </span>'
|
||||||
|
else:
|
||||||
|
sp = ' '
|
||||||
|
|
||||||
app.build()
|
app.build()
|
||||||
# [literalblock.txt]
|
# [literalblock.txt]
|
||||||
result = (app.outdir / 'literalblock.html').read_text(encoding='utf8')
|
result = (app.outdir / 'literalblock.html').read_text(encoding='utf8')
|
||||||
@ -1619,7 +1630,7 @@ def test_additional_targets_should_be_translated(app):
|
|||||||
# doctest block should not be translated but be highlighted
|
# doctest block should not be translated but be highlighted
|
||||||
expected_expr = (
|
expected_expr = (
|
||||||
"""<span class="gp">>>> </span>"""
|
"""<span class="gp">>>> </span>"""
|
||||||
"""<span class="kn">import</span> <span class="nn">sys</span> """
|
f"""<span class="kn">import</span>{sp}<span class="nn">sys</span> """
|
||||||
"""<span class="c1"># SYS IMPORTING</span>"""
|
"""<span class="c1"># SYS IMPORTING</span>"""
|
||||||
)
|
)
|
||||||
assert_count(expected_expr, result, 1)
|
assert_count(expected_expr, result, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user