Fix autodoc strings generated in Python builtin case and the test.

Use the proper AUTODOC_METHOD for autodoc strings generation when using
"-builtin", there is no reason to use AUTODOC_FUNC here when AUTODOC_METHOD is
used by default (i.e. without "-builtin").

This allows to (almost) stop differentiating between the two cases in the
autodoc unit test, allowing to simplify it significantly.

Also fix this test to pass after the recent changes removing docstring
indentation in the generated code.
This commit is contained in:
Vadim Zeitlin 2014-12-15 20:27:46 +01:00
commit fd47e6870e
2 changed files with 58 additions and 199 deletions

View file

@ -1,51 +1,20 @@
from autodoc import * from autodoc import *
import commentVerifier from commentVerifier import check
import sys import sys
def check(got, expected, expected_builtin = None, skip = False): check(A.__doc__, "Proxy of C++ A class")
if not skip:
expect = expected
if is_python_builtin() and expected_builtin != None:
expect = expected_builtin
commentVerifier.check(got, expect)
skip = True # skip builtin check - the autodoc is missing, but it probably should not be
check(A.__doc__, "Proxy of C++ A class", "::A")
check(A.funk.__doc__, "just a string") check(A.funk.__doc__, "just a string")
check(A.func0.__doc__, check(A.func0.__doc__, "func0(self, arg2, hello) -> int")
"func0(self, arg2, hello) -> int", check(A.func1.__doc__, "func1(A self, short arg2, Tuple hello) -> int")
"func0(arg2, hello) -> int")
check(A.func1.__doc__,
"func1(A self, short arg2, Tuple hello) -> int",
"func1(short arg2, Tuple hello) -> int")
check(A.func2.__doc__, check(A.func2.__doc__,
"\n" "func2(self, arg2, hello) -> int\n"
" func2(self, arg2, hello) -> int\n"
"\n"
" Parameters:\n"
" arg2: short\n"
" hello: int tuple[2]\n"
"\n"
" "
,
"func2(arg2, hello) -> int\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
" arg2: short\n" " arg2: short\n"
" hello: int tuple[2]\n" " hello: int tuple[2]\n"
) )
check(A.func3.__doc__, check(A.func3.__doc__,
"\n" "func3(A self, short arg2, Tuple hello) -> int\n"
" func3(A self, short arg2, Tuple hello) -> int\n"
"\n"
" Parameters:\n"
" arg2: short\n"
" hello: int tuple[2]\n"
"\n"
" "
,
"func3(short arg2, Tuple hello) -> int\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
" arg2: short\n" " arg2: short\n"
@ -53,43 +22,15 @@ check(A.func3.__doc__,
) )
check(A.func0default.__doc__, check(A.func0default.__doc__,
"\n" "func0default(self, e, arg3, hello, f=2) -> int\n"
" func0default(self, e, arg3, hello, f=2) -> int\n" "func0default(self, e, arg3, hello) -> int"
" func0default(self, e, arg3, hello) -> int\n"
" "
,
"func0default(e, arg3, hello, f=2) -> int\n"
"func0default(e, arg3, hello) -> int"
) )
check(A.func1default.__doc__, check(A.func1default.__doc__,
"\n" "func1default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
" func1default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n" "func1default(A self, A e, short arg3, Tuple hello) -> int"
" func1default(A self, A e, short arg3, Tuple hello) -> int\n"
" "
,
"func1default(A e, short arg3, Tuple hello, double f=2) -> int\n"
"func1default(A e, short arg3, Tuple hello) -> int"
) )
check(A.func2default.__doc__, check(A.func2default.__doc__,
"\n" "func2default(self, e, arg3, hello, f=2) -> int\n"
" func2default(self, e, arg3, hello, f=2) -> int\n"
"\n"
" Parameters:\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"
" e: A *\n"
" arg3: short\n"
" hello: int tuple[2]\n"
"\n"
" "
,
"func2default(e, arg3, hello, f=2) -> int\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
" e: A *\n" " e: A *\n"
@ -97,7 +38,7 @@ check(A.func2default.__doc__,
" hello: int tuple[2]\n" " hello: int tuple[2]\n"
" f: double\n" " f: double\n"
"\n" "\n"
"func2default(e, arg3, hello) -> int\n" "func2default(self, e, arg3, hello) -> int\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
" e: A *\n" " e: A *\n"
@ -105,25 +46,7 @@ check(A.func2default.__doc__,
" hello: int tuple[2]\n" " hello: int tuple[2]\n"
) )
check(A.func3default.__doc__, check(A.func3default.__doc__,
"\n" "func3default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
" func3default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
"\n"
" Parameters:\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"
" e: A *\n"
" arg3: short\n"
" hello: int tuple[2]\n"
"\n"
" "
,
"func3default(A e, short arg3, Tuple hello, double f=2) -> int\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
" e: A *\n" " e: A *\n"
@ -131,7 +54,7 @@ check(A.func3default.__doc__,
" hello: int tuple[2]\n" " hello: int tuple[2]\n"
" f: double\n" " f: double\n"
"\n" "\n"
"func3default(A e, short arg3, Tuple hello) -> int\n" "func3default(A self, A e, short arg3, Tuple hello) -> int\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
" e: A *\n" " e: A *\n"
@ -140,42 +63,14 @@ check(A.func3default.__doc__,
) )
check(A.func0static.__doc__, check(A.func0static.__doc__,
"\n"
" func0static(e, arg2, hello, f=2) -> int\n"
" func0static(e, arg2, hello) -> int\n"
" "
,
"func0static(e, arg2, hello, f=2) -> int\n" "func0static(e, arg2, hello, f=2) -> int\n"
"func0static(e, arg2, hello) -> int" "func0static(e, arg2, hello) -> int"
) )
check(A.func1static.__doc__, check(A.func1static.__doc__,
"\n"
" func1static(A e, short arg2, Tuple hello, double f=2) -> int\n"
" func1static(A e, short arg2, Tuple hello) -> int\n"
" "
,
"func1static(A e, short arg2, Tuple hello, double f=2) -> int\n" "func1static(A e, short arg2, Tuple hello, double f=2) -> int\n"
"func1static(A e, short arg2, Tuple hello) -> int" "func1static(A e, short arg2, Tuple hello) -> int"
) )
check(A.func2static.__doc__, check(A.func2static.__doc__,
"\n"
" func2static(e, arg2, hello, f=2) -> int\n"
"\n"
" Parameters:\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"
" e: A *\n"
" arg2: short\n"
" hello: int tuple[2]\n"
"\n"
" "
,
"func2static(e, arg2, hello, f=2) -> int\n" "func2static(e, arg2, hello, f=2) -> int\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
@ -192,24 +87,6 @@ check(A.func2static.__doc__,
" hello: int tuple[2]\n" " hello: int tuple[2]\n"
) )
check(A.func3static.__doc__, check(A.func3static.__doc__,
"\n"
" func3static(A e, short arg2, Tuple hello, double f=2) -> int\n"
"\n"
" Parameters:\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"
" e: A *\n"
" arg2: short\n"
" hello: int tuple[2]\n"
"\n"
" "
,
"func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" "func3static(A e, short arg2, Tuple hello, double f=2) -> int\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
@ -228,77 +105,59 @@ check(A.func3static.__doc__,
if sys.version_info[0:2] > (2, 4): if sys.version_info[0:2] > (2, 4):
# Python 2.4 does not seem to work # Python 2.4 does not seem to work
check(A.variable_a.__doc__, if is_python_builtin():
"A_variable_a_get(self) -> int", check(A.variable_a.__doc__, "A.variable_a")
"A.variable_a" check(A.variable_b.__doc__, "A.variable_b")
) check(A.variable_c.__doc__, "A.variable_c")
check(A.variable_b.__doc__, check(A.variable_d.__doc__, "A.variable_d")
"A_variable_b_get(A self) -> int", else:
"A.variable_b" check(A.variable_a.__doc__, "A_variable_a_get(self) -> int"
) )
check(A.variable_c.__doc__, check(A.variable_b.__doc__, "A_variable_b_get(A self) -> int")
"A_variable_c_get(self) -> int\n" check(A.variable_c.__doc__,
"A_variable_c_get(self) -> int\n"
"\n"
"Parameters:\n"
" self: A *\n"
)
check(A.variable_d.__doc__,
"A_variable_d_get(A self) -> int\n"
"\n"
"Parameters:\n"
" self: A *\n"
)
check(B.__doc__, "Proxy of C++ B class")
# skip builtin check - the autodoc is missing, but it probably should not be
if not is_python_builtin():
check(C.__init__.__doc__, "__init__(self, a, b, h) -> C")
check(D.__init__.__doc__, "__init__(D self, int a, int b, Hola h) -> D")
check(E.__init__.__doc__,
"__init__(self, a, b, h) -> E\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
" self: A *\n" " a: special comment for parameter a\n"
, " b: another special comment for parameter b\n"
"A.variable_c" " h: enum Hola\n"
) )
check(A.variable_d.__doc__, check(F.__init__.__doc__,
"A_variable_d_get(A self) -> int\n" "__init__(F self, int a, int b, Hola h) -> F\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
" self: A *\n" " a: special comment for parameter a\n"
, " b: another special comment for parameter b\n"
"A.variable_d" " h: enum Hola\n"
) )
check(B.__doc__, check(B.funk.__doc__, "funk(B self, int c, int d) -> int")
"Proxy of C++ B class",
"::B"
)
check(C.__init__.__doc__, "__init__(self, a, b, h) -> C", None, skip)
check(D.__init__.__doc__, "__init__(D self, int a, int b, Hola h) -> D", None, skip)
check(E.__init__.__doc__,
"\n"
" __init__(self, a, b, h) -> E\n"
"\n"
" Parameters:\n"
" a: special comment for parameter a\n"
" b: another special comment for parameter b\n"
" h: enum Hola\n"
"\n"
" "
, None, skip
)
check(F.__init__.__doc__,
"\n"
" __init__(F self, int a, int b, Hola h) -> F\n"
"\n"
" Parameters:\n"
" a: special comment for parameter a\n"
" b: another special comment for parameter b\n"
" h: enum Hola\n"
"\n"
" "
, None, skip
)
check(B.funk.__doc__,
"funk(B self, int c, int d) -> int",
"funk(int c, int d) -> int")
check(funk.__doc__, "funk(A e, short arg2, int c, int d) -> int") check(funk.__doc__, "funk(A e, short arg2, int c, int d) -> int")
check(funkdefaults.__doc__, check(funkdefaults.__doc__,
"\n"
" funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n"
" funkdefaults(A e, short arg2, int c, int d) -> int\n"
" "
,
"funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n" "funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n"
"funkdefaults(A e, short arg2, int c, int d) -> int" "funkdefaults(A e, short arg2, int c, int d) -> int"
) )
commentVerifier.check(func_input.__doc__, "func_input(int * INPUT) -> int") check(func_input.__doc__, "func_input(int * INPUT) -> int")
commentVerifier.check(func_output.__doc__, "func_output() -> int") check(func_output.__doc__, "func_output() -> int")
commentVerifier.check(func_inout.__doc__, "func_inout(int * INOUT) -> int") check(func_inout.__doc__, "func_inout(int * INOUT) -> int")
commentVerifier.check(banana.__doc__, "banana(S a, S b, int c, Integer d)") check(banana.__doc__, "banana(S a, S b, int c, Integer d)")

View file

@ -4273,7 +4273,7 @@ public:
String *wname = Swig_name_wrapper(fullname); String *wname = Swig_name_wrapper(fullname);
Setattr(class_members, symname, n); Setattr(class_members, symname, n);
int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2; int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2;
String *ds = have_docstring(n) ? cdocstring(n, AUTODOC_FUNC) : NewString(""); String *ds = have_docstring(n) ? cdocstring(n, AUTODOC_METHOD) : NewString("");
if (check_kwargs(n)) { if (check_kwargs(n)) {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS|METH_KEYWORDS, (char*) \"%s\" },\n", symname, wname, ds); Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS|METH_KEYWORDS, (char*) \"%s\" },\n", symname, wname, ds);
} else if (argcount == 0) { } else if (argcount == 0) {