aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-17 07:56:30 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-17 08:22:55 +0200
commit4c5e405e691f707f2765b5f920c28213a36d22e5 (patch)
tree48000f220fc2c4365b276146e3d08a05c3a90312 /sources/pyside2/tests
parent53181fb95d3884cc067d005f37accd92d128bccc (diff)
parent38814354ff6a30258b79947304fd3a6be4dc7089 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r--sources/pyside2/tests/QtCore/CMakeLists.txt2
-rw-r--r--sources/pyside2/tests/QtCore/multiple_feature_test.py29
-rw-r--r--sources/pyside2/tests/QtCore/snake_prop_feature_test.py (renamed from sources/pyside2/tests/QtCore/snake_case_feature_test.py)44
-rw-r--r--sources/pyside2/tests/signals/CMakeLists.txt1
-rw-r--r--sources/pyside2/tests/signals/signal_across_threads.py106
5 files changed, 161 insertions, 21 deletions
diff --git a/sources/pyside2/tests/QtCore/CMakeLists.txt b/sources/pyside2/tests/QtCore/CMakeLists.txt
index 98bfb9334..ee87345db 100644
--- a/sources/pyside2/tests/QtCore/CMakeLists.txt
+++ b/sources/pyside2/tests/QtCore/CMakeLists.txt
@@ -121,7 +121,7 @@ PYSIDE_TEST(quuid_test.py)
PYSIDE_TEST(qversionnumber_test.py)
PYSIDE_TEST(repr_test.py)
PYSIDE_TEST(setprop_on_ctor_test.py)
-PYSIDE_TEST(snake_case_feature_test.py)
+PYSIDE_TEST(snake_prop_feature_test.py)
PYSIDE_TEST(staticMetaObject_test.py)
PYSIDE_TEST(static_method_test.py)
PYSIDE_TEST(thread_signals_test.py)
diff --git a/sources/pyside2/tests/QtCore/multiple_feature_test.py b/sources/pyside2/tests/QtCore/multiple_feature_test.py
index 351090382..329e513fb 100644
--- a/sources/pyside2/tests/QtCore/multiple_feature_test.py
+++ b/sources/pyside2/tests/QtCore/multiple_feature_test.py
@@ -48,8 +48,7 @@ from init_paths import init_test_paths
init_test_paths(False)
from PySide2 import QtCore
-from PySide2.support.__feature__ import (
- _really_all_feature_names, pyside_feature_dict)
+from PySide2.support import __feature__
from textwrap import dedent
"""
@@ -62,6 +61,8 @@ The first feature is `snake_case` instead of `camelCase`.
There is much more to come.
"""
+MethodDescriptorType = type(str.split)
+
class FeaturesTest(unittest.TestCase):
def testAllFeatureCombinations(self):
@@ -69,7 +70,7 @@ class FeaturesTest(unittest.TestCase):
Test for all 256 possible combinations of `__feature__` imports.
"""
- def tst_bit0(flag, self):
+ def tst_bit0(flag, self, bits):
if flag == 0:
QtCore.QCborArray.isEmpty
QtCore.QCborArray.__dict__["isEmpty"]
@@ -85,13 +86,25 @@ class FeaturesTest(unittest.TestCase):
with self.assertRaises(KeyError):
QtCore.QCborArray.__dict__["isEmpty"]
+ def tst_bit1(flag, self, bits):
+ getter_name = "object_name" if bits & 1 else "objectName"
+ setter_name = "set_object_name" if bits & 1 else "setObjectName"
+ thing = getattr(QtCore.QObject, getter_name)
+ if flag:
+ self.assertEqual(type(thing), property)
+ with self.assertRaises(AttributeError):
+ getattr(QtCore.QObject, setter_name)
+ else:
+ self.assertEqual(type(thing), MethodDescriptorType)
+ getattr(QtCore.QObject, setter_name)
+
edict = {}
- for bit in range(1, 8):
+ for bit in range(2, 8):
# We are cheating here, since the functions are in the globals.
eval(compile(dedent("""
- def tst_bit{0}(flag, self):
+ def tst_bit{0}(flag, self, bits):
if flag == 0:
with self.assertRaises(AttributeError):
QtCore.QCborArray.fake_feature_{1:02x}
@@ -103,12 +116,12 @@ class FeaturesTest(unittest.TestCase):
""").format(bit, 1 << bit), "<string>", "exec"), globals(), edict)
globals().update(edict)
- feature_list = _really_all_feature_names
+ feature_list = __feature__._really_all_feature_names
func_list = [tst_bit0, tst_bit1, tst_bit2, tst_bit3,
tst_bit4, tst_bit5, tst_bit6, tst_bit7]
for idx in range(0x100):
- pyside_feature_dict.clear()
+ __feature__.set_selection(0)
config = "feature_{:02x}".format(idx)
print()
print("--- Feature Test Config `{}` ---".format(config))
@@ -121,7 +134,7 @@ class FeaturesTest(unittest.TestCase):
eval(compile(text, "<string>", "exec"), globals(), edict)
for bit in range(8):
value = idx & 1 << bit
- func_list[bit](value, self=self)
+ func_list[bit](value, self=self, bits=idx)
if __name__ == '__main__':
diff --git a/sources/pyside2/tests/QtCore/snake_case_feature_test.py b/sources/pyside2/tests/QtCore/snake_prop_feature_test.py
index b7f23396e..779b8a408 100644
--- a/sources/pyside2/tests/QtCore/snake_case_feature_test.py
+++ b/sources/pyside2/tests/QtCore/snake_prop_feature_test.py
@@ -46,41 +46,61 @@ from init_paths import init_test_paths
init_test_paths(False)
from PySide2 import QtWidgets
+from PySide2.support import __feature__
"""
-snake_case_feature_test.py
+snake_prop_feature_test.py
--------------------------
-Test the snake_case feature.
+Test the snake_case and true_property feature.
This works now. More tests needed!
"""
-class RenamingTest(unittest.TestCase):
+class Window(QtWidgets.QWidget):
+ def __init__(self):
+ super(Window, self).__init__()
+
+
+class FeatureTest(unittest.TestCase):
def setUp(self):
qApp or QtWidgets.QApplication()
+ __feature__.set_selection(0)
def tearDown(self):
qApp.shutdown()
def testRenamedFunctions(self):
-
- class Window(QtWidgets.QWidget):
- def __init__(self):
- super(Window, self).__init__()
-
window = Window()
window.setWindowTitle('camelCase')
# and now the same with snake_case enabled
from __feature__ import snake_case
- class Window(QtWidgets.QWidget):
- def __init__(self):
- super(Window, self).__init__()
+ # Works with the same window! window = Window()
+ window.set_window_title('snake_case')
+ def testPropertyAppearVanish(self):
window = Window()
- window.set_window_title('snake_case')
+
+ self.assertTrue(callable(window.isModal))
+ with self.assertRaises(AttributeError):
+ window.modal
+
+ from __feature__ import snake_case, true_property
+
+ self.assertTrue(isinstance(QtWidgets.QWidget.modal, property))
+ self.assertTrue(isinstance(window.modal, bool))
+ with self.assertRaises(AttributeError):
+ window.isModal
+
+ # switching back
+ __feature__.set_selection(0)
+
+ self.assertTrue(callable(window.isModal))
+ with self.assertRaises(AttributeError):
+ window.modal
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside2/tests/signals/CMakeLists.txt b/sources/pyside2/tests/signals/CMakeLists.txt
index 740319f39..14936869f 100644
--- a/sources/pyside2/tests/signals/CMakeLists.txt
+++ b/sources/pyside2/tests/signals/CMakeLists.txt
@@ -26,6 +26,7 @@ PYSIDE_TEST(segfault_proxyparent_test.py)
PYSIDE_TEST(self_connect_test.py)
PYSIDE_TEST(short_circuit_test.py)
PYSIDE_TEST(signal2signal_connect_test.py)
+PYSIDE_TEST(signal_across_threads.py)
PYSIDE_TEST(signal_autoconnect_test.py)
PYSIDE_TEST(signal_connectiontype_support_test.py)
PYSIDE_TEST(signal_enum_test.py)
diff --git a/sources/pyside2/tests/signals/signal_across_threads.py b/sources/pyside2/tests/signals/signal_across_threads.py
new file mode 100644
index 000000000..907f059a1
--- /dev/null
+++ b/sources/pyside2/tests/signals/signal_across_threads.py
@@ -0,0 +1,106 @@
+#############################################################################
+##
+## 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$
+##
+#############################################################################
+
+'''Test case for PYSIDE-1354: Ensure that slots are invoked from the receiver's
+thread context when using derived classes (and thus, a global receiver).'''
+
+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 PySide2.QtCore import QObject, QThread, QTimer, Slot
+from helper.usesqcoreapplication import UsesQCoreApplication
+
+
+class ReceiverBase(QObject):
+ def __init__(self, parent=None):
+ super(ReceiverBase, self).__init__(parent)
+ self.senderThread = None
+
+ @Slot()
+ def slot_function(self):
+ self.senderThread = QThread.currentThread()
+
+
+class Receiver(ReceiverBase):
+ pass
+
+
+class TestThread(QThread):
+ def __init__(self, parent=None):
+ super(TestThread, self).__init__(parent)
+
+ def run(self):
+ pass
+
+
+class SignalAcrossThreads(UsesQCoreApplication):
+ def setUp(self):
+ UsesQCoreApplication.setUp(self)
+ self._timer_tick = 0
+ self._timer = QTimer()
+ self._timer.setInterval(20)
+ self._timer.timeout.connect(self._control_test)
+ self._worker_thread = TestThread()
+
+ def tearDown(self):
+ UsesQCoreApplication.tearDown(self)
+
+ @Slot()
+ def _control_test(self):
+ if self._timer_tick == 0:
+ self._worker_thread.start()
+ elif self._timer_tick == 1:
+ self._worker_thread.wait()
+ else:
+ self._timer.stop()
+ self.app.quit()
+ self._timer_tick += 1
+
+ def test(self):
+ worker_thread_receiver = Receiver()
+ worker_thread_receiver.moveToThread(self._worker_thread)
+ self._worker_thread.started.connect(worker_thread_receiver.slot_function)
+
+ main_thread = QThread.currentThread()
+ main_thread_receiver = Receiver()
+ self._worker_thread.started.connect(main_thread_receiver.slot_function)
+
+ self._timer.start()
+ self.app.exec_()
+
+ self.assertEqual(worker_thread_receiver.senderThread, self._worker_thread)
+ self.assertEqual(main_thread_receiver.senderThread, main_thread)
+
+
+if __name__ == '__main__':
+ unittest.main()