test_docstring_options.cpp revision 11986
12SN/A/*
21762SN/A    tests/test_docstring_options.cpp -- generation of docstrings and signatures
32SN/A
42SN/A    Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
52SN/A
62SN/A    All rights reserved. Use of this source code is governed by a
72SN/A    BSD-style license that can be found in the LICENSE file.
82SN/A*/
92SN/A
102SN/A#include "pybind11_tests.h"
112SN/A
122SN/Astruct DocstringTestFoo {
132SN/A    int value;
142SN/A    void setValue(int v) { value = v; }
152SN/A    int getValue() const { return value; }
162SN/A};
172SN/A
182SN/Atest_initializer docstring_generation([](py::module &m) {
192SN/A
202SN/A    {
212SN/A        py::options options;
222SN/A        options.disable_function_signatures();
232SN/A
242SN/A        m.def("test_function1", [](int, int) {}, py::arg("a"), py::arg("b"));
252SN/A        m.def("test_function2", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
262SN/A
272665Ssaidi@eecs.umich.edu        options.enable_function_signatures();
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.edu        m.def("test_function3", [](int, int) {}, py::arg("a"), py::arg("b"));
302SN/A        m.def("test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
312SN/A
326216Snate@binkert.org        options.disable_function_signatures().disable_user_defined_docstrings();
336216Snate@binkert.org
342SN/A        m.def("test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
354046Sbinkertn@umich.edu
366216Snate@binkert.org        {
374046Sbinkertn@umich.edu            py::options nested_options;
387680Sgblack@eecs.umich.edu            nested_options.enable_user_defined_docstrings();
398232Snate@binkert.org            m.def("test_function6", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
408232Snate@binkert.org        }
416216Snate@binkert.org    }
424776Sgblack@eecs.umich.edu
432SN/A    m.def("test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
443064Sgblack@eecs.umich.edu
452SN/A    {
462SN/A        py::options options;
472SN/A        options.disable_user_defined_docstrings();
484776Sgblack@eecs.umich.edu
492SN/A        py::class_<DocstringTestFoo>(m, "DocstringTestFoo", "This is a class docstring")
502SN/A            .def_property("value_prop", &DocstringTestFoo::getValue, &DocstringTestFoo::setValue, "This is a property docstring")
514776Sgblack@eecs.umich.edu        ;
527720Sgblack@eecs.umich.edu    }
537720Sgblack@eecs.umich.edu});
545784Sgblack@eecs.umich.edu