~ubuntu-branches/ubuntu/oneiric/pyside/oneiric

« back to all changes in this revision

Viewing changes to tests/QtCore/duck_punching_test.py

  • Committer: Bazaar Package Importer
  • Author(s): Didier Raboud
  • Date: 2010-09-27 21:01:06 UTC
  • mfrom: (1.2.1 upstream) (6.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20100927210106-m1nrq8vmd3exqb9o
Tags: 0.4.1-0ubuntu1
* New 0.4.1 upstream release. (LP: #648612)
  - Add some 0.4.1 symbols.

* Patches:
  - u_c130273_fix_py25_QtScript_property.patch
    Remove, was from upstream.
  - u_20e226b_fix_missing_qcoreapplication_arguments_method.patch
    Remove, was from upstream.
  - u_268bf77_fixed_signal_signature_parser.patch
    Remove, was from upstream.
  + libPythonVersionPostfix.patch: Refresh
  + usePySpecificShiboken.patch: Refresh
  + lessBuildVerbosity.patch: Refresh

* Bump the B-D chain versions.
* Make sure the private.py is installed in QtCore module.
* Build against Qt 4.7.
  - Add libqtwebkit-dev
  - Drop QtMultimedia module.
  - Add the QtDeclarative package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
'''Test case for duck punching new implementations of C++ virtual methods into object instances.'''
 
4
 
 
5
import unittest
 
6
import types
 
7
from PySide.QtCore import QObject, QEvent
 
8
from helper import UsesQCoreApplication
 
9
 
 
10
class Duck(QObject):
 
11
    def __init__(self):
 
12
        QObject.__init__(self)
 
13
    def childEvent(self, event):
 
14
        QObject.childEvent(self, event)
 
15
 
 
16
class TestDuckPunchingOnQObjectInstance(UsesQCoreApplication):
 
17
    '''Test case for duck punching new implementations of C++ virtual methods into object instances.'''
 
18
 
 
19
    def setUp(self):
 
20
        #Acquire resources
 
21
        self.duck_childEvent_called = False
 
22
        UsesQCoreApplication.setUp(self)
 
23
 
 
24
    def tearDown(self):
 
25
        #Release resources
 
26
        del self.duck_childEvent_called
 
27
        UsesQCoreApplication.tearDown(self)
 
28
 
 
29
 
 
30
    def testChildEventMonkeyPatch(self):
 
31
        #Test if the new childEvent injected on QObject instance is called from C++
 
32
        parent = QObject()
 
33
        def childEvent(obj, event):
 
34
            self.duck_childEvent_called = True
 
35
            QObject.childEvent(obj, event)
 
36
        parent.childEvent = types.MethodType(childEvent, parent, QObject)
 
37
        child = 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
 
46
 
 
47
    def testChildEventMonkeyPatchWithInheritance(self):
 
48
        #Test if the new childEvent injected on a QObject's extension class instance is called from C++
 
49
        parent = Duck()
 
50
        def childEvent(obj, event):
 
51
            QObject.childEvent(obj, event)
 
52
            self.duck_childEvent_called = True
 
53
        child = QObject()
 
54
        child.setParent(parent)
 
55
        parent.childEvent = types.MethodType(childEvent, parent, QObject)
 
56
        child = 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
 
65
 
 
66
if __name__ == '__main__':
 
67
    unittest.main()
 
68