summaryrefslogtreecommitdiff
path: root/tests/test_domain_py.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-01-30 13:09:10 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-01 12:58:27 +0900
commit179a1f9cc2832f2abc24c0e574f86f4aa6e7e632 (patch)
tree63e04b2c29ced61f2afd2b0d8a002423b7912780 /tests/test_domain_py.py
parenta0a4eaad4e717094532e2567bf04cdbd6be8034f (diff)
downloadsphinx-git-179a1f9cc2832f2abc24c0e574f86f4aa6e7e632.tar.gz
py domain: Support type annotations for variables
This adds ``:type:`` and ``:value:`` options to both ``py:data`` and ``py:attribute`` directives. It allows to describe its annotation in detail.
Diffstat (limited to 'tests/test_domain_py.py')
-rw-r--r--tests/test_domain_py.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py
index 3ff29cbb7..ec7b56f57 100644
--- a/tests/test_domain_py.py
+++ b/tests/test_domain_py.py
@@ -268,6 +268,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 +477,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 +489,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')