aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/util/helper
diff options
context:
space:
mode:
authorChristian Tismer <[email protected]>2021-05-16 12:24:00 +0200
committerChristian Tismer <[email protected]>2023-03-16 17:32:29 +0100
commitf668df2e26803989a4d4730ae219767bc9f229a9 (patch)
tree3da8c28021ec65c4d0e359302d93975ccc5ec6ad /sources/pyside6/tests/util/helper
parent6d6f614fdd7510a1b8a00a51bb6232a3d151523b (diff)
testing: modernize UsesQApplication and remove other versions
The last change to UsesQApplication can be generalized to be able to remove the QtCore and QtGui versions. Instead, the module and class to use are computed from the content of sys.modules . Task-number: PYSIDE-1564 Change-Id: Iac1fe3a2d6bb5a9f7638eb889f55b079cb55c272 Pick-to: 6.4 Reviewed-by: Friedemann Kleint <[email protected]>
Diffstat (limited to 'sources/pyside6/tests/util/helper')
-rw-r--r--sources/pyside6/tests/util/helper/usesqapplication.py26
-rw-r--r--sources/pyside6/tests/util/helper/usesqcoreapplication.py37
-rw-r--r--sources/pyside6/tests/util/helper/usesqguiapplication.py27
3 files changed, 18 insertions, 72 deletions
diff --git a/sources/pyside6/tests/util/helper/usesqapplication.py b/sources/pyside6/tests/util/helper/usesqapplication.py
index ed46e1e48..d6d070c69 100644
--- a/sources/pyside6/tests/util/helper/usesqapplication.py
+++ b/sources/pyside6/tests/util/helper/usesqapplication.py
@@ -10,23 +10,33 @@ import unittest
# 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[list(_ for _ in sys.modules if _.endswith(".QtWidgets"))[0]]
- QApplication = getattr(module, "QApplication")
+ 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()