test_multiple_inheritance.py revision 11986
1 2 3def test_multiple_inheritance_cpp(): 4 from pybind11_tests import MIType 5 6 mt = MIType(3, 4) 7 8 assert mt.foo() == 3 9 assert mt.bar() == 4 10 11 12def test_multiple_inheritance_mix1(): 13 from pybind11_tests import Base2 14 15 class Base1: 16 def __init__(self, i): 17 self.i = i 18 19 def foo(self): 20 return self.i 21 22 class MITypePy(Base1, Base2): 23 def __init__(self, i, j): 24 Base1.__init__(self, i) 25 Base2.__init__(self, j) 26 27 mt = MITypePy(3, 4) 28 29 assert mt.foo() == 3 30 assert mt.bar() == 4 31 32 33def test_multiple_inheritance_mix2(): 34 from pybind11_tests import Base1 35 36 class Base2: 37 def __init__(self, i): 38 self.i = i 39 40 def bar(self): 41 return self.i 42 43 class MITypePy(Base1, Base2): 44 def __init__(self, i, j): 45 Base1.__init__(self, i) 46 Base2.__init__(self, j) 47 48 mt = MITypePy(3, 4) 49 50 assert mt.foo() == 3 51 assert mt.bar() == 4 52 53 54def test_multiple_inheritance_virtbase(): 55 from pybind11_tests import Base12a, bar_base2a, bar_base2a_sharedptr 56 57 class MITypePy(Base12a): 58 def __init__(self, i, j): 59 Base12a.__init__(self, i, j) 60 61 mt = MITypePy(3, 4) 62 assert mt.bar() == 4 63 assert bar_base2a(mt) == 4 64 assert bar_base2a_sharedptr(mt) == 4 65