test_docstring_options.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. tests/test_docstring_options.cpp -- generation of docstrings and signatures
  3. Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
  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. options.disable_function_signatures();
  37. m.def("test_function8", []() {});
  38. }
  39. {
  40. py::options options;
  41. options.disable_user_defined_docstrings();
  42. struct DocstringTestFoo {
  43. int value;
  44. void setValue(int v) { value = v; }
  45. int getValue() const { return value; }
  46. };
  47. py::class_<DocstringTestFoo>(m, "DocstringTestFoo", "This is a class docstring")
  48. .def_property("value_prop", &DocstringTestFoo::getValue, &DocstringTestFoo::setValue, "This is a property docstring")
  49. ;
  50. }
  51. }