3
'''Test case for duck punching new implementations of C++ virtual methods into object instances.'''
7
from PySide.QtCore import QObject, QEvent
8
from helper import UsesQCoreApplication
12
QObject.__init__(self)
13
def childEvent(self, event):
14
QObject.childEvent(self, event)
16
class TestDuckPunchingOnQObjectInstance(UsesQCoreApplication):
17
'''Test case for duck punching new implementations of C++ virtual methods into object instances.'''
21
self.duck_childEvent_called = False
22
UsesQCoreApplication.setUp(self)
26
del self.duck_childEvent_called
27
UsesQCoreApplication.tearDown(self)
30
def testChildEventMonkeyPatch(self):
31
#Test if the new childEvent injected on QObject instance is called from C++
33
def childEvent(obj, event):
34
self.duck_childEvent_called = True
35
QObject.childEvent(obj, event)
36
parent.childEvent = types.MethodType(childEvent, parent, QObject)
38
child.setParent(parent)
39
self.assert_(self.duck_childEvent_called)
40
# This is done to decrease the refcount of the vm object
41
# allowing the object wrapper to be deleted before the
42
# BindingManager. This is useful when compiling Shiboken
43
# for debug, since the BindingManager destructor has an
44
# assert that checks if the wrapper mapper is empty.
45
parent.childEvent = None
47
def testChildEventMonkeyPatchWithInheritance(self):
48
#Test if the new childEvent injected on a QObject's extension class instance is called from C++
50
def childEvent(obj, event):
51
QObject.childEvent(obj, event)
52
self.duck_childEvent_called = True
54
child.setParent(parent)
55
parent.childEvent = types.MethodType(childEvent, parent, QObject)
57
child.setParent(parent)
58
self.assert_(self.duck_childEvent_called)
59
# This is done to decrease the refcount of the vm object
60
# allowing the object wrapper to be deleted before the
61
# BindingManager. This is useful when compiling Shiboken
62
# for debug, since the BindingManager destructor has an
63
# assert that checks if the wrapper mapper is empty.
64
parent.childEvent = None
66
if __name__ == '__main__':