mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 08:03:55 +00:00
a8bc5f7904
``` 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). ```
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from pybind11_tests import class_sh_factory_constructors as m
|
|
|
|
|
|
def test_atyp_factories():
|
|
assert m.atyp_valu().get_mtxt() == "Valu"
|
|
assert m.atyp_rref().get_mtxt() == "Rref"
|
|
# sert m.atyp_cref().get_mtxt() == "Cref"
|
|
# sert m.atyp_mref().get_mtxt() == "Mref"
|
|
# sert m.atyp_cptr().get_mtxt() == "Cptr"
|
|
assert m.atyp_mptr().get_mtxt() == "Mptr"
|
|
assert m.atyp_shmp().get_mtxt() == "Shmp"
|
|
# sert m.atyp_shcp().get_mtxt() == "Shcp"
|
|
assert m.atyp_uqmp().get_mtxt() == "Uqmp"
|
|
# sert m.atyp_uqcp().get_mtxt() == "Uqcp"
|
|
assert m.atyp_udmp().get_mtxt() == "Udmp"
|
|
# sert m.atyp_udcp().get_mtxt() == "Udcp"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("init_args", "expected"),
|
|
[
|
|
((3,), 300),
|
|
((5, 7), 570),
|
|
((9, 11, 13), 1023),
|
|
],
|
|
)
|
|
def test_with_alias_success(init_args, expected):
|
|
assert m.with_alias(*init_args).val == expected
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("num_init_args", "smart_ptr"),
|
|
[
|
|
(4, "std::unique_ptr"),
|
|
(5, "std::shared_ptr"),
|
|
],
|
|
)
|
|
def test_with_alias_invalid(num_init_args, smart_ptr):
|
|
class PyDrvdWithAlias(m.with_alias):
|
|
pass
|
|
|
|
with pytest.raises(TypeError) as excinfo:
|
|
PyDrvdWithAlias(*((0,) * num_init_args))
|
|
assert (
|
|
str(excinfo.value)
|
|
== "pybind11::init(): construction failed: returned "
|
|
+ smart_ptr
|
|
+ " pointee is not an alias instance"
|
|
)
|