diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-03 13:44:51 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-09 13:20:13 +0200 |
| commit | 140b7df1263e2d24d1fc69b8ad305e8189d1dadc (patch) | |
| tree | 0f414ea7a55bd8407651ddb0441e0c05ed2e8f79 /sources/pyside6/tests/signals/lambda_gui_test.py | |
| parent | f619b4c45b042c3a656a80b57cb4f154ef15bd1a (diff) | |
Port signals tests to modern syntax
Use the modern syntax where appropriate. Some tests are
left unmodified to at least test the syntax.
As a drive-by, remove the hasQtGui import checks since
widgets should be built when this is run.
Pick-to: 6.7
Task-number: PYSIDE-2646
Change-Id: I9acf07d0b735009f6aff4a55382dae745d855786
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/tests/signals/lambda_gui_test.py')
| -rw-r--r-- | sources/pyside6/tests/signals/lambda_gui_test.py | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/sources/pyside6/tests/signals/lambda_gui_test.py b/sources/pyside6/tests/signals/lambda_gui_test.py index 736b800bf..2123e7206 100644 --- a/sources/pyside6/tests/signals/lambda_gui_test.py +++ b/sources/pyside6/tests/signals/lambda_gui_test.py @@ -12,43 +12,39 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from PySide6.QtCore import QObject, SIGNAL - -try: - from PySide6.QtWidgets import QSpinBox, QPushButton - hasQtGui = True -except ImportError: - hasQtGui = False +from PySide6.QtWidgets import QSpinBox, QPushButton from helper.usesqapplication import UsesQApplication -if hasQtGui: - class Control: - def __init__(self): - self.arg = False - - class QtGuiSigLambda(UsesQApplication): - - def testButton(self): - # Connecting a lambda to a QPushButton.clicked() - obj = QPushButton('label') - ctr = Control() - func = lambda: setattr(ctr, 'arg', True) # noqa: E731 - obj.clicked.connect(func) - obj.click() - self.assertTrue(ctr.arg) - QObject.disconnect(obj, SIGNAL('clicked()'), func) - - def testSpinButton(self): - # Connecting a lambda to a QPushButton.clicked() - obj = QSpinBox() - ctr = Control() - arg = 444 - func = lambda x: setattr(ctr, 'arg', 444) # noqa: E731 - obj.valueChanged.connect(func) - obj.setValue(444) - self.assertEqual(ctr.arg, arg) - QObject.disconnect(obj, SIGNAL('valueChanged(int)'), func) + +class Control: + def __init__(self): + self.arg = False + + +class QtWidgetsSigLambda(UsesQApplication): + + def testButton(self): + # Connecting a lambda to a QPushButton.clicked() + obj = QPushButton('label') + ctr = Control() + func = lambda: setattr(ctr, 'arg', True) # noqa: E731 + obj.clicked.connect(func) + obj.click() + self.assertTrue(ctr.arg) + self.assertTrue(obj.clicked.disconnect(func)) + + def testSpinButton(self): + # Connecting a lambda to a QPushButton.clicked() + obj = QSpinBox() + ctr = Control() + arg = 444 + func = lambda x: setattr(ctr, 'arg', 444) # noqa: E731 + obj.valueChanged.connect(func) + obj.setValue(444) + self.assertEqual(ctr.arg, arg) + self.assertTrue(obj.valueChanged.disconnect(func)) + if __name__ == '__main__': unittest.main() |
