mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add testcase for sphinx.domains.python
This commit is contained in:
parent
98e476779c
commit
8980f637c9
@ -14,7 +14,12 @@ import pytest
|
||||
from docutils import nodes
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.addnodes import (
|
||||
desc, desc_addname, desc_annotation, desc_content, desc_name, desc_optional,
|
||||
desc_parameter, desc_parameterlist, desc_returns, desc_signature
|
||||
)
|
||||
from sphinx.domains.python import py_sig_re, _pseudo_parse_arglist, PythonDomain
|
||||
from sphinx.testing import restructuredtext
|
||||
from sphinx.testing.util import assert_node
|
||||
|
||||
|
||||
@ -203,3 +208,68 @@ def test_get_full_qualified_name():
|
||||
kwargs = {'py:module': 'module1', 'py:class': 'Class'}
|
||||
node = nodes.reference(reftarget='func', **kwargs)
|
||||
assert domain.get_full_qualified_name(node) == 'module1.Class.func'
|
||||
|
||||
|
||||
def test_pyfunction_signature(app):
|
||||
text = ".. py:function:: hello(name: str) -> str"
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (addnodes.index,
|
||||
[desc, ([desc_signature, ([desc_name, "hello"],
|
||||
desc_parameterlist,
|
||||
[desc_returns, "str"])],
|
||||
desc_content)]))
|
||||
assert_node(doctree[1], addnodes.desc, desctype="function",
|
||||
domain="py", objtype="function", noindex=False)
|
||||
assert_node(doctree[1][0][1], [desc_parameterlist, desc_parameter, "name: str"])
|
||||
|
||||
|
||||
def test_optional_pyfunction_signature(app):
|
||||
text = ".. py:function:: compile(source [, filename [, symbol]]) -> ast object"
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (addnodes.index,
|
||||
[desc, ([desc_signature, ([desc_name, "compile"],
|
||||
desc_parameterlist,
|
||||
[desc_returns, "ast object"])],
|
||||
desc_content)]))
|
||||
assert_node(doctree[1], addnodes.desc, desctype="function",
|
||||
domain="py", objtype="function", noindex=False)
|
||||
assert_node(doctree[1][0][1],
|
||||
([desc_parameter, "source"],
|
||||
[desc_optional, ([desc_parameter, "filename"],
|
||||
[desc_optional, desc_parameter, "symbol"])]))
|
||||
|
||||
|
||||
def test_pyexception_signature(app):
|
||||
text = ".. py:exception:: exceptions.IOError"
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (addnodes.index,
|
||||
[desc, ([desc_signature, ([desc_annotation, "exception "],
|
||||
[desc_addname, "exceptions."],
|
||||
[desc_name, "IOError"])],
|
||||
desc_content)]))
|
||||
assert_node(doctree[1], desc, desctype="exception",
|
||||
domain="py", objtype="exception", noindex=False)
|
||||
|
||||
|
||||
def test_exceptions_module_is_ignored(app):
|
||||
text = (".. py:exception:: IOError\n"
|
||||
" :module: exceptions\n")
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (addnodes.index,
|
||||
[desc, ([desc_signature, ([desc_annotation, "exception "],
|
||||
[desc_name, "IOError"])],
|
||||
desc_content)]))
|
||||
assert_node(doctree[1], desc, desctype="exception",
|
||||
domain="py", objtype="exception", noindex=False)
|
||||
|
||||
|
||||
def test_pydata_signature(app):
|
||||
text = (".. py:data:: version\n"
|
||||
" :annotation: = 1\n")
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (addnodes.index,
|
||||
[desc, ([desc_signature, ([desc_name, "version"],
|
||||
[desc_annotation, " = 1"])],
|
||||
desc_content)]))
|
||||
assert_node(doctree[1], addnodes.desc, desctype="data",
|
||||
domain="py", objtype="data", noindex=False)
|
||||
|
Loading…
Reference in New Issue
Block a user