def testTypedef(self):
        obj = TestObject(0)
        receiver = Receiver()

        obj.signalWithTypedefValue.connect(receiver.slot)
        obj.emitSignalWithTypedefValue(2)
        self.assertEqual(receiver.received.value, 2)
Beispiel #2
0
 def testInstanceObject(self):
     TestObject.createApp()
     app1 = QApplication.instance()
     app2 = QApplication.instance()
     app1.setObjectName("MyApp")
     self.assertEqual(app1, app2)
     self.assertEqual(app2.objectName(), app1.objectName())
     app1.destroyed.connect(self.appDestroyed)
Beispiel #3
0
 def testConnection(self):
     o = TestObject(0)
     c = QObject()
     c.setObjectName("child")
     self._child = None
     o.childrenChanged.connect(self.childrenChanged)
     o.addChild(c)
     self.assertEquals(self._child.objectName(), "child")
Beispiel #4
0
 def testInstanceObject(self):
     TestObject.createApp()
     app1 = QApplication.instance()
     app2 = QApplication.instance()
     app1.setObjectName("MyApp")
     self.assertEqual(app1, app2)
     self.assertEqual(app2.objectName(), app1.objectName())
     app1.destroyed.connect(self.appDestroyed)
Beispiel #5
0
    def testReprWithoutNamespace(self):
        """Test that classes outside a namespace that have a operator<<(QDebug,...) defined use that
        for __repr__"""
        t = TestObject(123)

        # We don't define __str__, so str(q) should call __repr__
        self.assertEqual(t.__repr__(), str(t))

        # __repr__ should use the operator<<(QDebug,...) implementation
        self.assertIn('TestObject(id=123)', str(t))
 def testInstanceObject(self):
     self.assertEqual(type(qApp), type(None))
     TestObject.createApp()
     app1 = QApplication.instance()
     app2 = QApplication.instance()
     app1.setObjectName("MyApp")
     self.assertEqual(app1, app2)
     self.assertEqual(app2.objectName(), app1.objectName())
     if len(all) > 3:
         # an import triggers qApp initialization
         __import__("PySide2." + all[-1])
         self.assertEqual(app1, qApp)
     app1.destroyed.connect(self.appDestroyed)
class SignalWithDefaultValueTest(unittest.TestCase):

    def setUp(self):
        self.obj = TestObject(0)
        self.void_called = False
        self.bool_called = False

    def tearDown(self):
        del self.obj
        del self.void_called
        del self.bool_called

    def testConnectNewStyleEmitVoidSignal(self):
        def callbackVoid():
            self.void_called = True
        def callbackBool(value):
            self.bool_called = True
        self.obj.signalWithDefaultValue.connect(callbackVoid)
        self.obj.signalWithDefaultValue[bool].connect(callbackBool)
        self.obj.emitSignalWithDefaultValue_void()
        self.assert_(self.void_called)
        self.assert_(self.bool_called)

    def testConnectNewStyleEmitBoolSignal(self):
        def callbackVoid():
            self.void_called = True
        def callbackBool(value):
            self.bool_called = True
        self.obj.signalWithDefaultValue.connect(callbackVoid)
        self.obj.signalWithDefaultValue[bool].connect(callbackBool)
        self.obj.emitSignalWithDefaultValue_bool()
        self.assert_(self.void_called)
        self.assert_(self.bool_called)

    def testConnectOldStyleEmitVoidSignal(self):
        def callbackVoid():
            self.void_called = True
        def callbackBool(value):
            self.bool_called = True
        QObject.connect(self.obj, SIGNAL('signalWithDefaultValue()'), callbackVoid)
        QObject.connect(self.obj, SIGNAL('signalWithDefaultValue(bool)'), callbackBool)
        self.obj.emitSignalWithDefaultValue_void()
        self.assert_(self.void_called)
        self.assert_(self.bool_called)

    def testConnectOldStyleEmitBoolSignal(self):
        def callbackVoid():
            self.void_called = True
        def callbackBool(value):
            self.bool_called = True
        QObject.connect(self.obj, SIGNAL('signalWithDefaultValue()'), callbackVoid)
        QObject.connect(self.obj, SIGNAL('signalWithDefaultValue(bool)'), callbackBool)
        self.obj.emitSignalWithDefaultValue_bool()
        self.assert_(self.void_called)
        self.assert_(self.bool_called)
class SignalWithDefaultValueTest(unittest.TestCase):

    def setUp(self):
        self.obj = TestObject(0)
        self.void_called = False
        self.bool_called = False

    def tearDown(self):
        del self.obj
        del self.void_called
        del self.bool_called

    def testConnectNewStyleEmitVoidSignal(self):
        def callbackVoid():
            self.void_called = True
        def callbackBool(value):
            self.bool_called = True
        self.obj.signalWithDefaultValue.connect(callbackVoid)
        self.obj.signalWithDefaultValue[bool].connect(callbackBool)
        self.obj.emitSignalWithDefaultValue_void()
        self.assertTrue(self.void_called)
        self.assertTrue(self.bool_called)

    def testConnectNewStyleEmitBoolSignal(self):
        def callbackVoid():
            self.void_called = True
        def callbackBool(value):
            self.bool_called = True
        self.obj.signalWithDefaultValue.connect(callbackVoid)
        self.obj.signalWithDefaultValue[bool].connect(callbackBool)
        self.obj.emitSignalWithDefaultValue_bool()
        self.assertTrue(self.void_called)
        self.assertTrue(self.bool_called)

    def testConnectOldStyleEmitVoidSignal(self):
        def callbackVoid():
            self.void_called = True
        def callbackBool(value):
            self.bool_called = True
        QObject.connect(self.obj, SIGNAL('signalWithDefaultValue()'), callbackVoid)
        QObject.connect(self.obj, SIGNAL('signalWithDefaultValue(bool)'), callbackBool)
        self.obj.emitSignalWithDefaultValue_void()
        self.assertTrue(self.void_called)
        self.assertTrue(self.bool_called)

    def testConnectOldStyleEmitBoolSignal(self):
        def callbackVoid():
            self.void_called = True
        def callbackBool(value):
            self.bool_called = True
        QObject.connect(self.obj, SIGNAL('signalWithDefaultValue()'), callbackVoid)
        QObject.connect(self.obj, SIGNAL('signalWithDefaultValue(bool)'), callbackBool)
        self.obj.emitSignalWithDefaultValue_bool()
        self.assertTrue(self.void_called)
        self.assertTrue(self.bool_called)
Beispiel #9
0
    def testDuringCallback(self):
        """ Test to see if the C++ object for a connection is accessed after the
        method returns.  This causes a segfault if the memory that was used by the
        C++ object has been reused. """

        self.called = False
        obj = TestObject(0)

        def callback():
            obj.signalWithDefaultValue.disconnect(callback)

            # Connect more callbacks to try to overwrite memory
            for i in range(1000):
                obj.signalWithDefaultValue.connect(lambda: None)

            self.called = True

            # A non-None return value is needed
            return True

        obj.signalWithDefaultValue.connect(callback)
        obj.signalWithDefaultValue.emit()
        self.assertTrue(self.called)
class HomonymousSignalAndMethodTest(unittest.TestCase):
    def setUp(self):
        self.value = 123
        self.called = False
        self.obj = TestObject(self.value)

    def tearDown(self):
        del self.value
        del self.called
        del self.obj

    def testIdValueSignalEmission(self):
        def callback(idValue):
            self.assertEqual(idValue, self.value)

        self.obj.idValue.connect(callback)
        self.obj.emitIdValueSignal()

    def testStaticMethodDoubleSignalEmission(self):
        def callback():
            self.called = True

        self.obj.staticMethodDouble.connect(callback)
        self.obj.emitStaticMethodDoubleSignal()
        self.assertTrue(self.called)

    def testSignalNotCallable(self):
        self.assertRaises(TypeError, self.obj.justASignal)

    def testCallingInstanceMethodWithArguments(self):
        self.assertRaises(TypeError, TestObject.idValue, 1)

    def testCallingInstanceMethodWithoutArguments(self):
        self.assertRaises(TypeError, TestObject.idValue)

    def testHomonymousSignalAndMethod(self):
        self.assertEqual(self.obj.idValue(), self.value)

    def testHomonymousSignalAndStaticMethod(self):
        self.assertEqual(TestObject.staticMethodDouble(3), 6)

    def testHomonymousSignalAndStaticMethodFromInstance(self):
        self.assertEqual(self.obj.staticMethodDouble(4), 8)
class HomonymousSignalAndMethodTest(unittest.TestCase):

    def setUp(self):
        self.value = 123
        self.called = False
        self.obj = TestObject(self.value)

    def tearDown(self):
        del self.value
        del self.called
        del self.obj

    def testIdValueSignalEmission(self):
        def callback(idValue):
            self.assertEqual(idValue, self.value)
        self.obj.idValue.connect(callback)
        self.obj.emitIdValueSignal()

    def testStaticMethodDoubleSignalEmission(self):
        def callback():
            self.called = True
        self.obj.staticMethodDouble.connect(callback)
        self.obj.emitStaticMethodDoubleSignal()
        self.assert_(self.called)

    def testSignalNotCallable(self):
        self.assertRaises(TypeError, self.obj.justASignal)

    def testCallingInstanceMethodWithArguments(self):
        self.assertRaises(TypeError, TestObject.idValue, 1)

    def testCallingInstanceMethodWithoutArguments(self):
        self.assertRaises(TypeError, TestObject.idValue)

    def testHomonymousSignalAndMethod(self):
        self.assertEqual(self.obj.idValue(), self.value)

    def testHomonymousSignalAndStaticMethod(self):
        self.assertEqual(TestObject.staticMethodDouble(3), 6)

    def testHomonymousSignalAndStaticMethodFromInstance(self):
        self.assertEqual(self.obj.staticMethodDouble(4), 8)
 def testHomonymousSignalAndStaticMethod(self):
     self.assertEqual(TestObject.staticMethodDouble(3), 6)
 def setUp(self):
     self.obj1 = TestObject(0)
     self.obj2 = TestObject(0)
     self.one_called = 0
     self.two_called = 0
Beispiel #14
0
 def testCallingOfDecoratedSlot(self):
     obj = TestObject(0)
     receiver = Receiver()
     obj.staticMethodDouble.connect(receiver.slot)
     obj.emitStaticMethodDoubleSignal()
     self.assertTrue(receiver.called)
class SignalEmissionFromPython(unittest.TestCase):

    def setUp(self):
        self.obj1 = TestObject(0)
        self.obj2 = TestObject(0)
        self.one_called = 0
        self.two_called = 0

    def tearDown(self):
        del self.obj1
        del self.obj2
        del self.one_called
        del self.two_called

    def testConnectNewStyleEmitVoidSignal(self):
        def callbackOne():
            self.one_called += 1
            self.obj2.signalWithDefaultValue.emit()
        def callbackTwo():
            self.two_called += 1
        self.obj1.signalWithDefaultValue.connect(callbackOne)
        self.obj2.signalWithDefaultValue.connect(callbackTwo)
        self.obj1.emitSignalWithDefaultValue_void()
        self.obj2.emitSignalWithDefaultValue_void()
        self.assertEqual(self.one_called, 1)
        self.assertEqual(self.two_called, 2)

    def testConnectOldStyleEmitVoidSignal(self):
        def callbackOne():
            self.one_called += 1
            self.obj2.signalWithDefaultValue.emit()
        def callbackTwo():
            self.two_called += 1
        QObject.connect(self.obj1, SIGNAL('signalWithDefaultValue()'), callbackOne)
        QObject.connect(self.obj2, SIGNAL('signalWithDefaultValue()'), callbackTwo)
        self.obj1.emitSignalWithDefaultValue_void()
        self.obj2.emitSignalWithDefaultValue_void()
        self.assertEqual(self.one_called, 1)
        self.assertEqual(self.two_called, 2)

    def testConnectNewStyleEmitBoolSignal(self):
        def callbackOne():
            self.one_called += 1
            self.obj2.signalWithDefaultValue[bool].emit(True)
        def callbackTwo():
            self.two_called += 1
        self.obj1.signalWithDefaultValue.connect(callbackOne)
        self.obj2.signalWithDefaultValue.connect(callbackTwo)
        self.obj1.emitSignalWithDefaultValue_void()
        self.obj2.emitSignalWithDefaultValue_void()
        self.assertEqual(self.one_called, 1)
        self.assertEqual(self.two_called, 2)

    def testConnectOldStyleEmitBoolSignal(self):
        def callbackOne():
            self.one_called += 1
            self.obj2.signalWithDefaultValue[bool].emit(True)
        def callbackTwo():
            self.two_called += 1
        QObject.connect(self.obj1, SIGNAL('signalWithDefaultValue()'), callbackOne)
        QObject.connect(self.obj2, SIGNAL('signalWithDefaultValue()'), callbackTwo)
        self.obj1.emitSignalWithDefaultValue_void()
        self.obj2.emitSignalWithDefaultValue_void()
        self.assertEqual(self.one_called, 1)
        self.assertEqual(self.two_called, 2)
Beispiel #16
0
 def testCallingOfDecoratedSlot(self):
     obj = TestObject(0)
     receiver = Receiver()
     obj.staticMethodDouble.connect(receiver.slot)
     obj.emitStaticMethodDoubleSignal()
     self.assert_(receiver.called)
 def setUp(self):
     self.value = 123
     self.called = False
     self.obj = TestObject(self.value)
 def setUp(self):
     self.obj = TestObject(0)
     self.void_called = False
     self.bool_called = False
Beispiel #19
0
 def testQKeySequenceQVariantOperator(self):
     # bug #775
     ks = QKeySequence(Qt.SHIFT, Qt.CTRL, Qt.Key_P, Qt.Key_R)
     self.assertEqual(TestObject.checkType(ks), 76)
Beispiel #20
0
 def testQKeySequenceQVariantOperator(self):
     # bug #775
     ks = QKeySequence(Qt.SHIFT, Qt.CTRL, Qt.Key_P, Qt.Key_R)
     self.assertEqual(TestObject.checkType(ks), 75)
 def setUp(self):
     self.value = 123
     self.called = False
     self.obj = TestObject(self.value)
Beispiel #22
0
 def setUp(self):
     self.obj1 = TestObject(0)
     self.obj2 = TestObject(0)
     self.one_called = 0
     self.two_called = 0
Beispiel #23
0
class SignalEmissionFromPython(unittest.TestCase):

    def setUp(self):
        self.obj1 = TestObject(0)
        self.obj2 = TestObject(0)
        self.one_called = 0
        self.two_called = 0

    def tearDown(self):
        del self.obj1
        del self.obj2
        del self.one_called
        del self.two_called

    def testConnectNewStyleEmitVoidSignal(self):
        def callbackOne():
            self.one_called += 1
            self.obj2.signalWithDefaultValue.emit()
        def callbackTwo():
            self.two_called += 1
        self.obj1.signalWithDefaultValue.connect(callbackOne)
        self.obj2.signalWithDefaultValue.connect(callbackTwo)
        self.obj1.emitSignalWithDefaultValue_void()
        self.obj2.emitSignalWithDefaultValue_void()
        self.assertEqual(self.one_called, 1)
        self.assertEqual(self.two_called, 2)

    def testConnectOldStyleEmitVoidSignal(self):
        def callbackOne():
            self.one_called += 1
            self.obj2.signalWithDefaultValue.emit()
        def callbackTwo():
            self.two_called += 1
        QObject.connect(self.obj1, SIGNAL('signalWithDefaultValue()'), callbackOne)
        QObject.connect(self.obj2, SIGNAL('signalWithDefaultValue()'), callbackTwo)
        self.obj1.emitSignalWithDefaultValue_void()
        self.obj2.emitSignalWithDefaultValue_void()
        self.assertEqual(self.one_called, 1)
        self.assertEqual(self.two_called, 2)

    def testConnectNewStyleEmitBoolSignal(self):
        def callbackOne():
            self.one_called += 1
            self.obj2.signalWithDefaultValue[bool].emit(True)
        def callbackTwo():
            self.two_called += 1
        self.obj1.signalWithDefaultValue.connect(callbackOne)
        self.obj2.signalWithDefaultValue.connect(callbackTwo)
        self.obj1.emitSignalWithDefaultValue_void()
        self.obj2.emitSignalWithDefaultValue_void()
        self.assertEqual(self.one_called, 1)
        self.assertEqual(self.two_called, 2)

    def testConnectOldStyleEmitBoolSignal(self):
        def callbackOne():
            self.one_called += 1
            self.obj2.signalWithDefaultValue[bool].emit(True)
        def callbackTwo():
            self.two_called += 1
        QObject.connect(self.obj1, SIGNAL('signalWithDefaultValue()'), callbackOne)
        QObject.connect(self.obj2, SIGNAL('signalWithDefaultValue()'), callbackTwo)
        self.obj1.emitSignalWithDefaultValue_void()
        self.obj2.emitSignalWithDefaultValue_void()
        self.assertEqual(self.one_called, 1)
        self.assertEqual(self.two_called, 2)
 def setUp(self):
     self.obj = TestObject(0)
     self.void_called = False
     self.bool_called = False
 def testHomonymousSignalAndStaticMethod(self):
     self.assertEqual(TestObject.staticMethodDouble(3), 6)