mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-27 07:32:02 +00:00
5319ca3817
* Adaption of PyCLIF virtual_py_cpp_mix test. * Removing ValueError: Ownership of instance with virtual overrides in Python cannot be transferred to C++. TODO: static_assert alias class needs to inherit from virtual_overrider_self_life_support. * Bringing back ValueError: "... instance cannot safely be transferred to C++.", but based on dynamic_cast<AliasType>. * Fixing oversight: adding test_class_sh_virtual_py_cpp_mix.cpp to cmake file. * clang <= 3.6 compatibility. * Fixing oversight: dynamic_raw_ptr_cast_if_possible needs special handling for To = void. Adding corresponding missing test in test_class_sh_virtual_py_cpp_mix. Moving dynamic_raw_ptr_cast_if_possible to separate header. * Changing py::detail::virtual_overrider_self_life_support to py::virtual_overrider_self_life_support.
66 lines
1.3 KiB
Python
66 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
import pytest
|
|
|
|
from pybind11_tests import class_sh_virtual_py_cpp_mix as m
|
|
|
|
|
|
class PyBase(m.Base): # Avoiding name PyDerived, for more systematic naming.
|
|
def __init__(self):
|
|
m.Base.__init__(self)
|
|
|
|
def get(self):
|
|
return 323
|
|
|
|
|
|
class PyCppDerived(m.CppDerived):
|
|
def __init__(self):
|
|
m.CppDerived.__init__(self)
|
|
|
|
def get(self):
|
|
return 434
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"ctor, expected",
|
|
[
|
|
(m.Base, 101),
|
|
(PyBase, 323),
|
|
(m.CppDerivedPlain, 202),
|
|
(m.CppDerived, 212),
|
|
(PyCppDerived, 434),
|
|
],
|
|
)
|
|
def test_base_get(ctor, expected):
|
|
obj = ctor()
|
|
assert obj.get() == expected
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"ctor, expected",
|
|
[
|
|
(m.Base, 4101),
|
|
(PyBase, 4323),
|
|
(m.CppDerivedPlain, 4202),
|
|
(m.CppDerived, 4212),
|
|
(PyCppDerived, 4434),
|
|
],
|
|
)
|
|
def test_get_from_cpp_plainc_ptr(ctor, expected):
|
|
obj = ctor()
|
|
assert m.get_from_cpp_plainc_ptr(obj) == expected
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"ctor, expected",
|
|
[
|
|
(m.Base, 5101),
|
|
(PyBase, 5323),
|
|
(m.CppDerivedPlain, 5202),
|
|
(m.CppDerived, 5212),
|
|
(PyCppDerived, 5434),
|
|
],
|
|
)
|
|
def test_get_from_cpp_unique_ptr(ctor, expected):
|
|
obj = ctor()
|
|
assert m.get_from_cpp_unique_ptr(obj) == expected
|