Removed QVariant from PySide.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Marcelo Lira <marcelo.lira@openbossa.org>
This commit is contained in:
parent
d8a192b5e1
commit
1b6337d8b4
18 changed files with 170 additions and 601 deletions
|
|
@ -55,8 +55,6 @@ PYSIDE_TEST(qtimer_singleshot_test.py)
|
|||
PYSIDE_TEST(qtimer_timeout_test.py)
|
||||
PYSIDE_TEST(qtnamespace_test.py)
|
||||
PYSIDE_TEST(qurl_test.py)
|
||||
PYSIDE_TEST(qvariant_pyobject_test.py)
|
||||
PYSIDE_TEST(qvariant_test.py)
|
||||
PYSIDE_TEST(static_method_test.py)
|
||||
PYSIDE_TEST(static_protected_methods_test.py)
|
||||
PYSIDE_TEST(thread_signals_test.py)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
#!/usr/bin/python
|
||||
import unittest
|
||||
from sys import getrefcount
|
||||
from PySide.QtCore import QObject, SIGNAL, QCoreApplication, QTimer, QVariant
|
||||
from PySide.QtCore import QState, QFinalState, QStateMachine, QParallelAnimationGroup, QEventTransition
|
||||
from PySide.QtCore import *
|
||||
|
||||
def addStates(transition):
|
||||
sx = QState()
|
||||
|
|
@ -19,11 +18,11 @@ class QAbstractTransitionTest(unittest.TestCase):
|
|||
app = QCoreApplication([])
|
||||
|
||||
o = QObject()
|
||||
o.setProperty("text", QVariant("INdT"))
|
||||
o.setProperty("text", "INdT")
|
||||
|
||||
machine = QStateMachine()
|
||||
s1 = QState()
|
||||
s1.assignProperty(o, "text", QVariant("Rocks"))
|
||||
s1.assignProperty(o, "text", "Rocks")
|
||||
|
||||
s2 = QFinalState()
|
||||
t = s1.addTransition(o, SIGNAL("change()"), s2)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python
|
||||
import unittest
|
||||
from PySide.QtCore import QObject, QState, QFinalState, SIGNAL, QCoreApplication, QTimer, QStateMachine, QSignalTransition, QVariant, QParallelAnimationGroup, QSequentialAnimationGroup, QAnimationGroup
|
||||
from PySide.QtCore import *
|
||||
|
||||
class QAnimationGroupTest(unittest.TestCase):
|
||||
|
||||
|
|
|
|||
|
|
@ -5,16 +5,24 @@ import unittest
|
|||
|
||||
from PySide.QtCore import *
|
||||
|
||||
class Dummy(object):
|
||||
'''Pure python sample class'''
|
||||
pass
|
||||
|
||||
class MySize(QSize):
|
||||
'''Extended class'''
|
||||
pass
|
||||
|
||||
class PropertyCase(unittest.TestCase):
|
||||
'''Test case for QObject properties'''
|
||||
|
||||
def testObjectNameProperty(self):
|
||||
#QObject.setProperty() for existing C++ property
|
||||
obj = QObject()
|
||||
self.assert_(obj.setProperty('objectName', QVariant('dummy')))
|
||||
self.assert_(obj.setProperty('objectName', 'dummy'))
|
||||
self.assertEqual(obj.objectName(), 'dummy')
|
||||
|
||||
self.assert_(obj.setProperty('objectName', QVariant('foobar')))
|
||||
self.assert_(obj.setProperty('objectName', 'foobar'))
|
||||
self.assertEqual(obj.objectName(), 'foobar')
|
||||
|
||||
def testDynamicProperty(self):
|
||||
|
|
@ -22,50 +30,66 @@ class PropertyCase(unittest.TestCase):
|
|||
obj = QObject()
|
||||
|
||||
# Should return false when creating a new dynamic property
|
||||
self.assert_(not obj.setProperty('dummy', QVariant('mydata')))
|
||||
self.assert_(not obj.setProperty('dummy', 'mydata'))
|
||||
prop = obj.property('dummy')
|
||||
self.assert_(isinstance(prop, QVariant))
|
||||
self.assert_(prop.isValid())
|
||||
self.assertEqual(obj.property('dummy').toString(), 'mydata')
|
||||
self.assert_(isinstance(prop, unicode))
|
||||
self.assertEqual(obj.property('dummy'), 'mydata')
|
||||
|
||||
self.assert_(not obj.setProperty('dummy', QVariant('zigzag')))
|
||||
self.assert_(not obj.setProperty('dummy', 'zigzag'))
|
||||
prop = obj.property('dummy')
|
||||
self.assert_(isinstance(prop, QVariant))
|
||||
self.assert_(prop.isValid())
|
||||
self.assertEqual(obj.property('dummy').toString(), 'zigzag')
|
||||
self.assert_(isinstance(prop, unicode))
|
||||
self.assertEqual(obj.property('dummy'), 'zigzag')
|
||||
|
||||
self.assert_(not obj.setProperty('dummy', QVariant(42)))
|
||||
self.assert_(not obj.setProperty('dummy', 42))
|
||||
prop = obj.property('dummy')
|
||||
self.assert_(isinstance(prop, QVariant))
|
||||
self.assert_(prop.isValid())
|
||||
self.assert_(isinstance(prop, int))
|
||||
# QVariant.toInt has a bool* arg in C++, so returns a tuple
|
||||
self.assertEqual(obj.property('dummy').toInt(), (42, True))
|
||||
self.assertEqual(obj.property('dummy'), 42)
|
||||
|
||||
def testStringProperty(self):
|
||||
obj = QObject()
|
||||
self.assert_(not obj.setProperty('dummy', 'data'))
|
||||
prop = obj.property('dummy')
|
||||
|
||||
self.assert_(isinstance(prop, QVariant))
|
||||
self.assert_(prop.isValid())
|
||||
self.assertEqual(obj.property('dummy').toString(), 'data')
|
||||
self.assert_(isinstance(prop, unicode))
|
||||
self.assertEqual(obj.property('dummy'), 'data')
|
||||
|
||||
def testImplicitQVariantProperty(self):
|
||||
obj = QObject()
|
||||
self.assert_(not obj.setProperty('dummy', 'data'))
|
||||
prop = obj.property('dummy')
|
||||
|
||||
self.assert_(isinstance(prop, QVariant))
|
||||
self.assert_(prop.isValid())
|
||||
self.assertEqual(obj.property('dummy').toString(), 'data')
|
||||
self.assert_(isinstance(prop, unicode))
|
||||
self.assertEqual(obj.property('dummy'), 'data')
|
||||
|
||||
def testInvalidProperty(self):
|
||||
#QObject.property() for invalid properties
|
||||
obj = QObject()
|
||||
|
||||
prop = obj.property('dummy')
|
||||
self.assert_(not prop.isValid())
|
||||
self.assertEqual(prop, None)
|
||||
|
||||
def testTypeNamePythonClasses(self):
|
||||
'''QVariant of pure python classes'''
|
||||
d = Dummy()
|
||||
obj = QObject()
|
||||
obj.setProperty('foo', d)
|
||||
# inherited type name from other binding
|
||||
self.assertEqual(obj.property('foo'), d)
|
||||
|
||||
def testQVariantPyList(self):
|
||||
'''QVariant(QVariantList).toPyObject() equals original list'''
|
||||
obj = QObject()
|
||||
obj.setProperty('foo', [1, 'two', 3])
|
||||
self.assertEqual(obj.property('foo'), [1, 'two', 3])
|
||||
|
||||
def testSubClassConvertion(self):
|
||||
'''QVariant(QSize subclass) type is UserType and returns same object'''
|
||||
mysize = MySize(0, 0)
|
||||
obj = QObject()
|
||||
obj.setProperty('foo', mysize)
|
||||
|
||||
self.assertTrue(obj.property('foo') is mysize)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python
|
||||
import unittest
|
||||
from PySide.QtCore import QObject, QState, QFinalState, SIGNAL, QCoreApplication, QTimer, QStateMachine, QSignalTransition, QVariant
|
||||
from PySide.QtCore import *
|
||||
|
||||
|
||||
class QStateTest(unittest.TestCase):
|
||||
|
|
@ -8,11 +8,11 @@ class QStateTest(unittest.TestCase):
|
|||
app = QCoreApplication([])
|
||||
|
||||
o = QObject()
|
||||
o.setProperty("text", QVariant("INdT"))
|
||||
o.setProperty("text", "INdT")
|
||||
|
||||
machine = QStateMachine()
|
||||
s1 = QState()
|
||||
s1.assignProperty(o, "text", QVariant("Rocks"));
|
||||
s1.assignProperty(o, "text", "Rocks");
|
||||
|
||||
s2 = QFinalState()
|
||||
t = s1.addTransition(o, SIGNAL("change()"), s2);
|
||||
|
|
@ -28,7 +28,7 @@ class QStateTest(unittest.TestCase):
|
|||
QTimer.singleShot(100, app.quit)
|
||||
app.exec_()
|
||||
|
||||
txt = o.property("text").toString()
|
||||
txt = o.property("text")
|
||||
self.assert_(txt, "Rocks")
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
|
||||
'''QVariant handling of PyObjects, including pure-python or derived from Qt'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import *
|
||||
|
||||
|
||||
class Dummy(object):
|
||||
'''Pure python sample class'''
|
||||
pass
|
||||
|
||||
class MySize(QSize):
|
||||
'''Extended class'''
|
||||
pass
|
||||
|
||||
class QVariantPurePython(unittest.TestCase):
|
||||
'''QVariant + pure python classes'''
|
||||
|
||||
def testTypeNamePythonClasses(self):
|
||||
'''QVariant of pure python classes'''
|
||||
d = Dummy()
|
||||
obj = QVariant(d)
|
||||
# inherited type name from other binding
|
||||
self.assertEqual('PyQt_PyObject', obj.typeName())
|
||||
|
||||
class QVariantInheritedPython(unittest.TestCase):
|
||||
'''QVariant + classes inherited from C++'''
|
||||
|
||||
# This works only on PyQt4 4.5.x, not on PyQt4 4.4.x or PySide
|
||||
def testSubClassConvertion(self):
|
||||
'''QVariant(QSize subclass) type is UserType and returns same object'''
|
||||
mysize = MySize(0, 0)
|
||||
variant = QVariant(mysize)
|
||||
|
||||
self.assertEqual(variant.type(), QVariant.UserType)
|
||||
self.assertTrue(variant.toPyObject() is mysize)
|
||||
|
||||
|
||||
class QVariantToPyObject(unittest.TestCase):
|
||||
'''QVariant.toPyObject tests'''
|
||||
|
||||
def testQVariantPyList(self):
|
||||
'''QVariant(QVariantList).toPyObject() equals original list'''
|
||||
obj = QVariant([1, 'two', 3])
|
||||
self.assertEqual(obj.toPyObject(), [1, 'two', 3])
|
||||
|
||||
def testPyObject(self):
|
||||
'''QVariant(pure PyObject).toPyObject should return the same object'''
|
||||
d = Dummy()
|
||||
obj = QVariant(d)
|
||||
self.assert_(d is obj.toPyObject())
|
||||
|
||||
def testNoneToPyObject(self):
|
||||
'''QVariant().toPyObject() should return None'''
|
||||
obj = QVariant()
|
||||
self.assertEqual(None, obj.toPyObject())
|
||||
|
||||
def testQStringToPyObject(self):
|
||||
'''QVariant(python string).toPyObject() return an equal QString'''
|
||||
d = 'abc'
|
||||
obj = QVariant('abc')
|
||||
self.assert_(isinstance(obj.toPyObject(), unicode))
|
||||
self.assertEqual(d, obj.toPyObject())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
'''Test cases for QVariant'''
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from PySide.QtCore import *
|
||||
|
||||
|
||||
class QVariantToNumber(unittest.TestCase):
|
||||
'''QVariant of number types'''
|
||||
|
||||
def testToNumberInt(self):
|
||||
'''QVariant(int).toInt()'''
|
||||
obj = QVariant('37')
|
||||
self.assertEqual((37, True), obj.toInt())
|
||||
|
||||
def testToNumberLongLong(self):
|
||||
'''QVariant(int).toLongLong()'''
|
||||
obj = QVariant('37')
|
||||
self.assertEqual((37, True), obj.toLongLong())
|
||||
|
||||
def testToNumberUInt(self):
|
||||
'''QVariant(int).toUInt()'''
|
||||
obj = QVariant('37')
|
||||
self.assertEqual((37, True), obj.toUInt())
|
||||
|
||||
def testToNumberUIntNegative(self):
|
||||
'''QVariant(negative int).toUInt()'''
|
||||
obj = QVariant('-37')
|
||||
self.assert_(not obj.toUInt()[1])
|
||||
|
||||
def testToNumberULongLong(self):
|
||||
'''QVariant(int).toULongLong()'''
|
||||
obj = QVariant('37')
|
||||
self.assertEqual((37, True), obj.toULongLong())
|
||||
|
||||
def testToNumberULongLongNegative(self):
|
||||
'''QVariant(negative int).toULongLong()'''
|
||||
obj = QVariant('-37')
|
||||
self.assert_(not obj.toULongLong()[1])
|
||||
|
||||
def testToNumberFloat(self):
|
||||
'''QVariant(double).toFloat()'''
|
||||
obj = QVariant('37.109')
|
||||
self.assertEqual((37.109, True), obj.toDouble())
|
||||
|
||||
|
||||
class QVariantTypeName(unittest.TestCase):
|
||||
'''QVariant.typeName()'''
|
||||
|
||||
def testTypeNameString(self):
|
||||
'''QVariant(PyString).typeName()'''
|
||||
obj = QVariant('aaaa')
|
||||
self.assertEqual('QString', obj.typeName())
|
||||
|
||||
def testTypeNameInt(self):
|
||||
'''QVariant(int).typeName()'''
|
||||
obj = QVariant(34)
|
||||
self.assertEqual('int', obj.typeName())
|
||||
|
||||
def testTypeNameDouble(self):
|
||||
'''QVariant(double).typeName()'''
|
||||
obj = QVariant(3.14)
|
||||
self.assertEqual('double', obj.typeName())
|
||||
|
||||
def testTypeNameBool(self):
|
||||
'''QVariant(bool).typeName()'''
|
||||
obj = QVariant(True)
|
||||
self.assertEqual('bool', obj.typeName())
|
||||
|
||||
def testTypeNameQByteArray(self):
|
||||
'''QVariant(QByteArray).typeName()'''
|
||||
obj = QVariant(QByteArray('aaaa'))
|
||||
self.assertEqual('QByteArray', obj.typeName())
|
||||
|
||||
def testTypeNameNone(self):
|
||||
'''QVariant().typeName()'''
|
||||
obj = QVariant()
|
||||
self.assertEqual(None, obj.typeName())
|
||||
|
||||
def testTypeNameQVariantList(self):
|
||||
'''QVariant(QVariantList).typeName()'''
|
||||
obj = QVariant([1, 2, 3, 4])
|
||||
self.assertEqual('QVariantList', obj.typeName())
|
||||
|
||||
obj = QVariant([1.0, 2.2, 3.3, 4.2])
|
||||
self.assertEqual('QVariantList', obj.typeName())
|
||||
|
||||
obj = QVariant(['aaa', 'bbb', 'ccc', 'dddd'])
|
||||
self.assertEqual('QVariantList', obj.typeName())
|
||||
|
||||
class QVariantConstructor(unittest.TestCase):
|
||||
'''More qvariant constructions'''
|
||||
|
||||
def testCopyConstructor(self):
|
||||
'''QVariant copy constructor'''
|
||||
obj = QVariant(1)
|
||||
cpy = QVariant(obj)
|
||||
|
||||
self.assertEqual(obj.type(), cpy.type())
|
||||
|
||||
def testQStringConstructor(self):
|
||||
'''QVariant(PyString).type == QVariant.string'''
|
||||
obj = QVariant("PySide")
|
||||
self.assertEqual(obj.type(), QVariant.String)
|
||||
|
||||
def testQSizeConstructor(self):
|
||||
'''QVariant(QSize).type == QVariant.Size'''
|
||||
mysize = QSize(0, 0)
|
||||
variant = QVariant(mysize)
|
||||
|
||||
self.assertEqual(variant.type(), QVariant.Size)
|
||||
self.assertEqual(variant.toSize(), mysize)
|
||||
|
||||
def testToList(self):
|
||||
v = QVariant((1,2,3))
|
||||
self.assertEqual(v.toList(), (1, 2, 3))
|
||||
v = QVariant([0,1,2])
|
||||
self.assertEqual(v.toList(), [0, 1, 2])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -46,7 +46,6 @@ PYSIDE_TEST(qtabwidget_test.py)
|
|||
PYSIDE_TEST(qtextedit_test.py)
|
||||
PYSIDE_TEST(qtoolbar_test.py)
|
||||
PYSIDE_TEST(qtoolbox_test.py)
|
||||
PYSIDE_TEST(qvariant_test.py)
|
||||
PYSIDE_TEST(qwidget_setlayout_test.py)
|
||||
PYSIDE_TEST(qwidget_test.py TRUE) #Bug 237
|
||||
PYSIDE_TEST(reference_count_test.py)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import unittest
|
|||
|
||||
from sys import getrefcount
|
||||
from helper import UsesQApplication
|
||||
from PySide.QtCore import QAbstractTableModel, QVariant
|
||||
from PySide.QtCore import *
|
||||
from PySide.QtGui import QTableView
|
||||
|
||||
class TestModel(QAbstractTableModel):
|
||||
|
|
@ -15,7 +15,7 @@ class TestModel(QAbstractTableModel):
|
|||
def columnCount(self, parent):
|
||||
return 0
|
||||
def data(self, index, role):
|
||||
return QVariant()
|
||||
return None
|
||||
|
||||
class KeepReferenceTest(UsesQApplication):
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ from PySide.QtCore import *
|
|||
|
||||
class QPixmapTest(UsesQApplication):
|
||||
def testQVariantConstructor(self):
|
||||
obj = QObject()
|
||||
pixmap = QPixmap()
|
||||
v = QVariant(pixmap)
|
||||
pixmap_copy = QPixmap(v)
|
||||
obj.setProperty('foo', pixmap)
|
||||
self.assertEqual(type(obj.property('foo')), QPixmap)
|
||||
|
||||
def testQSizeConstructor(self):
|
||||
pixmap = QPixmap(QSize(10,20))
|
||||
|
|
@ -18,12 +19,6 @@ class QPixmapTest(UsesQApplication):
|
|||
def testQStringConstructor(self):
|
||||
pixmap = QPixmap("Testing!")
|
||||
|
||||
def testQVariantConstructor2(self):
|
||||
v = QVariant(QPixmap())
|
||||
pixmap2 = QPixmap(v)
|
||||
v = QVariant(QImage())
|
||||
pixmap2 = QPixmap(v)
|
||||
|
||||
def testQPixmapLoadFromDataWithQFile(self):
|
||||
f = QFile(os.path.join(os.path.dirname(__file__), 'sample.png'))
|
||||
self.assert_(f.open(QIODevice.ReadOnly))
|
||||
|
|
|
|||
|
|
@ -1,85 +0,0 @@
|
|||
#!/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()
|
||||
|
|
@ -39,16 +39,16 @@ class SqlDatabaseCreationDestructionAndQueries(unittest.TestCase):
|
|||
query.exec_("INSERT INTO person VALUES(101, 'George', 'Harrison')")
|
||||
query.prepare("INSERT INTO person (id, firstname, lastname) "
|
||||
"VALUES (:id, :firstname, :lastname)")
|
||||
query.bindValue(":id", QVariant(102))
|
||||
query.bindValue(":firstname", QVariant("John"))
|
||||
query.bindValue(":lastname", QVariant("Lennon"))
|
||||
query.bindValue(":id", 102)
|
||||
query.bindValue(":firstname", "John")
|
||||
query.bindValue(":lastname", "Lennon")
|
||||
query.exec_()
|
||||
|
||||
lastname = ''
|
||||
query.exec_("SELECT lastname FROM person where id=101")
|
||||
self.assertTrue(query.isActive())
|
||||
query.next()
|
||||
lastname = query.value(0).toString()
|
||||
lastname = query.value(0)
|
||||
self.assertEqual(lastname, 'Harrison')
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue