You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.7 KiB

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