aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py')
-rw-r--r--sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py36
1 files changed, 15 insertions, 21 deletions
diff --git a/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py b/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py
index 1c0d5d55d..bfcf40111 100644
--- a/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py
+++ b/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py
@@ -26,12 +26,21 @@
##
#############################################################################
+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)
+
import PySide2
# This test tests the new "macro" feature of qApp.
# It also uses the qApp variable to finish the instance and start over.
+# Note: this test makes qapplication_singleton_test.py obsolete.
+
class qAppMacroTest(unittest.TestCase):
_test_1093_is_first = True
@@ -44,36 +53,21 @@ class qAppMacroTest(unittest.TestCase):
QtWidgets = QtGui = QtCore
# qApp is in the builtins
self.assertEqual(bool(qApp), False)
- # and also in certain PySide modules
- QtCore.qApp, QtGui.qApp, QtWidgets.qApp
- # and they are all the same
- self.assertTrue(qApp is QtCore.qApp is QtGui.qApp is QtWidgets.qApp)
- # and the type is NoneType, but it is not None (cannot work)
- self.assertTrue(type(qApp) is type(None))
- self.assertTrue(qApp is not None)
+ # and the type is None
+ self.assertTrue(qApp is None)
# now we create an application for all cases
classes = (QtCore.QCoreApplication,
QtGui.QGuiApplication,
QtWidgets.QApplication)
for klass in classes:
print("created", klass([]))
- del __builtins__.qApp
- print("deleted qApp")
+ qApp.shutdown()
+ print("deleted qApp", qApp)
# creating without deletion raises:
QtCore.QCoreApplication([])
with self.assertRaises(RuntimeError):
QtCore.QCoreApplication([])
- # assigning qApp is obeyed
- QtCore.qApp = 42
- del __builtins__.qApp
- self.assertEqual(QtCore.qApp, 42)
- self.assertNotEqual(__builtins__, 42)
- # delete it and it re-appears
- del QtCore.qApp
- QtCore.QCoreApplication([])
- self.assertEqual(QtCore.QCoreApplication.instance(), QtCore.qApp)
- # and they are again all the same
- self.assertTrue(qApp is QtCore.qApp is QtGui.qApp is QtWidgets.qApp)
+ self.assertEqual(QtCore.QCoreApplication.instance(), qApp)
def test_1093(self):
# Test that without creating a QApplication staticMetaObject still exists.
@@ -87,7 +81,7 @@ class qAppMacroTest(unittest.TestCase):
if app is None:
app = QtCore.QCoreApplication([])
self.assertTrue(QtCore.QObject.staticMetaObject is not None)
- del __builtins__.qApp
+ qApp.shutdown()
if __name__ == '__main__':