mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-10-25 22:50:22 -05:00
Fix tests for Docutils 1.0 pre-releases
This commit is contained in:
1 parent
378a332a8f
commit
d19cbb5083
14 files changed
+163
-26
No files matched your search
@@ -5,11 +5,17 @@ from __future__ import annotations
|
||||
import re
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import docutils
|
||||
import pytest
|
||||
from docutils import nodes
|
||||
|
||||
from tests.test_builders.xpath_util import check_xpath
|
||||
|
||||
if docutils.__version_info__[:2] >= (1, 0):
|
||||
_RFC_1_URL = 'https://datatracker.ietf.org/doc/html/rfc1/'
|
||||
else:
|
||||
_RFC_1_URL = 'https://datatracker.ietf.org/doc/html/rfc1.html'
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable, Iterable
|
||||
from pathlib import Path
|
||||
@@ -147,14 +153,12 @@ def tail_check(check: str) -> Callable[[Iterable[Element]], Literal[True]]:
|
||||
),
|
||||
(
|
||||
'markup.html',
|
||||
".//a[@href='https://datatracker.ietf.org/doc/html/rfc1.html']"
|
||||
"[@class='rfc reference external']/strong",
|
||||
f".//a[@href='{_RFC_1_URL}'][@class='rfc reference external']/strong",
|
||||
'RFC 1',
|
||||
),
|
||||
(
|
||||
'markup.html',
|
||||
".//a[@href='https://datatracker.ietf.org/doc/html/rfc1.html']"
|
||||
"[@class='rfc reference external']/strong",
|
||||
f".//a[@href='{_RFC_1_URL}'][@class='rfc reference external']/strong",
|
||||
'Request for Comments #1',
|
||||
),
|
||||
(
|
||||
|
||||
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import re
|
||||
from types import SimpleNamespace
|
||||
|
||||
import docutils
|
||||
import pytest
|
||||
from docutils import nodes, utils
|
||||
from docutils.parsers.rst import Parser as RstParser
|
||||
@@ -23,6 +24,11 @@ from sphinx.writers.latex import LaTeXTranslator, LaTeXWriter
|
||||
|
||||
from tests.utils import extract_node
|
||||
|
||||
if docutils.__version_info__[:2] >= (1, 0):
|
||||
_RFC_2324_URL = 'https://datatracker.ietf.org/doc/html/rfc2324/'
|
||||
else:
|
||||
_RFC_2324_URL = 'https://datatracker.ietf.org/doc/html/rfc2324.html'
|
||||
|
||||
TYPE_CHECKING = False
|
||||
if TYPE_CHECKING:
|
||||
from sphinx.environment import BuildEnvironment
|
||||
@@ -212,12 +218,12 @@ def rst_to_latex(rst: str, *, app: SphinxTestApp) -> str:
|
||||
':rfc:`2324`',
|
||||
(
|
||||
'<p><span class="target" id="index-0"></span><a class="rfc reference external" '
|
||||
'href="https://datatracker.ietf.org/doc/html/rfc2324.html"><strong>RFC 2324</strong></a></p>'
|
||||
f'href="{_RFC_2324_URL}"><strong>RFC 2324</strong></a></p>'
|
||||
),
|
||||
(
|
||||
'\\sphinxAtStartPar\n'
|
||||
'\\index{RFC@\\spxentry{RFC}!RFC 2324@\\spxentry{RFC 2324}}'
|
||||
'\\sphinxhref{https://datatracker.ietf.org/doc/html/rfc2324.html}'
|
||||
rf'\sphinxhref{{{_RFC_2324_URL}}}'
|
||||
'{\\sphinxstylestrong{RFC 2324}}'
|
||||
),
|
||||
),
|
||||
@@ -226,13 +232,13 @@ def rst_to_latex(rst: str, *, app: SphinxTestApp) -> str:
|
||||
':rfc:`2324#section-1`',
|
||||
(
|
||||
'<p><span class="target" id="index-0"></span><a class="rfc reference external" '
|
||||
'href="https://datatracker.ietf.org/doc/html/rfc2324.html#section-1">'
|
||||
f'href="{_RFC_2324_URL}#section-1">'
|
||||
'<strong>RFC 2324 Section 1</strong></a></p>'
|
||||
),
|
||||
(
|
||||
'\\sphinxAtStartPar\n'
|
||||
'\\index{RFC@\\spxentry{RFC}!RFC 2324 Section 1@\\spxentry{RFC 2324 Section 1}}'
|
||||
'\\sphinxhref{https://datatracker.ietf.org/doc/html/rfc2324.html\\#section-1}'
|
||||
rf'\sphinxhref{{{_RFC_2324_URL}\#section-1}}'
|
||||
'{\\sphinxstylestrong{RFC 2324 Section 1}}'
|
||||
),
|
||||
),
|
||||
@@ -462,6 +468,16 @@ def test_inline(
|
||||
assert latex_expected == latex_translated, f'from {rst!r}'
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='_blank')
|
||||
def test_block_quote_attribution(app: SphinxTestApp) -> None:
|
||||
html = rst_to_html(' A quotation.\n\n -- The author\n', app=app)
|
||||
assert html == (
|
||||
'<blockquote>\n<div><p>A quotation.</p>\n'
|
||||
'<p class="attribution">—The author</p>\n'
|
||||
'</div></blockquote>'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('rst', 'html_expected', 'latex_expected'),
|
||||
[
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import docutils
|
||||
import pytest
|
||||
from docutils import nodes
|
||||
|
||||
from sphinx.testing import restructuredtext
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sphinx.testing.util import SphinxTestApp
|
||||
|
||||
|
||||
@pytest.mark.sphinx('dummy', testroot='_blank')
|
||||
def test_indented_doctest(app: SphinxTestApp) -> None:
|
||||
doctree = restructuredtext.parse(app, ' >>> 1 + 1\n 2\n')
|
||||
|
||||
assert len(doctree) == 1
|
||||
node = doctree[0]
|
||||
if docutils.__version_info__[:2] >= (1, 0):
|
||||
assert isinstance(node, nodes.literal_block)
|
||||
assert node['language'] == 'pycon'
|
||||
else:
|
||||
assert isinstance(node, nodes.doctest_block)
|
||||
assert node.astext() == '>>> 1 + 1\n2'
|
||||
assert 'doctest' in node['classes']
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('target', 'translate_doctest', 'translate_literal'),
|
||||
[('doctest-block', True, False), ('literal-block', False, True)],
|
||||
)
|
||||
@pytest.mark.sphinx('dummy', testroot='_blank')
|
||||
def test_doctest_translation(
|
||||
app: SphinxTestApp,
|
||||
target: str,
|
||||
translate_doctest: bool,
|
||||
translate_literal: bool,
|
||||
) -> None:
|
||||
app.config.gettext_additional_targets = [target]
|
||||
doctree = restructuredtext.parse(
|
||||
app, '>>> 1 + 1\n2\n\n::\n\n an ordinary literal block\n'
|
||||
)
|
||||
|
||||
doctest, literal = doctree.children
|
||||
assert isinstance(doctest, nodes.Element)
|
||||
assert doctest.get('translatable', False) is translate_doctest
|
||||
assert isinstance(literal, nodes.Element)
|
||||
assert literal.get('translatable', False) is translate_literal
|
||||
Reference in new issue
Block a user