Alexander Stukowski | 9a110e6 | 2016-11-15 12:38:05 +0100 | [diff] [blame] | 1 | |
Dean Moldovan | bad1740 | 2016-11-20 21:21:54 +0100 | [diff] [blame] | 2 | |
| 3 | def test_docstring_options(): |
Alexander Stukowski | 9a110e6 | 2016-11-15 12:38:05 +0100 | [diff] [blame] | 4 | from pybind11_tests import (test_function1, test_function2, test_function3, |
| 5 | test_function4, test_function5, test_function6, |
Jason Rhinelander | 10d1304 | 2017-03-08 12:32:42 -0500 | [diff] [blame] | 6 | test_function7, DocstringTestFoo, |
| 7 | test_overloaded1, test_overloaded2, test_overloaded3) |
Alexander Stukowski | 9a110e6 | 2016-11-15 12:38:05 +0100 | [diff] [blame] | 8 | |
| 9 | # options.disable_function_signatures() |
| 10 | assert not test_function1.__doc__ |
| 11 | |
| 12 | assert test_function2.__doc__ == "A custom docstring" |
| 13 | |
Jason Rhinelander | 10d1304 | 2017-03-08 12:32:42 -0500 | [diff] [blame] | 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 | |
Alexander Stukowski | 9a110e6 | 2016-11-15 12:38:05 +0100 | [diff] [blame] | 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__ |