1############################################################################# 2## 3## Copyright (C) 2016 The Qt Company Ltd. 4## Contact: https://www.qt.io/licensing/ 5## 6## This file is part of the test suite of Qt for Python. 7## 8## $QT_BEGIN_LICENSE:GPL-EXCEPT$ 9## Commercial License Usage 10## Licensees holding valid commercial Qt licenses may use this file in 11## accordance with the commercial license agreement provided with the 12## Software or, alternatively, in accordance with the terms contained in 13## a written agreement between you and The Qt Company. For licensing terms 14## and conditions see https://www.qt.io/terms-conditions. For further 15## information use the contact form at https://www.qt.io/contact-us. 16## 17## GNU General Public License Usage 18## Alternatively, this file may be used under the terms of the GNU 19## General Public License version 3 as published by the Free Software 20## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21## included in the packaging of this file. Please review the following 22## information to ensure the GNU General Public License requirements will 23## be met: https://www.gnu.org/licenses/gpl-3.0.html. 24## 25## $QT_END_LICENSE$ 26## 27############################################################################# 28 29import os 30import sys 31import unittest 32 33sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 34from init_paths import init_test_paths 35init_test_paths(False) 36 37from PySide2.QtCore import QObject, SIGNAL, SLOT 38 39class Dummy(QObject): 40 """Dummy class used in this test.""" 41 def __init__(self, parent=None): 42 QObject.__init__(self, parent) 43 44class ShortCircuitSignals(unittest.TestCase): 45 def setUp(self): 46 self.called = False 47 48 def tearDown(self): 49 try: 50 del self.args 51 except: 52 pass 53 54 def callback(self, *args): 55 if tuple(self.args) == args: 56 self.called = True 57 58 def testNoArgs(self): 59 """Short circuit signal without arguments""" 60 obj1 = Dummy() 61 QObject.connect(obj1, SIGNAL('foo()'), self.callback) 62 self.args = tuple() 63 obj1.emit(SIGNAL('foo()'), *self.args) 64 self.assertTrue(self.called) 65 66 def testWithArgs(self): 67 """Short circuit signal with integer arguments""" 68 obj1 = Dummy() 69 70 QObject.connect(obj1, SIGNAL('foo(int)'), self.callback) 71 self.args = (42,) 72 obj1.emit(SIGNAL('foo(int)'), *self.args) 73 74 self.assertTrue(self.called) 75 76 def testMultipleArgs(self): 77 """Short circuit signal with multiple arguments""" 78 obj1 = Dummy() 79 80 QObject.connect(obj1, SIGNAL('foo(int,int,QString)'), self.callback) 81 self.args = (42,33,'char') 82 obj1.emit(SIGNAL('foo(int,int,QString)'), *self.args) 83 84 self.assertTrue(self.called) 85 86 def testComplexArgs(self): 87 """Short circuit signal with complex arguments""" 88 obj1 = Dummy() 89 90 QObject.connect(obj1, SIGNAL('foo(int,QObject*)'), self.callback) 91 self.args = (42, obj1) 92 obj1.emit(SIGNAL('foo(int,QObject*)'), *self.args) 93 94 self.assertTrue(self.called) 95 96if __name__ == '__main__': 97 unittest.main() 98