コード例 #1
0
    def testTypedef(self):
        obj = TestObject(0)
        receiver = Receiver()

        obj.signalWithTypedefValue.connect(receiver.slot)
        obj.emitSignalWithTypedefValue(2)
        self.assertEqual(receiver.received.value, 2)
コード例 #2
0
ファイル: application_test.py プロジェクト: Hasimir/PySide
 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)
コード例 #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")
コード例 #4
0
ファイル: application_test.py プロジェクト: hz658832/PySide2
 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)
コード例 #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))
コード例 #6
0
 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)
コード例 #7
0
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)
コード例 #8
0
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)
コード例 #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)
コード例 #10
0
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)
コード例 #11
0
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)
コード例 #12
0
 def testHomonymousSignalAndStaticMethod(self):
     self.assertEqual(TestObject.staticMethodDouble(3), 6)
コード例 #13
0
 def setUp(self):
     self.obj1 = TestObject(0)
     self.obj2 = TestObject(0)
     self.one_called = 0
     self.two_called = 0
コード例 #14
0
 def testCallingOfDecoratedSlot(self):
     obj = TestObject(0)
     receiver = Receiver()
     obj.staticMethodDouble.connect(receiver.slot)
     obj.emitStaticMethodDoubleSignal()
     self.assertTrue(receiver.called)
コード例 #15
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)
コード例 #16
0
ファイル: decoratedslot_test.py プロジェクト: Hasimir/PySide
 def testCallingOfDecoratedSlot(self):
     obj = TestObject(0)
     receiver = Receiver()
     obj.staticMethodDouble.connect(receiver.slot)
     obj.emitStaticMethodDoubleSignal()
     self.assert_(receiver.called)
コード例 #17
0
 def setUp(self):
     self.value = 123
     self.called = False
     self.obj = TestObject(self.value)
コード例 #18
0
 def setUp(self):
     self.obj = TestObject(0)
     self.void_called = False
     self.bool_called = False
コード例 #19
0
ファイル: qvariant_test.py プロジェクト: donfaco/pyside2
 def testQKeySequenceQVariantOperator(self):
     # bug #775
     ks = QKeySequence(Qt.SHIFT, Qt.CTRL, Qt.Key_P, Qt.Key_R)
     self.assertEqual(TestObject.checkType(ks), 76)
コード例 #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)
コード例 #21
0
 def setUp(self):
     self.value = 123
     self.called = False
     self.obj = TestObject(self.value)
コード例 #22
0
 def setUp(self):
     self.obj1 = TestObject(0)
     self.obj2 = TestObject(0)
     self.one_called = 0
     self.two_called = 0
コード例 #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)
コード例 #24
0
 def setUp(self):
     self.obj = TestObject(0)
     self.void_called = False
     self.bool_called = False
コード例 #25
0
 def testHomonymousSignalAndStaticMethod(self):
     self.assertEqual(TestObject.staticMethodDouble(3), 6)