-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathconftest.py
More file actions
62 lines (54 loc) · 1.97 KB
/
conftest.py
File metadata and controls
62 lines (54 loc) · 1.97 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
"""Shared pytest configuration for all tests."""
import re
import pytest
from docutils import __version_info__ as docutils_version_info
DOCUTILS_0_22_PLUS = docutils_version_info >= (0, 22)
@pytest.fixture
def normalize_doctree_xml():
"""Normalize docutils XML output for cross-version compatibility.
In docutils 0.22+, boolean attributes are serialized as "1"/"0"
instead of "True"/"False". This function normalizes to the old format
for consistent test fixtures.
"""
def _normalize(text: str) -> str:
if DOCUTILS_0_22_PLUS:
# Normalize new format (1/0) to old format (1/0)
# Only replace when it's clearly a boolean attribute value
# Pattern: attribute="1" or attribute="0"
attrs = [
"force",
"glob",
"hidden",
"id_link",
"includehidden",
"inline",
"internal",
"is_div",
"linenos",
"multi_line_parameter_list",
"multi_line_trailing_comma",
"no-contents-entry",
"no-index",
"no-index-entry",
"no-typesetting",
"no-wrap",
"nocontentsentry",
"noindex",
"noindexentry",
"nowrap",
"refexplicit",
"refspecific",
"refwarn",
"sorted",
"titlesonly",
"toctree",
"translatable",
]
text = re.sub(rf' ({"|".join(attrs)})="1"', r' \1="True"', text)
text = re.sub(rf' ({"|".join(attrs)})="0"', r' \1="False"', text)
# numbered is changed in math_block, but not in toctree, so we have to be more precise
text = re.sub(
r' numbered="1" xml:space', r' numbered="True" xml:space', text
)
return text
return _normalize