diff options
Diffstat (limited to 'sources/pyside6/tests/signals/signal_emission_test.py')
-rw-r--r-- | sources/pyside6/tests/signals/signal_emission_test.py | 87 |
1 files changed, 30 insertions, 57 deletions
diff --git a/sources/pyside6/tests/signals/signal_emission_test.py b/sources/pyside6/tests/signals/signal_emission_test.py index faca38ccc..b31d89c2f 100644 --- a/sources/pyside6/tests/signals/signal_emission_test.py +++ b/sources/pyside6/tests/signals/signal_emission_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python - -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $QT_BEGIN_LICENSE:GPL-EXCEPT$ -## Commercial License Usage -## Licensees holding valid commercial Qt licenses may use this file in -## accordance with the commercial license agreement provided with the -## Software or, alternatively, in accordance with the terms contained in -## a written agreement between you and The Qt Company. For licensing terms -## and conditions see https://www.qt.io/terms-conditions. For further -## information use the contact form at https://www.qt.io/contact-us. -## -## GNU General Public License Usage -## Alternatively, this file may be used under the terms of the GNU -## General Public License version 3 as published by the Free Software -## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -## included in the packaging of this file. Please review the following -## information to ensure the GNU General Public License requirements will -## be met: https://www.gnu.org/licenses/gpl-3.0.html. -## -## $QT_END_LICENSE$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 """Tests covering signal emission and receiving to python slots""" @@ -40,47 +14,47 @@ 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, SLOT, QProcess, QTimeLine +from PySide6.QtCore import QObject, Signal, SIGNAL, QProcess, QTimeLine -from helper.basicpyslotcase import BasicPySlotCase -from helper.usesqcoreapplication import UsesQCoreApplication +from helper.usesqapplication import UsesQApplication -class ArgsOnEmptySignal(UsesQCoreApplication): +class ArgsOnEmptySignal(UsesQApplication): '''Trying to emit a signal without arguments passing some arguments''' def testArgsToNoArgsSignal(self): '''Passing arguments to a signal without arguments''' process = QProcess() - self.assertRaises(TypeError, process.emit, SIGNAL('started()'), 42) + self.assertRaises(TypeError, process.started.emit, 42) -class MoreArgsOnEmit(UsesQCoreApplication): +class MoreArgsOnEmit(UsesQApplication): '''Trying to pass more args than needed to emit (signals with args)''' def testMoreArgs(self): '''Passing more arguments than needed''' process = QProcess() - self.assertRaises(TypeError, process.emit, SIGNAL('finished(int)'), 55, 55) + self.assertRaises(TypeError, process.finished.emit, 55, QProcess.ExitStatus.NormalExit, 42) + +class Sender(QObject): + '''Sender class''' -class Dummy(QObject): - '''Dummy class''' - pass + dummy = Signal() + dummy_int = Signal(int) -class PythonSignalToCppSlots(UsesQCoreApplication): +class PythonSignalToCppSlots(UsesQApplication): '''Connect python signals to C++ slots''' def testWithoutArgs(self): '''Connect python signal to QTimeLine.toggleDirection()''' timeline = QTimeLine() - dummy = Dummy() - QObject.connect(dummy, SIGNAL('dummy()'), - timeline, SLOT('toggleDirection()')) + sender = Sender() + sender.dummy.connect(timeline.toggleDirection) orig_dir = timeline.direction() - dummy.emit(SIGNAL('dummy()')) + sender.dummy.emit() new_dir = timeline.direction() if orig_dir == QTimeLine.Forward: @@ -91,17 +65,16 @@ class PythonSignalToCppSlots(UsesQCoreApplication): def testWithArgs(self): '''Connect python signals to QTimeLine.setCurrentTime(int)''' timeline = QTimeLine() - dummy = Dummy() + sender = Sender() - QObject.connect(dummy, SIGNAL('dummy(int)'), - timeline, SLOT('setCurrentTime(int)')) + sender.dummy_int.connect(timeline.setCurrentTime) current = timeline.currentTime() - dummy.emit(SIGNAL('dummy(int)'), current + 42) + sender.dummy_int.emit(current + 42) self.assertEqual(timeline.currentTime(), current + 42) -class CppSignalsToCppSlots(UsesQCoreApplication): +class CppSignalsToCppSlots(UsesQApplication): '''Connection between C++ slots and signals''' def testWithoutArgs(self): @@ -109,13 +82,13 @@ class CppSignalsToCppSlots(UsesQCoreApplication): process = QProcess() timeline = QTimeLine() - QObject.connect(process, SIGNAL('finished(int, QProcess::ExitStatus)'), - timeline, SLOT('toggleDirection()')) + process.finished.connect(timeline.toggleDirection) orig_dir = timeline.direction() process.start(sys.executable, ['-c', '"print 42"']) - process.waitForFinished() + self.assertTrue(process.waitForStarted()) + self.assertTrue(process.waitForFinished()) new_dir = timeline.direction() @@ -133,25 +106,25 @@ def someSlot(args=None): called = True -class DynamicSignalsToFuncPartial(UsesQCoreApplication): +class DynamicSignalsToFuncPartial(UsesQApplication): def testIt(self): global called called = False - o = QObject() - o.connect(o, SIGNAL("ASignal()"), functools.partial(someSlot, "partial ..")) - o.emit(SIGNAL("ASignal()")) + o = Sender() + o.dummy.connect(functools.partial(someSlot, "partial ..")) + o.dummy.emit() self.assertTrue(called) -class EmitUnknownType(UsesQCoreApplication): +class EmitUnknownType(UsesQApplication): def testIt(self): a = QObject() a.connect(SIGNAL('foobar(Dummy)'), lambda x: 42) # Just connect with an unknown type self.assertRaises(TypeError, a.emit, SIGNAL('foobar(Dummy)'), 22) -class EmitEnum(UsesQCoreApplication): +class EmitEnum(UsesQApplication): """Test emission of enum arguments""" def slot(self, arg): |