2024-06-22 04:55:00 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2016-12-07 01:36:44 +00:00
|
|
|
import pytest
|
2020-09-12 02:06:52 +00:00
|
|
|
|
|
|
|
m = pytest.importorskip("pybind11_tests.smart_ptr")
|
|
|
|
from pybind11_tests import ConstructorStats # noqa: E402
|
2016-08-12 11:50:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_smart_ptr(capture):
|
|
|
|
# Object1
|
2020-10-16 20:38:13 +00:00
|
|
|
for i, o in enumerate(
|
|
|
|
[m.make_object_1(), m.make_object_2(), m.MyObject1(3)], start=1
|
|
|
|
):
|
2016-08-12 11:50:00 +00:00
|
|
|
assert o.getRefCount() == 1
|
|
|
|
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
|
|
|
m.print_object_1(o)
|
|
|
|
m.print_object_2(o)
|
|
|
|
m.print_object_3(o)
|
|
|
|
m.print_object_4(o)
|
2022-02-12 00:06:16 +00:00
|
|
|
assert capture == f"MyObject1[{i}]\n" * 4
|
2016-08-12 11:50:00 +00:00
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
for i, o in enumerate(
|
|
|
|
[m.make_myobject1_1(), m.make_myobject1_2(), m.MyObject1(6), 7], start=4
|
|
|
|
):
|
2016-08-12 11:50:00 +00:00
|
|
|
print(o)
|
|
|
|
with capture:
|
|
|
|
if not isinstance(o, int):
|
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.print_object_1(o)
|
|
|
|
m.print_object_2(o)
|
|
|
|
m.print_object_3(o)
|
|
|
|
m.print_object_4(o)
|
|
|
|
m.print_myobject1_1(o)
|
|
|
|
m.print_myobject1_2(o)
|
|
|
|
m.print_myobject1_3(o)
|
|
|
|
m.print_myobject1_4(o)
|
2020-10-16 20:38:13 +00:00
|
|
|
|
|
|
|
times = 4 if isinstance(o, int) else 8
|
2022-02-12 00:06:16 +00:00
|
|
|
assert capture == f"MyObject1[{i}]\n" * times
|
2016-08-12 11:50:00 +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
|
|
|
cstats = ConstructorStats.get(m.MyObject1)
|
2016-08-12 11:50:00 +00:00
|
|
|
assert cstats.alive() == 0
|
2022-02-12 00:06:16 +00:00
|
|
|
expected_values = [f"MyObject1[{i}]" for i in range(1, 7)] + ["MyObject1[7]"] * 4
|
2016-08-12 11:50:00 +00:00
|
|
|
assert cstats.values() == expected_values
|
|
|
|
assert cstats.default_constructions == 0
|
|
|
|
assert cstats.copy_constructions == 0
|
|
|
|
# assert cstats.move_constructions >= 0 # Doesn't invoke any
|
|
|
|
assert cstats.copy_assignments == 0
|
|
|
|
assert cstats.move_assignments == 0
|
|
|
|
|
|
|
|
# Object2
|
2020-10-16 20:38:13 +00:00
|
|
|
for i, o in zip(
|
|
|
|
[8, 6, 7], [m.MyObject2(8), m.make_myobject2_1(), m.make_myobject2_2()]
|
|
|
|
):
|
2016-08-12 11:50:00 +00:00
|
|
|
print(o)
|
|
|
|
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
|
|
|
m.print_myobject2_1(o)
|
|
|
|
m.print_myobject2_2(o)
|
|
|
|
m.print_myobject2_3(o)
|
|
|
|
m.print_myobject2_4(o)
|
2022-02-12 00:06:16 +00:00
|
|
|
assert capture == f"MyObject2[{i}]\n" * 4
|
2016-08-12 11:50:00 +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
|
|
|
cstats = ConstructorStats.get(m.MyObject2)
|
2016-08-12 11:50:00 +00:00
|
|
|
assert cstats.alive() == 1
|
|
|
|
o = None
|
|
|
|
assert cstats.alive() == 0
|
2020-10-16 20:38:13 +00:00
|
|
|
assert cstats.values() == ["MyObject2[8]", "MyObject2[6]", "MyObject2[7]"]
|
2016-08-12 11:50:00 +00:00
|
|
|
assert cstats.default_constructions == 0
|
|
|
|
assert cstats.copy_constructions == 0
|
|
|
|
# assert cstats.move_constructions >= 0 # Doesn't invoke any
|
|
|
|
assert cstats.copy_assignments == 0
|
|
|
|
assert cstats.move_assignments == 0
|
|
|
|
|
|
|
|
# Object3
|
2020-10-16 20:38:13 +00:00
|
|
|
for i, o in zip(
|
|
|
|
[9, 8, 9], [m.MyObject3(9), m.make_myobject3_1(), m.make_myobject3_2()]
|
|
|
|
):
|
2016-08-12 11:50:00 +00:00
|
|
|
print(o)
|
|
|
|
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
|
|
|
m.print_myobject3_1(o)
|
|
|
|
m.print_myobject3_2(o)
|
|
|
|
m.print_myobject3_3(o)
|
|
|
|
m.print_myobject3_4(o)
|
2022-02-12 00:06:16 +00:00
|
|
|
assert capture == f"MyObject3[{i}]\n" * 4
|
2016-08-12 11:50:00 +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
|
|
|
cstats = ConstructorStats.get(m.MyObject3)
|
2016-08-12 11:50:00 +00:00
|
|
|
assert cstats.alive() == 1
|
|
|
|
o = None
|
|
|
|
assert cstats.alive() == 0
|
2020-10-16 20:38:13 +00:00
|
|
|
assert cstats.values() == ["MyObject3[9]", "MyObject3[8]", "MyObject3[9]"]
|
2016-08-12 11:50:00 +00:00
|
|
|
assert cstats.default_constructions == 0
|
|
|
|
assert cstats.copy_constructions == 0
|
|
|
|
# assert cstats.move_constructions >= 0 # Doesn't invoke any
|
|
|
|
assert cstats.copy_assignments == 0
|
|
|
|
assert cstats.move_assignments == 0
|
|
|
|
|
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
|
|
|
# Object
|
|
|
|
cstats = ConstructorStats.get(m.Object)
|
2016-08-12 11:50:00 +00:00
|
|
|
assert cstats.alive() == 0
|
|
|
|
assert cstats.values() == []
|
|
|
|
assert cstats.default_constructions == 10
|
|
|
|
assert cstats.copy_constructions == 0
|
|
|
|
# assert cstats.move_constructions >= 0 # Doesn't invoke any
|
|
|
|
assert cstats.copy_assignments == 0
|
|
|
|
assert cstats.move_assignments == 0
|
|
|
|
|
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
|
|
|
# ref<>
|
|
|
|
cstats = m.cstats_ref()
|
2016-08-12 11:50:00 +00:00
|
|
|
assert cstats.alive() == 0
|
2020-10-16 20:38:13 +00:00
|
|
|
assert cstats.values() == ["from pointer"] * 10
|
2016-08-12 11:50:00 +00:00
|
|
|
assert cstats.default_constructions == 30
|
|
|
|
assert cstats.copy_constructions == 12
|
|
|
|
# assert cstats.move_constructions >= 0 # Doesn't invoke any
|
|
|
|
assert cstats.copy_assignments == 30
|
|
|
|
assert cstats.move_assignments == 0
|
2016-09-04 22:23:55 +00:00
|
|
|
|
2016-11-20 20:21:54 +00:00
|
|
|
|
2016-12-15 22:44:23 +00:00
|
|
|
def test_smart_ptr_refcounting():
|
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_object1_refcounting()
|
2016-12-15 22:44:23 +00:00
|
|
|
|
|
|
|
|
2016-11-20 20:21:54 +00:00
|
|
|
def test_unique_nodelete():
|
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
|
|
|
o = m.MyObject4(23)
|
2016-09-04 22:23:55 +00:00
|
|
|
assert o.value == 23
|
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
|
|
|
cstats = ConstructorStats.get(m.MyObject4)
|
2016-09-04 22:23:55 +00:00
|
|
|
assert cstats.alive() == 1
|
|
|
|
del o
|
2021-01-01 16:05:22 +00:00
|
|
|
assert cstats.alive() == 1
|
|
|
|
m.MyObject4.cleanup_all_instances()
|
|
|
|
assert cstats.alive() == 0
|
2016-12-07 01:36:44 +00:00
|
|
|
|
|
|
|
|
2018-11-11 18:36:55 +00:00
|
|
|
def test_unique_nodelete4a():
|
|
|
|
o = m.MyObject4a(23)
|
|
|
|
assert o.value == 23
|
|
|
|
cstats = ConstructorStats.get(m.MyObject4a)
|
|
|
|
assert cstats.alive() == 1
|
|
|
|
del o
|
2021-01-01 16:05:22 +00:00
|
|
|
assert cstats.alive() == 1
|
|
|
|
m.MyObject4a.cleanup_all_instances()
|
|
|
|
assert cstats.alive() == 0
|
2018-11-11 18:36:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_unique_deleter():
|
2021-01-01 16:05:22 +00:00
|
|
|
m.MyObject4a(0)
|
2018-11-11 18:36:55 +00:00
|
|
|
o = m.MyObject4b(23)
|
|
|
|
assert o.value == 23
|
|
|
|
cstats4a = ConstructorStats.get(m.MyObject4a)
|
2021-01-01 16:05:22 +00:00
|
|
|
assert cstats4a.alive() == 2
|
2018-11-11 18:36:55 +00:00
|
|
|
cstats4b = ConstructorStats.get(m.MyObject4b)
|
|
|
|
assert cstats4b.alive() == 1
|
|
|
|
del o
|
2021-01-01 16:05:22 +00:00
|
|
|
assert cstats4a.alive() == 1 # Should now only be one leftover
|
2018-11-11 18:36:55 +00:00
|
|
|
assert cstats4b.alive() == 0 # Should be deleted
|
2021-01-01 16:05:22 +00:00
|
|
|
m.MyObject4a.cleanup_all_instances()
|
|
|
|
assert cstats4a.alive() == 0
|
|
|
|
assert cstats4b.alive() == 0
|
2018-11-11 18:36:55 +00:00
|
|
|
|
|
|
|
|
2017-02-23 02:36:09 +00:00
|
|
|
def test_large_holder():
|
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
|
|
|
o = m.MyObject5(5)
|
2017-02-23 02:36:09 +00:00
|
|
|
assert o.value == 5
|
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
|
|
|
cstats = ConstructorStats.get(m.MyObject5)
|
2017-02-23 02:36:09 +00:00
|
|
|
assert cstats.alive() == 1
|
|
|
|
del o
|
|
|
|
assert cstats.alive() == 0
|
|
|
|
|
|
|
|
|
2016-12-07 01:36:44 +00:00
|
|
|
def test_shared_ptr_and_references():
|
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
|
|
|
s = m.SharedPtrRef()
|
|
|
|
stats = ConstructorStats.get(m.A)
|
2016-12-07 01:36:44 +00:00
|
|
|
assert stats.alive() == 2
|
|
|
|
|
|
|
|
ref = s.ref # init_holder_helper(holder_ptr=false, owned=false)
|
|
|
|
assert stats.alive() == 2
|
|
|
|
assert s.set_ref(ref)
|
|
|
|
with pytest.raises(RuntimeError) as excinfo:
|
|
|
|
assert s.set_holder(ref)
|
|
|
|
assert "Unable to cast from non-held to held instance" in str(excinfo.value)
|
|
|
|
|
|
|
|
copy = s.copy # init_holder_helper(holder_ptr=false, owned=true)
|
|
|
|
assert stats.alive() == 3
|
|
|
|
assert s.set_ref(copy)
|
|
|
|
assert s.set_holder(copy)
|
|
|
|
|
|
|
|
holder_ref = s.holder_ref # init_holder_helper(holder_ptr=true, owned=false)
|
|
|
|
assert stats.alive() == 3
|
|
|
|
assert s.set_ref(holder_ref)
|
|
|
|
assert s.set_holder(holder_ref)
|
|
|
|
|
|
|
|
holder_copy = s.holder_copy # init_holder_helper(holder_ptr=true, owned=true)
|
|
|
|
assert stats.alive() == 3
|
|
|
|
assert s.set_ref(holder_copy)
|
|
|
|
assert s.set_holder(holder_copy)
|
|
|
|
|
|
|
|
del ref, copy, holder_ref, holder_copy, s
|
|
|
|
assert stats.alive() == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_shared_ptr_from_this_and_references():
|
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
|
|
|
s = m.SharedFromThisRef()
|
|
|
|
stats = ConstructorStats.get(m.B)
|
2016-12-07 01:36:44 +00:00
|
|
|
assert stats.alive() == 2
|
|
|
|
|
|
|
|
ref = s.ref # init_holder_helper(holder_ptr=false, owned=false, bad_wp=false)
|
|
|
|
assert stats.alive() == 2
|
|
|
|
assert s.set_ref(ref)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert s.set_holder(
|
|
|
|
ref
|
|
|
|
) # std::enable_shared_from_this can create a holder from a reference
|
2016-12-07 01:36:44 +00:00
|
|
|
|
|
|
|
bad_wp = s.bad_wp # init_holder_helper(holder_ptr=false, owned=false, bad_wp=true)
|
|
|
|
assert stats.alive() == 2
|
|
|
|
assert s.set_ref(bad_wp)
|
|
|
|
with pytest.raises(RuntimeError) as excinfo:
|
|
|
|
assert s.set_holder(bad_wp)
|
|
|
|
assert "Unable to cast from non-held to held instance" in str(excinfo.value)
|
|
|
|
|
|
|
|
copy = s.copy # init_holder_helper(holder_ptr=false, owned=true, bad_wp=false)
|
|
|
|
assert stats.alive() == 3
|
|
|
|
assert s.set_ref(copy)
|
|
|
|
assert s.set_holder(copy)
|
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
holder_ref = (
|
|
|
|
s.holder_ref
|
|
|
|
) # init_holder_helper(holder_ptr=true, owned=false, bad_wp=false)
|
2016-12-07 01:36:44 +00:00
|
|
|
assert stats.alive() == 3
|
|
|
|
assert s.set_ref(holder_ref)
|
|
|
|
assert s.set_holder(holder_ref)
|
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
holder_copy = (
|
|
|
|
s.holder_copy
|
|
|
|
) # init_holder_helper(holder_ptr=true, owned=true, bad_wp=false)
|
2016-12-07 01:36:44 +00:00
|
|
|
assert stats.alive() == 3
|
|
|
|
assert s.set_ref(holder_copy)
|
|
|
|
assert s.set_holder(holder_copy)
|
|
|
|
|
|
|
|
del ref, bad_wp, copy, holder_ref, holder_copy, s
|
|
|
|
assert stats.alive() == 0
|
2017-01-31 16:05:44 +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
|
|
|
z = m.SharedFromThisVirt.get()
|
|
|
|
y = m.SharedFromThisVirt.get()
|
2017-05-19 17:34:55 +00:00
|
|
|
assert y is z
|
|
|
|
|
2017-01-31 16:05:44 +00:00
|
|
|
|
|
|
|
def test_move_only_holder():
|
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
|
|
|
a = m.TypeWithMoveOnlyHolder.make()
|
2020-06-30 23:53:09 +00:00
|
|
|
b = m.TypeWithMoveOnlyHolder.make_as_object()
|
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
|
|
|
stats = ConstructorStats.get(m.TypeWithMoveOnlyHolder)
|
2020-06-30 23:53:09 +00:00
|
|
|
assert stats.alive() == 2
|
|
|
|
del b
|
2017-01-31 16:05:44 +00:00
|
|
|
assert stats.alive() == 1
|
|
|
|
del a
|
|
|
|
assert stats.alive() == 0
|
2017-03-20 20:53:24 +00:00
|
|
|
|
|
|
|
|
2018-06-20 15:33:50 +00:00
|
|
|
def test_holder_with_addressof_operator():
|
|
|
|
# this test must not throw exception from c++
|
|
|
|
a = m.TypeForHolderWithAddressOf.make()
|
|
|
|
a.print_object_1()
|
|
|
|
a.print_object_2()
|
|
|
|
a.print_object_3()
|
|
|
|
a.print_object_4()
|
|
|
|
|
|
|
|
stats = ConstructorStats.get(m.TypeForHolderWithAddressOf)
|
|
|
|
assert stats.alive() == 1
|
|
|
|
|
|
|
|
np = m.TypeForHolderWithAddressOf.make()
|
|
|
|
assert stats.alive() == 2
|
|
|
|
del a
|
|
|
|
assert stats.alive() == 1
|
|
|
|
del np
|
|
|
|
assert stats.alive() == 0
|
|
|
|
|
|
|
|
b = m.TypeForHolderWithAddressOf.make()
|
|
|
|
c = b
|
|
|
|
assert b.get() is c.get()
|
|
|
|
assert stats.alive() == 1
|
|
|
|
|
|
|
|
del b
|
|
|
|
assert stats.alive() == 1
|
|
|
|
|
|
|
|
del c
|
|
|
|
assert stats.alive() == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_move_only_holder_with_addressof_operator():
|
|
|
|
a = m.TypeForMoveOnlyHolderWithAddressOf.make()
|
|
|
|
a.print_object()
|
|
|
|
|
|
|
|
stats = ConstructorStats.get(m.TypeForMoveOnlyHolderWithAddressOf)
|
|
|
|
assert stats.alive() == 1
|
|
|
|
|
|
|
|
a.value = 42
|
|
|
|
assert a.value == 42
|
|
|
|
|
|
|
|
del a
|
|
|
|
assert stats.alive() == 0
|
|
|
|
|
|
|
|
|
2017-03-20 20:53:24 +00:00
|
|
|
def test_smart_ptr_from_default():
|
2024-07-01 22:59:59 +00:00
|
|
|
pytest.skip("BAKEIN_BREAK: Failed: DID NOT RAISE <class 'RuntimeError'>")
|
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
|
|
|
instance = m.HeldByDefaultHolder()
|
2017-03-20 20:53:24 +00:00
|
|
|
with pytest.raises(RuntimeError) as excinfo:
|
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.HeldByDefaultHolder.load_shared_ptr(instance)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
"Unable to load a custom holder type from a "
|
|
|
|
"default-holder instance" in str(excinfo.value)
|
|
|
|
)
|
2017-06-07 14:52:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_shared_ptr_gc():
|
|
|
|
"""#187: issue involving std::shared_ptr<> return value policy & garbage collection"""
|
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
|
|
|
el = m.ElementList()
|
2017-06-07 14:52:50 +00:00
|
|
|
for i in range(10):
|
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
|
|
|
el.add(m.ElementA(i))
|
2017-06-07 14:52:50 +00:00
|
|
|
pytest.gc_collect()
|
|
|
|
for i, v in enumerate(el.get()):
|
|
|
|
assert i == v.value()
|