diff options
Diffstat (limited to 'sources/pyside2/tests/QtCore')
-rw-r--r-- | sources/pyside2/tests/QtCore/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/feature_with_uic/__init__.py | 29 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/feature_with_uic/window.py | 81 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/feature_with_uic/window.ui | 62 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/feature_with_uic_test.py | 76 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qobject_parent_test.py | 30 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qsettings_test.py | 16 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/translation_test.py | 13 |
8 files changed, 307 insertions, 1 deletions
diff --git a/sources/pyside2/tests/QtCore/CMakeLists.txt b/sources/pyside2/tests/QtCore/CMakeLists.txt index 9d268e079..c7e50d640 100644 --- a/sources/pyside2/tests/QtCore/CMakeLists.txt +++ b/sources/pyside2/tests/QtCore/CMakeLists.txt @@ -37,6 +37,7 @@ PYSIDE_TEST(deletelater_test.py) PYSIDE_TEST(destroysignal_test.py) PYSIDE_TEST(duck_punching_test.py) PYSIDE_TEST(emoji_string_test.py) +PYSIDE_TEST(feature_with_uic_test.py) PYSIDE_TEST(hash_test.py) PYSIDE_TEST(inherits_test.py) PYSIDE_TEST(max_signals.py) diff --git a/sources/pyside2/tests/QtCore/feature_with_uic/__init__.py b/sources/pyside2/tests/QtCore/feature_with_uic/__init__.py new file mode 100644 index 000000000..396f82fb1 --- /dev/null +++ b/sources/pyside2/tests/QtCore/feature_with_uic/__init__.py @@ -0,0 +1,29 @@ +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +# this file intentionally left blank diff --git a/sources/pyside2/tests/QtCore/feature_with_uic/window.py b/sources/pyside2/tests/QtCore/feature_with_uic/window.py new file mode 100644 index 000000000..db0fbd033 --- /dev/null +++ b/sources/pyside2/tests/QtCore/feature_with_uic/window.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +############################################################################# +## +## Copyright (C) 2021 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +################################################################################ +## Form generated from reading UI file 'window.ui' +## +## Created by: Qt User Interface Compiler version 5.15.2 +## +## WARNING! All changes made in this file will be lost when recompiling UI file! +################################################################################ + +from PySide2.QtCore import * +from PySide2.QtGui import * +from PySide2.QtWidgets import * + + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + if not MainWindow.objectName(): + MainWindow.setObjectName(u"MainWindow") + MainWindow.resize(263, 196) + self.centralwidget = QWidget(MainWindow) + self.centralwidget.setObjectName(u"centralwidget") + self.horizontalLayout = QHBoxLayout(self.centralwidget) + self.horizontalLayout.setObjectName(u"horizontalLayout") + self.verticalLayout = QVBoxLayout() + self.verticalLayout.setObjectName(u"verticalLayout") + self.pushButton = QPushButton(self.centralwidget) + self.pushButton.setObjectName(u"pushButton") + + self.verticalLayout.addWidget(self.pushButton) + + + self.horizontalLayout.addLayout(self.verticalLayout) + + MainWindow.setCentralWidget(self.centralwidget) + self.menubar = QMenuBar(MainWindow) + self.menubar.setObjectName(u"menubar") + self.menubar.setGeometry(QRect(0, 0, 263, 23)) + MainWindow.setMenuBar(self.menubar) + self.statusbar = QStatusBar(MainWindow) + self.statusbar.setObjectName(u"statusbar") + MainWindow.setStatusBar(self.statusbar) + + self.retranslateUi(MainWindow) + self.pushButton.clicked.connect(MainWindow.close) + + QMetaObject.connectSlotsByName(MainWindow) + # setupUi + + def retranslateUi(self, MainWindow): + MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None)) + self.pushButton.setText(QCoreApplication.translate("MainWindow", u"PushButton", None)) + # retranslateUi + diff --git a/sources/pyside2/tests/QtCore/feature_with_uic/window.ui b/sources/pyside2/tests/QtCore/feature_with_uic/window.ui new file mode 100644 index 000000000..0b85824ea --- /dev/null +++ b/sources/pyside2/tests/QtCore/feature_with_uic/window.ui @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>263</width> + <height>196</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>PushButton</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>263</width> + <height>23</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections> + <connection> + <sender>pushButton</sender> + <signal>clicked()</signal> + <receiver>MainWindow</receiver> + <slot>close()</slot> + <hints> + <hint type="sourcelabel"> + <x>131</x> + <y>97</y> + </hint> + <hint type="destinationlabel"> + <x>131</x> + <y>97</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/sources/pyside2/tests/QtCore/feature_with_uic_test.py b/sources/pyside2/tests/QtCore/feature_with_uic_test.py new file mode 100644 index 000000000..5b61a4afb --- /dev/null +++ b/sources/pyside2/tests/QtCore/feature_with_uic_test.py @@ -0,0 +1,76 @@ +############################################################################# +## +## Copyright (C) 2021 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +""" +feature_with_uic_test.py +------------------------ + +Check if feature switching works with a normal UIC file. +This crashed due to callbacks into QApplication. + +PYSIDE-1626: Switch early in `BindingManager::getOverride`. +""" + +import os +import sys +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths(False) + +from helper.usesqapplication import UsesQApplication + +from PySide2.QtCore import QLibraryInfo, qVersion +from PySide2.QtWidgets import QApplication, QMainWindow + +if sys.version_info[0] >= 3: + from __feature__ import snake_case + +from feature_with_uic.window import Ui_MainWindow + + +class MainWindow(QMainWindow, Ui_MainWindow): + + def __init__(self): + super().__init__() + self.setupUi(self) + + +class FeatureTest(UsesQApplication): + + def testFeaturesWorkWithUIC(self): + window = MainWindow() + window.set_window_title(qVersion()) + window.show() + while not window.window_handle().is_exposed(): + QCoreApplication.process_events() + + +if __name__ == '__main__' and sys.version_info[0] >= 3: + unittest.main() diff --git a/sources/pyside2/tests/QtCore/qobject_parent_test.py b/sources/pyside2/tests/QtCore/qobject_parent_test.py index 0a02fbc26..becc7c48e 100644 --- a/sources/pyside2/tests/QtCore/qobject_parent_test.py +++ b/sources/pyside2/tests/QtCore/qobject_parent_test.py @@ -39,6 +39,16 @@ init_test_paths(False) from PySide2.QtCore import * +class TestObject1(QTimer): + def __init(self, parent): + super().__init__(parent) + + +class TestObject2(TestObject1): + def __init(self, parent): + super().__init__(parent) + + class ParentRefCountCase(unittest.TestCase): '''Test case for the refcount changes of setParent''' @@ -158,6 +168,26 @@ class ParentCase(unittest.TestCase): child = QObject(parent) self.assertEqual(parent, child.parent()) + def testFindChildByType(self): + parent = QObject() + expected = TestObject2(parent) + actual = parent.findChild(TestObject2) + self.assertEqual(actual, expected) + actual = parent.findChild(TestObject1) + self.assertEqual(actual, expected) + actual = parent.findChild(QTimer) + self.assertEqual(actual, expected) + + def testFindChildrenByType(self): + parent = QObject() + expected = [TestObject2(parent)] + actual = parent.findChildren(TestObject2) + self.assertEqual(actual, expected) + actual = parent.findChildren(TestObject1) + self.assertEqual(actual, expected) + actual = parent.findChildren(QTimer) + self.assertEqual(actual, expected) + class TestParentOwnership(unittest.TestCase): '''Test case for Parent/Child object ownership''' diff --git a/sources/pyside2/tests/QtCore/qsettings_test.py b/sources/pyside2/tests/QtCore/qsettings_test.py index a9f42a5d5..d7e203734 100644 --- a/sources/pyside2/tests/QtCore/qsettings_test.py +++ b/sources/pyside2/tests/QtCore/qsettings_test.py @@ -38,7 +38,7 @@ init_test_paths(False) from helper.helper import adjust_filename import py3kcompat as py3k -from PySide2.QtCore import QDir, QSettings, QTemporaryDir +from PySide2.QtCore import QDir, QSettings, QTemporaryDir, QByteArray class TestQSettings(unittest.TestCase): def testConversions(self): @@ -57,6 +57,20 @@ class TestQSettings(unittest.TestCase): r = settings.value('var2', type=list) self.assertEqual(type(r), list) + # Test mixed conversions + if py3k.IS_PY3K: + ba = QByteArray("hello".encode("utf-8")) + + r = settings.value("test", ba, type=QByteArray) + self.assertEqual(type(r), QByteArray) + + r = settings.value("test", ba, type=str) + self.assertEqual(type(r), str) + + # Test invalid conversions + with self.assertRaises(TypeError): + r = settings.value("test", ba, type=dict) + def testDefaultValueConversion(self): temp_dir = QDir.tempPath() diff --git a/sources/pyside2/tests/QtCore/translation_test.py b/sources/pyside2/tests/QtCore/translation_test.py index 0f36067bd..b2e674aac 100644 --- a/sources/pyside2/tests/QtCore/translation_test.py +++ b/sources/pyside2/tests/QtCore/translation_test.py @@ -59,6 +59,19 @@ class TranslationTest(UsesQCoreApplication): obj = QObject() obj.setObjectName(obj.tr('Hello World!')) + self.assertEqual(obj.objectName(), 'Orbis, te saluto!') + + def testLatinDerived(self): + # PYSIDE-131: Test that derived classes work, too. + translator = QTranslator() + translator.load(os.path.join(self.trdir, 'trans_latin.qm')) + self.app.installTranslator(translator) + + class Derived(QObject): + pass + + obj = Derived() + obj.setObjectName(obj.tr('Hello World!')) self.assertEqual(obj.objectName(), py3k.unicode_('Orbis, te saluto!')) def testRussian(self): |