One of side effects of 15b369028f was that
the default values were only included in Python doc strings if we could
be sure that they could be interpreted as valid Python expressions, but
this change was actually undesirable as it may be useful to see C++
expression for the default value in the doc string even when it isn't
valid in Python.
Undo this part of the change and extend autodoc unit test to check that
this stays fixed.
Closes #1271.
211 lines
6.7 KiB
Python
211 lines
6.7 KiB
Python
from autodoc import *
|
|
import comment_verifier
|
|
import inspect
|
|
import sys
|
|
|
|
def check(got, expected, expected_builtin=None, skip=False):
|
|
if not skip:
|
|
expect = expected
|
|
if is_python_builtin() and expected_builtin != None:
|
|
expect = expected_builtin
|
|
comment_verifier.check(got, expect)
|
|
|
|
def is_fastproxy():
|
|
fastproxy = True
|
|
try:
|
|
from autodoc import _swig_new_instance_method
|
|
except ImportError:
|
|
fastproxy = False
|
|
return fastproxy
|
|
|
|
if is_fastproxy():
|
|
# Detect when -fastproxy is specified and skip test as it changes the function names making it
|
|
# hard to test... skip until the number of options are reduced in SWIG-3.1 and autodoc is improved
|
|
sys.exit(0)
|
|
|
|
# skip builtin check - the autodoc is missing, but it probably should not be
|
|
skip = True
|
|
|
|
check(inspect.getdoc(A), "Proxy of C++ A class.", "::A")
|
|
check(inspect.getdoc(A.funk), "just a string.")
|
|
check(inspect.getdoc(A.func0),
|
|
"func0(self, arg2, hello) -> int")
|
|
check(inspect.getdoc(A.func1),
|
|
"func1(A self, short arg2, Tuple hello) -> int")
|
|
check(inspect.getdoc(A.func2),
|
|
"func2(self, arg2, hello) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"arg2: short\n"
|
|
"hello: int tuple[2]")
|
|
check(inspect.getdoc(A.func3),
|
|
"func3(A self, short arg2, Tuple hello) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"arg2: short\n"
|
|
"hello: int tuple[2]")
|
|
|
|
check(inspect.getdoc(A.func0default),
|
|
"func0default(self, e, arg3, hello, f=2) -> int\n"
|
|
"func0default(self, e, arg3, hello) -> int")
|
|
check(inspect.getdoc(A.func1default),
|
|
"func1default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
|
|
"func1default(A self, A e, short arg3, Tuple hello) -> int")
|
|
check(inspect.getdoc(A.func2default),
|
|
"func2default(self, e, arg3, hello, f=2) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"e: A *\n"
|
|
"arg3: short\n"
|
|
"hello: int tuple[2]\n"
|
|
"f: double\n"
|
|
"\n"
|
|
"func2default(self, e, arg3, hello) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"e: A *\n"
|
|
"arg3: short\n"
|
|
"hello: int tuple[2]")
|
|
check(inspect.getdoc(A.func3default),
|
|
"func3default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"e: A *\n"
|
|
"arg3: short\n"
|
|
"hello: int tuple[2]\n"
|
|
"f: double\n"
|
|
"\n"
|
|
"func3default(A self, A e, short arg3, Tuple hello) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"e: A *\n"
|
|
"arg3: short\n"
|
|
"hello: int tuple[2]")
|
|
|
|
check(inspect.getdoc(A.func0static),
|
|
"func0static(e, arg2, hello, f=2) -> int\n"
|
|
"func0static(e, arg2, hello) -> int")
|
|
check(inspect.getdoc(A.func1static),
|
|
"func1static(A e, short arg2, Tuple hello, double f=2) -> int\n"
|
|
"func1static(A e, short arg2, Tuple hello) -> int")
|
|
check(inspect.getdoc(A.func2static),
|
|
"func2static(e, arg2, hello, f=2) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"e: A *\n"
|
|
"arg2: short\n"
|
|
"hello: int tuple[2]\n"
|
|
"f: double\n"
|
|
"\n"
|
|
"func2static(e, arg2, hello) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"e: A *\n"
|
|
"arg2: short\n"
|
|
"hello: int tuple[2]")
|
|
check(inspect.getdoc(A.func3static),
|
|
"func3static(A e, short arg2, Tuple hello, double f=2) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"e: A *\n"
|
|
"arg2: short\n"
|
|
"hello: int tuple[2]\n"
|
|
"f: double\n"
|
|
"\n"
|
|
"func3static(A e, short arg2, Tuple hello) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"e: A *\n"
|
|
"arg2: short\n"
|
|
"hello: int tuple[2]")
|
|
|
|
if sys.version_info[0:2] > (2, 4):
|
|
# Python 2.4 does not seem to work
|
|
check(inspect.getdoc(A.variable_a),
|
|
"A_variable_a_get(self) -> int",
|
|
"A.variable_a"
|
|
)
|
|
check(inspect.getdoc(A.variable_b),
|
|
"A_variable_b_get(A self) -> int",
|
|
"A.variable_b"
|
|
)
|
|
check(inspect.getdoc(A.variable_c),
|
|
"A_variable_c_get(self) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"self: A *",
|
|
"A.variable_c"
|
|
)
|
|
check(inspect.getdoc(A.variable_d),
|
|
"A_variable_d_get(A self) -> int\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"self: A *",
|
|
"A.variable_d"
|
|
)
|
|
|
|
check(inspect.getdoc(B),
|
|
"Proxy of C++ B class.",
|
|
"::B"
|
|
)
|
|
check(inspect.getdoc(C.__init__), "__init__(self, a, b, h) -> C", None, skip)
|
|
check(inspect.getdoc(D.__init__),
|
|
"__init__(D self, int a, int b, Hola h) -> D", None, skip)
|
|
check(inspect.getdoc(E.__init__),
|
|
"__init__(self, a, b, h) -> E\n"
|
|
"\n"
|
|
"__init__(self, a, b, h) -> E\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"a: special comment for parameter a\n"
|
|
"b: another special comment for parameter b\n"
|
|
"h: enum Hola", None, skip
|
|
)
|
|
check(inspect.getdoc(F.__init__),
|
|
"__init__(F self, int a, int b, Hola h) -> F\n"
|
|
"\n"
|
|
"__init__(F self, int a, int b, Hola h) -> F\n"
|
|
"\n"
|
|
"Parameters\n"
|
|
"----------\n"
|
|
"a: special comment for parameter a\n"
|
|
"b: another special comment for parameter b\n"
|
|
"h: enum Hola", None, skip
|
|
)
|
|
|
|
check(inspect.getdoc(B.funk),
|
|
"funk(B self, int c, int d) -> int")
|
|
check(inspect.getdoc(funk), "funk(A e, short arg2, int c, int d) -> int")
|
|
check(inspect.getdoc(funkdefaults),
|
|
"funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n"
|
|
"funkdefaults(A e, short arg2, int c, int d) -> int")
|
|
|
|
check(inspect.getdoc(func_input), "func_input(int * INPUT) -> int")
|
|
check(inspect.getdoc(func_output), "func_output() -> int")
|
|
check(inspect.getdoc(func_inout), "func_inout(int * INOUT) -> int")
|
|
check(inspect.getdoc(func_cb), "func_cb(int c, int d) -> int")
|
|
check(inspect.getdoc(banana), "banana(S a, S b, int c, Integer d)")
|
|
|
|
check(inspect.getdoc(TInteger), "Proxy of C++ T< int > class.", "::T< int >")
|
|
check(inspect.getdoc(TInteger.__init__), "__init__(TInteger self) -> TInteger", None, skip)
|
|
check(inspect.getdoc(TInteger.inout), "inout(TInteger self, TInteger t) -> TInteger")
|
|
|
|
check(inspect.getdoc(process), "process(int _from, int _in, int var) -> int")
|
|
check(inspect.getdoc(process2), "process2(int _from=0, int _in=1, int var=2) -> int")
|
|
check(inspect.getdoc(process3), "process3(int _from, int _in, int var) -> int")
|
|
check(inspect.getdoc(process4), "process4(int _from=0, int _in=1, int var=2) -> int")
|
|
|
|
check(inspect.getdoc(process_complex_defval), "process_complex_defval(val=PROCESS_DEFAULT_VALUE, factor=some_type(-1)) -> int")
|