2023-07-25 23:15:39 +00:00
|
|
|
# Adapted from:
|
|
|
|
# https://github.com/google/clif/blob/5718e4d0807fd3b6a8187dde140069120b81ecef/clif/testing/python/python_multiple_inheritance_test.py
|
|
|
|
|
2023-11-03 00:03:20 +00:00
|
|
|
import pytest
|
|
|
|
|
2023-07-25 23:15:39 +00:00
|
|
|
from pybind11_tests import python_multiple_inheritance as m
|
|
|
|
|
|
|
|
|
|
|
|
class PC(m.CppBase):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2023-07-28 22:20:03 +00:00
|
|
|
class PPCC(PC, m.CppDrvd):
|
|
|
|
pass
|
2023-07-25 23:15:39 +00:00
|
|
|
|
|
|
|
|
2023-11-03 00:03:20 +00:00
|
|
|
class PPPCCC(PPCC, m.CppDrvd2):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class PC1(m.CppDrvd):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class PC2(m.CppDrvd2):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class PCD(PC1, PC2):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2023-07-28 04:28:14 +00:00
|
|
|
def test_PC():
|
|
|
|
d = PC(11)
|
|
|
|
assert d.get_base_value() == 11
|
|
|
|
d.reset_base_value(13)
|
|
|
|
assert d.get_base_value() == 13
|
|
|
|
|
|
|
|
|
2023-07-28 22:20:03 +00:00
|
|
|
def test_PPCC():
|
|
|
|
d = PPCC(11)
|
|
|
|
assert d.get_drvd_value() == 33
|
2023-07-25 23:15:39 +00:00
|
|
|
d.reset_drvd_value(55)
|
|
|
|
assert d.get_drvd_value() == 55
|
|
|
|
|
2023-07-28 22:20:03 +00:00
|
|
|
assert d.get_base_value() == 11
|
|
|
|
assert d.get_base_value_from_drvd() == 11
|
2023-07-25 23:15:39 +00:00
|
|
|
d.reset_base_value(20)
|
|
|
|
assert d.get_base_value() == 20
|
2023-07-26 18:51:01 +00:00
|
|
|
assert d.get_base_value_from_drvd() == 20
|
2023-07-25 23:15:39 +00:00
|
|
|
d.reset_base_value_from_drvd(30)
|
2023-07-26 18:51:01 +00:00
|
|
|
assert d.get_base_value() == 30
|
2023-07-25 23:15:39 +00:00
|
|
|
assert d.get_base_value_from_drvd() == 30
|
2023-11-03 00:03:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def NOtest_PPPCCC():
|
|
|
|
# terminate called after throwing an instance of 'pybind11::error_already_set'
|
|
|
|
# what(): TypeError: bases include diverging derived types:
|
|
|
|
# base=pybind11_tests.python_multiple_inheritance.CppBase,
|
|
|
|
# derived1=pybind11_tests.python_multiple_inheritance.CppDrvd,
|
|
|
|
# derived2=pybind11_tests.python_multiple_inheritance.CppDrvd2
|
|
|
|
PPPCCC(11)
|
|
|
|
|
|
|
|
|
|
|
|
def test_PCD():
|
|
|
|
# This escapes all_type_info_check_for_divergence() because CppBase does not appear in bases.
|
|
|
|
with pytest.raises(
|
|
|
|
TypeError,
|
|
|
|
match=r"CppDrvd2\.__init__\(\) must be called when overriding __init__$",
|
|
|
|
):
|
|
|
|
PCD(11)
|