forked from bazel-contrib/rules_python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsphinx_output_test.py
More file actions
78 lines (69 loc) · 3.52 KB
/
sphinx_output_test.py
File metadata and controls
78 lines (69 loc) · 3.52 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
74
75
76
77
78
import importlib.resources
from xml.etree import ElementTree
import tests.sphinx_stardoc as sphinx_stardoc
from absl.testing import absltest, parameterized
class SphinxOutputTest(parameterized.TestCase):
def setUp(self):
super().setUp()
self._docs = {}
self._xmls = {}
def assert_xref(self, doc, *, text, href):
match = self._doc_element(doc).find(f".//*[.='{text}']")
if not match:
self.fail(f"No element found with {text=}")
actual = match.attrib.get("href", "<UNSET>")
self.assertEqual(
href,
actual,
msg=f"Unexpected href for {text=}: "
+ ElementTree.tostring(match).decode("utf8"),
)
def _read_doc(self, doc):
doc += ".html"
if doc not in self._docs:
self._docs[doc] = (
importlib.resources.files(sphinx_stardoc)
.joinpath("docs/_build/html")
.joinpath(doc)
.read_text()
)
return self._docs[doc]
def _doc_element(self, doc):
xml = self._read_doc(doc)
if doc not in self._xmls:
self._xmls[doc] = ElementTree.fromstring(xml)
return self._xmls[doc]
@parameterized.named_parameters(
# fmt: off
("short_func", "myfunc", "function.html#myfunc"),
("short_func_arg", "myfunc.arg1", "function.html#myfunc.arg1"),
("short_rule", "my_rule", "rule.html#my_rule"),
("short_rule_attr", "my_rule.ra1", "rule.html#my_rule.ra1"),
("short_provider", "LangInfo", "provider.html#LangInfo"),
("short_tag_class", "myext.mytag", "module_extension.html#myext.mytag"),
("full_norepo_func", "//lang:function.bzl%myfunc", "function.html#myfunc"),
("full_norepo_func_arg", "//lang:function.bzl%myfunc.arg1", "function.html#myfunc.arg1"),
("full_norepo_rule", "//lang:rule.bzl%my_rule", "rule.html#my_rule"),
("full_norepo_rule_attr", "//lang:rule.bzl%my_rule.ra1", "rule.html#my_rule.ra1"),
("full_norepo_provider", "//lang:provider.bzl%LangInfo", "provider.html#LangInfo"),
("full_norepo_aspect", "//lang:aspect.bzl%myaspect", "aspect.html#myaspect"),
("full_norepo_target", "//lang:relativetarget", "target.html#relativetarget"),
("full_repo_func", "@testrepo//lang:function.bzl%myfunc", "function.html#myfunc"),
("full_repo_func_arg", "@testrepo//lang:function.bzl%myfunc.arg1", "function.html#myfunc.arg1"),
("full_repo_rule", "@testrepo//lang:rule.bzl%my_rule", "rule.html#my_rule"),
("full_repo_rule_attr", "@testrepo//lang:rule.bzl%my_rule.ra1", "rule.html#my_rule.ra1"),
("full_repo_provider", "@testrepo//lang:provider.bzl%LangInfo", "provider.html#LangInfo"),
("full_repo_aspect", "@testrepo//lang:aspect.bzl%myaspect", "aspect.html#myaspect"),
("full_repo_target", "@testrepo//lang:relativetarget", "target.html#relativetarget"),
("tag_class_attr_using_attr_role", "myext.mytag.ta1", "module_extension.html#myext.mytag.ta1"),
("tag_class_attr_using_attr_role_just_attr_name", "ta1", "module_extension.html#myext.mytag.ta1"),
("file_without_repo", "//lang:rule.bzl", "rule.html"),
("file_with_repo", "@testrepo//lang:rule.bzl", "rule.html"),
("package_absolute", "//lang", "target.html"),
("package_basename", "lang", "target.html"),
# fmt: on
)
def test_xrefs(self, text, href):
self.assert_xref("xrefs", text=text, href=href)
if __name__ == "__main__":
absltest.main()