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

« back to all changes in this revision

Viewing changes to tests/qtcore/qvariant_pyobject_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
 
 
2
 
'''QVariant handling of PyObjects, including pure-python or derived from Qt'''
3
 
 
4
 
import unittest
5
 
 
6
 
from PySide.QtCore import QSize, QVariant, QString
7
 
 
8
 
 
9
 
class Dummy(object):
10
 
    '''Pure python sample class'''
11
 
    pass
12
 
 
13
 
 
14
 
class MySize(QSize):
15
 
    '''Extended class'''
16
 
    pass
17
 
 
18
 
 
19
 
class QVariantPurePython(unittest.TestCase):
20
 
    '''QVariant + pure python classes'''
21
 
 
22
 
    def testTypeNamePythonClasses(self):
23
 
        '''QVariant of pure python classes'''
24
 
        d = Dummy()
25
 
        obj = QVariant(d)
26
 
        # inherited type name from other binding
27
 
        self.assertEqual('PyQt_PyObject', obj.typeName())
28
 
 
29
 
 
30
 
class QVariantInheritedPython(unittest.TestCase):
31
 
    '''QVariant + classes inherited from C++'''
32
 
 
33
 
    # This works only on PyQt4 4.5.x, not on PyQt4 4.4.x or PySide
34
 
    def testSubClassConvertion(self):
35
 
        '''QVariant(QSize subclass) type is UserType and returns same object'''
36
 
        mysize = MySize(0, 0)
37
 
        variant = QVariant(mysize)
38
 
 
39
 
        self.assertEqual(variant.type(), QVariant.UserType)
40
 
        self.assertTrue(variant.toPyObject() is mysize)
41
 
 
42
 
 
43
 
class QVariantToPyObject(unittest.TestCase):
44
 
    '''QVariant.toPyObject tests'''
45
 
 
46
 
    def testQVariantPyList(self):
47
 
        '''QVariant(QVariantList).toPyObject() equals original list'''
48
 
        obj = QVariant([1, 'two', 3])
49
 
        self.assertEqual(obj.toPyObject(), [1, 'two', 3])
50
 
 
51
 
    def testPyObject(self):
52
 
        '''QVariant(pure PyObject).toPyObject should return the same object'''
53
 
        d = Dummy()
54
 
        obj = QVariant(d)
55
 
        self.assert_(d is obj.toPyObject())
56
 
 
57
 
    def testNoneToPyObject(self):
58
 
        '''QVariant().toPyObject() should return None'''
59
 
        obj = QVariant()
60
 
        self.assertEqual(None, obj.toPyObject())
61
 
 
62
 
    def testQStringToPyObject(self):
63
 
        '''QVariant(python string).toPyObject() return an equal QString'''
64
 
        d = 'abc'
65
 
        obj = QVariant('abc')
66
 
        self.assert_(isinstance(obj.toPyObject(), QString))
67
 
        self.assertEqual(d, obj.toPyObject())
68
 
 
69
 
 
70
 
if __name__ == '__main__':
71
 
    unittest.main()