MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_docstring_options

Function test_docstring_options

tests/test_docstring_options.py:6–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5
6def test_docstring_options():
7 # options.disable_function_signatures()
8 assert not m.test_function1.__doc__
9
10 assert m.test_function2.__doc__ == "A custom docstring"
11
12 # docstring specified on just the first overload definition:
13 assert m.test_overloaded1.__doc__ == "Overload docstring"
14
15 # docstring on both overloads:
16 assert m.test_overloaded2.__doc__ == "overload docstring 1\noverload docstring 2"
17
18 # docstring on only second overload:
19 assert m.test_overloaded3.__doc__ == "Overload docstr"
20
21 # options.enable_function_signatures()
22 assert m.test_function3.__doc__.startswith(
23 "test_function3(a: typing.SupportsInt | typing.SupportsIndex, b: typing.SupportsInt | typing.SupportsIndex) -> None"
24 )
25
26 assert m.test_function4.__doc__.startswith(
27 "test_function4(a: typing.SupportsInt | typing.SupportsIndex, b: typing.SupportsInt | typing.SupportsIndex) -> None"
28 )
29 assert m.test_function4.__doc__.endswith("A custom docstring\n")
30
31 # options.disable_function_signatures()
32 # options.disable_user_defined_docstrings()
33 assert not m.test_function5.__doc__
34
35 # nested options.enable_user_defined_docstrings()
36 assert m.test_function6.__doc__ == "A custom docstring"
37
38 # RAII destructor
39 assert m.test_function7.__doc__.startswith(
40 "test_function7(a: typing.SupportsInt | typing.SupportsIndex, b: typing.SupportsInt | typing.SupportsIndex) -> None"
41 )
42 assert m.test_function7.__doc__.endswith("A custom docstring\n")
43
44 # when all options are disabled, no docstring (instead of an empty one) should be generated
45 assert m.test_function8.__doc__ is None
46
47 # Suppression of user-defined docstrings for non-function objects
48 assert not m.DocstringTestFoo.__doc__
49 assert not m.DocstringTestFoo.value_prop.__doc__
50
51 # Check existing behaviour of enum docstings
52 assert (
53 m.DocstringTestEnum1.__doc__
54 == "Enum docstring\n\nMembers:\n\n Member1\n\n Member2"
55 )
56
57 # options.enable_enum_members_docstring()
58 assert (
59 m.DocstringTestEnum2.__doc__
60 == "Enum docstring\n\nMembers:\n\n Member1\n\n Member2"
61 )
62
63 # options.disable_enum_members_docstring()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected