diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/roots/test-domain-py/module.rst | 6 | ||||
-rw-r--r-- | tests/roots/test-ext-autodoc/target/typed_vars.py | 9 | ||||
-rw-r--r-- | tests/test_autodoc.py | 78 | ||||
-rw-r--r-- | tests/test_directive_other.py | 17 | ||||
-rw-r--r-- | tests/test_domain_py.py | 62 | ||||
-rw-r--r-- | tests/test_environment_toctree.py | 6 | ||||
-rw-r--r-- | tests/test_pycode_parser.py | 11 |
7 files changed, 143 insertions, 46 deletions
diff --git a/tests/roots/test-domain-py/module.rst b/tests/roots/test-domain-py/module.rst index 64601bc95..c01032b26 100644 --- a/tests/roots/test-domain-py/module.rst +++ b/tests/roots/test-domain-py/module.rst @@ -18,6 +18,12 @@ module * Link to :py:meth:`module_a.submodule.ModTopLevel.mod_child_1` +.. py:method:: ModTopLevel.prop + :property: + + * Link to :py:attr:`prop attribute <.prop>` + * Link to :py:meth:`prop method <.prop>` + .. py:currentmodule:: None .. py:class:: ModNoModule diff --git a/tests/roots/test-ext-autodoc/target/typed_vars.py b/tests/roots/test-ext-autodoc/target/typed_vars.py index 4a9a6f7b5..b0782787e 100644 --- a/tests/roots/test-ext-autodoc/target/typed_vars.py +++ b/tests/roots/test-ext-autodoc/target/typed_vars.py @@ -2,12 +2,17 @@ attr1: str = '' #: attr2 attr2: str +#: attr3 +attr3 = '' # type: str class Class: attr1: int = 0 attr2: int + attr3 = 0 # type: int def __init__(self): - self.attr3: int = 0 #: attr3 - self.attr4: int #: attr4 + self.attr4: int = 0 #: attr4 + self.attr5: int #: attr5 + self.attr6 = 0 # type: int + """attr6""" diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index 6fb4db6ad..52e9bf5c5 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -930,7 +930,7 @@ def test_autodoc_module_scope(app): '', '.. py:attribute:: Class.mdocattr', ' :module: target', - ' :annotation: = <_io.StringIO object>', + ' :value: <_io.StringIO object>', '', ' should be documented as well - süß', ' ' @@ -946,7 +946,7 @@ def test_autodoc_class_scope(app): '', '.. py:attribute:: Class.mdocattr', ' :module: target', - ' :annotation: = <_io.StringIO object>', + ' :value: <_io.StringIO object>', '', ' should be documented as well - süß', ' ' @@ -966,12 +966,12 @@ def test_class_attributes(app): ' ', ' .. py:attribute:: AttCls.a1', ' :module: target', - ' :annotation: = hello world', + ' :value: hello world', ' ', ' ', ' .. py:attribute:: AttCls.a2', ' :module: target', - ' :annotation: = None', + ' :value: None', ' ' ] @@ -990,7 +990,7 @@ def test_instance_attributes(app): ' ', ' .. py:attribute:: InstAttCls.ca1', ' :module: target', - " :annotation: = 'a'", + " :value: 'a'", ' ', ' Doc comment for class attribute InstAttCls.ca1.', ' It can have multiple lines.', @@ -998,28 +998,28 @@ def test_instance_attributes(app): ' ', ' .. py:attribute:: InstAttCls.ca2', ' :module: target', - " :annotation: = 'b'", + " :value: 'b'", ' ', ' Doc comment for InstAttCls.ca2. One line only.', ' ', ' ', ' .. py:attribute:: InstAttCls.ca3', ' :module: target', - " :annotation: = 'c'", + " :value: 'c'", ' ', ' Docstring for class attribute InstAttCls.ca3.', ' ', ' ', ' .. py:attribute:: InstAttCls.ia1', ' :module: target', - ' :annotation: = None', + ' :value: None', ' ', ' Doc comment for instance attribute InstAttCls.ia1', ' ', ' ', ' .. py:attribute:: InstAttCls.ia2', ' :module: target', - ' :annotation: = None', + ' :value: None', ' ', ' Docstring for instance attribute InstAttCls.ia2.', ' ' @@ -1038,7 +1038,7 @@ def test_instance_attributes(app): ' ', ' .. py:attribute:: InstAttCls.ca1', ' :module: target', - " :annotation: = 'a'", + " :value: 'a'", ' ', ' Doc comment for class attribute InstAttCls.ca1.', ' It can have multiple lines.', @@ -1046,7 +1046,7 @@ def test_instance_attributes(app): ' ', ' .. py:attribute:: InstAttCls.ia1', ' :module: target', - ' :annotation: = None', + ' :value: None', ' ', ' Doc comment for instance attribute InstAttCls.ia1', ' ' @@ -1114,28 +1114,28 @@ def test_enum_class(app): ' ', ' .. py:attribute:: EnumCls.val1', ' :module: target.enum', - ' :annotation: = 12', + ' :value: 12', ' ', ' doc for val1', ' ', ' ', ' .. py:attribute:: EnumCls.val2', ' :module: target.enum', - ' :annotation: = 23', + ' :value: 23', ' ', ' doc for val2', ' ', ' ', ' .. py:attribute:: EnumCls.val3', ' :module: target.enum', - ' :annotation: = 34', + ' :value: 34', ' ', ' doc for val3', ' ', ' ', ' .. py:attribute:: EnumCls.val4', ' :module: target.enum', - ' :annotation: = 34', + ' :value: 34', ' ' ] @@ -1145,7 +1145,7 @@ def test_enum_class(app): '', '.. py:attribute:: EnumCls.val1', ' :module: target.enum', - ' :annotation: = 12', + ' :value: 12', '', ' doc for val1', ' ' @@ -1429,40 +1429,68 @@ def test_autodoc_typed_instance_variables(app): ' ', ' .. py:attribute:: Class.attr1', ' :module: target.typed_vars', - ' :annotation: = 0', + ' :type: int', + ' :value: 0', ' ', ' ', ' .. py:attribute:: Class.attr2', ' :module: target.typed_vars', - ' :annotation: = None', + ' :type: int', + ' :value: None', ' ', ' ', ' .. py:attribute:: Class.attr3', ' :module: target.typed_vars', - ' :annotation: = None', + ' :type: int', + ' :value: 0', ' ', - ' attr3', - ' ', ' ', ' .. py:attribute:: Class.attr4', ' :module: target.typed_vars', - ' :annotation: = None', + ' :type: int', + ' :value: None', ' ', ' attr4', ' ', + ' ', + ' .. py:attribute:: Class.attr5', + ' :module: target.typed_vars', + ' :type: int', + ' :value: None', + ' ', + ' attr5', + ' ', + ' ', + ' .. py:attribute:: Class.attr6', + ' :module: target.typed_vars', + ' :type: int', + ' :value: None', + ' ', + ' attr6', + ' ', '', '.. py:data:: attr1', ' :module: target.typed_vars', - " :annotation: = ''", + ' :type: str', + " :value: ''", '', ' attr1', ' ', '', '.. py:data:: attr2', ' :module: target.typed_vars', - " :annotation: = None", + ' :type: str', + ' :value: None', '', ' attr2', + ' ', + '', + '.. py:data:: attr3', + ' :module: target.typed_vars', + ' :type: str', + " :value: ''", + '', + ' attr3', ' ' ] @@ -1479,7 +1507,7 @@ def test_autodoc_for_egged_code(app): '', '.. py:data:: CONSTANT', ' :module: sample', - ' :annotation: = 1', + ' :value: 1', '', ' constant on sample.py', ' ', diff --git a/tests/test_directive_other.py b/tests/test_directive_other.py index bfdc1aac8..52e4a937c 100644 --- a/tests/test_directive_other.py +++ b/tests/test_directive_other.py @@ -127,6 +127,23 @@ def test_toctree_glob_and_url(app): @pytest.mark.sphinx(testroot='toctree-glob') +def test_reversed_toctree(app): + text = (".. toctree::\n" + " :reversed:\n" + "\n" + " foo\n" + " bar/index\n" + " baz\n") + + app.env.find_files(app.config, app.builder) + doctree = restructuredtext.parse(app, text, 'index') + assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree]) + assert_node(doctree[0][0], + entries=[(None, 'baz'), (None, 'bar/index'), (None, 'foo')], + includefiles=['baz', 'bar/index', 'foo']) + + +@pytest.mark.sphinx(testroot='toctree-glob') def test_toctree_twice(app): text = (".. toctree::\n" "\n" diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index 3ff29cbb7..f78c1e9d8 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -105,19 +105,22 @@ def test_domain_py_xrefs(app, status, warning): 'mod_child_2', 'meth') assert_refnode(refnodes[4], 'module_a.submodule', 'ModTopLevel', 'module_a.submodule.ModTopLevel.mod_child_1', 'meth') - assert_refnode(refnodes[5], 'module_b.submodule', None, + assert_refnode(refnodes[5], 'module_a.submodule', 'ModTopLevel', + 'prop', 'attr') + assert_refnode(refnodes[6], 'module_a.submodule', 'ModTopLevel', + 'prop', 'meth') + assert_refnode(refnodes[7], 'module_b.submodule', None, 'ModTopLevel', 'class') - assert_refnode(refnodes[6], 'module_b.submodule', 'ModTopLevel', + assert_refnode(refnodes[8], 'module_b.submodule', 'ModTopLevel', 'ModNoModule', 'class') - assert_refnode(refnodes[7], False, False, 'int', 'class') - assert_refnode(refnodes[8], False, False, 'tuple', 'class') - assert_refnode(refnodes[9], False, False, 'str', 'class') - assert_refnode(refnodes[10], False, False, 'float', 'class') - assert_refnode(refnodes[11], False, False, 'list', 'class') - assert_refnode(refnodes[11], False, False, 'list', 'class') - assert_refnode(refnodes[12], False, False, 'ModTopLevel', 'class') - assert_refnode(refnodes[13], False, False, 'index', 'doc', domain='std') - assert len(refnodes) == 14 + assert_refnode(refnodes[9], False, False, 'int', 'class') + assert_refnode(refnodes[10], False, False, 'tuple', 'class') + assert_refnode(refnodes[11], False, False, 'str', 'class') + assert_refnode(refnodes[12], False, False, 'float', 'class') + assert_refnode(refnodes[13], False, False, 'list', 'class') + assert_refnode(refnodes[14], False, False, 'ModTopLevel', 'class') + assert_refnode(refnodes[15], False, False, 'index', 'doc', domain='std') + assert len(refnodes) == 16 doctree = app.env.get_doctree('module_option') refnodes = list(doctree.traverse(addnodes.pending_xref)) @@ -161,6 +164,21 @@ def test_domain_py_objects(app, status, warning): assert objects['NestedParentB.child_1'] == ('roles', 'method') +@pytest.mark.sphinx('html', testroot='domain-py') +def test_resolve_xref_for_properties(app, status, warning): + app.builder.build_all() + + content = (app.outdir / 'module.html').text() + assert ('Link to <a class="reference internal" href="#module_a.submodule.ModTopLevel.prop"' + ' title="module_a.submodule.ModTopLevel.prop">' + '<code class="xref py py-attr docutils literal notranslate"><span class="pre">' + 'prop</span> <span class="pre">attribute</span></code></a>' in content) + assert ('Link to <a class="reference internal" href="#module_a.submodule.ModTopLevel.prop"' + ' title="module_a.submodule.ModTopLevel.prop">' + '<code class="xref py py-meth docutils literal notranslate"><span class="pre">' + 'prop</span> <span class="pre">method</span></code></a>' in content) + + @pytest.mark.sphinx('dummy', testroot='domain-py') def test_domain_py_find_obj(app, status, warning): @@ -268,6 +286,20 @@ def test_exceptions_module_is_ignored(app): def test_pydata_signature(app): text = (".. py:data:: version\n" + " :type: int\n" + " :value: 1\n") + doctree = restructuredtext.parse(app, text) + assert_node(doctree, (addnodes.index, + [desc, ([desc_signature, ([desc_name, "version"], + [desc_annotation, ": int"], + [desc_annotation, " = 1"])], + desc_content)])) + assert_node(doctree[1], addnodes.desc, desctype="data", + domain="py", objtype="data", noindex=False) + + +def test_pydata_signature_old(app): + text = (".. py:data:: version\n" " :annotation: = 1\n") doctree = restructuredtext.parse(app, text) assert_node(doctree, (addnodes.index, @@ -463,7 +495,9 @@ def test_pystaticmethod(app): def test_pyattribute(app): text = (".. py:class:: Class\n" "\n" - " .. py:attribute:: attr\n") + " .. py:attribute:: attr\n" + " :type: str\n" + " :value: ''\n") domain = app.env.get_domain('py') doctree = restructuredtext.parse(app, text) assert_node(doctree, (addnodes.index, @@ -473,7 +507,9 @@ def test_pyattribute(app): desc)])])) assert_node(doctree[1][1][0], addnodes.index, entries=[('single', 'attr (Class attribute)', 'Class.attr', '', None)]) - assert_node(doctree[1][1][1], ([desc_signature, desc_name, "attr"], + assert_node(doctree[1][1][1], ([desc_signature, ([desc_name, "attr"], + [desc_annotation, ": str"], + [desc_annotation, " = ''"])], [desc_content, ()])) assert 'Class.attr' in domain.objects assert domain.objects['Class.attr'] == ('index', 'attribute') diff --git a/tests/test_environment_toctree.py b/tests/test_environment_toctree.py index 6a23b384a..a8c7da62e 100644 --- a/tests/test_environment_toctree.py +++ b/tests/test_environment_toctree.py @@ -119,16 +119,14 @@ def test_glob(app): [bullet_list, addnodes.toctree])]) # [0][1][1][1][0] assert_node(toctree[0][1][1][1][0], addnodes.toctree, caption=None, glob=True, hidden=False, titlesonly=False, - maxdepth=-1, numbered=0, includefiles=includefiles, + maxdepth=-1, numbered=0, includefiles=list(reversed(includefiles)), entries=[(None, 'qux/index'), (None, 'baz'), (None, 'bar/bar_3'), (None, 'bar/bar_2'), (None, 'bar/bar_1'), (None, 'bar/index'), (None, 'foo')]) - includefiles = ['foo', 'bar/index', 'bar/bar_1', 'bar/bar_2', - 'bar/bar_3', 'baz', 'qux/index'] # other collections assert app.env.toc_num_entries['index'] == 3 - assert app.env.toctree_includes['index'] == includefiles + includefiles + assert app.env.toctree_includes['index'] == includefiles + list(reversed(includefiles)) for file in includefiles: assert 'index' in app.env.files_to_rebuild[file] assert 'index' in app.env.glob_toctrees diff --git a/tests/test_pycode_parser.py b/tests/test_pycode_parser.py index b8bece84e..0bf505a33 100644 --- a/tests/test_pycode_parser.py +++ b/tests/test_pycode_parser.py @@ -99,12 +99,19 @@ def test_annotated_assignment_py36(): source = ('a: str = "Sphinx" #: comment\n' 'b: int = 1\n' '"""string on next line"""\n' - 'c: int #: comment') + 'c: int #: comment\n' + 'd = 1 # type: int\n' + '"""string on next line"""\n') parser = Parser(source) parser.parse() assert parser.comments == {('', 'a'): 'comment', ('', 'b'): 'string on next line', - ('', 'c'): 'comment'} + ('', 'c'): 'comment', + ('', 'd'): 'string on next line'} + assert parser.annotations == {('', 'a'): 'str', + ('', 'b'): 'int', + ('', 'c'): 'int', + ('', 'd'): 'int'} assert parser.definitions == {} |