Skip to content

Commit 63e34ac

Browse files
mitya57NGC2023
andcommitted
Make the tests pass with Sphinx 7.x and 8.x
Fixes #43. Co-authored-by: Yogeswaran Umasankar <kd8mbd@gmail.com>
1 parent 1f55a88 commit 63e34ac

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ testing = [
3434
"pytest",
3535
"pytest-regressions",
3636
"pytest-cov",
37-
"sphinx>=4.0.0,<7",
37+
"sphinx>=4.0.0,<9",
3838
]
3939
docs = [
4040
"sphinx>=4.0.0",

tests/test_render.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for the rendering."""
22

33
import io
4+
import os
45
from pathlib import Path
56
from textwrap import dedent
67

@@ -12,8 +13,13 @@
1213
from autodoc2.render.rst_ import RstRenderer
1314
from autodoc2.utils import yield_modules
1415
import pytest
16+
import sphinx
1517
from sphinx.testing.util import SphinxTestApp
16-
from sphinx.testing.util import path as sphinx_path
18+
19+
if sphinx.version_info >= (7, 2):
20+
sphinx_path = Path
21+
else:
22+
from sphinx.testing.path import path as sphinx_path
1723

1824

1925
@pytest.mark.parametrize(
@@ -94,8 +100,8 @@ def test_sphinx_build(tmp_path: Path, with_rebuild: bool):
94100
build = tmp_path / "build"
95101
app = SphinxTestApp(
96102
buildername="html",
97-
srcdir=sphinx_path(source),
98-
builddir=sphinx_path(build),
103+
srcdir=sphinx_path(os.path.abspath(source)),
104+
builddir=sphinx_path(os.path.abspath(build)),
99105
warning=warnings,
100106
)
101107
try:
@@ -137,8 +143,8 @@ def test_sphinx_build(tmp_path: Path, with_rebuild: bool):
137143
rebuild_warnings = io.StringIO()
138144
rebuild_app = SphinxTestApp(
139145
buildername="html",
140-
srcdir=sphinx_path(source),
141-
builddir=sphinx_path(build),
146+
srcdir=sphinx_path(os.path.abspath(source)),
147+
builddir=sphinx_path(os.path.abspath(build)),
142148
warning=rebuild_warnings,
143149
)
144150
try:
@@ -210,8 +216,8 @@ def test_sphinx_build_directives(tmp_path: Path, file_regression):
210216
build = tmp_path / "build"
211217
app = SphinxTestApp(
212218
buildername="html",
213-
srcdir=sphinx_path(source),
214-
builddir=sphinx_path(build),
219+
srcdir=sphinx_path(os.path.abspath(source)),
220+
builddir=sphinx_path(os.path.abspath(build)),
215221
warning=warnings,
216222
)
217223
try:
@@ -224,6 +230,25 @@ def test_sphinx_build_directives(tmp_path: Path, file_regression):
224230
doctree = app.env.get_doctree("index")
225231
doctree["source"] = "index.rst"
226232
content = "\n".join([line.rstrip() for line in doctree.pformat().splitlines()])
233+
if sphinx.version_info < (7, 1):
234+
content = content.replace(
235+
'<document source="index.rst">',
236+
"<document source=\"index.rst\" translation_progress=\"{'total': 0, 'translated': 0}\">",
237+
)
238+
content = content.replace(
239+
'<desc_parameterlist xml:space="preserve">',
240+
'<desc_parameterlist multi_line_parameter_list="False" xml:space="preserve">',
241+
)
242+
if sphinx.version_info < (7, 2):
243+
content = content.replace(
244+
'<desc classes="py function" desctype="function" domain="py"',
245+
'<desc classes="py function" desctype="function" domain="py" no-contents-entry="False" no-index="False" no-index-entry="False" no-typesetting="False"',
246+
)
247+
if sphinx.version_info < (8, 2):
248+
content = content.replace(
249+
'<desc_parameterlist multi_line_parameter_list="False"',
250+
'<desc_parameterlist multi_line_parameter_list="False" multi_line_trailing_comma="True"',
251+
)
227252
file_regression.check(content, extension=".xml")
228253

229254

tests/test_render/test_sphinx_build_directives.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<document source="index.rst">
1+
<document source="index.rst" translation_progress="{'total': 0, 'translated': 0}">
22
<section ids="test" names="test">
33
<title>
44
Test
@@ -19,13 +19,13 @@
1919
```
2020
````
2121
<index entries="('single',\ 'func()\ (in\ module\ package)',\ 'package.func',\ '',\ None)">
22-
<desc classes="py function" desctype="function" domain="py" nocontentsentry="False" noindex="False" noindexentry="False" objtype="function">
22+
<desc classes="py function" desctype="function" domain="py" no-contents-entry="False" no-index="False" no-index-entry="False" no-typesetting="False" nocontentsentry="False" noindex="False" noindexentry="False" objtype="function">
2323
<desc_signature _toc_name="func()" _toc_parts="('package', 'func')" class="" classes="sig sig-object" fullname="func" ids="package.func" module="package">
2424
<desc_addname classes="sig-prename descclassname" xml:space="preserve">
2525
package.
2626
<desc_name classes="sig-name descname" xml:space="preserve">
2727
func
28-
<desc_parameterlist xml:space="preserve">
28+
<desc_parameterlist multi_line_parameter_list="False" multi_line_trailing_comma="True" xml:space="preserve">
2929
<desc_parameter xml:space="preserve">
3030
<desc_sig_name classes="n">
3131
a

0 commit comments

Comments
 (0)