From 4410668776a364bfbcc17159e37d252a3d48f499 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 9 Jul 2020 01:49:34 +0900 Subject: Fix #7928: py domain: failed to resolve a type annotation for the attribute --- tests/test_domain_py.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'tests/test_domain_py.py') diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index 61cc5145b..ccf539b6d 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -236,18 +236,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"], @@ -255,14 +255,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, "["], @@ -275,12 +275,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) @@ -458,14 +457,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') + 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') def test_pyfunction(app): @@ -698,6 +705,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') -- cgit v1.2.1