-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathtest_myst_config.py
More file actions
47 lines (41 loc) · 1.83 KB
/
test_myst_config.py
File metadata and controls
47 lines (41 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Test (docutils) parsing with different ``MdParserConfig`` options set."""
import shlex
from io import StringIO
from pathlib import Path
import pytest
from docutils import __version_info__ as docutils_version
from docutils.core import Publisher, publish_string
from pytest_param_files import ParamTestData
from myst_parser.parsers.docutils_ import Parser
FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures")
INV_PATH = Path(__file__).parent.parent.absolute() / "static" / "objects_v2.inv"
@pytest.mark.param_file(FIXTURE_PATH / "myst-config.txt")
def test_cmdline(file_params: ParamTestData, normalize_doctree_xml):
"""The description is parsed as a docutils commandline"""
if file_params.title == "attrs_image" and docutils_version < (0, 22):
# loose system messages are also output to ast in 0.22 https://github.com/live-clones/docutils/commit/dc4e16315b4fbe391417a6f7aad215b9389a9c74
pytest.skip("different in docutils>=0.22")
pub = Publisher(parser=Parser())
try:
pub.process_command_line(shlex.split(file_params.description or ""))
except Exception as err:
raise AssertionError(
f"Failed to parse commandline: {file_params.description}\n{err}"
) from err
settings = vars(pub.settings)
report_stream = StringIO()
settings["output_encoding"] = "unicode"
settings["warning_stream"] = report_stream
if "inv_" in file_params.title:
settings["myst_inventories"] = {"key": ["https://example.com", str(INV_PATH)]}
output = publish_string(
file_params.content,
parser=Parser(),
writer_name="pseudoxml",
settings_overrides=settings,
)
output = normalize_doctree_xml(output)
warnings = report_stream.getvalue()
if warnings:
output += "\n" + warnings
file_params.assert_expected(output, rstrip_lines=True)