sphinx/tests/test_domain_py.py

47 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
"""
test_domain_py
~~~~~~~~~~~~~~
Tests the Python Domain
2015-01-03 14:36:32 -06:00
:copyright: Copyright 2007-2015 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
2014-07-12 21:43:12 -05:00
from six import text_type
from sphinx import addnodes
from sphinx.domains.python import py_sig_re, _pseudo_parse_arglist
def parse(sig):
m = py_sig_re.match(sig)
if m is None:
raise ValueError
name_prefix, name, arglist, retann = m.groups()
signode = addnodes.desc_signature(sig, '')
_pseudo_parse_arglist(signode, arglist)
return signode.astext()
def test_function_signatures():
rv = parse('func(a=1) -> int object')
2014-07-12 21:43:12 -05:00
assert text_type(rv) == u'a=1'
rv = parse('func(a=1, [b=None])')
2014-07-12 21:43:12 -05:00
assert text_type(rv) == u'a=1, [b=None]'
rv = parse('func(a=1[, b=None])')
2014-07-12 21:43:12 -05:00
assert text_type(rv) == u'a=1, [b=None]'
rv = parse("compile(source : string, filename, symbol='file')")
2014-07-12 21:43:12 -05:00
assert text_type(rv) == u"source : string, filename, symbol='file'"
rv = parse('func(a=[], [b=None])')
2014-07-12 21:43:12 -05:00
assert text_type(rv) == u'a=[], [b=None]'
rv = parse('func(a=[][, b=None])')
2014-07-12 21:43:12 -05:00
assert text_type(rv) == u'a=[], [b=None]'