diff options
Diffstat (limited to 'sources/pyside6/tests/QtQml')
22 files changed, 85 insertions, 26 deletions
diff --git a/sources/pyside6/tests/QtQml/bug_1029.py b/sources/pyside6/tests/QtQml/bug_1029.py index 23dc8c26e..c46df7736 100644 --- a/sources/pyside6/tests/QtQml/bug_1029.py +++ b/sources/pyside6/tests/QtQml/bug_1029.py @@ -41,13 +41,15 @@ from PySide6.QtGui import QGuiApplication from PySide6.QtQml import qmlRegisterType from PySide6.QtQuick import QQuickView, QQuickItem + def register_qml_types(): class TestClass(QQuickItem): - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickItem.__init__(self, parent) qmlRegisterType(TestClass, "UserTypes", 1, 0, "TestClass") + def main(): app = QGuiApplication([]) @@ -61,5 +63,6 @@ def main(): url = QUrl(__file__.replace(".py", ".qml")) view.setSource(url) + if __name__ == "__main__": main() diff --git a/sources/pyside6/tests/QtQml/bug_451.py b/sources/pyside6/tests/QtQml/bug_451.py index d14f538a7..bfa2eb83e 100644 --- a/sources/pyside6/tests/QtQml/bug_451.py +++ b/sources/pyside6/tests/QtQml/bug_451.py @@ -78,6 +78,7 @@ class PythonObject(QObject): arg1 = Property(int, getArg1, setArg1) arg2 = Property('QVariant', getArg2, setArg2) + class TestBug(unittest.TestCase): def testQMLFunctionCall(self): app = QGuiApplication(sys.argv) diff --git a/sources/pyside6/tests/QtQml/bug_456.py b/sources/pyside6/tests/QtQml/bug_456.py index 96654808a..270e56ee8 100644 --- a/sources/pyside6/tests/QtQml/bug_456.py +++ b/sources/pyside6/tests/QtQml/bug_456.py @@ -57,6 +57,7 @@ class RotateValue(QObject): rotation = Property(int, getRotation, setRotation) + class TestConnectionWithInvalidSignature(TimedQApplication): def testSlotRetur(self): @@ -78,5 +79,6 @@ class TestConnectionWithInvalidSignature(TimedQApplication): button.entered.emit() self.assertEqual(rotatevalue.rotation, 100) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/bug_726.py b/sources/pyside6/tests/QtQml/bug_726.py index ee8e77089..f4dd93145 100644 --- a/sources/pyside6/tests/QtQml/bug_726.py +++ b/sources/pyside6/tests/QtQml/bug_726.py @@ -79,5 +79,6 @@ class TestConnectionWithInvalidSignature(TimedQApplication): button.entered.emit() self.assertEqual(proxy._receivedName, "PySideObject") + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/bug_814.py b/sources/pyside6/tests/QtQml/bug_814.py index f90c8894d..9b5ac7af0 100644 --- a/sources/pyside6/tests/QtQml/bug_814.py +++ b/sources/pyside6/tests/QtQml/bug_814.py @@ -52,6 +52,7 @@ from helper.timedqapplication import TimedQApplication from PySide6.QtCore import QUrl, QAbstractListModel, QModelIndex, Qt from PySide6.QtQuick import QQuickView + class ListModel(QAbstractListModel): def __init__(self): super().__init__() @@ -59,7 +60,7 @@ class ListModel(QAbstractListModel): def roleNames(self): return { Qt.DisplayRole: b'pysideModelData' } - def rowCount(self, parent = QModelIndex()): + def rowCount(self, parent=QModelIndex()): return 3 def data(self, index, role): @@ -67,6 +68,7 @@ class ListModel(QAbstractListModel): return 'blubb' return None + class TestBug814(TimedQApplication): def testAbstractItemModelTransferToQML(self): view = QQuickView() @@ -79,6 +81,7 @@ class TestBug814(TimedQApplication): self.assertTrue(root, quickview_errorstring(view)) view.show() + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/bug_825.py b/sources/pyside6/tests/QtQml/bug_825.py index 039611c70..3deebe6d0 100644 --- a/sources/pyside6/tests/QtQml/bug_825.py +++ b/sources/pyside6/tests/QtQml/bug_825.py @@ -45,32 +45,39 @@ from PySide6.QtQuick import QQuickView, QQuickItem, QQuickPaintedItem paintCalled = False + class MetaA(type): pass + class A(object): __metaclass__ = MetaA + MetaB = type(QQuickPaintedItem) B = QQuickPaintedItem + class MetaC(MetaA, MetaB): pass + class C(A, B): __metaclass__ = MetaC + class Bug825 (C): - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickPaintedItem.__init__(self, parent) def paint(self, painter): global paintCalled pen = QPen(Qt.black, 2) - painter.setPen(pen); - painter.drawPie(self.boundingRect(), 0, 128); + painter.setPen(pen) + painter.drawPie(self.boundingRect(), 0, 128) paintCalled = True + class TestBug825 (unittest.TestCase): def testIt(self): global paintCalled @@ -88,5 +95,6 @@ class TestBug825 (unittest.TestCase): app.exec_() self.assertTrue(paintCalled) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/bug_847.py b/sources/pyside6/tests/QtQml/bug_847.py index ffa688a32..d4c9f9faf 100644 --- a/sources/pyside6/tests/QtQml/bug_847.py +++ b/sources/pyside6/tests/QtQml/bug_847.py @@ -49,6 +49,7 @@ from helper.usesqapplication import UsesQApplication from PySide6.QtCore import Slot, Signal, QUrl, QTimer, QCoreApplication from PySide6.QtQuick import QQuickView + class View(QQuickView): def __init__(self): super().__init__() @@ -59,6 +60,7 @@ class View(QQuickView): def blubb(self, x, y): self.called.emit(x, y) + class TestQML(UsesQApplication): def done(self, x, y): self._sucess = True @@ -89,6 +91,7 @@ class TestQML(UsesQApplication): self.app.exec_() self.assertTrue(self._sucess) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/bug_915.py b/sources/pyside6/tests/QtQml/bug_915.py index 7074a503c..312ee341b 100644 --- a/sources/pyside6/tests/QtQml/bug_915.py +++ b/sources/pyside6/tests/QtQml/bug_915.py @@ -42,6 +42,7 @@ from helper.timedqapplication import TimedQApplication from PySide6.QtQuick import QQuickView, QQuickItem + class TestBug915(TimedQApplication): def testReturnPolicy(self): view = QQuickView() @@ -49,16 +50,17 @@ class TestBug915(TimedQApplication): item1 = QQuickItem() item1.setObjectName("Item1") item1.setParentItem(view.contentItem()) - self.assertEqual(item1.objectName(), "Item1") # check if the item still valid + self.assertEqual(item1.objectName(), "Item1") # check if the item still valid item2 = QQuickItem() item2.setObjectName("Item2") item2.setParentItem(view.contentItem()) item1 = None - self.assertEqual(item2.objectName(), "Item2") # check if the item still valid + self.assertEqual(item2.objectName(), "Item2") # check if the item still valid view = None + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/bug_926.py b/sources/pyside6/tests/QtQml/bug_926.py index 6ca5b4170..e8ac50858 100644 --- a/sources/pyside6/tests/QtQml/bug_926.py +++ b/sources/pyside6/tests/QtQml/bug_926.py @@ -43,6 +43,7 @@ from PySide6.QtGui import QGuiApplication from PySide6.QtQml import qmlRegisterType from PySide6.QtQuick import QQuickView + class MyClass (QObject): def __init__(self): @@ -52,19 +53,20 @@ class MyClass (QObject): def getUrl(self): return self.__url - def setUrl(self,value): + def setUrl(self, value): newUrl = QUrl(value) if (newUrl != self.__url): self.__url = newUrl self.urlChanged.emit() urlChanged = Signal() - urla = Property(QUrl, getUrl, setUrl, notify = urlChanged) + urla = Property(QUrl, getUrl, setUrl, notify=urlChanged) + class TestBug926 (unittest.TestCase): def testIt(self): app = QGuiApplication([]) - qmlRegisterType(MyClass,'Example',1,0,'MyClass') + qmlRegisterType(MyClass,'Example', 1, 0, 'MyClass') view = QQuickView() file = Path(__file__).resolve().parent / 'bug_926.qml' self.assertTrue(file.is_file()) @@ -75,5 +77,6 @@ class TestBug926 (unittest.TestCase): QTimer.singleShot(0, app.quit) app.exec_() + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/bug_951.py b/sources/pyside6/tests/QtQml/bug_951.py index fb4eeefca..9a75550a8 100644 --- a/sources/pyside6/tests/QtQml/bug_951.py +++ b/sources/pyside6/tests/QtQml/bug_951.py @@ -42,9 +42,11 @@ from PySide6.QtCore import QUrl from PySide6.QtQml import qmlRegisterType from PySide6.QtQuick import QQuickItem, QQuickView + class MyItem(QQuickItem): COMPONENT_COMPLETE_CALLED = False - def __init__(self,parent=None): + + def __init__(self, parent=None): super().__init__(parent) self.setObjectName("myitem") @@ -52,9 +54,10 @@ class MyItem(QQuickItem): MyItem.COMPONENT_COMPLETE_CALLED = True super(MyItem, self).componentComplete() + class TestRegisterQMLType(TimedQApplication): def setup(self): - TimedQApplication.setup(self, 100 * 3) # 3s + TimedQApplication.setup(self, 100 * 3) # 3s def testSignalEmission(self): qmlRegisterType(MyItem, "my.item", 1, 0, "MyItem") @@ -68,5 +71,6 @@ class TestRegisterQMLType(TimedQApplication): self.app.exec_() self.assertTrue(MyItem.COMPONENT_COMPLETE_CALLED) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/bug_997.py b/sources/pyside6/tests/QtQml/bug_997.py index ce5ee14db..18fbfcb63 100644 --- a/sources/pyside6/tests/QtQml/bug_997.py +++ b/sources/pyside6/tests/QtQml/bug_997.py @@ -61,5 +61,6 @@ class TestBug(UsesQApplication): self.app.exec_() self.assertEqual(ownerData.value('newName'), ownerData.value('name')) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/connect_python_qml.py b/sources/pyside6/tests/QtQml/connect_python_qml.py index 0b1e926cd..c24346620 100644 --- a/sources/pyside6/tests/QtQml/connect_python_qml.py +++ b/sources/pyside6/tests/QtQml/connect_python_qml.py @@ -74,5 +74,6 @@ class TestConnectionWithInvalidSignature(TimedQApplication): self.app.exec_() self.assertTrue(self.buttonClicked) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/javascript_exceptions.py b/sources/pyside6/tests/QtQml/javascript_exceptions.py index 6d238b35c..7bb3aa43f 100644 --- a/sources/pyside6/tests/QtQml/javascript_exceptions.py +++ b/sources/pyside6/tests/QtQml/javascript_exceptions.py @@ -59,6 +59,7 @@ property_test_string = """ test_1 = False test_2 = False + class TestClass(QObject): @Slot() def methodThrows(self): @@ -77,6 +78,7 @@ class TestClass(QObject): else: test_2 = True + class JavaScriptExceptionsTest(UsesQApplication): def test_jsengine(self): engine = QJSEngine() @@ -96,7 +98,7 @@ class JavaScriptExceptionsTest(UsesQApplication): self.assertEqual(result_2.property('name').toString(), 'TypeError') def test_qml_type(self): - qmlRegisterType(TestClass, 'JavaScriptExceptions', 1, 0, 'JavaScriptExceptions'); + qmlRegisterType(TestClass, 'JavaScriptExceptions', 1, 0, 'JavaScriptExceptions') view = QQuickView() file = Path(__file__).resolve().parent / 'javascript_exceptions.qml' diff --git a/sources/pyside6/tests/QtQml/listproperty.py b/sources/pyside6/tests/QtQml/listproperty.py index 17b9ecce5..0e1e3548f 100644 --- a/sources/pyside6/tests/QtQml/listproperty.py +++ b/sources/pyside6/tests/QtQml/listproperty.py @@ -38,12 +38,15 @@ init_test_paths(False) from PySide6.QtCore import QObject from PySide6.QtQml import ListProperty + class InheritsQObject(QObject): pass + def dummyFunc(): pass + class TestListProperty(unittest.TestCase): def testIt(self): @@ -84,5 +87,6 @@ class TestListProperty(unittest.TestCase): self.assertTrue(method_check_error) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py b/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py index 519341b6a..11e666c08 100644 --- a/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py +++ b/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py @@ -45,6 +45,7 @@ from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlIncubationController, VolatileBool from PySide6.QtQuick import QQuickView + class CustomIncubationController(QObject, QQmlIncubationController): def __init__(self, test): QObject.__init__(self) @@ -69,6 +70,7 @@ class CustomIncubationController(QObject, QQmlIncubationController): # Incubate items for 2000 milliseconds, or until the volatile bool is set to false. self.incubateWhile(self.incubationShouldContinue, 2000) + class TestBug(unittest.TestCase): def testIncubateWhileCall(self): app = QGuiApplication(sys.argv) @@ -101,5 +103,6 @@ class TestBug(unittest.TestCase): del view del app + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/qqmlnetwork_test.py b/sources/pyside6/tests/QtQml/qqmlnetwork_test.py index 35843cf3d..75de98b9e 100644 --- a/sources/pyside6/tests/QtQml/qqmlnetwork_test.py +++ b/sources/pyside6/tests/QtQml/qqmlnetwork_test.py @@ -47,14 +47,16 @@ from helper.timedqapplication import TimedQApplication class CustomManager(QNetworkAccessManager): - def createRequest(self, op, req, data = None): + def createRequest(self, op, req, data=None): print(">> createRequest ", self, op, req.url(), data) return QNetworkAccessManager.createRequest(self, op, req, data) + class CustomFactory(QQmlNetworkAccessManagerFactory): - def create(self, parent = None): + def create(self, parent=None): return CustomManager() + class TestQQmlNetworkFactory(TimedQApplication): def setUp(self): TimedQApplication.setUp(self, timeout=1000) @@ -76,5 +78,6 @@ class TestQQmlNetworkFactory(TimedQApplication): self.app.exec_() + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py b/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py index 1b61ddbb0..2843c0a92 100644 --- a/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py +++ b/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py @@ -67,6 +67,7 @@ class TestGrabToSharedPointerImage(TimedQApplication): self.assertTrue(grabResultSharedPtr) self.grabbedColor = None + def onGrabReady(): # Signal early exit. QTimer.singleShot(0, self.app.quit) @@ -81,7 +82,7 @@ class TestGrabToSharedPointerImage(TimedQApplication): # Get the first pixel color of the grabbed image. self.image = grabResultSharedPtr.image() self.assertTrue(self.image) - self.grabbedColor = self.image.pixelColor(0,0) + self.grabbedColor = self.image.pixelColor(0, 0) self.assertTrue(self.grabbedColor.isValid()) # Compare the grabbed color with the one we set in the rectangle. diff --git a/sources/pyside6/tests/QtQml/qquickview_test.py b/sources/pyside6/tests/QtQml/qquickview_test.py index 99b8ab055..9cf9bbabb 100644 --- a/sources/pyside6/tests/QtQml/qquickview_test.py +++ b/sources/pyside6/tests/QtQml/qquickview_test.py @@ -44,6 +44,7 @@ from PySide6.QtCore import QUrl, QObject, Property, Slot from PySide6.QtQml import QQmlEngine from PySide6.QtQuick import QQuickView + class MyObject(QObject): def __init__(self, text, parent=None): QObject.__init__(self, parent) @@ -52,7 +53,6 @@ class MyObject(QObject): def getText(self): return self._text - @Slot(str) def qmlText(self, text): self._qmlText = text diff --git a/sources/pyside6/tests/QtQml/registersingletontype.py b/sources/pyside6/tests/QtQml/registersingletontype.py index 90846fc43..01b841675 100644 --- a/sources/pyside6/tests/QtQml/registersingletontype.py +++ b/sources/pyside6/tests/QtQml/registersingletontype.py @@ -44,8 +44,9 @@ from PySide6.QtQuick import QQuickView finalResult = 0 + class SingletonQObject(QObject): - def __init__(self, parent = None): + def __init__(self, parent=None): QObject.__init__(self, parent) self._data = 100 @@ -58,14 +59,17 @@ class SingletonQObject(QObject): data = Property(int, getData, setData) + def singletonQObjectCallback(engine): obj = SingletonQObject() obj.setData(50) return obj + def singletonQJSValueCallback(engine): return engine.evaluate("new Object({data: 50})") + class TestQmlSupport(unittest.TestCase): def testIt(self): app = QGuiApplication([]) @@ -86,5 +90,6 @@ class TestQmlSupport(unittest.TestCase): app.exec_() self.assertEqual(finalResult, 200) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/registertype.py b/sources/pyside6/tests/QtQml/registertype.py index cb1208b9c..254208dcb 100644 --- a/sources/pyside6/tests/QtQml/registertype.py +++ b/sources/pyside6/tests/QtQml/registertype.py @@ -45,9 +45,10 @@ from PySide6.QtQuick import QQuickView, QQuickItem, QQuickPaintedItem QML_IMPORT_NAME = "Charts" QML_IMPORT_MAJOR_VERSION = 1 + @QmlElement class PieSlice (QQuickPaintedItem): - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickPaintedItem.__init__(self, parent) self._color = QColor() self._fromAngle = 0 @@ -78,14 +79,15 @@ class PieSlice (QQuickPaintedItem): def paint(self, painter): global paintCalled pen = QPen(self._color, 2) - painter.setPen(pen); - painter.setRenderHints(QPainter.Antialiasing, True); - painter.drawPie(self.boundingRect(), self._fromAngle * 16, self._angleSpan * 16); + painter.setPen(pen) + painter.setRenderHints(QPainter.Antialiasing, True) + painter.drawPie(self.boundingRect(), self._fromAngle * 16, self._angleSpan * 16) paintCalled = True + @QmlElement class PieChart (QQuickItem): - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickItem.__init__(self, parent) self._name = '' self._slices = [] @@ -106,9 +108,11 @@ class PieChart (QQuickItem): slices = ListProperty(PieSlice, append=appendSlice) + appendCalled = False paintCalled = False + class TestQmlSupport(unittest.TestCase): def testIt(self): @@ -125,5 +129,6 @@ class TestQmlSupport(unittest.TestCase): self.assertTrue(appendCalled) self.assertTrue(paintCalled) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtQml/registeruncreatabletype.py b/sources/pyside6/tests/QtQml/registeruncreatabletype.py index ce70ab542..6d399b8ae 100644 --- a/sources/pyside6/tests/QtQml/registeruncreatabletype.py +++ b/sources/pyside6/tests/QtQml/registeruncreatabletype.py @@ -41,10 +41,11 @@ from PySide6.QtCore import Property, QObject, QUrl from PySide6.QtGui import QGuiApplication from PySide6.QtQml import qmlRegisterUncreatableType, QQmlEngine, QQmlComponent -noCreationReason = 'Cannot create an item of type: Uncreatable (expected)'; +noCreationReason = 'Cannot create an item of type: Uncreatable (expected)' + class Uncreatable(QObject): - def __init__(self, parent = None): + def __init__(self, parent=None): QObject.__init__(self, parent) self._name = 'uncreatable' @@ -56,13 +57,14 @@ class Uncreatable(QObject): name = Property(str, getName, setName) + class TestQmlSupport(unittest.TestCase): def testIt(self): app = QGuiApplication([]) self.assertTrue(qmlRegisterUncreatableType(Uncreatable, 'Charts', 1, 0, - 'Uncreatable', noCreationReason) != -1); + 'Uncreatable', noCreationReason) != -1) engine = QQmlEngine() file = Path(__file__).resolve().parent / 'registeruncreatable.qml' diff --git a/sources/pyside6/tests/QtQml/signal_arguments.py b/sources/pyside6/tests/QtQml/signal_arguments.py index b3bd59491..2848a4a6a 100644 --- a/sources/pyside6/tests/QtQml/signal_arguments.py +++ b/sources/pyside6/tests/QtQml/signal_arguments.py @@ -41,6 +41,7 @@ from helper.timedqapplication import TimedQApplication from PySide6.QtQuick import QQuickView from PySide6.QtCore import QObject, Signal, Slot, QUrl, QTimer, Property + class Obj(QObject): def __init__(self): super().__init__() @@ -76,5 +77,6 @@ class TestConnectionWithQml(TimedQApplication): button.clicked.emit() self.assertEqual(obj.value, 42) + if __name__ == '__main__': unittest.main() |