aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-07-19 09:25:44 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-07-20 10:19:26 +0000
commit6460ab0b2a2d2e7167c9bf5977f76db1b7592aa7 (patch)
tree10bee1a381a5cdad099c7fe2657f5206d34afbef /sources
parent3fb2e0bdef4db7da3ee31bf6d810a59df22e9a2a (diff)
helper: Add UsesQGuiApplication
Add helper for testing with QGuiApplication. Change-Id: Ib56b0b118a5fe8e01c822c859419784921418913 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside2/tests/util/helper/__init__.py39
1 files changed, 25 insertions, 14 deletions
diff --git a/sources/pyside2/tests/util/helper/__init__.py b/sources/pyside2/tests/util/helper/__init__.py
index ff7af699..fa119c96 100644
--- a/sources/pyside2/tests/util/helper/__init__.py
+++ b/sources/pyside2/tests/util/helper/__init__.py
@@ -36,12 +36,19 @@ from random import randint
from PySide2.QtCore import QCoreApplication, QTimer
try:
- from PySide2.QtWidgets import QApplication
+ from PySide2.QtGui import QGuiApplication
except ImportError:
has_gui = False
else:
has_gui = True
+try:
+ from PySide2.QtWidgets import QApplication
+except ImportError:
+ has_widgets = False
+else:
+ has_widgets = True
+
def adjust_filename(filename, orig_mod_filename):
dirpath = os.path.dirname(os.path.abspath(orig_mod_filename))
return os.path.join(dirpath, filename)
@@ -76,11 +83,23 @@ class BasicPySlotCase(object):
else:
raise ValueError('Invalid arguments for callback')
+if has_gui:
+ class UsesQGuiApplication(unittest.TestCase):
+ '''Helper class to provide QGuiApplication instances'''
-_instance = None
-_timed_instance = None
+ def setUp(self):
+ '''Creates the QGuiApplication instance'''
-if has_gui:
+ # 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
+ super(UsesQGuiApplication, self).tearDown()
+
+if has_widgets:
class UsesQApplication(unittest.TestCase):
'''Helper class to provide QApplication instances'''
@@ -91,11 +110,7 @@ if has_gui:
# Simple way of making instance a singleton
super(UsesQApplication, self).setUp()
- global _instance
- if _instance is None:
- _instance = QApplication([])
-
- self.app = _instance
+ self.app = QApplication.instance() or QApplication([])
def tearDown(self):
'''Deletes the reference owned by self'''
@@ -110,11 +125,7 @@ if has_gui:
'''Setups this Application.
timeout - timeout in milisseconds'''
- global _timed_instance
- if _timed_instance is None:
- _timed_instance = QApplication([])
-
- self.app = _timed_instance
+ self.app = QApplication.instance() or QApplication([])
QTimer.singleShot(timeout, self.app.quit)
def tearDown(self):