test_docstring_options.cpp revision 12037
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        m.def("test_overloaded1", [](int) {}, py::arg("i"), "Overload docstring");
28        m.def("test_overloaded1", [](double) {}, py::arg("d"));
29
30        m.def("test_overloaded2", [](int) {}, py::arg("i"), "overload docstring 1");
31        m.def("test_overloaded2", [](double) {}, py::arg("d"), "overload docstring 2");
32
33        m.def("test_overloaded3", [](int) {}, py::arg("i"));
34        m.def("test_overloaded3", [](double) {}, py::arg("d"), "Overload docstr");
35
36        options.enable_function_signatures();
37
38        m.def("test_function3", [](int, int) {}, py::arg("a"), py::arg("b"));
39        m.def("test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
40
41        options.disable_function_signatures().disable_user_defined_docstrings();
42
43        m.def("test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
44
45        {
46            py::options nested_options;
47            nested_options.enable_user_defined_docstrings();
48            m.def("test_function6", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
49        }
50    }
51
52    m.def("test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
53
54    {
55        py::options options;
56        options.disable_user_defined_docstrings();
57
58        py::class_<DocstringTestFoo>(m, "DocstringTestFoo", "This is a class docstring")
59            .def_property("value_prop", &DocstringTestFoo::getValue, &DocstringTestFoo::setValue, "This is a property docstring")
60        ;
61    }
62});
63