6 from pybind11_tests
import ConstructorStats
7 from pybind11_tests
import multiple_inheritance
as m
17 @pytest.mark.skipif(
"env.PYPY and env.PY2")
18 @pytest.mark.xfail(
"env.PYPY and not env.PY2")
21 def __init__(self, i):
27 class MITypePy(Base1, m.Base2):
28 def __init__(self, i, j):
29 Base1.__init__(self, i)
30 m.Base2.__init__(self, j)
40 def __init__(self, i):
46 class MITypePy(m.Base1, Base2):
47 def __init__(self, i, j):
48 m.Base1.__init__(self, i)
49 Base2.__init__(self, j)
57 @pytest.mark.skipif(
"env.PYPY and env.PY2")
58 @pytest.mark.xfail(
"env.PYPY and not env.PY2")
60 class MI1(m.Base1, m.Base2):
61 def __init__(self, i, j):
62 m.Base1.__init__(self, i)
63 m.Base2.__init__(self, j)
69 class MI2(B1, m.Base1, m.Base2):
70 def __init__(self, i, j):
72 m.Base1.__init__(self, i)
73 m.Base2.__init__(self, j)
76 def __init__(self, i, j):
77 MI2.__init__(self, i, j)
79 class MI4(MI3, m.Base2):
80 def __init__(self, i, j):
81 MI3.__init__(self, i, j)
83 m.Base2.__init__(self, i + 100)
85 class MI5(m.Base2, B1, m.Base1):
86 def __init__(self, i, j):
88 m.Base1.__init__(self, i)
89 m.Base2.__init__(self, j)
91 class MI6(m.Base2, B1):
92 def __init__(self, i):
93 m.Base2.__init__(self, i)
109 def __init__(self, i):
111 MI6.__init__(self, i)
114 def __init__(self, i):
115 MI6.__init__(self, i)
119 def __init__(self, i):
121 MI6.__init__(self, i)
124 assert mi1.foo() == 1
125 assert mi1.bar() == 2
129 assert mi2.foo() == 3
130 assert mi2.bar() == 4
134 assert mi3.foo() == 5
135 assert mi3.bar() == 6
139 assert mi4.foo() == 7
140 assert mi4.bar() == 8
144 assert mi5.foo() == 10
145 assert mi5.bar() == 11
149 assert mi6.bar() == 12
153 assert mi7.bar() == 13
157 assert mi8.bar() == 14
161 assert mi8b.bar() == 15
165 class MIMany14(m.BaseN1, m.BaseN2, m.BaseN3, m.BaseN4):
167 m.BaseN1.__init__(self, 1)
168 m.BaseN2.__init__(self, 2)
169 m.BaseN3.__init__(self, 3)
170 m.BaseN4.__init__(self, 4)
172 class MIMany58(m.BaseN5, m.BaseN6, m.BaseN7, m.BaseN8):
174 m.BaseN5.__init__(self, 5)
175 m.BaseN6.__init__(self, 6)
176 m.BaseN7.__init__(self, 7)
177 m.BaseN8.__init__(self, 8)
190 m.BaseN9.__init__(self, 9)
191 m.BaseN10.__init__(self, 10)
192 m.BaseN11.__init__(self, 11)
193 m.BaseN12.__init__(self, 12)
194 m.BaseN13.__init__(self, 13)
195 m.BaseN14.__init__(self, 14)
196 m.BaseN15.__init__(self, 15)
197 m.BaseN16.__init__(self, 16)
199 class MIMany19(MIMany14, MIMany58, m.BaseN9):
201 MIMany14.__init__(self)
202 MIMany58.__init__(self)
203 m.BaseN9.__init__(self, 9)
205 class MIMany117(MIMany14, MIMany58, MIMany916, m.BaseN17):
207 MIMany14.__init__(self)
208 MIMany58.__init__(self)
209 MIMany916.__init__(self)
210 m.BaseN17.__init__(self, 17)
214 for i
in range(1, 4):
219 for i
in range(9, 16):
224 for i
in range(1, 9):
229 for i
in range(1, 17):
234 class MITypePy(m.Base12a):
235 def __init__(self, i, j):
236 m.Base12a.__init__(self, i, j)
240 assert m.bar_base2a(mt) == 4
241 assert m.bar_base2a_sharedptr(mt) == 4
245 """Mixing bases with and without static properties should be possible
246 and the result should be independent of base definition order"""
248 for d
in (m.VanillaStaticMix1(), m.VanillaStaticMix2()):
249 assert d.vanilla() ==
"Vanilla"
250 assert d.static_func1() ==
"WithStatic1"
251 assert d.static_func2() ==
"WithStatic2"
252 assert d.static_func() == d.__class__.__name__
254 m.WithStatic1.static_value1 = 1
255 m.WithStatic2.static_value2 = 2
256 assert d.static_value1 == 1
257 assert d.static_value2 == 2
258 assert d.static_value == 12
261 assert d.static_value1 == 0
263 assert d.static_value2 == 0
265 assert d.static_value == 0
270 """Mixing bases with and without dynamic attribute support"""
272 for d
in (m.VanillaDictMix1(), m.VanillaDictMix2()):
274 assert d.dynamic == 1
278 """Returning an offset (non-first MI) base class pointer should recognize the instance"""
280 n_inst = ConstructorStats.detail_reg_inst()
285 assert ConstructorStats.detail_reg_inst() == n_inst + 4
295 assert ConstructorStats.detail_reg_inst() == n_inst + 4
297 assert ConstructorStats.detail_reg_inst() == n_inst + 2
299 assert ConstructorStats.detail_reg_inst() == n_inst
303 """Tests returning an offset (non-first MI) base class pointer to a derived instance"""
305 n_inst = ConstructorStats.detail_reg_inst()
308 assert type(c1)
is m.I801C
313 assert type(d1)
is m.I801D
317 assert ConstructorStats.detail_reg_inst() == n_inst + 4
320 assert type(c2)
is m.I801C
325 assert type(d2)
is m.I801D
329 assert ConstructorStats.detail_reg_inst() == n_inst + 8
332 assert ConstructorStats.detail_reg_inst() == n_inst + 6
334 assert ConstructorStats.detail_reg_inst() == n_inst
340 assert type(e1)
is m.I801C
345 assert type(e2)
is m.I801B2
350 """Tests that diamond inheritance works as expected (issue #959)"""
359 assert d
is d.c0().b()
360 assert d
is d.c1().b()
361 assert d
is d.c0().c1().b().c0().b()