diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-04-13 19:46:34 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-13 19:46:34 +0900 |
commit | a337cb793cf067a94f498b8842d7bc3ad96a87b2 (patch) | |
tree | 99e2eda2d64314859f30db18ff5cf6db9ee9abbd /tests/test_domain_py.py | |
parent | 817cb6e96b60b9daf2a28f57f2e9d926ade9a29b (diff) | |
parent | b0b3f5a677162f97f7e0fb62428fa09468b0f23c (diff) | |
download | sphinx-git-a337cb793cf067a94f498b8842d7bc3ad96a87b2.tar.gz |
Merge pull request #6268 from tk0miya/refactor_py_domain
Refactoring python domain: Add new description classes for methods and attributes
Diffstat (limited to 'tests/test_domain_py.py')
-rw-r--r-- | tests/test_domain_py.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index fb6e70914..afc34a697 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -290,3 +290,85 @@ def test_pyobject_prefix(app): desc)])])) assert doctree[1][1][1].astext().strip() == 'say' # prefix is stripped assert doctree[1][1][3].astext().strip() == 'FooBar.say' # not stripped + + +def test_pymethod(app): + text = (".. py:class:: Class\n" + "\n" + " .. py:method:: meth\n") + domain = app.env.get_domain('py') + doctree = restructuredtext.parse(app, text) + assert_node(doctree, (addnodes.index, + [desc, ([desc_signature, ([desc_annotation, "class "], + [desc_name, "Class"])], + [desc_content, (addnodes.index, + desc)])])) + + assert_node(doctree[1][1][0], addnodes.index, + entries=[('single', 'meth() (Class method)', 'Class.meth', '', None)]) + assert_node(doctree[1][1][1], ([desc_signature, ([desc_name, "meth"], + [desc_parameterlist, ()])], + [desc_content, ()])) + assert 'Class.meth' in domain.objects + assert domain.objects['Class.meth'] == ('index', 'method') + + +def test_pyclassmethod(app): + text = (".. py:class:: Class\n" + "\n" + " .. py:classmethod:: meth\n") + domain = app.env.get_domain('py') + doctree = restructuredtext.parse(app, text) + assert_node(doctree, (addnodes.index, + [desc, ([desc_signature, ([desc_annotation, "class "], + [desc_name, "Class"])], + [desc_content, (addnodes.index, + desc)])])) + assert_node(doctree[1][1][0], addnodes.index, + entries=[('single', 'meth() (Class class method)', 'Class.meth', '', None)]) + assert_node(doctree[1][1][1], ([desc_signature, ([desc_annotation, "classmethod "], + [desc_name, "meth"], + [desc_parameterlist, ()])], + [desc_content, ()])) + assert 'Class.meth' in domain.objects + assert domain.objects['Class.meth'] == ('index', 'classmethod') + + +def test_pystaticmethod(app): + text = (".. py:class:: Class\n" + "\n" + " .. py:staticmethod:: meth\n") + domain = app.env.get_domain('py') + doctree = restructuredtext.parse(app, text) + assert_node(doctree, (addnodes.index, + [desc, ([desc_signature, ([desc_annotation, "class "], + [desc_name, "Class"])], + [desc_content, (addnodes.index, + desc)])])) + assert_node(doctree[1][1][0], addnodes.index, + entries=[('single', 'meth() (Class static method)', 'Class.meth', '', None)]) + assert_node(doctree[1][1][1], ([desc_signature, ([desc_annotation, "static "], + [desc_name, "meth"], + [desc_parameterlist, ()])], + [desc_content, ()])) + assert 'Class.meth' in domain.objects + assert domain.objects['Class.meth'] == ('index', 'staticmethod') + + +def test_pyattribute(app): + text = (".. py:class:: Class\n" + "\n" + " .. py:attribute:: attr\n") + domain = app.env.get_domain('py') + doctree = restructuredtext.parse(app, text) + assert_node(doctree, (addnodes.index, + [desc, ([desc_signature, ([desc_annotation, "class "], + [desc_name, "Class"])], + [desc_content, (addnodes.index, + 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"], + [desc_content, ()])) + assert 'Class.attr' in domain.objects + assert domain.objects['Class.attr'] == ('index', 'attribute') |