Dean Moldovan | bad1740 | 2016-11-20 21:21:54 +0100 | [diff] [blame] | 1 | def test_multiple_inheritance_cpp(): |
Wenzel Jakob | 8e5dceb | 2016-09-11 20:00:40 +0900 | [diff] [blame] | 2 | from pybind11_tests import MIType |
| 3 | |
| 4 | mt = MIType(3, 4) |
| 5 | |
| 6 | assert mt.foo() == 3 |
| 7 | assert mt.bar() == 4 |
| 8 | |
| 9 | |
Dean Moldovan | bad1740 | 2016-11-20 21:21:54 +0100 | [diff] [blame] | 10 | def test_multiple_inheritance_mix1(): |
Wenzel Jakob | 8e5dceb | 2016-09-11 20:00:40 +0900 | [diff] [blame] | 11 | from pybind11_tests import Base2 |
| 12 | |
| 13 | class Base1: |
| 14 | def __init__(self, i): |
| 15 | self.i = i |
| 16 | |
| 17 | def foo(self): |
| 18 | return self.i |
| 19 | |
| 20 | class MITypePy(Base1, Base2): |
| 21 | def __init__(self, i, j): |
| 22 | Base1.__init__(self, i) |
| 23 | Base2.__init__(self, j) |
| 24 | |
| 25 | mt = MITypePy(3, 4) |
| 26 | |
| 27 | assert mt.foo() == 3 |
| 28 | assert mt.bar() == 4 |
| 29 | |
| 30 | |
Dean Moldovan | bad1740 | 2016-11-20 21:21:54 +0100 | [diff] [blame] | 31 | def test_multiple_inheritance_mix2(): |
Wenzel Jakob | 8e5dceb | 2016-09-11 20:00:40 +0900 | [diff] [blame] | 32 | from pybind11_tests import Base1 |
| 33 | |
| 34 | class Base2: |
| 35 | def __init__(self, i): |
| 36 | self.i = i |
| 37 | |
| 38 | def bar(self): |
| 39 | return self.i |
| 40 | |
| 41 | class MITypePy(Base1, Base2): |
| 42 | def __init__(self, i, j): |
| 43 | Base1.__init__(self, i) |
| 44 | Base2.__init__(self, j) |
| 45 | |
| 46 | mt = MITypePy(3, 4) |
| 47 | |
| 48 | assert mt.foo() == 3 |
| 49 | assert mt.bar() == 4 |
| 50 | |
| 51 | |
Dean Moldovan | bad1740 | 2016-11-20 21:21:54 +0100 | [diff] [blame] | 52 | def test_multiple_inheritance_virtbase(): |
Wenzel Jakob | 8e5dceb | 2016-09-11 20:00:40 +0900 | [diff] [blame] | 53 | from pybind11_tests import Base12a, bar_base2a, bar_base2a_sharedptr |
| 54 | |
| 55 | class MITypePy(Base12a): |
| 56 | def __init__(self, i, j): |
| 57 | Base12a.__init__(self, i, j) |
| 58 | |
| 59 | mt = MITypePy(3, 4) |
| 60 | assert mt.bar() == 4 |
| 61 | assert bar_base2a(mt) == 4 |
| 62 | assert bar_base2a_sharedptr(mt) == 4 |