diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-07-24 23:49:45 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-07-24 23:49:45 +0900 |
commit | 327c1872841bc6a98aa766fc3d7ee921e6d3b658 (patch) | |
tree | d3424f7aadc4a3118eb7fb72e245b4fbe8391e58 /tests/test_domain_py.py | |
parent | dc63eaf196d37c70410d37c3d28297fb513f7f6d (diff) | |
parent | 5b096c42ff3a907fa7bcce3fa620209da16d40bd (diff) | |
download | sphinx-git-327c1872841bc6a98aa766fc3d7ee921e6d3b658.tar.gz |
Merge branch '3.x'
Diffstat (limited to 'tests/test_domain_py.py')
-rw-r--r-- | tests/test_domain_py.py | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index 43128ece1..d53c6a658 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -238,18 +238,18 @@ def test_get_full_qualified_name(): assert domain.get_full_qualified_name(node) == 'module1.Class.func' -def test_parse_annotation(): - doctree = _parse_annotation("int") +def test_parse_annotation(app): + doctree = _parse_annotation("int", app.env) assert_node(doctree, ([pending_xref, "int"],)) assert_node(doctree[0], pending_xref, refdomain="py", reftype="class", reftarget="int") - doctree = _parse_annotation("List[int]") + doctree = _parse_annotation("List[int]", app.env) assert_node(doctree, ([pending_xref, "List"], [desc_sig_punctuation, "["], [pending_xref, "int"], [desc_sig_punctuation, "]"])) - doctree = _parse_annotation("Tuple[int, int]") + doctree = _parse_annotation("Tuple[int, int]", app.env) assert_node(doctree, ([pending_xref, "Tuple"], [desc_sig_punctuation, "["], [pending_xref, "int"], @@ -257,14 +257,14 @@ def test_parse_annotation(): [pending_xref, "int"], [desc_sig_punctuation, "]"])) - doctree = _parse_annotation("Tuple[()]") + doctree = _parse_annotation("Tuple[()]", app.env) assert_node(doctree, ([pending_xref, "Tuple"], [desc_sig_punctuation, "["], [desc_sig_punctuation, "("], [desc_sig_punctuation, ")"], [desc_sig_punctuation, "]"])) - doctree = _parse_annotation("Callable[[int, int], int]") + doctree = _parse_annotation("Callable[[int, int], int]", app.env) assert_node(doctree, ([pending_xref, "Callable"], [desc_sig_punctuation, "["], [desc_sig_punctuation, "["], @@ -277,12 +277,11 @@ def test_parse_annotation(): [desc_sig_punctuation, "]"])) # None type makes an object-reference (not a class reference) - doctree = _parse_annotation("None") + doctree = _parse_annotation("None", app.env) assert_node(doctree, ([pending_xref, "None"],)) assert_node(doctree[0], pending_xref, refdomain="py", reftype="obj", reftarget="None") - def test_pyfunction_signature(app): text = ".. py:function:: hello(name: str) -> str" doctree = restructuredtext.parse(app, text) @@ -460,14 +459,22 @@ def test_pyobject_prefix(app): def test_pydata(app): - text = ".. py:data:: var\n" + text = (".. py:module:: example\n" + ".. py:data:: var\n" + " :type: int\n") domain = app.env.get_domain('py') doctree = restructuredtext.parse(app, text) - assert_node(doctree, (addnodes.index, - [desc, ([desc_signature, desc_name, "var"], + assert_node(doctree, (nodes.target, + addnodes.index, + addnodes.index, + [desc, ([desc_signature, ([desc_addname, "example."], + [desc_name, "var"], + [desc_annotation, (": ", + [pending_xref, "int"])])], [desc_content, ()])])) - assert 'var' in domain.objects - assert domain.objects['var'] == ('index', 'var', 'data', False) + assert_node(doctree[3][0][2][1], pending_xref, **{"py:module": "example"}) + assert 'example.var' in domain.objects + assert domain.objects['example.var'] == ('index', 'example.var', 'data', False) def test_pyfunction(app): @@ -700,6 +707,8 @@ def test_pyattribute(app): [desc_sig_punctuation, "]"])], [desc_annotation, " = ''"])], [desc_content, ()])) + assert_node(doctree[1][1][1][0][1][1], pending_xref, **{"py:class": "Class"}) + assert_node(doctree[1][1][1][0][1][3], pending_xref, **{"py:class": "Class"}) assert 'Class.attr' in domain.objects assert domain.objects['Class.attr'] == ('index', 'Class.attr', 'attribute', False) |