aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLuciano Wolf <luciano.wolf@openbossa.org>2010-05-17 19:48:16 -0300
committerRenato Filho <renato.filho@openbossa.org>2010-05-17 19:55:33 -0300
commit9a8bc9c3d14f37e8a25ef820d1cdc25807842ee4 (patch)
tree0ae157c42a570627f7b6a6b9b52ea1b93b30d638 /tests
parent16809db86b7fbdde8cb4cf3d525d9d8e34fc03be (diff)
Adding new-style signal/slot tests.
Based on Marcelo Lira's source code. Reviewer: Hugo Parente Lima <hugo.lima@openbossa.org>, Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/signals/ref01_test.py27
-rwxr-xr-xtests/signals/ref02_test.py47
-rwxr-xr-xtests/signals/ref03_test.py29
-rwxr-xr-xtests/signals/ref04_test.py56
-rwxr-xr-xtests/signals/ref05_test.py46
-rwxr-xr-xtests/signals/ref06_test.py49
6 files changed, 254 insertions, 0 deletions
diff --git a/tests/signals/ref01_test.py b/tests/signals/ref01_test.py
new file mode 100755
index 00000000..ba6839ec
--- /dev/null
+++ b/tests/signals/ref01_test.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import unittest
+from PySide.QtCore import QObject, Signal
+
+class BoundAndUnboundSignalsTest(unittest.TestCase):
+
+ def setUp(self):
+ self.methods = set(('connect', 'disconnect', 'emit'))
+
+ def tearDown(self):
+ del self.methods
+
+ def testUnboundSignal(self):
+ self.assertEqual(type(QObject.destroyed), Signal)
+ self.assertFalse(self.methods.issubset(dir(QObject.destroyed)))
+
+ def testBoundSignal(self):
+ obj = QObject()
+ self.assertNotEqual(type(obj.destroyed), Signal)
+ self.assert_(self.methods.issubset(dir(obj.destroyed)))
+
+if __name__ == '__main__':
+ unittest.main()
+
+
diff --git a/tests/signals/ref02_test.py b/tests/signals/ref02_test.py
new file mode 100755
index 00000000..4580f04a
--- /dev/null
+++ b/tests/signals/ref02_test.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import unittest
+from PySide.QtCore import QCoreApplication, QTimeLine
+from helper import UsesQCoreApplication
+
+class NativeSignalsTest(UsesQCoreApplication):
+
+ def setUp(self):
+ UsesQCoreApplication.setUp(self)
+ self.called = False
+ self.timeline = QTimeLine(100)
+
+ def tearDown(self):
+ del self.called
+ del self.timeline
+ UsesQCoreApplication.tearDown(self)
+
+ def testSignalWithIntArgument(self):
+
+ def valueChangedSlot(value):
+ self.called = True
+ self.assertEqual(type(value), float)
+ self.app.quit()
+
+ self.timeline.valueChanged.connect(valueChangedSlot)
+ self.timeline.start()
+
+ self.app.exec_()
+ self.assert_(self.called)
+
+ def testSignalWithoutArguments(self):
+
+ def finishedSlot():
+ self.called = True
+ self.app.quit()
+
+ self.timeline.finished.connect(finishedSlot)
+ self.timeline.start()
+
+ self.app.exec_()
+ self.assert_(self.called)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/signals/ref03_test.py b/tests/signals/ref03_test.py
new file mode 100755
index 00000000..f974d743
--- /dev/null
+++ b/tests/signals/ref03_test.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import unittest
+from sys import getrefcount
+from PySide.QtCore import QObject
+
+class DisconnectSignalsTest(unittest.TestCase):
+
+ def setUp(self):
+ self.emitter = QObject()
+
+ def tearDown(self):
+ del self.emitter
+
+ def testConnectionRefCount(self):
+
+ def destroyedSlot():
+ pass
+
+ self.assertEqual(getrefcount(destroyedSlot), 2)
+ self.emitter.destroyed.connect(destroyedSlot)
+ self.assertEqual(getrefcount(destroyedSlot), 3)
+ self.emitter.destroyed.disconnect(destroyedSlot)
+ self.assertEqual(getrefcount(destroyedSlot), 2)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/signals/ref04_test.py b/tests/signals/ref04_test.py
new file mode 100755
index 00000000..88a59f68
--- /dev/null
+++ b/tests/signals/ref04_test.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import unittest
+from PySide.QtCore import QObject, Signal
+
+class ExtQObject(QObject):
+
+ mySignal = Signal()
+
+ def __init__(self):
+ QObject.__init__(self)
+
+
+class UserSignalTest(unittest.TestCase):
+
+ def setUp(self):
+ self.emitter = ExtQObject()
+ self.counter = 0
+
+ def tearDown(self):
+ del self.emitter
+ del self.counter
+
+ def testConnectEmitDisconnect(self):
+
+ def slot():
+ self.counter += 1
+
+ self.emitter.mySignal.connect(slot)
+
+ self.assertEqual(self.counter, 0)
+ self.emitter.mySignal.emit()
+ self.assertEqual(self.counter, 1)
+ self.emitter.mySignal.emit()
+ self.assertEqual(self.counter, 2)
+
+ self.emitter.mySignal.disconnect(slot)
+
+ self.emitter.mySignal.emit()
+ self.assertEqual(self.counter, 2)
+
+# def testConnectWithConfigureMethod(self):
+#
+# def slot():
+# self.counter += 1
+#
+# self.emitter.pyqtConfigure(mySignal=slot)
+# self.assertEqual(self.counter, 0)
+# self.emitter.mySignal.emit()
+# self.assertEqual(self.counter, 1)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/signals/ref05_test.py b/tests/signals/ref05_test.py
new file mode 100755
index 00000000..7c53300a
--- /dev/null
+++ b/tests/signals/ref05_test.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import unittest
+from PySide.QtCore import QObject, QCoreApplication, QTimeLine, Slot
+from helper import UsesQCoreApplication
+
+class ExtQObject(QObject):
+
+ def __init__(self):
+ QObject.__init__(self)
+ self.counter = 0
+
+ @Slot('qreal')
+ def foo(self, value):
+ self.counter += 1
+
+
+class UserSlotTest(UsesQCoreApplication):
+
+ def setUp(self):
+ UsesQCoreApplication.setUp(self)
+ self.receiver = ExtQObject()
+ self.timeline = QTimeLine(100)
+
+ def tearDown(self):
+ del self.timeline
+ del self.receiver
+ UsesQCoreApplication.tearDown(self)
+
+ def testUserSlot(self):
+ self.timeline.setUpdateInterval(10)
+
+ self.timeline.finished.connect(self.app.quit)
+
+ self.timeline.valueChanged.connect(self.receiver.foo)
+ self.timeline.start()
+
+ self.app.exec_()
+
+ self.assertEqual(self.receiver.counter, 10)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/signals/ref06_test.py b/tests/signals/ref06_test.py
new file mode 100755
index 00000000..05712b3b
--- /dev/null
+++ b/tests/signals/ref06_test.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import unittest
+from PySide.QtCore import QObject, QCoreApplication, QTimeLine, Signal, Slot
+from helper import UsesQCoreApplication
+
+class ExtQObject(QObject):
+ signalbetween = Signal('qreal')
+
+ def __init__(self):
+ QObject.__init__(self)
+ self.counter = 0
+
+ @Slot('qreal')
+ def foo(self, value):
+ self.counter += 1
+
+
+class SignaltoSignalTest(UsesQCoreApplication):
+
+ def setUp(self):
+ UsesQCoreApplication.setUp(self)
+ self.receiver = ExtQObject()
+ self.timeline = QTimeLine(100)
+
+ def tearDown(self):
+ del self.timeline
+ del self.receiver
+ UsesQCoreApplication.tearDown(self)
+
+ def testSignaltoSignal(self):
+ self.timeline.setUpdateInterval(10)
+
+ self.timeline.finished.connect(self.app.quit)
+
+ self.timeline.valueChanged.connect(self.receiver.signalbetween)
+ self.receiver.signalbetween.connect(self.receiver.foo)
+
+ self.timeline.start()
+
+ self.app.exec_()
+
+ self.assertEqual(self.receiver.counter, 10)
+
+
+if __name__ == '__main__':
+ unittest.main()
+