Skip to content

Commit 051db37

Browse files
committed
fix breaking tests
1 parent c994609 commit 051db37

File tree

10 files changed

+46
-16
lines changed

10 files changed

+46
-16
lines changed

AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ tox -e py311-sphinx8
8585
# Run with coverage
8686
tox -- --cov=myst_parser
8787

88-
# Update regression test fixtures
88+
# Update regression test fixtures (this will initially produce an error code if the files change)
89+
# but note, these files must pass for all python/sphinx/docutils versions
8990
tox -- --regen-file-failure --force-regen
9091
```
9192

@@ -337,5 +338,6 @@ flowchart TB
337338
- [markdown-it-py Documentation](https://markdown-it-py.readthedocs.io/)
338339
- [Docutils Repository](https://github.com/live-clones/docutils)
339340
- [Docutils Documentation](https://docutils.sourceforge.io/)
341+
- [Docutils release log](https://docutils.sourceforge.io/RELEASE-NOTES.html)
340342
- [Sphinx Repository](https://github.com/sphinx-doc/sphinx)
341343
- [Sphinx Extension Development](https://www.sphinx-doc.org/en/master/extdev/index.html)

myst_parser/mocking.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,12 +454,18 @@ def run(self) -> list[nodes.Element]:
454454
literal_block.line = 1 # TODO don;t think this should be 1?
455455
self.add_name(literal_block)
456456
if "number-lines" in self.options:
457-
try:
458-
startline = int(self.options["number-lines"] or 1)
459-
except ValueError as err:
460-
raise DirectiveError(
461-
3, ":number-lines: with non-integer start value"
462-
) from err
457+
# note starting in docutils 0.22 this option is now an integer instead of a string, see: https://github.com/live-clones/docutils/commit/f39ac1413e56a330c8fea6e0d080fed0ff2b8483
458+
if self.options["number-lines"] is None:
459+
startline = 1
460+
elif isinstance(self.options["number-lines"], int):
461+
startline = self.options["number-lines"]
462+
else:
463+
try:
464+
startline = int(self.options["number-lines"] or 1)
465+
except ValueError as err:
466+
raise DirectiveError(
467+
3, ":number-lines: with non-integer start value"
468+
) from err
463469
endline = startline + len(file_content.splitlines())
464470
file_content = file_content.removesuffix("\n")
465471
tokens = NumberLines([([], file_content)], startline, endline)

tests/test_renderers/fixtures/docutil_link_resolution.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,15 @@
128128
Test
129129
<subtitle ids="other test-1" names="other test">
130130
Other
131-
<system_message backrefs="test-1" level="1" line="3" source="<src>/index.md" type="INFO">
132-
<paragraph>
133-
Duplicate implicit target name: "test".
134131
<target refid="test-1">
135132
<paragraph>
136133
<reference id_link="True" refid="test-1">
137134
<inline classes="std std-ref">
138135
Other
136+
137+
138+
<src>/index.md:3: (INFO/1) Target name overrides implicit target name "test".
139+
<src>/index.md:3: (INFO/1) Hyperlink target "test-1" is not referenced.
139140
.
140141

141142
[id-with-spaces]

tests/test_renderers/fixtures/myst-config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ a
263263
<document source="<string>">
264264
<paragraph>
265265
a
266+
<section classes="system-messages">
267+
<title>
268+
Docutils System Messages
269+
<system_message level="2" source="<string>" type="WARNING">
270+
<paragraph>
271+
The `attrs_image` extension is deprecated, please use `attrs_inline` instead. [myst.deprecated]
266272

267273
<string>:: (WARNING/2) The `attrs_image` extension is deprecated, please use `attrs_inline` instead. [myst.deprecated]
268274
.

tests/test_renderers/test_error_reporting.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ def test_basic(file_params):
2020
parser=Parser(),
2121
settings_overrides={"warning_stream": report_stream},
2222
)
23-
file_params.assert_expected(report_stream.getvalue(), rstrip=True)
23+
text = report_stream.getvalue()
24+
# changed in docutils 0.23
25+
text = text.replace(
26+
"corresponding footnote available", "corresponding footnotes available"
27+
)
28+
file_params.assert_expected(text, rstrip=True)

tests/test_renderers/test_fixtures_docutils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import pytest
1414
from conftest import normalize_doctree_xml
15+
from docutils import __version_info__ as docutils_version
1516
from docutils.core import Publisher, publish_doctree
1617
from pytest_param_files import ParamTestData
1718

@@ -51,6 +52,11 @@ def test_link_resolution(file_params: ParamTestData):
5152
settings = settings_from_cmdline(file_params.description)
5253
report_stream = StringIO()
5354
settings["warning_stream"] = report_stream
55+
if file_params.title == "explicit>implicit":
56+
if docutils_version < (0, 22):
57+
# reporting changed in docutils 0.22
58+
pytest.skip("different in docutils>=0.22")
59+
settings["report_level"] = 0
5460
doctree = publish_doctree(
5561
file_params.content,
5662
source_path="<src>/index.md",

tests/test_renderers/test_myst_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import pytest
88
from conftest import normalize_doctree_xml
9+
from docutils import __version_info__ as docutils_version
910
from docutils.core import Publisher, publish_string
1011
from pytest_param_files import ParamTestData
1112

@@ -18,6 +19,9 @@
1819
@pytest.mark.param_file(FIXTURE_PATH / "myst-config.txt")
1920
def test_cmdline(file_params: ParamTestData):
2021
"""The description is parsed as a docutils commandline"""
22+
if file_params.title == "attrs_image" and docutils_version < (0, 22):
23+
# loose system messages are also output to ast in 0.22 https://github.com/live-clones/docutils/commit/dc4e16315b4fbe391417a6f7aad215b9389a9c74
24+
pytest.skip("different in docutils>=0.22")
2125
pub = Publisher(parser=Parser())
2226
try:
2327
pub.process_command_line(shlex.split(file_params.description or ""))

tests/test_sphinx/sourcedirs/includes/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
```{include} include_code.py
1616
:code: python
17-
:number-lines: 0
17+
:number-lines: 1
1818
```
1919

2020
```{include} include_literal.txt

tests/test_sphinx/test_sphinx_builds/test_includes.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ <h2>
115115
</pre>
116116
</div>
117117
</div>
118-
<pre class="code python literal-block"><small class="ln">0 </small><code data-lineno="0 "><span class="keyword">def</span><span class="whitespace"> </span><span class="name function">a_func</span><span class="punctuation">(</span><span class="name">param</span><span class="punctuation">):</span><span class="whitespace">
119-
</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>
118+
<pre class="code python literal-block"><small class="ln">1 </small><code data-lineno="1 "><span class="keyword">def</span><span class="whitespace"> </span><span class="name function">a_func</span><span class="punctuation">(</span><span class="name">param</span><span class="punctuation">):</span><span class="whitespace">
119+
</span></code><small class="ln">2 </small><code data-lineno="2 "><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>
120120
<div class="highlight-default notranslate">
121121
<div class="highlight">
122122
<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>

tests/test_sphinx/test_sphinx_builds/test_includes.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
)
7777
<literal_block classes="code python" source="include_code.py" xml:space="preserve">
7878
<inline classes="ln">
79-
0
79+
1
8080
<inline classes="keyword">
8181
def
8282
<inline classes="whitespace">
@@ -92,7 +92,7 @@
9292
<inline classes="whitespace">
9393

9494
<inline classes="ln">
95-
1
95+
2
9696
<inline classes="whitespace">
9797

9898
<inline classes="name builtin">

0 commit comments

Comments
 (0)