2
'''QVariant handling of PyObjects, including pure-python or derived from Qt'''
6
from PySide.QtCore import QSize, QVariant, QString
10
'''Pure python sample class'''
19
class QVariantPurePython(unittest.TestCase):
20
'''QVariant + pure python classes'''
22
def testTypeNamePythonClasses(self):
23
'''QVariant of pure python classes'''
26
# inherited type name from other binding
27
self.assertEqual('PyQt_PyObject', obj.typeName())
30
class QVariantInheritedPython(unittest.TestCase):
31
'''QVariant + classes inherited from C++'''
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'''
37
variant = QVariant(mysize)
39
self.assertEqual(variant.type(), QVariant.UserType)
40
self.assertTrue(variant.toPyObject() is mysize)
43
class QVariantToPyObject(unittest.TestCase):
44
'''QVariant.toPyObject tests'''
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])
51
def testPyObject(self):
52
'''QVariant(pure PyObject).toPyObject should return the same object'''
55
self.assert_(d is obj.toPyObject())
57
def testNoneToPyObject(self):
58
'''QVariant().toPyObject() should return None'''
60
self.assertEqual(None, obj.toPyObject())
62
def testQStringToPyObject(self):
63
'''QVariant(python string).toPyObject() return an equal QString'''
66
self.assert_(isinstance(obj.toPyObject(), QString))
67
self.assertEqual(d, obj.toPyObject())
70
if __name__ == '__main__':