mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-29 08:32:02 +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). ```
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from pybind11_tests import class_sh_mi_thunks as m
|
|
|
|
|
|
def test_ptrdiff_drvd_base0():
|
|
ptrdiff = m.ptrdiff_drvd_base0()
|
|
# A failure here does not (necessarily) mean that there is a bug, but that
|
|
# test_class_sh_mi_thunks is not exercising what it is supposed to.
|
|
# If this ever fails on some platforms: use pytest.skip()
|
|
# If this ever fails on all platforms: don't know, seems extremely unlikely.
|
|
assert ptrdiff != 0
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"vec_size_fn",
|
|
[
|
|
m.vec_size_base0_raw_ptr,
|
|
m.vec_size_base0_shared_ptr,
|
|
],
|
|
)
|
|
@pytest.mark.parametrize(
|
|
"get_fn",
|
|
[
|
|
m.get_drvd_as_base0_raw_ptr,
|
|
m.get_drvd_as_base0_shared_ptr,
|
|
m.get_drvd_as_base0_unique_ptr,
|
|
],
|
|
)
|
|
def test_get_vec_size_raw_shared(get_fn, vec_size_fn):
|
|
obj = get_fn()
|
|
assert vec_size_fn(obj) == 5
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"get_fn", [m.get_drvd_as_base0_raw_ptr, m.get_drvd_as_base0_unique_ptr]
|
|
)
|
|
def test_get_vec_size_unique(get_fn):
|
|
obj = get_fn()
|
|
assert m.vec_size_base0_unique_ptr(obj) == 5
|
|
with pytest.raises(ValueError, match="Python instance was disowned"):
|
|
m.vec_size_base0_unique_ptr(obj)
|
|
|
|
|
|
def test_get_shared_vec_size_unique():
|
|
obj = m.get_drvd_as_base0_shared_ptr()
|
|
with pytest.raises(ValueError) as exc_info:
|
|
m.vec_size_base0_unique_ptr(obj)
|
|
assert (
|
|
str(exc_info.value)
|
|
== "Cannot disown external shared_ptr (loaded_as_unique_ptr)."
|
|
)
|