MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_inherited_virtuals

Function test_inherited_virtuals

tests/test_virtual_functions.py:316–442  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

314
315
316def test_inherited_virtuals():
317 class AR(m.A_Repeat):
318 def unlucky_number(self):
319 return 99
320
321 class AT(m.A_Tpl):
322 def unlucky_number(self):
323 return 999
324
325 obj = AR()
326 assert obj.say_something(3) == "hihihi"
327 assert obj.unlucky_number() == 99
328 assert obj.say_everything() == "hi 99"
329
330 obj = AT()
331 assert obj.say_something(3) == "hihihi"
332 assert obj.unlucky_number() == 999
333 assert obj.say_everything() == "hi 999"
334
335 for obj in [m.B_Repeat(), m.B_Tpl()]:
336 assert obj.say_something(3) == "B says hi 3 times"
337 assert obj.unlucky_number() == 13
338 assert obj.lucky_number() == 7.0
339 assert obj.say_everything() == "B says hi 1 times 13"
340
341 for obj in [m.C_Repeat(), m.C_Tpl()]:
342 assert obj.say_something(3) == "B says hi 3 times"
343 assert obj.unlucky_number() == 4444
344 assert obj.lucky_number() == 888.0
345 assert obj.say_everything() == "B says hi 1 times 4444"
346
347 class CR(m.C_Repeat):
348 def lucky_number(self):
349 return m.C_Repeat.lucky_number(self) + 1.25
350
351 obj = CR()
352 assert obj.say_something(3) == "B says hi 3 times"
353 assert obj.unlucky_number() == 4444
354 assert obj.lucky_number() == 889.25
355 assert obj.say_everything() == "B says hi 1 times 4444"
356
357 class CT(m.C_Tpl):
358 pass
359
360 obj = CT()
361 assert obj.say_something(3) == "B says hi 3 times"
362 assert obj.unlucky_number() == 4444
363 assert obj.lucky_number() == 888.0
364 assert obj.say_everything() == "B says hi 1 times 4444"
365
366 class CCR(CR):
367 def lucky_number(self):
368 return CR.lucky_number(self) * 10
369
370 obj = CCR()
371 assert obj.say_something(3) == "B says hi 3 times"
372 assert obj.unlucky_number() == 4444
373 assert obj.lucky_number() == 8892.5

Callers

nothing calls this directly

Calls 12

say_somethingMethod · 0.95
unlucky_numberMethod · 0.95
lucky_numberMethod · 0.95
ARClass · 0.85
ATClass · 0.85
CRClass · 0.85
CTClass · 0.85
CCRClass · 0.85
CCTClass · 0.85
DRClass · 0.85
DTClass · 0.85
BTClass · 0.85

Tested by

no test coverage detected