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