Skip to content

Commit

Permalink
馃И Fix Sphinx 7.2 tests (#811)
Browse files Browse the repository at this point in the history
Fix tests broken by recent sphinx releases, up to sphinx v7.2.6
  • Loading branch information
chrisjsewell committed Sep 20, 2023
1 parent 350c633 commit 4f670fc
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 37 deletions.
4 changes: 4 additions & 0 deletions tests/test_renderers/fixtures/mock_include.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ Include code:
<document source="tmpdir/test.md">
<literal_block classes="code md" source="tmpdir/other.md" xml:space="preserve">
a
<inline classes="whitespace">
b
<inline classes="whitespace">
c
.
12 changes: 6 additions & 6 deletions tests/test_renderers/fixtures/sphinx_directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ object (`sphinx.directives.ObjectDescription`):
.
<document source="<src>/index.md">
<index entries="">
<desc classes="object" desctype="object" domain="" noindex="False" objtype="object">
<desc_signature classes="sig sig-object">
<desc classes="object" desctype="object" domain="" nocontentsentry="False" noindex="False" noindexentry="False" objtype="object">
<desc_signature _toc_name="" _toc_parts="()" classes="sig sig-object">
<desc_name classes="sig-name descname" xml:space="preserve">
something
<desc_content>
Expand Down Expand Up @@ -404,8 +404,8 @@ cmdoption (`sphinx.domains.std.Cmdoption`):
.
<document source="<src>/index.md">
<index entries="('pair',\ 'command\ line\ option;\ a',\ 'cmdoption-arg-a',\ '',\ None)">
<desc classes="std cmdoption" desctype="cmdoption" domain="std" noindex="False" objtype="cmdoption">
<desc_signature allnames="a" classes="sig sig-object" ids="cmdoption-arg-a">
<desc classes="std cmdoption" desctype="cmdoption" domain="std" nocontentsentry="False" noindex="False" noindexentry="False" objtype="cmdoption">
<desc_signature _toc_name="" _toc_parts="()" allnames="a" classes="sig sig-object" ids="cmdoption-arg-a">
<desc_name classes="sig-name descname" xml:space="preserve">
a
<desc_addname classes="sig-prename descclassname" xml:space="preserve">
Expand All @@ -419,8 +419,8 @@ rst:directive (`sphinx.domains.rst.ReSTDirective`):
.
<document source="<src>/index.md">
<index entries="('single',\ 'a\ (directive)',\ 'directive-a',\ '',\ None)">
<desc classes="rst directive" desctype="directive" domain="rst" noindex="False" objtype="directive">
<desc_signature classes="sig sig-object" ids="directive-a">
<desc classes="rst directive" desctype="directive" domain="rst" nocontentsentry="False" noindex="False" noindexentry="False" objtype="directive">
<desc_signature _toc_name=".. a::" _toc_parts="('a',)" classes="sig sig-object" fullname="a" ids="directive-a">
<desc_name classes="sig-name descname" xml:space="preserve">
.. a::
<desc_content>
Expand Down
27 changes: 20 additions & 7 deletions tests/test_renderers/test_fixtures_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,26 @@ def test_sphinx_directives(file_params, sphinx_doctree_no_tr: CreateDoctree):
# see https://github.com/executablebooks/MyST-Parser/issues/522
if sys.maxsize == 2147483647:
pformat = pformat.replace('"2147483647"', '"9223372036854775807"')
# changed in sphinx 5.3 for desc node
pformat = pformat.replace('nocontentsentry="False" ', "")
pformat = pformat.replace('noindexentry="False" ', "")
# changed in sphinx 5.3 for desc_signature node
pformat = pformat.replace('_toc_name="" _toc_parts="()" ', "")
pformat = pformat.replace('_toc_name=".. a::" _toc_parts="(\'a\',)" ', "")
pformat = pformat.replace('fullname="a" ', "")
# changed in sphinx 7.2
pformat = pformat.replace(
'classes="sig sig-object sig sig-object"', 'classes="sig sig-object"'
)
pformat = pformat.replace(
'classes="sig-name descname sig-name descname"', 'classes="sig-name descname"'
)
pformat = pformat.replace(
'classes="sig-prename descclassname sig-prename descclassname"',
'classes="sig-prename descclassname"',
)
# changed in sphinx 7.2 (#11533)
pformat = pformat.replace(
(
'no-contents-entry="False" no-index="False" '
'no-index-entry="False" no-typesetting="False" '
),
"",
)

file_params.assert_expected(pformat, rstrip_lines=True)


Expand Down
5 changes: 0 additions & 5 deletions tests/test_renderers/test_include_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ def test_render(file_params, tmp_path, monkeypatch):
)

doctree["source"] = "tmpdir/test.md"
if file_params.title.startswith("Include code:"):
# from sphinx 5.3 whitespace nodes are now present
for node in doctree.traverse():
if node.tagname == "inline" and node["classes"] == ["whitespace"]:
node.parent.remove(node)
output = doctree.pformat().replace(str(tmp_path) + os.sep, "tmpdir/").rstrip()

file_params.assert_expected(output, rstrip=True)
Expand Down
1 change: 1 addition & 0 deletions tests/test_renderers/test_myst_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_parse(
assert not result.warnings

doctree["source"] = "root/index.md"
doctree.attributes.pop("translation_progress", None)
outcome = doctree.pformat()
if result.warnings.strip():
outcome += "\n\n" + result.warnings.strip().replace("", "").replace(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_sphinx/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_basic(app, status, warning, get_sphinx_app_output):

import pytest
from bs4 import BeautifulSoup
from docutils import nodes
from sphinx.testing.path import path

from myst_parser._compat import findall
Expand Down Expand Up @@ -83,6 +84,8 @@ def read(
for pygment_whitespace in doc_div.select("pre > span.w"):
pygment_whitespace.replace_with(pygment_whitespace.text)
text = doc_div.prettify()
# changed in sphinx 7.2
text = text.replace('"Link to this', '"Permalink to this')
for find, rep in (replace or {}).items():
text = text.replace(find, rep)
file_regression.check(text, extension=regress_ext, encoding="utf8")
Expand Down Expand Up @@ -116,6 +119,13 @@ def read(
):
node["source"] = pathlib.Path(node["source"]).name

doctree = doctree.deepcopy()

# remove attrs added in sphinx 7.1
doctree.attributes.pop("translation_progress", None)
for node in findall(doctree)(nodes.Element):
node.attributes.pop("translated", None)

if regress:
text = doctree.pformat() # type: str
for find, rep in (replace or {}).items():
Expand Down
40 changes: 25 additions & 15 deletions tests/test_sphinx/test_sphinx_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ def test_basic(
app,
docname="content",
regress=True,
replace={
# changed in sphinx 7.1
'<literal classes="code" language="">': '<literal classes="code">',
},
)
finally:
get_sphinx_app_doctree(
app,
docname="content",
resolve=True,
regress=True,
replace={
# changed in sphinx 7.1
'<literal classes="code" language="">': '<literal classes="code">',
},
)
get_sphinx_app_output(
app,
Expand Down Expand Up @@ -257,8 +265,8 @@ def test_includes(
r"subfolder\example2.jpg": "subfolder/example2.jpg",
r"subfolder\\example2.jpg": "subfolder/example2.jpg",
r"subfolder\\\\example2.jpg": "subfolder/example2.jpg",
# in sphinx 5.3 whitespace nodes were added
' <inline classes="whitespace">\n ': "",
# added in sphinx 7.2 (#9846)
'original_uri="/subfolder/example2.jpg" ': "",
},
)
finally:
Expand All @@ -271,9 +279,6 @@ def test_includes(
r"'subfolder\\example2'": "'subfolder/example2'",
r'uri="subfolder\\example2"': 'uri="subfolder/example2"',
"_images/example21.jpg": "_images/example2.jpg",
# in sphinx 5.3 whitespace nodes were added
'<span class="whitespace"></span>': "",
'<span class="whitespace">\n</span>': "\n",
},
)

Expand Down Expand Up @@ -457,6 +462,10 @@ def test_gettext_html(
filename="index.html",
regress_html=True,
regress_ext=".html",
replace={
# upstream bug https://github.com/sphinx-doc/sphinx/issues/11689
'"Permalink to this heading"': '"Lien permanent vers cette rubrique"'
},
)


Expand Down Expand Up @@ -539,17 +548,18 @@ def test_fieldlist_extension(
docname="index",
regress=True,
replace={
# changed in:
# https://www.sphinx-doc.org/en/master/changes.html#release-4-4-0-released-jan-17-2022
# changed in sphinx 7.2 for desc_sig_name node
'classes="n n"': 'classes="n"',
# changed in sphinx 7.2 for desc_parameterlist node
'multi_line_parameter_list="False" ': "",
# changed in sphinx 7.2 for desc_signature/desc_name nodes
'classes="sig sig-object sig sig-object"': 'classes="sig sig-object"',
'classes="sig-name descname sig-name descname"': 'classes="sig-name descname"',
# changed in sphinx 7.2 (#11533)
(
'<literal_strong py:class="True" '
'py:module="True" refspecific="True">'
): "<literal_strong>",
# changed in sphinx 5.3, for `desc` node
'nocontentsentry="False" ': "",
'noindexentry="False" ': "",
# changed in sphinx 5.3, for `desc_signature` node
'_toc_name="send_message()" _toc_parts="(\'send_message\',)" ': "",
'no-contents-entry="False" no-index="False" '
'no-index-entry="False" no-typesetting="False" '
): "",
},
)
finally:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<paragraph>
content
<index entries="('pair',\ 'built-in\ function;\ send_message()',\ 'send_message',\ '',\ None)">
<desc classes="py function" desctype="function" domain="py" noindex="False" objtype="function">
<desc_signature class="" classes="sig sig-object" fullname="send_message" ids="send_message" module="True">
<desc classes="py function" desctype="function" domain="py" nocontentsentry="False" noindex="False" noindexentry="False" objtype="function">
<desc_signature _toc_name="send_message()" _toc_parts="('send_message',)" class="" classes="sig sig-object" fullname="send_message" ids="send_message" module="True">
<desc_name classes="sig-name descname" xml:space="preserve">
send_message
<desc_parameterlist xml:space="preserve">
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sphinx/test_sphinx_builds/test_includes.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ <h2>
</pre>
</div>
</div>
<pre class="code python literal-block"><small class="ln">0 </small><code data-lineno="0 "><span class="keyword">def</span> <span class="name function">a_func</span><span class="punctuation">(</span><span class="name">param</span><span class="punctuation">):</span>
</code><small class="ln">1 </small><code data-lineno="1 "> <span class="name builtin">print</span><span class="punctuation">(</span><span class="name">param</span><span class="punctuation">)</span></code></pre>
<pre class="code python literal-block"><small class="ln">0 </small><code data-lineno="0 "><span class="keyword">def</span> <span class="name function">a_func</span><span class="punctuation">(</span><span class="name">param</span><span class="punctuation">):</span><span class="whitespace">
</span></code><small class="ln">1 </small><code data-lineno="1 "><span class="whitespace"></span> <span class="name builtin">print</span><span class="punctuation">(</span><span class="name">param</span><span class="punctuation">)</span></code></pre>
<div class="highlight-default notranslate">
<div class="highlight">
<pre><span></span><span class="n">This</span> <span class="n">should</span> <span class="n">be</span> <span class="o">*</span><span class="n">literal</span><span class="o">*</span>
Expand Down
3 changes: 3 additions & 0 deletions tests/test_sphinx/test_sphinx_builds/test_includes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
param
<inline classes="punctuation">
):
<inline classes="whitespace">


<inline classes="name builtin">
Expand All @@ -80,9 +81,11 @@
param
<inline classes="punctuation">
):
<inline classes="whitespace">

<inline classes="ln">
1
<inline classes="whitespace">

<inline classes="name builtin">
print
Expand Down

0 comments on commit 4f670fc

Please sign in to comment.