diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2009-09-21 14:51:26 -0300 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2009-09-21 14:52:09 -0300 |
commit | 9af36fbb64f19842c0cc797c0b586b3a686805e8 (patch) | |
tree | 6bbc050ded0f85517ea75f5dc6dc1ed172168248 /tests/signals/signal_emission_test.py | |
parent | aa12538d63685ef8f75adaa79411b751929b727d (diff) |
Added all original pyside unit tests to the shiboken version.
Diffstat (limited to 'tests/signals/signal_emission_test.py')
-rw-r--r-- | tests/signals/signal_emission_test.py | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/tests/signals/signal_emission_test.py b/tests/signals/signal_emission_test.py new file mode 100644 index 000000000..8d9af620c --- /dev/null +++ b/tests/signals/signal_emission_test.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python + +"""Tests covering signal emission and receiving to python slots""" + +import sys +import unittest + +from PySide.QtCore import QObject, QTimer, QCoreApplication, SIGNAL, SLOT +from PySide.QtGui import QSpinBox, QPushButton, QApplication +from helper import BasicPySlotCase, UsesQApplication + +class ButtonPySlot(UsesQApplication, BasicPySlotCase): + """Tests the connection of python slots to QPushButton signals""" + + qapplication = True + + def setUp(self): + super(ButtonPySlot, self).setUp() + + def tearDown(self): + super(ButtonPySlot, self).setUp() + + def testButtonClicked(self): + """Connection of a python slot to QPushButton.clicked()""" + button = QPushButton('Mylabel') + QObject.connect(button, SIGNAL('clicked()'), self.cb) + self.args = tuple() + button.emit(SIGNAL('clicked()')) + self.assert_(self.called) + + def testButtonClickedWrongArgs(self): + """Python slot connected to QPushButton.clicked() and more args""" + button = QPushButton('Mylabel') + QObject.connect(button, SIGNAL('clicked()'), self.cb) + self.args = tuple() + button.emit(SIGNAL('clicked()'), 44) + self.assert_(self.called) + + def testButtonClick(self): + """Indirect qt signal emission using the QPushButton.click() method """ + button = QPushButton('label') + QObject.connect(button, SIGNAL('clicked()'), self.cb) + self.args = tuple() + button.click() + self.assert_(self.called) + + +class SpinBoxPySlot(UsesQApplication, BasicPySlotCase): + """Tests the connection of python slots to QSpinBox signals""" + + qapplication = True + + def setUp(self): + super(SpinBoxPySlot, self).setUp() + self.spin = QSpinBox() + + def tearDown(self): + del self.spin + super(SpinBoxPySlot, self).tearDown() + + def testSpinBoxValueChanged(self): + """Connection of a python slot to QSpinBox.valueChanged(int)""" + QObject.connect(self.spin, SIGNAL('valueChanged(int)'), self.cb) + self.args = [3] + self.spin.emit(SIGNAL('valueChanged(int)'), *self.args) + self.assert_(self.called) + + def testSpinBoxValueChangedImplicit(self): + """Indirect qt signal emission using QSpinBox.setValue(int)""" + QObject.connect(self.spin, SIGNAL('valueChanged(int)'), self.cb) + self.args = [42] + self.spin.setValue(self.args[0]) + self.assert_(self.called) + + def atestSpinBoxValueChangedFewArgs(self): + """Emission of signals with fewer arguments than needed""" + # XXX: PyQt4 crashes on the assertRaises + QObject.connect(self.spin, SIGNAL('valueChanged(int)'), self.cb) + self.args = (554,) + self.assertRaises(TypeError, self.spin.emit, SIGNAL('valueChanged(int)')) + +class QSpinBoxQtSlots(UsesQApplication): + """Tests the connection to QSpinBox qt slots""" + + qapplication = True + + def testSetValueIndirect(self): + """Indirect signal emission: QSpinBox using valueChanged(int)/setValue(int)""" + spinSend = QSpinBox() + spinRec = QSpinBox() + + spinRec.setValue(5) + + QObject.connect(spinSend, SIGNAL('valueChanged(int)'), spinRec, SLOT('setValue(int)')) + self.assertEqual(spinRec.value(), 5) + spinSend.setValue(3) + self.assertEqual(spinRec.value(), 3) + self.assertEqual(spinSend.value(), 3) + + def testSetValue(self): + """Direct signal emission: QSpinBox using valueChanged(int)/setValue(int)""" + spinSend = QSpinBox() + spinRec = QSpinBox() + + spinRec.setValue(5) + spinSend.setValue(42) + + QObject.connect(spinSend, SIGNAL('valueChanged(int)'), spinRec, SLOT('setValue(int)')) + self.assertEqual(spinRec.value(), 5) + self.assertEqual(spinSend.value(), 42) + spinSend.emit(SIGNAL('valueChanged(int)'), 3) + + self.assertEqual(spinRec.value(), 3) + #Direct emission shouldn't change the value of the emitter + self.assertEqual(spinSend.value(), 42) + + spinSend.emit(SIGNAL('valueChanged(int)'), 66) + self.assertEqual(spinRec.value(), 66) + self.assertEqual(spinSend.value(), 42) + + +if __name__ == '__main__': + unittest.main() |