test_docstring_options.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. tests/test_docstring_options.cpp -- generation of docstrings and signatures
  3. Copyright (c) 2016 Wenzel Jakob <[email protected]>
  4. All rights reserved. Use of this source code is governed by a
  5. BSD-style license that can be found in the LICENSE file.
  6. */
  7. #include "pybind11_tests.h"
  8. TEST_SUBMODULE(docstring_options, m) {
  9. // test_docstring_options
  10. {
  11. py::options options;
  12. options.disable_function_signatures();
  13. m.def("test_function1", [](int, int) {}, py::arg("a"), py::arg("b"));
  14. m.def("test_function2", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  15. m.def("test_overloaded1", [](int) {}, py::arg("i"), "Overload docstring");
  16. m.def("test_overloaded1", [](double) {}, py::arg("d"));
  17. m.def("test_overloaded2", [](int) {}, py::arg("i"), "overload docstring 1");
  18. m.def("test_overloaded2", [](double) {}, py::arg("d"), "overload docstring 2");
  19. m.def("test_overloaded3", [](int) {}, py::arg("i"));
  20. m.def("test_overloaded3", [](double) {}, py::arg("d"), "Overload docstr");
  21. options.enable_function_signatures();
  22. m.def("test_function3", [](int, int) {}, py::arg("a"), py::arg("b"));
  23. m.def("test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  24. options.disable_function_signatures().disable_user_defined_docstrings();
  25. m.def("test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  26. {
  27. py::options nested_options;
  28. nested_options.enable_user_defined_docstrings();
  29. m.def("test_function6", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  30. }
  31. }
  32. m.def("test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  33. {
  34. py::options options;
  35. options.disable_user_defined_docstrings();
  36. struct DocstringTestFoo {
  37. int value;
  38. void setValue(int v) { value = v; }
  39. int getValue() const { return value; }
  40. };
  41. py::class_<DocstringTestFoo>(m, "DocstringTestFoo", "This is a class docstring")
  42. .def_property("value_prop", &DocstringTestFoo::getValue, &DocstringTestFoo::setValue, "This is a property docstring")
  43. ;
  44. }
  45. }