pybind11/tests/test_class_sh_shared_ptr_copy_move.py

42 lines
1.1 KiB
Python
Raw Normal View History

ruff automatic fixes: `from __future__ import annotations` ``` ruff.....................................................................Failed - hook id: ruff - files were modified by this hook Fixed 44 errors: - tests/test_class_sh_basic.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_disowning.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_disowning_mi.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_factory_constructors.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_inheritance.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_mi_thunks.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_module_local.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_property.py: 1 × I002 (missing-required-import) - tests/test_class_sh_property_non_owning.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_shared_ptr_copy_move.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_trampoline_basic.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_trampoline_self_life_support.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_trampoline_shared_from_this.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_trampoline_unique_ptr.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_unique_ptr_custom_deleter.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_unique_ptr_member.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_class_sh_virtual_py_cpp_mix.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_classh_mock.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_descr_src_loc.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_exc_namespace_visibility.py: 1 × I002 (missing-required-import) - tests/test_type_caster_odr_guard_1.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - tests/test_type_caster_odr_guard_2.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) Found 44 errors (44 fixed, 0 remaining). ```
2024-06-22 06:00:13 +00:00
from __future__ import annotations
2021-06-19 14:35:20 +00:00
from pybind11_tests import class_sh_shared_ptr_copy_move as m
def test_shptr_copy():
txt = m.test_ShPtr_copy()[0].get_history()
assert txt == "FooShPtr_copy"
2021-06-19 14:35:20 +00:00
def test_smhld_copy():
txt = m.test_SmHld_copy()[0].get_history()
assert txt == "FooSmHld_copy"
2021-06-19 14:35:20 +00:00
def test_shptr_move():
txt = m.test_ShPtr_move()[0].get_history()
assert txt == "FooShPtr_move"
2021-06-19 14:35:20 +00:00
def test_smhld_move():
txt = m.test_SmHld_move()[0].get_history()
assert txt == "FooSmHld_move"
2021-06-29 10:35:50 +00:00
2021-06-29 10:56:34 +00:00
def _check_property(foo_typ, prop_typ, policy):
2021-06-29 10:35:50 +00:00
o = m.Outer()
name = f"{foo_typ}_{prop_typ}_{policy}"
history = f"Foo{foo_typ}_Outer"
2021-06-29 10:35:50 +00:00
f = getattr(o, name)
assert f.get_history() == history
# and try again to check that o did not get changed
f = getattr(o, name)
assert f.get_history() == history
def test_properties():
for prop_typ in ("readonly", "readwrite", "property_readonly"):
for foo_typ in ("ShPtr", "SmHld"):
for policy in ("default", "copy", "move"):
_check_property(foo_typ, prop_typ, policy)