aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/util
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/tests/util')
-rw-r--r--sources/pyside6/tests/util/helper/docmodifier.py12
-rw-r--r--sources/pyside6/tests/util/helper/usesqapplication.py30
-rw-r--r--sources/pyside6/tests/util/helper/usesqcoreapplication.py37
-rw-r--r--sources/pyside6/tests/util/helper/usesqguiapplication.py27
-rw-r--r--sources/pyside6/tests/util/processtimer.py2
-rw-r--r--sources/pyside6/tests/util/pyqt_diff.py39
6 files changed, 29 insertions, 118 deletions
diff --git a/sources/pyside6/tests/util/helper/docmodifier.py b/sources/pyside6/tests/util/helper/docmodifier.py
index 5a2421609..cfb665640 100644
--- a/sources/pyside6/tests/util/helper/docmodifier.py
+++ b/sources/pyside6/tests/util/helper/docmodifier.py
@@ -83,9 +83,9 @@ if __name__ == '__main__':
doc_filter = lambda x: x.startswith('test')
doc_suffix = 'suffix'
- assert(Implementing.testBase.__doc__ == 'prefixbasesuffix')
- assert(Implementing.testWithoutDoc.__doc__ == None)
- assert(OnlySuffix.testBase.__doc__ == 'basesuffix')
- assert(OnlySuffix.testWithoutDoc.__doc__ == None)
- assert(OnlyPrefix.testBase.__doc__ == 'prefixbase')
- assert(OnlyPrefix.testWithoutDoc.__doc__ == None)
+ assert (Implementing.testBase.__doc__ == 'prefixbasesuffix')
+ assert (Implementing.testWithoutDoc.__doc__ == None)
+ assert (OnlySuffix.testBase.__doc__ == 'basesuffix')
+ assert (OnlySuffix.testWithoutDoc.__doc__ == None)
+ assert (OnlyPrefix.testBase.__doc__ == 'prefixbase')
+ assert (OnlyPrefix.testWithoutDoc.__doc__ == None)
diff --git a/sources/pyside6/tests/util/helper/usesqapplication.py b/sources/pyside6/tests/util/helper/usesqapplication.py
index d09d1eb7a..f62e320f4 100644
--- a/sources/pyside6/tests/util/helper/usesqapplication.py
+++ b/sources/pyside6/tests/util/helper/usesqapplication.py
@@ -4,26 +4,40 @@
'''Helper classes and functions'''
import gc
+import sys
import unittest
-from PySide6.QtWidgets import QApplication
+# This version avoids explicit import in order to adapt to the
+# import decision of the main module.
+# This should work with every compatible library.
+# Replaces the QtGui and QtCore versions as well.
class UsesQApplication(unittest.TestCase):
- '''Helper class to provide QApplication instances'''
-
- qapplication = True
+ '''Helper class to provide Q(Core|Gui|)Application instances
+ Just connect or call self.exit_app_cb. When called, will ask
+ self.app to exit.
+ '''
def setUp(self):
'''Creates the QApplication instance'''
-
+ module = sys.modules[sorted(_ for _ in sys.modules
+ if _.endswith((".QtCore", ".QtGui", ".QtWidgets")))[-1]]
+ found = module.__name__.rsplit(".")[-1]
+ cls = getattr(module, {"QtWidgets": "QApplication",
+ "QtGui": "QGuiApplication",
+ "QtCore": "QCoreApplication"}[found])
# Simple way of making instance a singleton
- super(UsesQApplication, self).setUp()
- self.app = QApplication.instance() or QApplication([])
+ super().setUp()
+ self.app = cls.instance() or cls([])
def tearDown(self):
'''Deletes the reference owned by self'''
del self.app
# PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
gc.collect()
- super(UsesQApplication, self).tearDown()
+ super().tearDown()
+
+ def exit_app_cb(self):
+ '''Quits the application'''
+ self.app.exit(0)
diff --git a/sources/pyside6/tests/util/helper/usesqcoreapplication.py b/sources/pyside6/tests/util/helper/usesqcoreapplication.py
deleted file mode 100644
index 85f78d066..000000000
--- a/sources/pyside6/tests/util/helper/usesqcoreapplication.py
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-'''Helper classes and functions'''
-
-import gc
-import unittest
-
-from PySide6.QtCore import QCoreApplication
-
-_core_instance = None
-
-
-class UsesQCoreApplication(unittest.TestCase):
- '''Helper class for test cases that require an QCoreApplication
- Just connect or call self.exit_app_cb. When called, will ask
- self.app to exit.
- '''
-
- def setUp(self):
- '''Set up resources'''
-
- global _core_instance
- if _core_instance is None:
- _core_instance = QCoreApplication([])
-
- self.app = _core_instance
-
- def tearDown(self):
- '''Release resources'''
- del self.app
- # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
- gc.collect()
-
- def exit_app_cb(self):
- '''Quits the application'''
- self.app.exit(0)
diff --git a/sources/pyside6/tests/util/helper/usesqguiapplication.py b/sources/pyside6/tests/util/helper/usesqguiapplication.py
deleted file mode 100644
index e02b57476..000000000
--- a/sources/pyside6/tests/util/helper/usesqguiapplication.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-'''Helper classes and functions'''
-
-import gc
-import unittest
-
-from PySide6.QtGui import QGuiApplication
-
-
-class UsesQGuiApplication(unittest.TestCase):
- '''Helper class to provide QGuiApplication instances'''
-
- def setUp(self):
- '''Creates the QGuiApplication instance'''
-
- # Simple way of making instance a singleton
- super(UsesQGuiApplication, self).setUp()
- self.app = QGuiApplication.instance() or QGuiApplication([])
-
- def tearDown(self):
- '''Deletes the reference owned by self'''
- del self.app
- # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
- gc.collect()
- super(UsesQGuiApplication, self).tearDown()
diff --git a/sources/pyside6/tests/util/processtimer.py b/sources/pyside6/tests/util/processtimer.py
index fb38943c8..e471cf167 100644
--- a/sources/pyside6/tests/util/processtimer.py
+++ b/sources/pyside6/tests/util/processtimer.py
@@ -27,7 +27,7 @@ class ProcessTimer(object):
def waitfor(self):
time_passed = 0
- while(self.proc.poll() is None and time_passed < self.timeout):
+ while (self.proc.poll() is None and time_passed < self.timeout):
time_passed = time_passed + 1
time.sleep(1)
diff --git a/sources/pyside6/tests/util/pyqt_diff.py b/sources/pyside6/tests/util/pyqt_diff.py
deleted file mode 100644
index ac3d949d5..000000000
--- a/sources/pyside6/tests/util/pyqt_diff.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-'''Script to show the difference between PyQt5 and ours'''
-
-import sys
-
-from color import print_colored
-
-
-def check_module_diff(module_name):
- '''Difference between PySide6 and PyQt5 versions of qt bindings.
- Returns a tuple with the members present only on PySide6 and only on PyQt5'''
- shiboken_module = getattr(__import__('PySide6.' + module_name), module_name)
- orig_module = getattr(__import__('PyQt5.' + module_name), module_name)
-
- shiboken_set = set(dir(shiboken_module))
- orig_set = set(dir(orig_module))
-
- return sorted(shiboken_set - orig_set), sorted(orig_set - shiboken_set)
-
-
-def main(argv=None):
- if argv is None:
- argv = sys.argv
-
- module_name = argv[1] if len(argv) >= 2 else 'QtCore'
-
- only_shiboken, only_orig = check_module_diff(module_name)
-
- print_colored('Only on Shiboken version')
- print(only_shiboken)
-
- print_colored('Only on SIP version')
- print(only_orig)
-
-
-if __name__ == '__main__':
- main()