2024-07-05 21:47:39 +00:00
|
|
|
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):
|
MESSY but success for: test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]
scons -j 48 selected_test_cpp=test_class_sh_mi_thunks.cpp && "$(cat PYROOT)"/bin/python3 $HOME/clone/pybind11_scons/run_tests.py ../pybind11 test_class_sh_mi_thunks.py -s -vv -k 'test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]'
```
=========================================================== test session starts ============================================================
platform linux -- Python 3.11.8, pytest-7.4.4, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
C++ Info: 13.2.0 C++20 __pybind11_internals_v10000000_gcc_libstdcpp_cxxabi1018__ PYBIND11_SIMPLE_GIL_MANAGEMENT=False PYBIND11_NUMPY_1_ONLY=False
rootdir: /usr/local/google/home/rwgk/forked/pybind11/tests
configfile: pytest.ini
plugins: xdist-3.5.0
collected 10 items / 9 deselected / 1 selected
test_class_sh_mi_thunks.py::test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]
LOOOK A
LOOOK get raw drvd 47927280
LOOOK get raw base 47927312
LOOOK B
LOOOK shd load(src, convert) X
LOOOK shd try_implicit_casts(src, convert) Q
LOOOK shd try_implicit_casts(src, convert) R
LOOOK shd load(src, convert) X
LOOOK shd load_value(v_h) ENTRY
LOOOK shd load_value(v_h) A
LOOOK shd load_value(v_h) B
LOOOK shd load(src, convert) Y 47927280
LOOOK shd try_implicit_casts(src, convert) S
LOOOK shd load(src, convert) Y 47927312
LOOOK operator std::shared_ptr<type> & A 47927312 /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../cast.h:891
LOOOK /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../detail/type_caster_base.h:838
LOOOK /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../detail/type_caster_base.h:842
LOOOK operator std::shared_ptr<type> & B 47927312 /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../cast.h:893
LOOOK shd const Base0 *obj 47927312
LOOOK shd const auto *obj_der 47927280
LOOOK C
PASSED
===================================================== 1 passed, 9 deselected in 0.01s ======================================================
```
2024-07-06 22:27:04 +00:00
|
|
|
print(f"\nLOOOK A", flush=True)
|
2024-07-05 21:47:39 +00:00
|
|
|
obj = get_fn()
|
MESSY but success for: test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]
scons -j 48 selected_test_cpp=test_class_sh_mi_thunks.cpp && "$(cat PYROOT)"/bin/python3 $HOME/clone/pybind11_scons/run_tests.py ../pybind11 test_class_sh_mi_thunks.py -s -vv -k 'test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]'
```
=========================================================== test session starts ============================================================
platform linux -- Python 3.11.8, pytest-7.4.4, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
C++ Info: 13.2.0 C++20 __pybind11_internals_v10000000_gcc_libstdcpp_cxxabi1018__ PYBIND11_SIMPLE_GIL_MANAGEMENT=False PYBIND11_NUMPY_1_ONLY=False
rootdir: /usr/local/google/home/rwgk/forked/pybind11/tests
configfile: pytest.ini
plugins: xdist-3.5.0
collected 10 items / 9 deselected / 1 selected
test_class_sh_mi_thunks.py::test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]
LOOOK A
LOOOK get raw drvd 47927280
LOOOK get raw base 47927312
LOOOK B
LOOOK shd load(src, convert) X
LOOOK shd try_implicit_casts(src, convert) Q
LOOOK shd try_implicit_casts(src, convert) R
LOOOK shd load(src, convert) X
LOOOK shd load_value(v_h) ENTRY
LOOOK shd load_value(v_h) A
LOOOK shd load_value(v_h) B
LOOOK shd load(src, convert) Y 47927280
LOOOK shd try_implicit_casts(src, convert) S
LOOOK shd load(src, convert) Y 47927312
LOOOK operator std::shared_ptr<type> & A 47927312 /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../cast.h:891
LOOOK /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../detail/type_caster_base.h:838
LOOOK /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../detail/type_caster_base.h:842
LOOOK operator std::shared_ptr<type> & B 47927312 /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../cast.h:893
LOOOK shd const Base0 *obj 47927312
LOOOK shd const auto *obj_der 47927280
LOOOK C
PASSED
===================================================== 1 passed, 9 deselected in 0.01s ======================================================
```
2024-07-06 22:27:04 +00:00
|
|
|
print(f"\nLOOOK B", flush=True)
|
2024-07-05 21:47:39 +00:00
|
|
|
assert vec_size_fn(obj) == 5
|
MESSY but success for: test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]
scons -j 48 selected_test_cpp=test_class_sh_mi_thunks.cpp && "$(cat PYROOT)"/bin/python3 $HOME/clone/pybind11_scons/run_tests.py ../pybind11 test_class_sh_mi_thunks.py -s -vv -k 'test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]'
```
=========================================================== test session starts ============================================================
platform linux -- Python 3.11.8, pytest-7.4.4, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
C++ Info: 13.2.0 C++20 __pybind11_internals_v10000000_gcc_libstdcpp_cxxabi1018__ PYBIND11_SIMPLE_GIL_MANAGEMENT=False PYBIND11_NUMPY_1_ONLY=False
rootdir: /usr/local/google/home/rwgk/forked/pybind11/tests
configfile: pytest.ini
plugins: xdist-3.5.0
collected 10 items / 9 deselected / 1 selected
test_class_sh_mi_thunks.py::test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]
LOOOK A
LOOOK get raw drvd 47927280
LOOOK get raw base 47927312
LOOOK B
LOOOK shd load(src, convert) X
LOOOK shd try_implicit_casts(src, convert) Q
LOOOK shd try_implicit_casts(src, convert) R
LOOOK shd load(src, convert) X
LOOOK shd load_value(v_h) ENTRY
LOOOK shd load_value(v_h) A
LOOOK shd load_value(v_h) B
LOOOK shd load(src, convert) Y 47927280
LOOOK shd try_implicit_casts(src, convert) S
LOOOK shd load(src, convert) Y 47927312
LOOOK operator std::shared_ptr<type> & A 47927312 /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../cast.h:891
LOOOK /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../detail/type_caster_base.h:838
LOOOK /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../detail/type_caster_base.h:842
LOOOK operator std::shared_ptr<type> & B 47927312 /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../cast.h:893
LOOOK shd const Base0 *obj 47927312
LOOOK shd const auto *obj_der 47927280
LOOOK C
PASSED
===================================================== 1 passed, 9 deselected in 0.01s ======================================================
```
2024-07-06 22:27:04 +00:00
|
|
|
print(f"\nLOOOK C", flush=True)
|
2024-07-05 21:47:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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)."
|
|
|
|
)
|