blob: 8c8f79fd5f6308caab1ee2d22525af2a408eca07 [file] [log] [blame]
Alexander Stukowski9a110e62016-11-15 12:38:05 +01001/*
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
Jason Rhinelander391c7542017-07-25 16:47:36 -040012TEST_SUBMODULE(docstring_options, m) {
13 // test_docstring_options
Alexander Stukowski9a110e62016-11-15 12:38:05 +010014 {
15 py::options options;
16 options.disable_function_signatures();
17
18 m.def("test_function1", [](int, int) {}, py::arg("a"), py::arg("b"));
19 m.def("test_function2", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
20
Jason Rhinelander10d13042017-03-08 12:32:42 -050021 m.def("test_overloaded1", [](int) {}, py::arg("i"), "Overload docstring");
22 m.def("test_overloaded1", [](double) {}, py::arg("d"));
23
24 m.def("test_overloaded2", [](int) {}, py::arg("i"), "overload docstring 1");
25 m.def("test_overloaded2", [](double) {}, py::arg("d"), "overload docstring 2");
26
27 m.def("test_overloaded3", [](int) {}, py::arg("i"));
28 m.def("test_overloaded3", [](double) {}, py::arg("d"), "Overload docstr");
29
Alexander Stukowski9a110e62016-11-15 12:38:05 +010030 options.enable_function_signatures();
31
32 m.def("test_function3", [](int, int) {}, py::arg("a"), py::arg("b"));
33 m.def("test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
34
35 options.disable_function_signatures().disable_user_defined_docstrings();
36
37 m.def("test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
38
39 {
40 py::options nested_options;
41 nested_options.enable_user_defined_docstrings();
42 m.def("test_function6", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
43 }
44 }
45
46 m.def("test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
47
48 {
49 py::options options;
50 options.disable_user_defined_docstrings();
51
Jason Rhinelander391c7542017-07-25 16:47:36 -040052 struct DocstringTestFoo {
53 int value;
54 void setValue(int v) { value = v; }
55 int getValue() const { return value; }
56 };
Alexander Stukowski9a110e62016-11-15 12:38:05 +010057 py::class_<DocstringTestFoo>(m, "DocstringTestFoo", "This is a class docstring")
58 .def_property("value_prop", &DocstringTestFoo::getValue, &DocstringTestFoo::setValue, "This is a property docstring")
59 ;
60 }
Jason Rhinelander391c7542017-07-25 16:47:36 -040061}