diff options
Diffstat (limited to 'tests/test_domains/test_domain_py.py')
-rw-r--r-- | tests/test_domains/test_domain_py.py | 80 |
1 files changed, 63 insertions, 17 deletions
diff --git a/tests/test_domains/test_domain_py.py b/tests/test_domains/test_domain_py.py index e653c80..ce3d444 100644 --- a/tests/test_domains/test_domain_py.py +++ b/tests/test_domains/test_domain_py.py @@ -92,19 +92,21 @@ def test_domain_py_xrefs(app, status, warning): refnodes = list(doctree.findall(pending_xref)) assert_refnode(refnodes[0], None, None, 'TopLevel', 'class') assert_refnode(refnodes[1], None, None, 'top_level', 'meth') - assert_refnode(refnodes[2], None, 'NestedParentA', 'child_1', 'meth') - assert_refnode(refnodes[3], None, 'NestedParentA', 'NestedChildA.subchild_2', 'meth') - assert_refnode(refnodes[4], None, 'NestedParentA', 'child_2', 'meth') - assert_refnode(refnodes[5], False, 'NestedParentA', 'any_child', domain='') - assert_refnode(refnodes[6], None, 'NestedParentA', 'NestedChildA', 'class') - assert_refnode(refnodes[7], None, 'NestedParentA.NestedChildA', 'subchild_2', 'meth') - assert_refnode(refnodes[8], None, 'NestedParentA.NestedChildA', + assert_refnode(refnodes[2], None, None, 'TopLevelType', 'type') + assert_refnode(refnodes[3], None, 'NestedParentA', 'child_1', 'meth') + assert_refnode(refnodes[4], None, 'NestedParentA', 'NestedChildA.subchild_2', 'meth') + assert_refnode(refnodes[5], None, 'NestedParentA', 'child_2', 'meth') + assert_refnode(refnodes[6], False, 'NestedParentA', 'any_child', domain='') + assert_refnode(refnodes[7], None, 'NestedParentA', 'NestedChildA', 'class') + assert_refnode(refnodes[8], None, 'NestedParentA.NestedChildA', 'subchild_2', 'meth') + assert_refnode(refnodes[9], None, 'NestedParentA.NestedChildA', 'NestedParentA.child_1', 'meth') - assert_refnode(refnodes[9], None, 'NestedParentA', 'NestedChildA.subchild_1', 'meth') - assert_refnode(refnodes[10], None, 'NestedParentB', 'child_1', 'meth') - assert_refnode(refnodes[11], None, 'NestedParentB', 'NestedParentB', 'class') - assert_refnode(refnodes[12], None, None, 'NestedParentA.NestedChildA', 'class') - assert len(refnodes) == 13 + assert_refnode(refnodes[10], None, 'NestedParentA', 'NestedChildA.subchild_1', 'meth') + assert_refnode(refnodes[11], None, 'NestedParentB', 'child_1', 'meth') + assert_refnode(refnodes[12], None, 'NestedParentB', 'NestedParentB', 'class') + assert_refnode(refnodes[13], None, None, 'NestedParentA.NestedChildA', 'class') + assert_refnode(refnodes[14], None, None, 'NestedParentA.NestedTypeA', 'type') + assert len(refnodes) == 15 doctree = app.env.get_doctree('module') refnodes = list(doctree.findall(pending_xref)) @@ -135,7 +137,10 @@ def test_domain_py_xrefs(app, status, warning): assert_refnode(refnodes[15], False, False, 'index', 'doc', domain='std') assert_refnode(refnodes[16], False, False, 'typing.Literal', 'obj', domain='py') assert_refnode(refnodes[17], False, False, 'typing.Literal', 'obj', domain='py') - assert len(refnodes) == 18 + assert_refnode(refnodes[18], False, False, 'list', 'class', domain='py') + assert_refnode(refnodes[19], False, False, 'int', 'class', domain='py') + assert_refnode(refnodes[20], False, False, 'str', 'class', domain='py') + assert len(refnodes) == 21 doctree = app.env.get_doctree('module_option') refnodes = list(doctree.findall(pending_xref)) @@ -191,7 +196,9 @@ def test_domain_py_objects(app, status, warning): assert objects['TopLevel'][2] == 'class' assert objects['top_level'][2] == 'method' + assert objects['TopLevelType'][2] == 'type' assert objects['NestedParentA'][2] == 'class' + assert objects['NestedParentA.NestedTypeA'][2] == 'type' assert objects['NestedParentA.child_1'][2] == 'method' assert objects['NestedParentA.any_child'][2] == 'method' assert objects['NestedParentA.NestedChildA'][2] == 'class' @@ -233,6 +240,9 @@ def test_domain_py_find_obj(app, status, warning): assert (find_obj(None, None, 'NONEXISTANT', 'class') == []) assert (find_obj(None, None, 'NestedParentA', 'class') == [('NestedParentA', ('roles', 'NestedParentA', 'class', False))]) + assert (find_obj(None, None, 'NestedParentA.NestedTypeA', 'type') == + [('NestedParentA.NestedTypeA', + ('roles', 'NestedParentA.NestedTypeA', 'type', False))]) assert (find_obj(None, None, 'NestedParentA.NestedChildA', 'class') == [('NestedParentA.NestedChildA', ('roles', 'NestedParentA.NestedChildA', 'class', False))]) @@ -360,6 +370,27 @@ def test_parse_annotation(app): [desc_sig_punctuation, "]"])) assert_node(doctree[0], pending_xref, refdomain="py", reftype="obj", reftarget="typing.Literal") + # Annotated type with callable gets parsed + doctree = _parse_annotation("Annotated[Optional[str], annotated_types.MaxLen(max_length=10)]", app.env) + assert_node(doctree, ( + [pending_xref, 'Annotated'], + [desc_sig_punctuation, '['], + [pending_xref, 'str'], + [desc_sig_space, ' '], + [desc_sig_punctuation, '|'], + [desc_sig_space, ' '], + [pending_xref, 'None'], + [desc_sig_punctuation, ','], + [desc_sig_space, ' '], + [pending_xref, 'annotated_types.MaxLen'], + [desc_sig_punctuation, '('], + [desc_sig_name, 'max_length'], + [desc_sig_operator, '='], + [desc_sig_literal_number, '10'], + [desc_sig_punctuation, ')'], + [desc_sig_punctuation, ']'], + )) + def test_parse_annotation_suppress(app): doctree = _parse_annotation("~typing.Dict[str, str]", app.env) @@ -743,7 +774,7 @@ def test_function_pep_695(app): S,\ T: int,\ U: (int, str),\ - R: int | int,\ + R: int | str,\ A: int | Annotated[int, ctype("char")],\ *V,\ **P\ @@ -785,14 +816,29 @@ def test_function_pep_695(app): desc_sig_space, [desc_sig_punctuation, '|'], desc_sig_space, - [pending_xref, 'int'], + [pending_xref, 'str'], )], )], [desc_type_parameter, ( [desc_sig_name, 'A'], [desc_sig_punctuation, ':'], desc_sig_space, - [desc_sig_name, ([pending_xref, 'int | Annotated[int, ctype("char")]'])], + [desc_sig_name, ( + [pending_xref, 'int'], + [desc_sig_space, ' '], + [desc_sig_punctuation, '|'], + [desc_sig_space, ' '], + [pending_xref, 'Annotated'], + [desc_sig_punctuation, '['], + [pending_xref, 'int'], + [desc_sig_punctuation, ','], + [desc_sig_space, ' '], + [pending_xref, 'ctype'], + [desc_sig_punctuation, '('], + [desc_sig_literal_string, "'char'"], + [desc_sig_punctuation, ')'], + [desc_sig_punctuation, ']'], + )], )], [desc_type_parameter, ( [desc_sig_operator, '*'], @@ -977,7 +1023,7 @@ def test_class_def_pep_696(app): ('[T:(*Ts)|int]', '[T: (*Ts) | int]'), ('[T:(int|(*Ts))]', '[T: (int | (*Ts))]'), ('[T:((*Ts)|int)]', '[T: ((*Ts) | int)]'), - ('[T:Annotated[int,ctype("char")]]', '[T: Annotated[int, ctype("char")]]'), + ("[T:Annotated[int,ctype('char')]]", "[T: Annotated[int, ctype('char')]]"), ]) def test_pep_695_and_pep_696_whitespaces_in_bound(app, tp_list, tptext): text = f'.. py:function:: f{tp_list}()' |