2024-06-22 04:55:00 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2016-12-16 14:00:46 +00:00
|
|
|
import pytest
|
2020-08-16 20:02:12 +00:00
|
|
|
|
|
|
|
import env # noqa: F401
|
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 ConstructorStats
|
2021-08-13 16:37:05 +00:00
|
|
|
from pybind11_tests import call_policies as m
|
2016-08-12 11:50:00 +00:00
|
|
|
|
|
|
|
|
2020-08-16 20:02:12 +00:00
|
|
|
@pytest.mark.xfail("env.PYPY", reason="sometimes comes out 1 off on PyPy", strict=False)
|
2024-10-07 21:12:04 +00:00
|
|
|
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
|
2016-08-12 11:50:00 +00:00
|
|
|
def test_keep_alive_argument(capture):
|
2017-06-24 12:58:42 +00:00
|
|
|
n_inst = ConstructorStats.detail_reg_inst()
|
2016-08-12 11:50:00 +00:00
|
|
|
with capture:
|
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
|
|
|
p = m.Parent()
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Allocating parent."
|
|
|
|
with capture:
|
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
|
|
|
p.addChild(m.Child())
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 1
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2016-08-12 11:50:00 +00:00
|
|
|
Allocating child.
|
|
|
|
Releasing child.
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2016-08-12 11:50:00 +00:00
|
|
|
with capture:
|
|
|
|
del p
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Releasing parent."
|
|
|
|
|
|
|
|
with capture:
|
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
|
|
|
p = m.Parent()
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Allocating parent."
|
|
|
|
with capture:
|
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
|
|
|
p.addChildKeepAlive(m.Child())
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 2
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Allocating child."
|
|
|
|
with capture:
|
|
|
|
del p
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2016-08-12 11:50:00 +00:00
|
|
|
Releasing parent.
|
|
|
|
Releasing child.
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2016-08-12 11:50:00 +00:00
|
|
|
|
2021-05-06 14:13:30 +00:00
|
|
|
p = m.Parent()
|
|
|
|
c = m.Child()
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 2
|
|
|
|
m.free_function(p, c)
|
|
|
|
del c
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 2
|
|
|
|
del p
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
|
|
|
|
|
|
|
with pytest.raises(RuntimeError) as excinfo:
|
|
|
|
m.invalid_arg_index()
|
|
|
|
assert str(excinfo.value) == "Could not activate keep_alive!"
|
|
|
|
|
2016-08-12 11:50:00 +00:00
|
|
|
|
2024-10-07 21:12:04 +00:00
|
|
|
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
|
2016-08-12 11:50:00 +00:00
|
|
|
def test_keep_alive_return_value(capture):
|
2017-06-24 12:58:42 +00:00
|
|
|
n_inst = ConstructorStats.detail_reg_inst()
|
2016-08-12 11:50:00 +00:00
|
|
|
with capture:
|
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
|
|
|
p = m.Parent()
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Allocating parent."
|
|
|
|
with capture:
|
|
|
|
p.returnChild()
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 1
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2016-08-12 11:50:00 +00:00
|
|
|
Allocating child.
|
|
|
|
Releasing child.
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2016-08-12 11:50:00 +00:00
|
|
|
with capture:
|
|
|
|
del p
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Releasing parent."
|
|
|
|
|
|
|
|
with capture:
|
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
|
|
|
p = m.Parent()
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Allocating parent."
|
|
|
|
with capture:
|
|
|
|
p.returnChildKeepAlive()
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 2
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Allocating child."
|
|
|
|
with capture:
|
|
|
|
del p
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2017-06-24 12:58:42 +00:00
|
|
|
Releasing parent.
|
|
|
|
Releasing child.
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2017-06-24 12:58:42 +00:00
|
|
|
|
2021-05-06 14:13:30 +00:00
|
|
|
p = m.Parent()
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 1
|
|
|
|
with capture:
|
|
|
|
m.Parent.staticFunction(p)
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 2
|
|
|
|
assert capture == "Allocating child."
|
|
|
|
with capture:
|
|
|
|
del p
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
|
|
|
Releasing parent.
|
|
|
|
Releasing child.
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
2017-06-24 12:58:42 +00:00
|
|
|
|
2020-08-16 20:02:12 +00:00
|
|
|
# https://foss.heptapod.net/pypy/pypy/-/issues/2447
|
|
|
|
@pytest.mark.xfail("env.PYPY", reason="_PyObject_GetDictPtr is unimplemented")
|
2024-10-07 21:12:04 +00:00
|
|
|
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
|
2017-06-24 12:58:42 +00:00
|
|
|
def test_alive_gc(capture):
|
|
|
|
n_inst = ConstructorStats.detail_reg_inst()
|
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
|
|
|
p = m.ParentGC()
|
|
|
|
p.addChildKeepAlive(m.Child())
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 2
|
|
|
|
lst = [p]
|
2020-10-16 20:38:13 +00:00
|
|
|
lst.append(lst) # creates a circular reference
|
2017-06-24 12:58:42 +00:00
|
|
|
with capture:
|
|
|
|
del p, lst
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2017-06-24 12:58:42 +00:00
|
|
|
Releasing parent.
|
|
|
|
Releasing child.
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2017-06-24 12:58:42 +00:00
|
|
|
|
|
|
|
|
2024-10-07 21:12:04 +00:00
|
|
|
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
|
2017-06-24 12:58:42 +00:00
|
|
|
def test_alive_gc_derived(capture):
|
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
|
|
|
class Derived(m.Parent):
|
2017-06-24 12:58:42 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
n_inst = ConstructorStats.detail_reg_inst()
|
|
|
|
p = Derived()
|
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
|
|
|
p.addChildKeepAlive(m.Child())
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 2
|
|
|
|
lst = [p]
|
2020-10-16 20:38:13 +00:00
|
|
|
lst.append(lst) # creates a circular reference
|
2017-06-24 12:58:42 +00:00
|
|
|
with capture:
|
|
|
|
del p, lst
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2017-06-24 12:58:42 +00:00
|
|
|
Releasing parent.
|
|
|
|
Releasing child.
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2017-06-24 12:58:42 +00:00
|
|
|
|
|
|
|
|
2024-10-07 21:12:04 +00:00
|
|
|
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
|
2017-06-24 12:58:42 +00:00
|
|
|
def test_alive_gc_multi_derived(capture):
|
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
|
|
|
class Derived(m.Parent, m.Child):
|
2017-07-25 04:53:23 +00:00
|
|
|
def __init__(self):
|
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
|
|
|
m.Parent.__init__(self)
|
|
|
|
m.Child.__init__(self)
|
2017-06-24 12:58:42 +00:00
|
|
|
|
|
|
|
n_inst = ConstructorStats.detail_reg_inst()
|
|
|
|
p = Derived()
|
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
|
|
|
p.addChildKeepAlive(m.Child())
|
2017-06-24 12:58:42 +00:00
|
|
|
# +3 rather than +2 because Derived corresponds to two registered instances
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 3
|
|
|
|
lst = [p]
|
2020-10-16 20:38:13 +00:00
|
|
|
lst.append(lst) # creates a circular reference
|
2017-06-24 12:58:42 +00:00
|
|
|
with capture:
|
|
|
|
del p, lst
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2016-08-12 11:50:00 +00:00
|
|
|
Releasing parent.
|
|
|
|
Releasing child.
|
2017-07-25 04:53:23 +00:00
|
|
|
Releasing child.
|
2016-08-12 11:50:00 +00:00
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2016-08-12 11:50:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_return_none(capture):
|
2017-06-24 12:58:42 +00:00
|
|
|
n_inst = ConstructorStats.detail_reg_inst()
|
2016-08-12 11:50:00 +00:00
|
|
|
with capture:
|
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
|
|
|
p = m.Parent()
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Allocating parent."
|
|
|
|
with capture:
|
|
|
|
p.returnNullChildKeepAliveChild()
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 1
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == ""
|
|
|
|
with capture:
|
|
|
|
del p
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Releasing parent."
|
|
|
|
|
|
|
|
with capture:
|
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
|
|
|
p = m.Parent()
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Allocating parent."
|
|
|
|
with capture:
|
|
|
|
p.returnNullChildKeepAliveParent()
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 1
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == ""
|
|
|
|
with capture:
|
|
|
|
del p
|
2017-06-24 12:58:42 +00:00
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
2016-08-12 11:50:00 +00:00
|
|
|
assert capture == "Releasing parent."
|
2017-03-16 10:22:26 +00:00
|
|
|
|
|
|
|
|
2017-09-04 11:49:19 +00:00
|
|
|
def test_keep_alive_constructor(capture):
|
|
|
|
n_inst = ConstructorStats.detail_reg_inst()
|
|
|
|
|
|
|
|
with capture:
|
|
|
|
p = m.Parent(m.Child())
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst + 2
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2017-09-04 11:49:19 +00:00
|
|
|
Allocating child.
|
|
|
|
Allocating parent.
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2017-09-04 11:49:19 +00:00
|
|
|
with capture:
|
|
|
|
del p
|
|
|
|
assert ConstructorStats.detail_reg_inst() == n_inst
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2017-09-04 11:49:19 +00:00
|
|
|
Releasing parent.
|
|
|
|
Releasing child.
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2017-09-04 11:49:19 +00:00
|
|
|
|
|
|
|
|
2017-03-16 10:22:26 +00:00
|
|
|
def test_call_guard():
|
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.unguarded_call() == "unguarded"
|
|
|
|
assert m.guarded_call() == "guarded"
|
2017-03-16 10:22:26 +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.multiple_guards_correct_order() == "guarded & guarded"
|
|
|
|
assert m.multiple_guards_wrong_order() == "unguarded & guarded"
|
2017-03-16 10:22:26 +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
|
|
|
if hasattr(m, "with_gil"):
|
|
|
|
assert m.with_gil() == "GIL held"
|
|
|
|
assert m.without_gil() == "GIL released"
|