test_docstring_options.cpp revision 11986:c12e4625ab56
112837Sgabeblack@google.com/*
212837Sgabeblack@google.com    tests/test_docstring_options.cpp -- generation of docstrings and signatures
312837Sgabeblack@google.com
412837Sgabeblack@google.com    Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
512837Sgabeblack@google.com
612837Sgabeblack@google.com    All rights reserved. Use of this source code is governed by a
712837Sgabeblack@google.com    BSD-style license that can be found in the LICENSE file.
812837Sgabeblack@google.com*/
912837Sgabeblack@google.com
1012837Sgabeblack@google.com#include "pybind11_tests.h"
1112837Sgabeblack@google.com
1212837Sgabeblack@google.comstruct DocstringTestFoo {
1312837Sgabeblack@google.com    int value;
1412837Sgabeblack@google.com    void setValue(int v) { value = v; }
1512837Sgabeblack@google.com    int getValue() const { return value; }
1612837Sgabeblack@google.com};
1712837Sgabeblack@google.com
1812837Sgabeblack@google.comtest_initializer docstring_generation([](py::module &m) {
1912837Sgabeblack@google.com
2012837Sgabeblack@google.com    {
2112837Sgabeblack@google.com        py::options options;
2212837Sgabeblack@google.com        options.disable_function_signatures();
2312837Sgabeblack@google.com
2412837Sgabeblack@google.com        m.def("test_function1", [](int, int) {}, py::arg("a"), py::arg("b"));
2512837Sgabeblack@google.com        m.def("test_function2", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
2612837Sgabeblack@google.com
2712837Sgabeblack@google.com        options.enable_function_signatures();
2812837Sgabeblack@google.com
2912837Sgabeblack@google.com        m.def("test_function3", [](int, int) {}, py::arg("a"), py::arg("b"));
3012837Sgabeblack@google.com        m.def("test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
3112837Sgabeblack@google.com
3212837Sgabeblack@google.com        options.disable_function_signatures().disable_user_defined_docstrings();
3312837Sgabeblack@google.com
3412837Sgabeblack@google.com        m.def("test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
3512837Sgabeblack@google.com
3612837Sgabeblack@google.com        {
3712837Sgabeblack@google.com            py::options nested_options;
3812837Sgabeblack@google.com            nested_options.enable_user_defined_docstrings();
3912837Sgabeblack@google.com            m.def("test_function6", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
4012837Sgabeblack@google.com        }
4112837Sgabeblack@google.com    }
4212837Sgabeblack@google.com
4312837Sgabeblack@google.com    m.def("test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
4412837Sgabeblack@google.com
4512837Sgabeblack@google.com    {
4612837Sgabeblack@google.com        py::options options;
4712837Sgabeblack@google.com        options.disable_user_defined_docstrings();
4812837Sgabeblack@google.com
4912837Sgabeblack@google.com        py::class_<DocstringTestFoo>(m, "DocstringTestFoo", "This is a class docstring")
5012837Sgabeblack@google.com            .def_property("value_prop", &DocstringTestFoo::getValue, &DocstringTestFoo::setValue, "This is a property docstring")
5112837Sgabeblack@google.com        ;
5212837Sgabeblack@google.com    }
5312837Sgabeblack@google.com});
5412837Sgabeblack@google.com