Skip to content

Fix test_util for Docutils 0.22+ #13548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions tests/test_util/test_util_docutils_sphinx_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from types import SimpleNamespace

import docutils
import pytest
from docutils import nodes
from docutils.parsers.rst.languages import en as english # type: ignore[attr-defined]
from docutils.parsers.rst.states import (
Expand All @@ -16,11 +15,6 @@

from sphinx.util.docutils import SphinxDirective, new_document

xfail_du_22 = pytest.mark.xfail(
docutils.__version_info__ >= (0, 22, 0, 'alpha', 0),
reason='expected failure on Docutils 0.22+',
)


def make_directive(
*, env: SimpleNamespace, input_lines: StringList | None = None
Expand All @@ -37,23 +31,30 @@ def make_directive_and_state(
if input_lines is not None:
sm.input_lines = input_lines
state = RSTState(sm)
state.document = new_document('<tests>')
state.document.settings.env = env
state.document.settings.tab_width = 4
state.document.settings.pep_references = None
state.document.settings.rfc_references = None
document = state.document = new_document('<tests>')
document.settings.env = env
document.settings.tab_width = 4
document.settings.pep_references = None
document.settings.rfc_references = None
inliner = Inliner()
inliner.init_customizations(state.document.settings)
inliner.init_customizations(document.settings)
state.inliner = inliner
state.parent = None
state.memo = SimpleNamespace(
document=state.document,
document=document,
reporter=document.reporter,
language=english,
inliner=state.inliner,
reporter=state.document.reporter,
section_level=0,
title_styles=[],
# section_parents=[], # Docutils 0.22+
section_level=0,
section_bubble_up_kludge=False,
inliner=inliner,
)
if docutils.__version_info__ >= (0, 22, 0, 'alpha', 0):
# https://github.com/sphinx-doc/sphinx/issues/13539
# https://sourceforge.net/p/docutils/code/10093/
# https://sourceforge.net/p/docutils/patches/213/
state.memo.section_parents = []
directive = SphinxDirective(
name='test_directive',
arguments=[],
Expand Down Expand Up @@ -111,7 +112,6 @@ def test_sphinx_directive_get_location() -> None:
assert directive.get_location() == '<source>:1'


@xfail_du_22
def test_sphinx_directive_parse_content_to_nodes() -> None:
directive = make_directive(env=SimpleNamespace())
content = 'spam\n====\n\nEggs! *Lobster thermidor.*'
Expand All @@ -128,7 +128,6 @@ def test_sphinx_directive_parse_content_to_nodes() -> None:
assert node.children[1].astext() == 'Eggs! Lobster thermidor.'


@xfail_du_22
def test_sphinx_directive_parse_text_to_nodes() -> None:
directive = make_directive(env=SimpleNamespace())
content = 'spam\n====\n\nEggs! *Lobster thermidor.*'
Expand Down
Loading