test_docstring_options.py revision 12037:d28054ac6ec9
1 2 3def test_docstring_options(): 4 from pybind11_tests import (test_function1, test_function2, test_function3, 5 test_function4, test_function5, test_function6, 6 test_function7, DocstringTestFoo, 7 test_overloaded1, test_overloaded2, test_overloaded3) 8 9 # options.disable_function_signatures() 10 assert not test_function1.__doc__ 11 12 assert test_function2.__doc__ == "A custom docstring" 13 14 # 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 23 # 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__ 43