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