Signal emission tests with non QtGui tests

Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
This commit is contained in:
Lauro Neto 2009-12-16 15:47:30 -03:00
commit fb040f76c1

View file

@ -5,10 +5,11 @@
import sys import sys
import unittest import unittest
from PySide.QtCore import QObject, QTimer, QCoreApplication, SIGNAL, SLOT, QProcess from PySide.QtCore import QObject, SIGNAL, SLOT, QProcess, QTimeLine
from PySide.QtCore import QTimer, QThread
try: try:
from PySide.QtGui import QSpinBox, QPushButton, QApplication from PySide.QtGui import QSpinBox, QPushButton
except ImportError: except ImportError:
QSpinBox = object QSpinBox = object
QPushButton = object QPushButton = object
@ -135,6 +136,70 @@ class MoreArgsOnEmit(UsesQCoreApplication):
process = QProcess() process = QProcess()
self.assertRaises(TypeError, process.emit, SIGNAL('finished(int)'), 55, 55) self.assertRaises(TypeError, process.emit, SIGNAL('finished(int)'), 55, 55)
class Dummy(QObject):
'''Dummy class'''
pass
class PythonSignalToCppSlots(UsesQCoreApplication):
'''Connect python signals to C++ slots'''
def testWithoutArgs(self):
'''Connect python signal to QTimeLine.toggleDirection()'''
timeline = QTimeLine()
dummy = Dummy()
QObject.connect(dummy, SIGNAL('dummy()'),
timeline, SLOT('toggleDirection()'))
orig_dir = timeline.direction()
dummy.emit(SIGNAL('dummy()'))
new_dir = timeline.direction()
if orig_dir == QTimeLine.Forward:
self.assertEqual(new_dir, QTimeLine.Backward)
else:
self.assertEqual(new_dir, QTimeLine.Forward)
def testWithArgs(self):
'''Connect python signals to QTimeLine.setCurrentTime(int)'''
timeline = QTimeLine()
dummy = Dummy()
QObject.connect(dummy, SIGNAL('dummy(int)'),
timeline, SLOT('setCurrentTime(int)'))
current = timeline.currentTime()
dummy.emit(SIGNAL('dummy(int)'), current+42)
self.assertEqual(timeline.currentTime(), current+42)
class CppSignalsToCppSlots(UsesQCoreApplication):
'''Connection between C++ slots and signals'''
def testWithoutArgs(self):
'''Connect QThread.started() to QTimeLine.togglePaused()'''
thread = QThread()
timeline = QTimeLine()
QObject.connect(thread, SIGNAL('started()'),
timeline, SLOT('toggleDirection()'))
QObject.connect(thread, SIGNAL('started()'),
self.exit_app_cb)
orig_dir = timeline.direction()
timer = QTimer.singleShot(1000, self.exit_app_cb) # Just for safety
thread.start()
self.app.exec_()
thread.wait()
new_dir = timeline.direction()
if orig_dir == QTimeLine.Forward:
self.assertEqual(new_dir, QTimeLine.Backward)
else:
self.assertEqual(new_dir, QTimeLine.Forward)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()