-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test suite cleanup and reorganisation #898
Conversation
4998f6b
to
bd6704c
Compare
This all sounds pretty good to me. Breaking up of test_python_types was definitely the next logical step after dispersing test_issues. I'm more lukewarm on coalescing common types. I worry a bit that this is going to run into conflicts if pushed too far because future tests are going to want to change something something which in turn breaks other tests. As for the As for moving into submodules, I think that's a great idea: I used to run into cases where |
The intention here isn't to consolidate everything -- only the most common types in order to remove needless duplication. If a test needs something very specific then it's fine to introduce a new class only in its translation unit. But if a test just needs to check builtin vs. user-defined types then it doesn't make sense to create yet another
Sure, that makes sense. If a test uses a function very frequently, |
I suggest we merge this one now (after also moving the new, conflicting tests added to test_python_types), and deal with transitioning the others one by one. Otherwise I think it's going to be painful keeping up with the resulting merge conflicts. |
bd6704c
to
97624ba
Compare
`nullptr` is not expected to work in this case.
97624ba
to
4513d7f
Compare
Agreed. I've rebased and resolved the conflicts with the new tests. I've also included a few smaller changes:
If there are no objections I'd like to merge this soon to avoid more conflicts with PRs. Porting the other tests to submodules can be done gradually later. Note: I have accidentally pushed the latest changes to both my fork and origin. I've deleted the branch on origin, but Travis and AppVeyor have already registered it and now show both the PR tests and branch tests. The latter will fail because the branch has been deleted. |
This udpates all the remaining tests to the new test suite code and comment styles started in pybind#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 some unused definitions `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.
This udpates all the remaining tests to the new test suite code and comment styles started in pybind#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.
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.
The first part of this PR closes #861: the
test_issues.cpp
/.py
files are removed completely and the tests are redistributed into more appropriate files.Part two breaks up
test_python_types.cpp
because it has also started to accumulate various not-so-related parts. The tests are redistributed into:test_builtin_casters
for casters which are available in pybind11 without extra headers,test_stl
forstl.h
andtest_pytypes
for Python type wrappers and their C++ interfaces. There were also a couple ofpy::class_
tests which were moved intotest_class
(renamed fromtest_class_args
).Along the way, this also adds a few things to the main
pybind11_tests.h
header:UnregisteredType
which is used to test conversion errors. A few test files were already using various versions of this.UserType
which serves as the official user-defined type for testing (simpleint
holder). Multiple tests have their own versions of this (or use some locally exported class) but a lot of that is unnecessary duplication (I haven't gone through to replace everything yet).IncType
: adapted from @jagerman'sreference_wrapper
tests. It's likeUserType
, but incrementsvalue
on copy for quick reference vs. copy tests. Should be useful for quick tests without the need for fullConstructorStats
instrumentation.TEST_SUBMODULE
is a convenience macro which wrapstest_initializer
and defines a new submodule (instead of adding to the mainpybind11_tests
module). It also defines a function instead of a lambda because MSVC has issues with lambdas and local structs.Proposal for new test conventions:
.cpp
file should create its own submodule. (Made easier byTEST_SUBMODULE
)..py
files imports that module asfrom pybind11_tests import submodule as m
. This should reduce the number ofimport
statements and them
name reflects the convention from the.cpp
files..py
files has a function calledtest_name()
then the.cpp
file should add a corresponding// test_name
comment above the bindings. This should help navigation between files.py::class_
bindings and related lambdadef
bindings. As long as the classes are single-purpose for a specific test, this should help with organization. MSVC would frequently choke on this which made it impractical, but theTEST_SUBMODULE
macro resolves that.Thoughts?
Right now this is only applied to the new test files which have come out of
test_python_types
. If this seems good, it could be applied everywhere. There are also some other frequently reinvented classes which can be pulled out (seems like a move-only type is needed frequently for testing, etc.).Closes #842, closes #861.