diff options
author | Lauro Neto <lauro.neto@openbossa.org> | 2010-03-06 21:49:02 -0300 |
---|---|---|
committer | Lauro Neto <lauro.neto@openbossa.org> | 2010-03-22 15:02:01 -0300 |
commit | 737952531b367f4adc3bc73d326f350e58948634 (patch) | |
tree | a41b4766d2ccc75eeb57032f8250d5bbf1ef7043 /tests/qtcore/qvariant_pyobject_test.py | |
parent | 1356f832ae7a51435e904218014261072099d3c2 (diff) |
Isolate QVariant tests that use pure python objs
Diffstat (limited to 'tests/qtcore/qvariant_pyobject_test.py')
-rw-r--r-- | tests/qtcore/qvariant_pyobject_test.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/qtcore/qvariant_pyobject_test.py b/tests/qtcore/qvariant_pyobject_test.py new file mode 100644 index 000000000..82da5556f --- /dev/null +++ b/tests/qtcore/qvariant_pyobject_test.py @@ -0,0 +1,71 @@ + +'''QVariant handling of PyObjects, including pure-python or derived from Qt''' + +import unittest + +from PySide.QtCore import QSize, QVariant, QString + + +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(), QString)) + self.assertEqual(d, obj.toPyObject()) + + +if __name__ == '__main__': + unittest.main() |