blob: 5e40f68687832fbf8ed5fcec735b9cff05459b8d [file] [log] [blame]
Alexander Stukowski9a110e62016-11-15 12:38:05 +01001
Dean Moldovanbad17402016-11-20 21:21:54 +01002
3def test_docstring_options():
Alexander Stukowski9a110e62016-11-15 12:38:05 +01004 from pybind11_tests import (test_function1, test_function2, test_function3,
5 test_function4, test_function5, test_function6,
Jason Rhinelander10d13042017-03-08 12:32:42 -05006 test_function7, DocstringTestFoo,
7 test_overloaded1, test_overloaded2, test_overloaded3)
Alexander Stukowski9a110e62016-11-15 12:38:05 +01008
9 # options.disable_function_signatures()
10 assert not test_function1.__doc__
11
12 assert test_function2.__doc__ == "A custom docstring"
13
Jason Rhinelander10d13042017-03-08 12:32:42 -050014 # docstring specified on just the first overload definition:
15 assert test_overloaded1.__doc__ == "Overload docstring"
16
17 # docstring on both overloads:
18 assert test_overloaded2.__doc__ == "overload docstring 1\noverload docstring 2"
19
20 # docstring on only second overload:
21 assert test_overloaded3.__doc__ == "Overload docstr"
22
Alexander Stukowski9a110e62016-11-15 12:38:05 +010023 # options.enable_function_signatures()
24 assert test_function3.__doc__ .startswith("test_function3(a: int, b: int) -> None")
25
26 assert test_function4.__doc__ .startswith("test_function4(a: int, b: int) -> None")
27 assert test_function4.__doc__ .endswith("A custom docstring\n")
28
29 # options.disable_function_signatures()
30 # options.disable_user_defined_docstrings()
31 assert not test_function5.__doc__
32
33 # nested options.enable_user_defined_docstrings()
34 assert test_function6.__doc__ == "A custom docstring"
35
36 # RAII destructor
37 assert test_function7.__doc__ .startswith("test_function7(a: int, b: int) -> None")
38 assert test_function7.__doc__ .endswith("A custom docstring\n")
39
40 # Suppression of user-defined docstrings for non-function objects
41 assert not DocstringTestFoo.__doc__
42 assert not DocstringTestFoo.value_prop.__doc__