2024-06-22 04:55:00 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
from pybind11_tests import docstring_options as m
|
2016-11-15 11:38:05 +00:00
|
|
|
|
2016-11-20 20:21:54 +00:00
|
|
|
|
|
|
|
def test_docstring_options():
|
2016-11-15 11:38:05 +00:00
|
|
|
# options.disable_function_signatures()
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert not m.test_function1.__doc__
|
2016-11-15 11:38:05 +00:00
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.test_function2.__doc__ == "A custom docstring"
|
2016-11-15 11:38:05 +00:00
|
|
|
|
2017-03-08 17:32:42 +00:00
|
|
|
# docstring specified on just the first overload definition:
|
2024-08-18 13:36:46 +00:00
|
|
|
assert m.test_overloaded1.__doc__ == (
|
|
|
|
"test_overloaded1(i: int) -> None\n"
|
|
|
|
"test_overloaded1(d: float) -> None\n"
|
|
|
|
"Overload docstring"
|
|
|
|
)
|
2017-03-08 17:32:42 +00:00
|
|
|
|
|
|
|
# docstring on both overloads:
|
2024-08-18 13:36:46 +00:00
|
|
|
assert m.test_overloaded2.__doc__ == (
|
|
|
|
"test_overloaded2(i: int) -> None\n"
|
|
|
|
"test_overloaded2(d: float) -> None\n"
|
|
|
|
"overload docstring 1\n"
|
|
|
|
"overload docstring 2"
|
|
|
|
)
|
2017-03-08 17:32:42 +00:00
|
|
|
|
|
|
|
# docstring on only second overload:
|
2024-08-18 13:36:46 +00:00
|
|
|
assert m.test_overloaded3.__doc__ == (
|
|
|
|
"test_overloaded3(i: int) -> None\n"
|
|
|
|
"test_overloaded3(d: float) -> None\n"
|
|
|
|
"Overload docstr"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Check overload configuration behaviour matches the documentation
|
|
|
|
assert m.test_overloaded4.__doc__ == (
|
|
|
|
"test_overloaded4(arg0: int, arg1: int) -> int\n"
|
|
|
|
"test_overloaded4(arg0: float, arg1: float) -> float\n"
|
|
|
|
"test_overloaded4(arg0: None, arg1: None) -> None\n"
|
|
|
|
"A function which adds two numbers.\n\n"
|
|
|
|
"Internally, a simple addition is performed.\n"
|
|
|
|
"Both numbers can be None, and None will be returned."
|
|
|
|
)
|
|
|
|
|
|
|
|
assert m.test_overloaded5.__doc__ == (
|
|
|
|
"test_overloaded5(arg0: int, arg1: int) -> int\n"
|
|
|
|
"test_overloaded5(arg0: float, arg1: float) -> float\n"
|
|
|
|
"Overloaded function.\n"
|
|
|
|
"\n"
|
|
|
|
"1. test_overloaded5(arg0: int, arg1: int) -> int\n"
|
|
|
|
"\n"
|
|
|
|
"Add two integers together.\n"
|
|
|
|
"\n"
|
|
|
|
"2. test_overloaded5(arg0: float, arg1: float) -> float\n"
|
|
|
|
"\n"
|
|
|
|
"Add two floating point numbers together.\n"
|
|
|
|
)
|
2017-03-08 17:32:42 +00:00
|
|
|
|
2016-11-15 11:38:05 +00:00
|
|
|
# options.enable_function_signatures()
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.test_function3.__doc__.startswith("test_function3(a: int, b: int) -> None")
|
2016-11-15 11:38:05 +00:00
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.test_function4.__doc__.startswith("test_function4(a: int, b: int) -> None")
|
|
|
|
assert m.test_function4.__doc__.endswith("A custom docstring\n")
|
2016-11-15 11:38:05 +00:00
|
|
|
|
|
|
|
# options.disable_function_signatures()
|
|
|
|
# options.disable_user_defined_docstrings()
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert not m.test_function5.__doc__
|
2016-11-15 11:38:05 +00:00
|
|
|
|
|
|
|
# nested options.enable_user_defined_docstrings()
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.test_function6.__doc__ == "A custom docstring"
|
2016-11-15 11:38:05 +00:00
|
|
|
|
|
|
|
# RAII destructor
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.test_function7.__doc__.startswith("test_function7(a: int, b: int) -> None")
|
|
|
|
assert m.test_function7.__doc__.endswith("A custom docstring\n")
|
2016-11-15 11:38:05 +00:00
|
|
|
|
2020-12-28 03:56:30 +00:00
|
|
|
# when all options are disabled, no docstring (instead of an empty one) should be generated
|
|
|
|
assert m.test_function8.__doc__ is None
|
|
|
|
|
2016-11-15 11:38:05 +00:00
|
|
|
# Suppression of user-defined docstrings for non-function objects
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert not m.DocstringTestFoo.__doc__
|
|
|
|
assert not m.DocstringTestFoo.value_prop.__doc__
|
2022-12-09 07:10:10 +00:00
|
|
|
|
|
|
|
# Check existig behaviour of enum docstings
|
|
|
|
assert (
|
|
|
|
m.DocstringTestEnum1.__doc__
|
|
|
|
== "Enum docstring\n\nMembers:\n\n Member1\n\n Member2"
|
|
|
|
)
|
|
|
|
|
|
|
|
# options.enable_enum_members_docstring()
|
|
|
|
assert (
|
|
|
|
m.DocstringTestEnum2.__doc__
|
|
|
|
== "Enum docstring\n\nMembers:\n\n Member1\n\n Member2"
|
|
|
|
)
|
|
|
|
|
|
|
|
# options.disable_enum_members_docstring()
|
|
|
|
assert m.DocstringTestEnum3.__doc__ == "Enum docstring"
|
|
|
|
|
|
|
|
# options.disable_user_defined_docstrings()
|
|
|
|
assert m.DocstringTestEnum4.__doc__ == "Members:\n\n Member1\n\n Member2"
|
|
|
|
|
|
|
|
# options.disable_user_defined_docstrings()
|
|
|
|
# options.disable_enum_members_docstring()
|
|
|
|
# When all options are disabled, no docstring (instead of an empty one) should be generated
|
|
|
|
assert m.DocstringTestEnum5.__doc__ is None
|