2 from pybind11_tests
import ConstructorStats
3 from pybind11_tests
import multiple_inheritance
as m
15 def __init__(self, i):
21 class MITypePy(Base1, m.Base2):
22 def __init__(self, i, j):
23 Base1.__init__(self, i)
24 m.Base2.__init__(self, j)
35 def __init__(self, i):
41 class MITypePy(m.Base1, Base2):
42 def __init__(self, i, j):
43 m.Base1.__init__(self, i)
44 Base2.__init__(self, j)
54 class MI1(m.Base1, m.Base2):
55 def __init__(self, i, j):
56 m.Base1.__init__(self, i)
57 m.Base2.__init__(self, j)
63 class MI2(B1, m.Base1, m.Base2):
64 def __init__(self, i, j):
66 m.Base1.__init__(self, i)
67 m.Base2.__init__(self, j)
70 def __init__(self, i, j):
71 MI2.__init__(self, i, j)
73 class MI4(MI3, m.Base2):
74 def __init__(self, i, j):
75 MI3.__init__(self, i, j)
77 m.Base2.__init__(self, i + 100)
79 class MI5(m.Base2, B1, m.Base1):
80 def __init__(self, i, j):
82 m.Base1.__init__(self, i)
83 m.Base2.__init__(self, j)
85 class MI6(m.Base2, B1):
86 def __init__(self, i):
87 m.Base2.__init__(self, i)
103 def __init__(self, i):
105 MI6.__init__(self, i)
108 def __init__(self, i):
109 MI6.__init__(self, i)
113 def __init__(self, i):
115 MI6.__init__(self, i)
118 assert mi1.foo() == 1
119 assert mi1.bar() == 2
123 assert mi2.foo() == 3
124 assert mi2.bar() == 4
128 assert mi3.foo() == 5
129 assert mi3.bar() == 6
133 assert mi4.foo() == 7
134 assert mi4.bar() == 8
138 assert mi5.foo() == 10
139 assert mi5.bar() == 11
143 assert mi6.bar() == 12
147 assert mi7.bar() == 13
151 assert mi8.bar() == 14
155 assert mi8b.bar() == 15
160 class MIMany14(m.BaseN1, m.BaseN2, m.BaseN3, m.BaseN4):
162 m.BaseN1.__init__(self, 1)
163 m.BaseN2.__init__(self, 2)
164 m.BaseN3.__init__(self, 3)
165 m.BaseN4.__init__(self, 4)
167 class MIMany58(m.BaseN5, m.BaseN6, m.BaseN7, m.BaseN8):
169 m.BaseN5.__init__(self, 5)
170 m.BaseN6.__init__(self, 6)
171 m.BaseN7.__init__(self, 7)
172 m.BaseN8.__init__(self, 8)
174 class MIMany916(m.BaseN9, m.BaseN10, m.BaseN11, m.BaseN12, m.BaseN13, m.BaseN14, m.BaseN15,
177 m.BaseN9.__init__(self, 9)
178 m.BaseN10.__init__(self, 10)
179 m.BaseN11.__init__(self, 11)
180 m.BaseN12.__init__(self, 12)
181 m.BaseN13.__init__(self, 13)
182 m.BaseN14.__init__(self, 14)
183 m.BaseN15.__init__(self, 15)
184 m.BaseN16.__init__(self, 16)
186 class MIMany19(MIMany14, MIMany58, m.BaseN9):
188 MIMany14.__init__(self)
189 MIMany58.__init__(self)
190 m.BaseN9.__init__(self, 9)
192 class MIMany117(MIMany14, MIMany58, MIMany916, m.BaseN17):
194 MIMany14.__init__(self)
195 MIMany58.__init__(self)
196 MIMany916.__init__(self)
197 m.BaseN17.__init__(self, 17)
201 for i
in range(1, 4):
206 for i
in range(9, 16):
211 for i
in range(1, 9):
216 for i
in range(1, 17):
222 class MITypePy(m.Base12a):
223 def __init__(self, i, j):
224 m.Base12a.__init__(self, i, j)
228 assert m.bar_base2a(mt) == 4
229 assert m.bar_base2a_sharedptr(mt) == 4
233 """Mixing bases with and without static properties should be possible 234 and the result should be independent of base definition order""" 236 for d
in (m.VanillaStaticMix1(), m.VanillaStaticMix2()):
237 assert d.vanilla() ==
"Vanilla" 238 assert d.static_func1() ==
"WithStatic1" 239 assert d.static_func2() ==
"WithStatic2" 240 assert d.static_func() == d.__class__.__name__
242 m.WithStatic1.static_value1 = 1
243 m.WithStatic2.static_value2 = 2
244 assert d.static_value1 == 1
245 assert d.static_value2 == 2
246 assert d.static_value == 12
249 assert d.static_value1 == 0
251 assert d.static_value2 == 0
253 assert d.static_value == 0
256 @pytest.unsupported_on_pypy
258 """Mixing bases with and without dynamic attribute support""" 260 for d
in (m.VanillaDictMix1(), m.VanillaDictMix2()):
262 assert d.dynamic == 1
266 """Returning an offset (non-first MI) base class pointer should recognize the instance""" 268 n_inst = ConstructorStats.detail_reg_inst()
273 assert ConstructorStats.detail_reg_inst() == n_inst + 4
283 assert ConstructorStats.detail_reg_inst() == n_inst + 4
285 assert ConstructorStats.detail_reg_inst() == n_inst + 2
287 assert ConstructorStats.detail_reg_inst() == n_inst
291 """Tests returning an offset (non-first MI) base class pointer to a derived instance""" 293 n_inst = ConstructorStats.detail_reg_inst()
296 assert type(c1)
is m.I801C
301 assert type(d1)
is m.I801D
305 assert ConstructorStats.detail_reg_inst() == n_inst + 4
308 assert type(c2)
is m.I801C
313 assert type(d2)
is m.I801D
317 assert ConstructorStats.detail_reg_inst() == n_inst + 8
320 assert ConstructorStats.detail_reg_inst() == n_inst + 6
322 assert ConstructorStats.detail_reg_inst() == n_inst
328 assert type(e1)
is m.I801C
333 assert type(e2)
is m.I801B2
338 """Tests that diamond inheritance works as expected (issue #959)""" 347 assert d
is d.c0().b()
348 assert d
is d.c1().b()
349 assert d
is d.c0().c1().b().c0().b()
def test_multiple_inheritance_python()
object getattr(handle obj, handle name)
def test_mi_unaligned_base()
def test_diamond_inheritance()
def test_multiple_inheritance_virtbase()
def test_mi_base_return()
def test_multiple_inheritance_python_many_bases()
def test_multiple_inheritance_cpp()
const detail::type_info * type
def test_multiple_inheritance_mix1()
def test_multiple_inheritance_mix2()
def test_mi_dynamic_attributes()
def test_mi_static_properties()