diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/QtCore/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/QtCore/bug_332.py | 2 | ||||
-rw-r--r-- | tests/QtCore/bug_408.py | 28 | ||||
-rw-r--r-- | tests/QtCore/deepcopy_test.py | 79 | ||||
-rw-r--r-- | tests/QtCore/hash_test.py | 3 | ||||
-rw-r--r-- | tests/QtCore/qflags_test.py | 20 | ||||
-rw-r--r-- | tests/QtCore/qobject_parent_test.py | 11 | ||||
-rw-r--r-- | tests/QtGui/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/QtGui/bug_400.py | 26 | ||||
-rw-r--r-- | tests/QtGui/bug_416.py | 43 | ||||
-rw-r--r-- | tests/QtGui/deepcopy_test.py | 93 | ||||
-rw-r--r-- | tests/QtGui/qcolor_test.py | 15 | ||||
-rw-r--r-- | tests/QtGui/qlistwidget_test.py | 9 | ||||
-rw-r--r-- | tests/QtUiTools/bug_376.py | 2 | ||||
-rw-r--r-- | tests/QtUiTools/bug_392.py | 30 | ||||
-rw-r--r-- | tests/QtUiTools/pycustomwidget.ui | 36 | ||||
-rw-r--r-- | tests/QtUiTools/pycustomwidget2.ui | 48 |
17 files changed, 444 insertions, 8 deletions
diff --git a/tests/QtCore/CMakeLists.txt b/tests/QtCore/CMakeLists.txt index 30f3ff697..36b8776f5 100644 --- a/tests/QtCore/CMakeLists.txt +++ b/tests/QtCore/CMakeLists.txt @@ -1,7 +1,9 @@ PYSIDE_TEST(bug_278_test.py) PYSIDE_TEST(bug_332.py) +PYSIDE_TEST(bug_408.py) PYSIDE_TEST(blocking_signals_test.py) PYSIDE_TEST(child_event_test.py) +PYSIDE_TEST(deepcopy_test.py) PYSIDE_TEST(deletelater_test.py) PYSIDE_TEST(duck_punching_test.py) PYSIDE_TEST(hash_test.py) diff --git a/tests/QtCore/bug_332.py b/tests/QtCore/bug_332.py index ae087421b..32ff414ad 100644 --- a/tests/QtCore/bug_332.py +++ b/tests/QtCore/bug_332.py @@ -14,3 +14,5 @@ class TestBug(unittest.TestCase): l.tryLock() # this cause a assertion +if __name__ == '__main__': + unittest.main() diff --git a/tests/QtCore/bug_408.py b/tests/QtCore/bug_408.py new file mode 100644 index 000000000..5827e56d6 --- /dev/null +++ b/tests/QtCore/bug_408.py @@ -0,0 +1,28 @@ +import unittest + +from PySide.QtCore import * + +class MyDevice(QIODevice): + def __init__(self, txt): + QIODevice.__init__(self) + self.txt = txt + self.ptr = 0 + + def readData(self, size): + size = min(len(self.txt) - self.ptr, size) + retval = self.txt[self.ptr:size] + self.ptr += size + return retval + +class QIODeviceTest(unittest.TestCase): + + def testIt(self): + device = MyDevice("hello world\nhello again") + device.open(QIODevice.ReadOnly) + + s = QTextStream(device) + self.assertEqual(s.readLine(), "hello world") + self.assertEqual(s.readLine(), "hello again") + +if __name__ == '__main__': + unittest.main() diff --git a/tests/QtCore/deepcopy_test.py b/tests/QtCore/deepcopy_test.py new file mode 100644 index 000000000..d44017747 --- /dev/null +++ b/tests/QtCore/deepcopy_test.py @@ -0,0 +1,79 @@ + +import unittest +from copy import deepcopy + +from PySide.QtCore import QByteArray, QDate, QDateTime, QTime, QLine, QLineF +from PySide.QtCore import Qt, QSize, QSizeF, QRect, QRectF, QDir, QPoint, QPointF +from PySide.QtCore import QUuid + +class DeepCopyHelper: + def testCopy(self): + copy = deepcopy([self.original])[0] + self.assert_(copy is not self.original) + self.assertEqual(copy, self.original) + +class QByteArrayDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QByteArray('the quick brown fox jumps over the lazy dog') + + +class QDateDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QDate(2010, 11, 22) + + +class QTimeDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QTime(11, 37, 55, 692) + + +class QDateTimeDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QDateTime(2010, 5, 18, 10, 24, 45, 223, Qt.LocalTime) + + +class QSizeDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QSize(42, 190) + + +class QSizeFDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QSizeF(42.7, 190.2) + + +class QRectDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QRect(100, 200, 300, 400) + + +class QRectFDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QRectF(100.33, 200.254, 300.321, 400.123) + +class QLineDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QLine(1, 2, 3, 4) + +class QLineFDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QLineF(1.1, 2.2, 3.3, 4.4) + +class QPointDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QPoint(1, 2) + +class QPointFDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QPointF(1.1, 2.2) + +class QDirDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QDir("./") + +class QUuiCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QUuid("67C8770B-44F1-410A-AB9A-F9B5446F13EE") + +if __name__ == '__main__': + unittest.main() diff --git a/tests/QtCore/hash_test.py b/tests/QtCore/hash_test.py index 6ff24f39f..bf02176e0 100644 --- a/tests/QtCore/hash_test.py +++ b/tests/QtCore/hash_test.py @@ -10,16 +10,19 @@ class HashTest(unittest.TestCase): qdatetime = QDateTime.currentDateTime() qtime = QTime.currentTime() qurl = QUrl("http://www.pyside.org") + qpoint = QPoint(12, 42) myHash[qdate] = "QDate" myHash[qdatetime] = "QDateTime" myHash[qtime] = "QTime" myHash[qurl] = "QUrl" + myHash[qpoint] = "QPoint" self.assertEqual(myHash[qdate], "QDate") self.assertEqual(myHash[qdatetime], "QDateTime") self.assertEqual(myHash[qtime], "QTime") self.assertEqual(myHash[qurl], "QUrl") + self.assertEqual(myHash[qpoint], "QPoint") def testQPointHash(self): p1 = QPoint(12, 34) diff --git a/tests/QtCore/qflags_test.py b/tests/QtCore/qflags_test.py index 3ecaa2f2f..8c088d69b 100644 --- a/tests/QtCore/qflags_test.py +++ b/tests/QtCore/qflags_test.py @@ -56,11 +56,31 @@ class QFlagOperatorTest(unittest.TestCase): flag_type = (flags & Qt.WindowType_Mask) self.assertEqual(flag_type, Qt.Window) + def testOperatorBetweenFlags(self): + '''QFlags & QFlags''' + flags = Qt.NoItemFlags | Qt.ItemIsUserCheckable + newflags = Qt.NoItemFlags | Qt.ItemIsUserCheckable + self.assert_(flags & newflags) + + def testOperatorDifferentOrder(self): + '''Different ordering of arguments''' + flags = Qt.NoItemFlags | Qt.ItemIsUserCheckable + self.assertEqual(flags | Qt.ItemIsEnabled, Qt.ItemIsEnabled | flags) + class QFlagsOnQVariant(unittest.TestCase): def testQFlagsOnQVariant(self): o = QObject() o.setProperty("foo", QIODevice.ReadOnly | QIODevice.WriteOnly) self.assertEqual(type(o.property("foo")), int) +class QFlagsWrongType(unittest.TestCase): + def testWrongType(self): + '''Wrong type passed to QFlags binary operators''' + self.assertRaises(TypeError, lambda :Qt.NoItemFlags | '43') + self.assertRaises(TypeError, lambda :Qt.NoItemFlags & '43') + self.assertRaises(TypeError, lambda :'jabba' & Qt.NoItemFlags) + self.assertRaises(TypeError, lambda :'hut' & Qt.NoItemFlags) + self.assertRaises(TypeError, lambda :Qt.NoItemFlags & QObject()) + if __name__ == '__main__': unittest.main() diff --git a/tests/QtCore/qobject_parent_test.py b/tests/QtCore/qobject_parent_test.py index 4699fc60c..eb8cae2d8 100644 --- a/tests/QtCore/qobject_parent_test.py +++ b/tests/QtCore/qobject_parent_test.py @@ -71,6 +71,17 @@ class ParentCase(unittest.TestCase): for i, child in enumerate(children): self.assertEqual(child, parent.findChild(QObject, name % i)) + def testFindChildWithoutName(self): + parent = QObject() + name = 'object%d' + children = [QObject(parent) for i in range(20)] + + for i, child in enumerate(children): + child.setObjectName(name % i) + + child = parent.findChild(QObject) + self.assert_(isinstance(child, QObject)) + def testFindChildren(self): #QObject.findChildren() with all QObject parent = QObject() diff --git a/tests/QtGui/CMakeLists.txt b/tests/QtGui/CMakeLists.txt index 350948bf3..21aa7690d 100644 --- a/tests/QtGui/CMakeLists.txt +++ b/tests/QtGui/CMakeLists.txt @@ -1,6 +1,7 @@ #Keep this in alphabetical sort PYSIDE_TEST(api2_test.py) +PYSIDE_TEST(add_action_test.py) PYSIDE_TEST(bug_172.py) PYSIDE_TEST(bug_243.py) PYSIDE_TEST(bug_300_test.py) @@ -10,8 +11,10 @@ PYSIDE_TEST(bug_338.py) PYSIDE_TEST(bug_363.py) PYSIDE_TEST(bug_367.py) PYSIDE_TEST(bug_389.py) -PYSIDE_TEST(add_action_test.py) +PYSIDE_TEST(bug_400.py) +PYSIDE_TEST(bug_416.py) PYSIDE_TEST(customproxywidget_test.py) +PYSIDE_TEST(deepcopy_test.py) PYSIDE_TEST(float_to_int_implicit_conversion_test.py) PYSIDE_TEST(grandparent_method_test.py) PYSIDE_TEST(hashabletype_test.py) diff --git a/tests/QtGui/bug_400.py b/tests/QtGui/bug_400.py new file mode 100644 index 000000000..0038a3e62 --- /dev/null +++ b/tests/QtGui/bug_400.py @@ -0,0 +1,26 @@ +''' Test bug 389: http://bugs.openbossa.org/show_bug.cgi?id=389''' + +import unittest +from helper import UsesQApplication +from PySide.QtGui import QTreeWidgetItemIterator, QTreeWidgetItem, QTreeWidget + +class BugTest(UsesQApplication): + def testCase(self): + treeWidget = QTreeWidget() + treeWidget.setColumnCount(1) + items = [] + for i in range(10): + items.append(QTreeWidgetItem(None, ["item: %i" % i])) + + treeWidget.insertTopLevelItems(0, items); + _iter = QTreeWidgetItemIterator(treeWidget) + index = 0 + while(_iter.value()): + item = _iter.value() + self.assert_(item is items[index]) + index += 1 + _iter += 1 + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/QtGui/bug_416.py b/tests/QtGui/bug_416.py new file mode 100644 index 000000000..20b8d0c12 --- /dev/null +++ b/tests/QtGui/bug_416.py @@ -0,0 +1,43 @@ +#!/usr/bin/python + +import unittest +from helper import TimedQApplication +from PySide.QtCore import QSignalTransition, QState, Qt, QStateMachine +from PySide.QtGui import QCheckBox + +class CheckedTransition(QSignalTransition): + def __init__(self, check): + QSignalTransition.__init__(self, check.stateChanged[int]) + self.eventTested = False + + def eventTest(self, event): + self.eventTested = True + if not QSignalTransition.eventTest(self, event): + return False + return event.arguments()[0] == Qt.Checked + +class TestBug(TimedQApplication): + def testCase(self): + check = QCheckBox() + check.setTristate(True) + + s1 = QState() + s2 = QState() + + t1 = CheckedTransition(check) + t1.setTargetState(s2) + s1.addTransition(t1) + + machine = QStateMachine() + machine.addState(s1) + machine.addState(s2) + machine.setInitialState(s1) + machine.start() + + check.stateChanged[int].emit(1) + check.show() + self.app.exec_() + self.assert_(t1.eventTested) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/QtGui/deepcopy_test.py b/tests/QtGui/deepcopy_test.py new file mode 100644 index 000000000..2f8f7deb7 --- /dev/null +++ b/tests/QtGui/deepcopy_test.py @@ -0,0 +1,93 @@ + +import unittest +from copy import deepcopy + +from PySide.QtCore import QPoint +from PySide.QtGui import QMatrix +from PySide.QtGui import QMatrix2x2, QMatrix2x3, QMatrix2x4 +from PySide.QtGui import QMatrix3x2, QMatrix3x3, QMatrix3x4 +from PySide.QtGui import QMatrix4x2, QMatrix4x3, QMatrix4x4 +from PySide.QtGui import QVector2D, QVector3D, QVector4D +from PySide.QtGui import QColor, QTransform, QKeySequence, QQuaternion +from PySide.QtGui import QPolygon + +class DeepCopyHelper: + def testCopy(self): + copy = deepcopy([self.original])[0] + self.assert_(copy is not self.original) + self.assertEqual(copy, self.original) + +class QColorDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QColor("red") + +class QTransformDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QTransform(1, 2, 3, 4, 5, 6, 7, 8) + +class QKeySequenceDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QKeySequence("Ctrl+P") + +class QQuaternionDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QQuaternion(1, 2, 3, 4) + +class QVector2DDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QVector2D(1, 2) + +class QVector3DDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QVector3D(1, 2, 3) + +class QVector4DDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QVector4D(1, 2, 3, 4) + +class QPolygonDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QPolygon([QPoint(1, 2), QPoint(3, 4), QPoint(5, 6)]) + +class QMatrixDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QMatrix(1, 2, 3, 4, 5, 6) + +class QMatrix2x2DeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QMatrix2x2([1, 2, 3, 4]) + +class QMatrix2x3DeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QMatrix2x3([1, 2, 3, 4, 5, 6]) + +class QMatrix2x4DeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QMatrix2x4([1, 2, 3, 4, 5, 6, 7, 8]) + +class QMatrix3x2DeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QMatrix3x2([1, 2, 3, 4, 5, 6]) + +class QMatrix3x3DeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QMatrix3x3([1, 2, 3, 4, 5, 6, 7, 8, 9]) + +class QMatrix3x4DeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QMatrix3x4([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) + +class QMatrix4x2DeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QMatrix4x2([1, 2, 3, 4, 5, 6, 7, 8]) + +class QMatrix4x3DeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QMatrix4x3([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) + +class QMatrix4x4DeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QMatrix4x4([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/QtGui/qcolor_test.py b/tests/QtGui/qcolor_test.py index 3c2f11ba0..a636ad6c1 100644 --- a/tests/QtGui/qcolor_test.py +++ b/tests/QtGui/qcolor_test.py @@ -64,5 +64,20 @@ class QColorEqualGlobalColor(unittest.TestCase): self.assertEqual(QColor(255, 0, 0), Qt.red) +class QColorCopy(unittest.TestCase): + + def testDeepCopy(self): + '''QColor deepcopy''' + + from copy import deepcopy + + original = QColor(0, 0, 255) + copy = deepcopy([original])[0] + + self.assert_(original is not copy) + self.assertEqual(original, copy) + del original + self.assertEqual(copy, QColor(0, 0, 255)) + if __name__ == '__main__': unittest.main() diff --git a/tests/QtGui/qlistwidget_test.py b/tests/QtGui/qlistwidget_test.py index b473c61a4..16c919bdc 100644 --- a/tests/QtGui/qlistwidget_test.py +++ b/tests/QtGui/qlistwidget_test.py @@ -41,6 +41,15 @@ class QListWidgetTest(UsesQApplication): self.assert_(sys.getrefcount(i), 2) del i + def testIt(self): + lst = QtGui.QListWidget() + lst.show() + slot = lambda : lst.removeItemWidget(lst.currentItem()) + lst.addItem(QtGui.QListWidgetItem("foo")) + QtCore.QTimer.singleShot(0, slot) + QtCore.QTimer.singleShot(0, lst.close) + self.app.exec_() + self.assertEqual(lst.count(), 1) if __name__ == '__main__': unittest.main() diff --git a/tests/QtUiTools/bug_376.py b/tests/QtUiTools/bug_376.py index 2bd6b5ca2..054a02036 100644 --- a/tests/QtUiTools/bug_376.py +++ b/tests/QtUiTools/bug_376.py @@ -12,7 +12,7 @@ class BugTest(UsesQApplication): filePath = os.path.join(os.path.dirname(__file__), 'test.ui') result = loader.load(filePath, w) - self.assertEqual(type(result.child_object), QtGui.QFrame) + self.assert_(isinstance(result.child_object, QtGui.QFrame)) if __name__ == '__main__': unittest.main() diff --git a/tests/QtUiTools/bug_392.py b/tests/QtUiTools/bug_392.py index 5717d457c..69817ff9f 100644 --- a/tests/QtUiTools/bug_392.py +++ b/tests/QtUiTools/bug_392.py @@ -2,9 +2,16 @@ import unittest import os from helper import UsesQApplication -from PySide import QtCore, QtGui, QtDeclarative +from PySide import QtGui from PySide.QtUiTools import QUiLoader +class MyWidget(QtGui.QComboBox): + def __init__(self, parent=None): + QtGui.QComboBox.__init__(self, parent) + + def isPython(self): + return True + class BugTest(UsesQApplication): def testCase(self): w = QtGui.QWidget() @@ -12,17 +19,28 @@ class BugTest(UsesQApplication): filePath = os.path.join(os.path.dirname(__file__), 'action.ui') result = loader.load(filePath, w) - self.assertEqual(type(result.statusbar.actionFoo), QtGui.QAction) + self.assert_(isinstance(result.statusbar.actionFoo, QtGui.QAction)) - def testCustomWidgets(self): + def testPythonCustomWidgets(self): w = QtGui.QWidget() loader = QUiLoader() + loader.registerCustomWidget(MyWidget) - filePath = os.path.join(os.path.dirname(__file__), 'customwidget.ui') + filePath = os.path.join(os.path.dirname(__file__), 'pycustomwidget.ui') result = loader.load(filePath, w) - self.assert_(type(result.declarativeView), QtDeclarative.QDeclarativeView) - self.assert_(type(result.worldTimeClock), QtGui.QWidget) + self.assert_(isinstance(result.custom, MyWidget)) + self.assert_(result.custom.isPython()) + + def testPythonCustomWidgetsTwice(self): + w = QtGui.QWidget() + loader = QUiLoader() + loader.registerCustomWidget(MyWidget) + filePath = os.path.join(os.path.dirname(__file__), 'pycustomwidget2.ui') + result = loader.load(filePath, w) + self.assert_(isinstance(result.custom, MyWidget)) + self.assert_(isinstance(result.custom2, MyWidget)) + self.assert_(result.custom.isPython()) if __name__ == '__main__': unittest.main() diff --git a/tests/QtUiTools/pycustomwidget.ui b/tests/QtUiTools/pycustomwidget.ui new file mode 100644 index 000000000..c066153a0 --- /dev/null +++ b/tests/QtUiTools/pycustomwidget.ui @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>qwidget</class> + <widget class="QWidget" name="qwidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string/> + </property> + <widget class="MyWidget" name="custom"> + <property name="geometry"> + <rect> + <x>10</x> + <y>10</y> + <width>79</width> + <height>23</height> + </rect> + </property> + </widget> + </widget> + <customwidgets> + <customwidget> + <class>MyWidget</class> + <extends>QComboBox</extends> + <header>customwidget</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/tests/QtUiTools/pycustomwidget2.ui b/tests/QtUiTools/pycustomwidget2.ui new file mode 100644 index 000000000..8826ac1fb --- /dev/null +++ b/tests/QtUiTools/pycustomwidget2.ui @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>qwidget</class> + <widget class="QWidget" name="qwidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string/> + </property> + + <widget class="MyWidget" name="custom"> + <property name="geometry"> + <rect> + <x>10</x> + <y>10</y> + <width>79</width> + <height>23</height> + </rect> + </property> + </widget> + + <widget class="MyWidget" name="custom2"> + <property name="geometry"> + <rect> + <x>10</x> + <y>10</y> + <width>79</width> + <height>23</height> + </rect> + </property> + </widget> + </widget> + <customwidgets> + <customwidget> + <class>MyWidget</class> + <extends>QComboBox</extends> + <header>customwidget</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> |