-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_exercise_references.py
More file actions
73 lines (66 loc) · 2.07 KB
/
test_exercise_references.py
File metadata and controls
73 lines (66 loc) · 2.07 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
63
64
65
66
67
68
69
70
71
72
73
from bs4 import BeautifulSoup
import pytest
import sphinx
SPHINX_VERSION = f".sphinx{sphinx.version_info[0]}"
@pytest.mark.sphinx("html", testroot="mybook")
@pytest.mark.parametrize(
"idir",
[
"_enum_ref_mathtitle.html",
"_enum_ref_notitle.html",
"_enum_ref_title.html",
"_enum_numref_mathtitle.html",
"_enum_numref_notitle.html",
"_enum_numref_title.html",
"_unenum_ref_mathtitle.html",
"_unenum_ref_notitle.html",
"_unenum_ref_title.html",
"_unenum_numref_mathtitle.html",
"_unenum_numref_notitle.html",
"_unenum_numref_title.html",
"_enum_numref_placeholders.html",
],
)
def test_reference(app, idir, file_regression):
"""Test exercise ref and numref role markup."""
app.builder.build_all()
path_exc_directive = app.outdir / "exercise" / idir
assert path_exc_directive.exists()
# get content markup
soup = BeautifulSoup(path_exc_directive.read_text(encoding="utf8"), "html.parser")
excs = ""
all_refs = soup.select("p")
for ref in all_refs:
excs += f"{ref}\n"
file_regression.check(
str(excs[:-1]), basename=idir.split(".")[0], extension=f"{SPHINX_VERSION}.html"
)
@pytest.mark.sphinx("html", testroot="mybook")
@pytest.mark.parametrize(
"docname",
[
"_enum_numref_mathtitle",
"_enum_numref_notitle",
"_enum_numref_placeholders",
"_enum_numref_title",
"_enum_ref_mathtitle",
"_enum_ref_notitle",
"_enum_ref_title",
"_unenum_numref_mathtitle",
"_unenum_numref_notitle",
"_unenum_numref_title",
"_unenum_ref_mathtitle",
"_unenum_ref_notitle",
"_unenum_ref_title",
],
)
def test_exercise_doctree(app, docname, file_regression, get_sphinx_app_doctree):
app.build()
docname = "exercise" + "/" + docname
get_sphinx_app_doctree(
app,
docname,
resolve=False,
regress=True,
flatten_outdir=True, # noqa: E501 flatten files "solution/<file> -> <file>.xml" for convenience
)