-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathtest_myst_refs.py
More file actions
62 lines (56 loc) · 1.83 KB
/
test_myst_refs.py
File metadata and controls
62 lines (56 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys
import pytest
from sphinx.util.console import strip_colors
from sphinx_pytest.plugin import CreateDoctree
@pytest.mark.parametrize(
"test_name,text,should_warn",
[
("null", "", False),
pytest.param(
"missing",
"[](ref)",
True,
marks=pytest.mark.skipif(
sys.platform == "win32",
reason="Path separators differ on Windows",
),
),
("doc", "[](index)", False),
("doc_with_extension", "[](index.md)", False),
("doc_nested", "[*text*](index)", False),
("ref", "(ref)=\n# Title\n[](ref)", False),
("ref_nested", "(ref)=\n# Title\n[*text*](ref)", False),
pytest.param(
"duplicate",
"(index)=\n# Title\n[](index)",
True,
marks=pytest.mark.skipif(
sys.platform == "win32",
reason="Path separators differ on Windows",
),
),
("ref_colon", "(ref:colon)=\n# Title\n[](ref:colon)", False),
],
)
def test_parse(
test_name: str,
text: str,
should_warn: bool,
sphinx_doctree: CreateDoctree,
file_regression,
normalize_doctree_xml,
):
sphinx_doctree.set_conf({"extensions": ["myst_parser"], "show_warning_types": True})
result = sphinx_doctree(text, "index.md")
assert not result.warnings
doctree = result.get_resolved_doctree("index")
if should_warn:
assert result.warnings
else:
assert not result.warnings
doctree["source"] = "root/index.md"
doctree.attributes.pop("translation_progress", None)
outcome = normalize_doctree_xml(doctree.pformat())
if result.warnings.strip():
outcome += "\n\n" + strip_colors(result.warnings.strip())
file_regression.check(outcome, basename=test_name, extension=".xml")