Skip to content

Commit c153116

Browse files
committed
Update binding tests on bound signal.
1 parent a0ead2e commit c153116

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

tests/binding_tests.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import sys
55
import unittest
6-
from shim import QtCore, Signal, Slot, is_pyqt, run_test_script
6+
from shim import QtCore, QtWidgets, Signal, Slot, is_pyqt, run_test_script
77

88

99
qc = QtCore.Qt.ConnectionType.QueuedConnection
@@ -356,6 +356,14 @@ def test_raise_KeyboardInterrupt_from_slot(self):
356356

357357
class TestBoundSignal(unittest.TestCase):
358358
# Tests related to a bound signal.
359+
def setUp(self):
360+
if QtWidgets.QApplication.instance() is not None:
361+
self.app = QtWidgets.QApplication.instance()
362+
else:
363+
self.app = QtWidgets.QApplication([])
364+
365+
def tearDown(self):
366+
self.app = None
359367

360368
def test_identity(self):
361369
# Test various identity/equality relation between two bound signals
@@ -366,8 +374,21 @@ def test_identity(self):
366374
if is_pyqt:
367375
self.assertTrue(s1 == s2)
368376
self.assertTrue(s1 is not s2)
369-
elif QtCore.__name__.startswith('PySide2'):
377+
else:
370378
self.assertTrue(s1 == s2)
379+
self.assertTrue(s1 is s2)
380+
381+
def test_identity_exceptions(self):
382+
# The previous test looks nice, but PySide2 'breaks the rule' for
383+
# certain bound signals, strangely.
384+
sender = QtWidgets.QPushButton()
385+
s1 = sender.clicked
386+
s2 = sender.clicked
387+
if is_pyqt:
388+
self.assertTrue(s1 == s2)
389+
self.assertTrue(s1 is not s2)
390+
elif QtCore.__name__.startswith('PySide2'):
391+
self.assertTrue(s1 != s2)
371392
self.assertTrue(s1 is not s2)
372393
elif QtCore.__name__.startswith('PySide6'):
373394
self.assertTrue(s1 == s2)
@@ -398,14 +419,12 @@ def handler2(v):
398419
bound_signal.emit(True)
399420
sender = None
400421

401-
app = QtCore.QCoreApplication([])
402422
qt_loop = QtCore.QEventLoop()
403423
QtCore.QTimer.singleShot(100, qt_loop.quit)
404424
if hasattr(qt_loop, "exec"):
405425
qt_loop.exec()
406426
else:
407427
qt_loop.exec_()
408-
app = None
409428

410429
self.assertEqual(var1, 26)
411430
if is_pyqt:

0 commit comments

Comments
 (0)