diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-04-06 11:14:25 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-04-06 15:29:32 +0200 |
commit | 04d45f0429c6c6d8eae9c4fcf269ffbcc7d074d8 (patch) | |
tree | 8ad179ccdec7bd45042e15619542b704eac3e867 /sources | |
parent | 27bb3f7839d9673b125f8b1b775c4398293932e2 (diff) |
Port tests to pathlib
Replace test helper function adjust_filename() by pathlib
handling. Add asserts on the existence everywhere. Add error
handling with helper functions to QML loading, printing the
error message in the assert statements.
Task-number: PYSIDE-1499
Task-number: PYSIDE-1532
Change-Id: I206929effb37f21d1f621be921bb996162398b4d
Reviewed-by: Christian Tismer <tismer@stackless.com>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources')
32 files changed, 170 insertions, 79 deletions
diff --git a/sources/pyside6/tests/QtCore/qresource_test.py b/sources/pyside6/tests/QtCore/qresource_test.py index 40d90c65c..bc6fa0aa1 100644 --- a/sources/pyside6/tests/QtCore/qresource_test.py +++ b/sources/pyside6/tests/QtCore/qresource_test.py @@ -39,8 +39,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename -from PySide6.QtCore import QFile, QIODevice +from PySide6.QtCore import QByteArray, QFile, QIODevice import resources_mc class ResourcesUsage(unittest.TestCase): @@ -48,25 +47,30 @@ class ResourcesUsage(unittest.TestCase): def testPhrase(self): #Test loading of quote.txt resource - f = open(adjust_filename('quoteEnUS.txt', __file__), "r") - orig = f.read() - f.close() + file = Path(__file__).resolve().parent / 'quoteEnUS.txt' + self.assertTrue(file.is_file()) + orig = QByteArray(file.read_bytes()) + # In case the file is checked out in 'crlf' mode, strip '\r' + # since we read binary. + if sys.platform == 'win32': + carriage_return = orig.indexOf('\r') + if carriage_return != -1: + orig.remove(carriage_return, 1) - f = QFile(':/quote.txt') - f.open(QIODevice.ReadOnly) #|QIODevice.Text) - print("Error:", f.errorString()) + f = QFile(':/quote.txt') #|QIODevice.Text + self.assertTrue(f.open(QIODevice.ReadOnly), f.errorString()) copy = f.readAll() f.close() self.assertEqual(orig, copy) def testImage(self): #Test loading of sample.png resource - f = open(adjust_filename('sample.png', __file__), "rb") - orig = f.read() - f.close() + file = Path(__file__).resolve().parent / 'sample.png' + self.assertTrue(file.is_file()) + orig = file.read_bytes() f = QFile(':/sample.png') - f.open(QIODevice.ReadOnly) + self.assertTrue(f.open(QIODevice.ReadOnly), f.errorString()) copy = f.readAll() f.close() self.assertEqual(len(orig), len(copy)) diff --git a/sources/pyside6/tests/QtCore/qsettings_test.py b/sources/pyside6/tests/QtCore/qsettings_test.py index 00eec2679..aa42f30c3 100644 --- a/sources/pyside6/tests/QtCore/qsettings_test.py +++ b/sources/pyside6/tests/QtCore/qsettings_test.py @@ -37,12 +37,13 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename -from PySide6.QtCore import QSettings +from PySide6.QtCore import QDir, QSettings class TestQSettings(unittest.TestCase): def testConversions(self): - file_path = adjust_filename('qsettings_test.ini', __file__) + file = Path(__file__).resolve().parent / 'qsettings_test.ini' + self.assertTrue(file.is_file()) + file_path = QDir.fromNativeSeparators(os.fspath(file)) settings = QSettings(file_path, QSettings.IniFormat) r = settings.value('var1') diff --git a/sources/pyside6/tests/QtQml/bug_451.py b/sources/pyside6/tests/QtQml/bug_451.py index 9924ee854..7fd73ba90 100644 --- a/sources/pyside6/tests/QtQml/bug_451.py +++ b/sources/pyside6/tests/QtQml/bug_451.py @@ -42,7 +42,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from PySide6 import QtCore, QtGui, QtQuick @@ -83,8 +83,11 @@ class TestBug(unittest.TestCase): obj = PythonObject() context = view.rootContext() context.setContextProperty("python", obj) - view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('bug_451.qml', __file__))) + file = Path(__file__).resolve().parent / 'bug_451.qml' + self.assertTrue(file.is_file()) + view.setSource(QtCore.QUrl.fromLocalFile(os.fspath(file))) root = view.rootObject() + self.assertTrue(root, quickview_errorstring(view)) root.simpleFunction() self.assertEqual(obj.called, "simpleFunction") diff --git a/sources/pyside6/tests/QtQml/bug_456.py b/sources/pyside6/tests/QtQml/bug_456.py index 8a5c54478..17028a902 100644 --- a/sources/pyside6/tests/QtQml/bug_456.py +++ b/sources/pyside6/tests/QtQml/bug_456.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.timedqapplication import TimedQApplication from PySide6 import QtCore, QtGui, QtQuick @@ -67,8 +67,11 @@ class TestConnectionWithInvalidSignature(TimedQApplication): context = view.rootContext() context.setContextProperty("rotatevalue", rotatevalue) - view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('bug_456.qml', __file__))) + file = Path(__file__).resolve().parent / 'bug_456.qml' + self.assertTrue(file.is_file()) + view.setSource(QtCore.QUrl.fromLocalFile(os.fspath(file))) root = view.rootObject() + self.assertTrue(root, quickview_errorstring(view)) button = root.findChild(QtCore.QObject, "buttonMouseArea") view.show() button.entered.emit() diff --git a/sources/pyside6/tests/QtQml/bug_557.py b/sources/pyside6/tests/QtQml/bug_557.py index 88366a5bf..172a15777 100644 --- a/sources/pyside6/tests/QtQml/bug_557.py +++ b/sources/pyside6/tests/QtQml/bug_557.py @@ -47,5 +47,7 @@ engine = QQmlEngine() component = QQmlComponent(engine) # This should segfault if the QDeclarativeComponent has not QQmlEngine -component.loadUrl(QUrl.fromLocalFile(adjust_filename('foo.qml', __file__))) +file = Path(__file__).resolve().parent / 'foo.qml' +assert(not file.is_file()) +component.loadUrl(QUrl.fromLocalFile(os.fspath(file))) diff --git a/sources/pyside6/tests/QtQml/bug_726.py b/sources/pyside6/tests/QtQml/bug_726.py index 9d1f9cd82..aab597675 100644 --- a/sources/pyside6/tests/QtQml/bug_726.py +++ b/sources/pyside6/tests/QtQml/bug_726.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.timedqapplication import TimedQApplication from PySide6 import QtCore, QtGui, QtQuick @@ -68,8 +68,11 @@ class TestConnectionWithInvalidSignature(TimedQApplication): context = view.rootContext() context.setContextProperty("proxy", proxy) - view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('bug_726.qml', __file__))) + file = Path(__file__).resolve().parent / 'bug_726.qml' + self.assertTrue(file.is_file()) + view.setSource(QtCore.QUrl.fromLocalFile(os.fspath(file))) root = view.rootObject() + self.assertTrue(root, quickview_errorstring(view)) button = root.findChild(QtCore.QObject, "buttonMouseArea") view.show() button.entered.emit() diff --git a/sources/pyside6/tests/QtQml/bug_814.py b/sources/pyside6/tests/QtQml/bug_814.py index 4c6b1f488..b89eb93f6 100644 --- a/sources/pyside6/tests/QtQml/bug_814.py +++ b/sources/pyside6/tests/QtQml/bug_814.py @@ -46,7 +46,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.timedqapplication import TimedQApplication from PySide6.QtCore import QUrl, QAbstractListModel, QModelIndex, Qt @@ -72,8 +72,11 @@ class TestBug814(TimedQApplication): view = QQuickView() model = ListModel() view.rootContext().setContextProperty("pythonModel", model) - view.setSource(QUrl.fromLocalFile(adjust_filename('bug_814.qml', __file__))) + file = Path(__file__).resolve().parent / 'bug_814.qml' + self.assertTrue(file.is_file()) + view.setSource(QUrl.fromLocalFile(os.fspath(file))) root = view.rootObject() + self.assertTrue(root, quickview_errorstring(view)) view.show() if __name__ == '__main__': diff --git a/sources/pyside6/tests/QtQml/bug_825.py b/sources/pyside6/tests/QtQml/bug_825.py index f3315c6ed..039611c70 100644 --- a/sources/pyside6/tests/QtQml/bug_825.py +++ b/sources/pyside6/tests/QtQml/bug_825.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from PySide6.QtCore import Qt, QUrl, QTimer from PySide6.QtGui import QGuiApplication, QPen @@ -79,7 +79,10 @@ class TestBug825 (unittest.TestCase): self.assertRaises(TypeError, qmlRegisterType, A, 'bugs', 1, 0, 'A') view = QQuickView() - view.setSource(QUrl.fromLocalFile(adjust_filename('bug_825.qml', __file__))) + file = Path(__file__).resolve().parent / 'bug_825.qml' + self.assertTrue(file.is_file()) + view.setSource(QUrl.fromLocalFile(os.fspath(file))) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() QTimer.singleShot(250, view.close) app.exec_() diff --git a/sources/pyside6/tests/QtQml/bug_847.py b/sources/pyside6/tests/QtQml/bug_847.py index 35acea051..99e3d54eb 100644 --- a/sources/pyside6/tests/QtQml/bug_847.py +++ b/sources/pyside6/tests/QtQml/bug_847.py @@ -43,7 +43,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.usesqapplication import UsesQApplication from PySide6.QtCore import Slot, Signal, QUrl, QTimer, QCoreApplication @@ -71,11 +71,13 @@ class TestQML(UsesQApplication): # Connect first, then set the property. view.called.connect(self.done) - view.setSource(QUrl.fromLocalFile(adjust_filename('bug_847.qml', __file__))) + file = Path(__file__).resolve().parent / 'bug_847.qml' + self.assertTrue(file.is_file()) + view.setSource(QUrl.fromLocalFile(os.fspath(file))) while view.status() == QQuickView.Loading: self.app.processEvents() self.assertEqual(view.status(), QQuickView.Ready) - self.assertTrue(view.rootObject()) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.rootObject().setProperty('pythonObject', view) view.show() diff --git a/sources/pyside6/tests/QtQml/bug_926.py b/sources/pyside6/tests/QtQml/bug_926.py index 63d2107c8..f76c3c310 100644 --- a/sources/pyside6/tests/QtQml/bug_926.py +++ b/sources/pyside6/tests/QtQml/bug_926.py @@ -36,7 +36,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from PySide6.QtCore import QUrl, QTimer, QObject, Signal, Property from PySide6.QtGui import QGuiApplication @@ -66,8 +66,11 @@ class TestBug926 (unittest.TestCase): app = QGuiApplication([]) qmlRegisterType(MyClass,'Example',1,0,'MyClass') view = QQuickView() - view.setSource(QUrl.fromLocalFile(adjust_filename('bug_926.qml', __file__))) - self.assertEqual(len(view.errors()), 0) + file = Path(__file__).resolve().parent / 'bug_926.qml' + self.assertTrue(file.is_file()) + view.setSource(QUrl.fromLocalFile(os.fspath(file))) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) + view.show() QTimer.singleShot(0, app.quit) app.exec_() diff --git a/sources/pyside6/tests/QtQml/bug_951.py b/sources/pyside6/tests/QtQml/bug_951.py index 59776c327..2996fada7 100644 --- a/sources/pyside6/tests/QtQml/bug_951.py +++ b/sources/pyside6/tests/QtQml/bug_951.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.timedqapplication import TimedQApplication from PySide6.QtCore import QUrl @@ -60,7 +60,10 @@ class TestRegisterQMLType(TimedQApplication): qmlRegisterType(MyItem, "my.item", 1, 0, "MyItem") view = QQuickView() - view.setSource(QUrl.fromLocalFile(adjust_filename('bug_951.qml', __file__))) + file = Path(__file__).resolve().parent / 'bug_951.qml' + self.assertTrue(file.is_file()) + view.setSource(QUrl.fromLocalFile(os.fspath(file))) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) self.app.exec_() self.assertTrue(MyItem.COMPONENT_COMPLETE_CALLED) diff --git a/sources/pyside6/tests/QtQml/bug_995.py b/sources/pyside6/tests/QtQml/bug_995.py index 0f9a7449f..7db0c2e77 100644 --- a/sources/pyside6/tests/QtQml/bug_995.py +++ b/sources/pyside6/tests/QtQml/bug_995.py @@ -38,11 +38,14 @@ init_test_paths(False) from helper.helper import adjust_filename from helper.usesqapplication import UsesQApplication +from PySide6.QtCore import QUrl from PySide6.QtGui import QGuiApplication from PySide6.QtQuick import QQuickView app = QGuiApplication([]) -view = QQuickView(adjust_filename('bug_995.qml', __file__)) +file = Path(__file__).resolve().parent / 'bug_995.qml' +assert(file.is_file()) +view = QQuickView(QUrl.fromLocalFile(os.fspath(file))) view.show() view.resize(200, 200) contentItem = view.contentItem() diff --git a/sources/pyside6/tests/QtQml/bug_997.py b/sources/pyside6/tests/QtQml/bug_997.py index a66db98bc..3d77e18e7 100644 --- a/sources/pyside6/tests/QtQml/bug_997.py +++ b/sources/pyside6/tests/QtQml/bug_997.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.usesqapplication import UsesQApplication from PySide6 import QtCore, QtQml, QtQuick @@ -50,7 +50,10 @@ class TestBug(UsesQApplication): view = QtQuick.QQuickView() ctxt = view.rootContext() ctxt.setContextProperty('owner', ownerData) - view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('bug_997.qml', __file__))) + file = Path(__file__).resolve().parent / 'bug_997.qml' + self.assertTrue(file.is_file()) + view.setSource(QtCore.QUrl.fromLocalFile(os.fspath(file))) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() QtCore.QTimer.singleShot(1000, self.app.quit) self.app.exec_() diff --git a/sources/pyside6/tests/QtQml/connect_python_qml.py b/sources/pyside6/tests/QtQml/connect_python_qml.py index 47e0fdae0..40b695b95 100644 --- a/sources/pyside6/tests/QtQml/connect_python_qml.py +++ b/sources/pyside6/tests/QtQml/connect_python_qml.py @@ -42,7 +42,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.timedqapplication import TimedQApplication from PySide6 import QtCore, QtGui, QtQuick @@ -59,8 +59,11 @@ class TestConnectionWithInvalidSignature(TimedQApplication): self.buttonClicked = False self.buttonFailClicked = False view = QtQuick.QQuickView() - view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('connect_python_qml.qml', __file__))) + file = Path(__file__).resolve().parent / 'connect_python_qml.qml' + self.assertTrue(file.is_file()) + view.setSource(QtCore.QUrl.fromLocalFile(os.fspath(file))) root = view.rootObject() + self.assertTrue(root, quickview_errorstring(view)) button = root.findChild(QtCore.QObject, "buttonMouseArea") self.assertRaises(TypeError, QtCore.QObject.connect, [button,QtCore.SIGNAL('entered()'), self.onButtonFailClicked]) button.entered.connect(self.onButtonClicked) diff --git a/sources/pyside6/tests/QtQml/javascript_exceptions.py b/sources/pyside6/tests/QtQml/javascript_exceptions.py index fbf84fcf6..6d238b35c 100644 --- a/sources/pyside6/tests/QtQml/javascript_exceptions.py +++ b/sources/pyside6/tests/QtQml/javascript_exceptions.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.usesqapplication import UsesQApplication from PySide6.QtCore import Slot, Property, Signal, QObject, QUrl @@ -99,9 +99,12 @@ class JavaScriptExceptionsTest(UsesQApplication): qmlRegisterType(TestClass, 'JavaScriptExceptions', 1, 0, 'JavaScriptExceptions'); view = QQuickView() - qml_url = QUrl.fromLocalFile(adjust_filename('javascript_exceptions.qml', __file__)) + file = Path(__file__).resolve().parent / 'javascript_exceptions.qml' + self.assertTrue(file.is_file()) + qml_url = QUrl.fromLocalFile(os.fspath(file)) view.setSource(qml_url) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) self.assertTrue(test_1) self.assertTrue(test_2) diff --git a/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py b/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py index dee5601e6..519341b6a 100644 --- a/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py +++ b/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py @@ -38,7 +38,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from PySide6.QtCore import QObject, QUrl, Slot, QTimer from PySide6.QtGui import QGuiApplication @@ -76,8 +76,10 @@ class TestBug(unittest.TestCase): controller = CustomIncubationController(self) view.engine().setIncubationController(controller) view.setResizeMode(QQuickView.SizeRootObjectToView) - view.setSource(QUrl.fromLocalFile(adjust_filename('qqmlincubator_incubateWhile.qml', - __file__))) + file = Path(__file__).resolve().parent / 'qqmlincubator_incubateWhile.qml' + self.assertTrue(file.is_file()) + view.setSource(QUrl.fromLocalFile(os.fspath(file))) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() root = view.rootObject() diff --git a/sources/pyside6/tests/QtQml/qqmlnetwork_test.py b/sources/pyside6/tests/QtQml/qqmlnetwork_test.py index 5f9b18d6d..35843cf3d 100644 --- a/sources/pyside6/tests/QtQml/qqmlnetwork_test.py +++ b/sources/pyside6/tests/QtQml/qqmlnetwork_test.py @@ -42,7 +42,7 @@ from PySide6.QtQuick import QQuickView from PySide6.QtQml import QQmlNetworkAccessManagerFactory from PySide6.QtNetwork import QNetworkAccessManager -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.timedqapplication import TimedQApplication @@ -64,9 +64,12 @@ class TestQQmlNetworkFactory(TimedQApplication): self.factory = CustomFactory() view.engine().setNetworkAccessManagerFactory(self.factory) - url = QUrl.fromLocalFile(adjust_filename('hw.qml', __file__)) + file = Path(__file__).resolve().parent / 'hw.qml' + self.assertTrue(file.is_file()) + url = QUrl.fromLocalFile(os.fspath(file)) view.setSource(url) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() self.assertEqual(view.status(), QQuickView.Ready) diff --git a/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py b/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py index 0aae8e974..36d6ac097 100644 --- a/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py +++ b/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.timedqapplication import TimedQApplication from PySide6 import QtCore, QtGui, QtQuick @@ -46,8 +46,10 @@ class TestGrabToSharedPointerImage(TimedQApplication): def testQQuickItemGrabToImageSharedPointer(self): view = QtQuick.QQuickView() - view.setSource(QtCore.QUrl.fromLocalFile( - adjust_filename('qquickitem_grabToImage.qml', __file__))) + file = Path(__file__).resolve().parent / 'qquickitem_grabToImage.qml' + self.assertTrue(file.is_file()) + view.setSource(QtCore.QUrl.fromLocalFile(os.fspath(file))) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() # Get the QQuickItem objects for the blue Rectangle and the Image item. diff --git a/sources/pyside6/tests/QtQml/qquickview_test.py b/sources/pyside6/tests/QtQml/qquickview_test.py index 56d71cb5f..99b8ab055 100644 --- a/sources/pyside6/tests/QtQml/qquickview_test.py +++ b/sources/pyside6/tests/QtQml/qquickview_test.py @@ -37,7 +37,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.timedqapplication import TimedQApplication from PySide6.QtCore import QUrl, QObject, Property, Slot @@ -70,8 +70,11 @@ class TestQQuickView(TimedQApplication): ctxt = view.rootContext() ctxt.setContextProperty("myModel", dataList) - url = QUrl.fromLocalFile(adjust_filename('view.qml', __file__)) + file = Path(__file__).resolve().parent / 'view.qml' + self.assertTrue(file.is_file()) + url = QUrl.fromLocalFile(os.fspath(file)) view.setSource(url) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() self.assertEqual(view.status(), QQuickView.Ready) @@ -88,8 +91,11 @@ class TestQQuickView(TimedQApplication): ctxt = view.rootContext() ctxt.setContextProperty("myModel", dataList) - url = QUrl.fromLocalFile(adjust_filename('viewmodel.qml', __file__)) + file = Path(__file__).resolve().parent / 'viewmodel.qml' + self.assertTrue(file.is_file()) + url = QUrl.fromLocalFile(os.fspath(file)) view.setSource(url) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() self.assertEqual(view.status(), QQuickView.Ready) diff --git a/sources/pyside6/tests/QtQml/registersingletontype.py b/sources/pyside6/tests/QtQml/registersingletontype.py index 72b5238d0..90846fc43 100644 --- a/sources/pyside6/tests/QtQml/registersingletontype.py +++ b/sources/pyside6/tests/QtQml/registersingletontype.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from PySide6.QtCore import Property, Signal, QTimer, QUrl, QObject from PySide6.QtGui import QGuiApplication @@ -77,7 +77,10 @@ class TestQmlSupport(unittest.TestCase): qmlRegisterSingletonType('Singletons', 1, 0, 'SingletonQJSValue', singletonQJSValueCallback) view = QQuickView() - view.setSource(QUrl.fromLocalFile(adjust_filename('registersingletontype.qml', __file__))) + file = Path(__file__).resolve().parent / 'registersingletontype.qml' + self.assertTrue(file.is_file()) + view.setSource(QUrl.fromLocalFile(os.fspath(file))) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() QTimer.singleShot(250, view.close) app.exec_() diff --git a/sources/pyside6/tests/QtQml/registertype.py b/sources/pyside6/tests/QtQml/registertype.py index 6d8ad47eb..cb1208b9c 100644 --- a/sources/pyside6/tests/QtQml/registertype.py +++ b/sources/pyside6/tests/QtQml/registertype.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from PySide6.QtCore import Property, QObject, QTimer, QUrl from PySide6.QtGui import QGuiApplication, QPen, QColor, QPainter @@ -115,7 +115,10 @@ class TestQmlSupport(unittest.TestCase): app = QGuiApplication([]) view = QQuickView() - view.setSource(QUrl.fromLocalFile(adjust_filename('registertype.qml', __file__))) + file = Path(__file__).resolve().parent / 'registertype.qml' + self.assertTrue(file.is_file()) + view.setSource(QUrl.fromLocalFile(os.fspath(file))) + self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() QTimer.singleShot(250, view.close) app.exec_() diff --git a/sources/pyside6/tests/QtQml/registeruncreatabletype.py b/sources/pyside6/tests/QtQml/registeruncreatabletype.py index 06a18970a..ce70ab542 100644 --- a/sources/pyside6/tests/QtQml/registeruncreatabletype.py +++ b/sources/pyside6/tests/QtQml/registeruncreatabletype.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import qmlcomponent_errorstring from PySide6.QtCore import Property, QObject, QUrl from PySide6.QtGui import QGuiApplication @@ -65,7 +65,9 @@ class TestQmlSupport(unittest.TestCase): 'Uncreatable', noCreationReason) != -1); engine = QQmlEngine() - component = QQmlComponent(engine, QUrl.fromLocalFile(adjust_filename('registeruncreatable.qml', __file__))) + file = Path(__file__).resolve().parent / 'registeruncreatable.qml' + self.assertTrue(file.is_file()) + component = QQmlComponent(engine, QUrl.fromLocalFile(os.fspath(file))) # Check that the uncreatable item produces the correct error self.assertEqual(component.status(), QQmlComponent.Error) diff --git a/sources/pyside6/tests/QtQml/signal_arguments.py b/sources/pyside6/tests/QtQml/signal_arguments.py index 65dedce45..9fc8af24d 100644 --- a/sources/pyside6/tests/QtQml/signal_arguments.py +++ b/sources/pyside6/tests/QtQml/signal_arguments.py @@ -35,7 +35,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename +from helper.helper import quickview_errorstring from helper.timedqapplication import TimedQApplication from PySide6.QtQuick import QQuickView @@ -65,9 +65,11 @@ class TestConnectionWithQml(TimedQApplication): context = view.rootContext() context.setContextProperty("o", obj) - view.setSource(QUrl.fromLocalFile(adjust_filename('signal_arguments.qml', __file__))) + file = Path(__file__).resolve().parent / 'signal_arguments.qml' + self.assertTrue(file.is_file()) + view.setSource(QUrl.fromLocalFile(os.fspath(file))) root = view.rootObject() - self.assertTrue(root) + self.assertTrue(root, quickview_errorstring(view)) button = root.findChild(QObject, "button") self.assertTrue(button) view.show() diff --git a/sources/pyside6/tests/QtUiTools/bug_1060.py b/sources/pyside6/tests/QtUiTools/bug_1060.py index 317e33345..c84268cb3 100644 --- a/sources/pyside6/tests/QtUiTools/bug_1060.py +++ b/sources/pyside6/tests/QtUiTools/bug_1060.py @@ -36,7 +36,6 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename from PySide6.QtWidgets import QApplication from PySide6.QtUiTools import QUiLoader @@ -51,5 +50,7 @@ class MyQUiLoader(QUiLoader): if __name__ == "__main__": app = QApplication([]) - ui = MyQUiLoader().load(adjust_filename("bug_1060.ui", __file__)) + file = Path(__file__).resolve().parent / 'bug_1060.ui' + assert(file.is_file()) + ui = MyQUiLoader().load(os.fspath(file)) ui.show() diff --git a/sources/pyside6/tests/QtUiTools/bug_552.py b/sources/pyside6/tests/QtUiTools/bug_552.py index 8d4ca4536..a4c8ae630 100644 --- a/sources/pyside6/tests/QtUiTools/bug_552.py +++ b/sources/pyside6/tests/QtUiTools/bug_552.py @@ -35,7 +35,6 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename from PySide6 import QtWidgets, QtCore from PySide6.QtUiTools import QUiLoader @@ -44,7 +43,9 @@ class View_1(QtWidgets.QWidget): def __init__(self): QtWidgets.QWidget.__init__(self) loader = QUiLoader() - widget = loader.load(adjust_filename('bug_552.ui', __file__), self) + file = Path(__file__).resolve().parent / 'bug_552.ui' + assert(file.is_file()) + widget = loader.load(os.fspath(file), self) self.children = [] for child in widget.findChildren(QtCore.QObject, None): self.children.append(child) diff --git a/sources/pyside6/tests/QtUiTools/bug_797.py b/sources/pyside6/tests/QtUiTools/bug_797.py index 8956c31b0..6bcb318da 100644 --- a/sources/pyside6/tests/QtUiTools/bug_797.py +++ b/sources/pyside6/tests/QtUiTools/bug_797.py @@ -35,8 +35,6 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename - from PySide6 import QtUiTools from PySide6 import QtCore from PySide6 import QtWidgets @@ -44,7 +42,9 @@ from PySide6 import QtWidgets app = QtWidgets.QApplication([]) loader = QtUiTools.QUiLoader() -file = QtCore.QFile(adjust_filename('bug_552.ui', __file__)) +file = Path(__file__).resolve().parent / 'bug_552.ui' +assert(file.is_file()) +file = QtCore.QFile(os.fspath(file)) w = QtWidgets.QWidget() # An exception can't be thrown mainWindow = loader.load(file, w) diff --git a/sources/pyside6/tests/QtUiTools/bug_909.py b/sources/pyside6/tests/QtUiTools/bug_909.py index 8aab7d27a..ce963f31f 100644 --- a/sources/pyside6/tests/QtUiTools/bug_909.py +++ b/sources/pyside6/tests/QtUiTools/bug_909.py @@ -40,11 +40,12 @@ from PySide6.QtWidgets import QTabWidget from PySide6.QtUiTools import QUiLoader from helper.usesqapplication import UsesQApplication -from helper.helper import adjust_filename class TestDestruction(UsesQApplication): def testBug909(self): - fileName = QFile(adjust_filename('bug_909.ui', __file__)) + file = Path(__file__).resolve().parent / 'bug_909.ui' + self.assertTrue(file.is_file()) + fileName = QFile(os.fspath(file)) loader = QUiLoader() main_win = loader.load(fileName) self.assertEqual(sys.getrefcount(main_win), 2) diff --git a/sources/pyside6/tests/QtUiTools/bug_913.py b/sources/pyside6/tests/QtUiTools/bug_913.py index 637769daa..69012e165 100644 --- a/sources/pyside6/tests/QtUiTools/bug_913.py +++ b/sources/pyside6/tests/QtUiTools/bug_913.py @@ -38,8 +38,6 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from helper.helper import adjust_filename - from PySide6.QtCore import * from PySide6.QtWidgets import * from PySide6.QtUiTools import * @@ -50,7 +48,9 @@ class TestBug913 (unittest.TestCase): app = QApplication([]) loader = QUiLoader() - widget = loader.load(adjust_filename('bug_913.ui', __file__)) + file = Path(__file__).resolve().parent / 'bug_913.ui' + self.assertTrue(file.is_file()) + widget = loader.load(os.fspath(file)) widget.tabWidget.currentIndex() # direct child is available as member widget.le_first.setText('foo') # child of QTabWidget must also be available! diff --git a/sources/pyside6/tests/QtUiTools/bug_958.py b/sources/pyside6/tests/QtUiTools/bug_958.py index 5084a1262..f5cd57ba3 100644 --- a/sources/pyside6/tests/QtUiTools/bug_958.py +++ b/sources/pyside6/tests/QtUiTools/bug_958.py @@ -36,7 +36,6 @@ from init_paths import init_test_paths init_test_paths(False) from PySide6 import QtWidgets, QtUiTools -from helper.helper import adjust_filename from helper.timedqapplication import TimedQApplication class Gui_Qt(QtWidgets.QMainWindow): @@ -46,7 +45,9 @@ class Gui_Qt(QtWidgets.QMainWindow): lLoader = QtUiTools.QUiLoader() # this used to cause a segfault because the old inject code used to destroy the parent layout - self._cw = lLoader.load(adjust_filename('bug_958.ui', __file__), self) + file = Path(__file__).resolve().parent / 'bug_958.ui' + assert(file.is_file()) + self._cw = lLoader.load(os.fspath(file), self) self.setCentralWidget(self._cw) diff --git a/sources/pyside6/tests/QtUiTools/bug_965.py b/sources/pyside6/tests/QtUiTools/bug_965.py index 98fe2fa28..82afe7d76 100644 --- a/sources/pyside6/tests/QtUiTools/bug_965.py +++ b/sources/pyside6/tests/QtUiTools/bug_965.py @@ -38,7 +38,6 @@ init_test_paths(False) from PySide6.QtUiTools import QUiLoader from helper.usesqapplication import UsesQApplication -from helper.helper import adjust_filename class MyQUiLoader(QUiLoader): def __init__(self): @@ -50,7 +49,9 @@ class MyQUiLoader(QUiLoader): class BugTest(UsesQApplication): def testCase(self): loader = MyQUiLoader() - self.assertRaises(RuntimeError, loader.load, adjust_filename('bug_965.ui', __file__)) + file = Path(__file__).resolve().parent / 'bug_965.ui' + self.assertTrue(file.is_file()) + self.assertRaises(RuntimeError, loader.load, os.fspath(file)) if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qimage_test.py b/sources/pyside6/tests/QtWidgets/qimage_test.py index dc7f4854f..38b71a7af 100644 --- a/sources/pyside6/tests/QtWidgets/qimage_test.py +++ b/sources/pyside6/tests/QtWidgets/qimage_test.py @@ -39,7 +39,6 @@ init_test_paths(False) from PySide6.QtGui import * from PySide6.QtWidgets import * -from helper.helper import adjust_filename from helper.usesqapplication import UsesQApplication xpm = [ @@ -279,7 +278,9 @@ class QImageTest(UsesQApplication): def testQImageStringBuffer(self): '''Test if the QImage signatures receiving string buffers exist.''' - img0 = QImage(adjust_filename('sample.png', __file__)) + file = Path(__file__).resolve().parent / 'sample.png' + self.assertTrue(file.is_file()) + img0 = QImage(os.fspath(file)) # btw let's test the bits() method img1 = QImage(img0.bits(), img0.width(), img0.height(), img0.format()) diff --git a/sources/pyside6/tests/util/helper/helper.py b/sources/pyside6/tests/util/helper/helper.py index f03a4e90c..f500e3fa9 100644 --- a/sources/pyside6/tests/util/helper/helper.py +++ b/sources/pyside6/tests/util/helper/helper.py @@ -37,6 +37,26 @@ def adjust_filename(filename, orig_mod_filename): return os.path.join(dirpath, filename) +def _join_qml_errors(errors): + '''Return an error string from a list of QQmlError''' + result = '' + for i, error in enumerate(errors): + if i: + result += ', ' + result += error.toString() + return result + + +def quickview_errorstring(quickview): + '''Return an error string from a QQuickView''' + return _join_qml_errors(quickview.errors()) + + +def qmlcomponent_errorstring(component): + '''Return an error string from a QQmlComponent''' + return _join_qml_errors(component.errors()) + + def random_string(size=5): '''Generate random string with the given size''' return ''.join(map(chr, [randint(33, 126) for x in range(size)])) |