test_docstring_options.py 1.6 KB

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