test_docstring_options.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from pybind11_tests import docstring_options as m
  2. def test_docstring_options():
  3. # options.disable_function_signatures()
  4. assert not m.test_function1.__doc__
  5. assert m.test_function2.__doc__ == "A custom docstring"
  6. # docstring specified on just the first overload definition:
  7. assert m.test_overloaded1.__doc__ == "Overload docstring"
  8. # docstring on both overloads:
  9. assert m.test_overloaded2.__doc__ == "overload docstring 1\noverload docstring 2"
  10. # docstring on only second overload:
  11. assert m.test_overloaded3.__doc__ == "Overload docstr"
  12. # options.enable_function_signatures()
  13. assert m.test_function3.__doc__ .startswith("test_function3(a: int, b: int) -> None")
  14. assert m.test_function4.__doc__ .startswith("test_function4(a: int, b: int) -> None")
  15. assert m.test_function4.__doc__ .endswith("A custom docstring\n")
  16. # options.disable_function_signatures()
  17. # options.disable_user_defined_docstrings()
  18. assert not m.test_function5.__doc__
  19. # nested options.enable_user_defined_docstrings()
  20. assert m.test_function6.__doc__ == "A custom docstring"
  21. # RAII destructor
  22. assert m.test_function7.__doc__ .startswith("test_function7(a: int, b: int) -> None")
  23. assert m.test_function7.__doc__ .endswith("A custom docstring\n")
  24. # Suppression of user-defined docstrings for non-function objects
  25. assert not m.DocstringTestFoo.__doc__
  26. assert not m.DocstringTestFoo.value_prop.__doc__