1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''Test cases for QVariant with QtGui types'''
import unittest
from PySide.QtCore import *
from PySide.QtGui import *
from helper import UsesQApplication
class Dummy(object):
pass
class QVariantTypeName(unittest.TestCase):
def testQPen(self):
obj = QVariant(QPen(Qt.red))
self.assertEqual('QPen', obj.typeName())
def testQColor(self):
obj = QVariant(QColor(Qt.red))
self.assertEqual('QColor', obj.typeName())
def testGlobalColor(self):
obj = QVariant(Qt.red)
# XXX: PyQt4 returns int instead of QColor like the C++ version
self.assertEqual('QColor', obj.typeName())
def testEnums(self):
obj = QVariant(Qt.SolidLine)
self.assertEqual('int', obj.typeName())
class QVariantQColorImplicitlyConvertion(unittest.TestCase):
def testConversions(self):
c1 = QColor(0, 0, 0)
v = QVariant(c1)
c2 = QColor(v)
self.assertEqual(c1, c2)
class QVariantQPixmap(UsesQApplication):
'''QVariant(QPixmap)'''
def testBasic(self):
'''QVariant(QPixmap)'''
pixmap = QPixmap(10,20)
pixmap.fill(Qt.blue)
variant = QVariant(pixmap)
self.assertEqual(variant.typeName(), "QPixmap")
def testQObject(self):
obj = QObject()
v = QVariant(obj)
self.assertEqual(v.typeName(), 'QObject*')
def testQWidget(self):
obj = QWidget()
v = QVariant(obj)
self.assertEqual(v.typeName(), 'QWidget*')
class MyColor(QColor):
pass
class MyPrimitive(int):
pass
class QVariantMess(unittest.TestCase):
def testMyColor(self):
c1 = MyColor()
v = QVariant(c1)
self.assertEqual(type(v.toPyObject()), MyColor)
def testMyPrimitive(self):
p = MyPrimitive(3)
v = QVariant(p)
self.assertNotEqual(v.type(), QVariant.Int)
self.assertTrue(v.toPyObject() is p)
def testMatrix2x2(self):
m = QMatrix2x2()
v = QVariant(m)
self.assertEqual('QMatrix2x2', v.typeName())
if __name__ == '__main__':
unittest.main()
|