test_docstring_options.cpp (11986:c12e4625ab56) test_docstring_options.cpp (12037:d28054ac6ec9)
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
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
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});
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});