Adding no-qtgui tests for lambda and multiple sig
Lambda tests using QProcess Multiple connections using QProcess and split into separate test cases
This commit is contained in:
parent
d345245c9d
commit
9e6100816e
2 changed files with 67 additions and 7 deletions
|
|
@ -1,20 +1,27 @@
|
|||
|
||||
import sys
|
||||
import unittest
|
||||
import random
|
||||
from functools import partial
|
||||
|
||||
from PySide.QtCore import QObject, SIGNAL
|
||||
from PySide.QtGui import QPushButton, QSpinBox, QApplication
|
||||
from PySide.QtCore import QObject, SIGNAL, QProcess
|
||||
|
||||
try:
|
||||
from PySide.QtGui import QPushButton, QSpinBox
|
||||
except ImportError:
|
||||
QPushButton = object
|
||||
QSpinBox = object
|
||||
|
||||
from helper import BasicPySlotCase, UsesQApplication, UsesQCoreApplication
|
||||
|
||||
from helper import BasicPySlotCase, UsesQApplication
|
||||
|
||||
def random_gen(count=100, largest=99, lowest=0):
|
||||
for i in range(count):
|
||||
yield random.randint(lowest, largest)
|
||||
|
||||
class MultipleSignalConnections(UsesQApplication):
|
||||
|
||||
qapplication = True
|
||||
class MultipleSignalConnections(unittest.TestCase):
|
||||
'''Base class for multiple signal connection testing'''
|
||||
|
||||
def run_many(self, sender, signal, emitter, receivers, args=None):
|
||||
"""Utility method to connect a list of receivers to a signal.
|
||||
|
|
@ -38,6 +45,10 @@ class MultipleSignalConnections(UsesQApplication):
|
|||
for rec in receivers:
|
||||
self.assert_(rec.called)
|
||||
|
||||
|
||||
class QtGuiMultipleSlots(UsesQApplication, MultipleSignalConnections):
|
||||
'''Multiple connections to QtGui signals'''
|
||||
|
||||
def testButtonClick(self):
|
||||
"""Multiple connections to QPushButton.clicked()"""
|
||||
sender = QPushButton('button')
|
||||
|
|
@ -53,8 +64,13 @@ class MultipleSignalConnections(UsesQApplication):
|
|||
self.run_many(sender, 'valueChanged(int)', sender.setValue,
|
||||
receivers, (test,))
|
||||
|
||||
|
||||
class PythonMultipleSlots(UsesQCoreApplication, MultipleSignalConnections):
|
||||
'''Multiple connections to python signals'''
|
||||
|
||||
def testPythonSignal(self):
|
||||
"""Multiple connections to a python signal (short-circuit)"""
|
||||
|
||||
class Dummy(QObject):
|
||||
pass
|
||||
|
||||
|
|
@ -64,6 +80,31 @@ class MultipleSignalConnections(UsesQApplication):
|
|||
self.run_many(sender, 'foobar', partial(sender.emit,
|
||||
SIGNAL('foobar')), receivers, (test, ))
|
||||
|
||||
|
||||
class QProcessMultipleSlots(UsesQCoreApplication, MultipleSignalConnections):
|
||||
'''Multiple connections to QProcess signals'''
|
||||
|
||||
def testQProcessStarted(self):
|
||||
'''Multiple connections to QProcess.started()'''
|
||||
sender = QProcess()
|
||||
receivers = [BasicPySlotCase() for x in range(10)]
|
||||
|
||||
def start_proc(*args):
|
||||
sender.start(sys.executable, ['-c', '""'])
|
||||
sender.waitForFinished()
|
||||
|
||||
self.run_many(sender, 'started()', start_proc, receivers)
|
||||
|
||||
def testQProcessFinished(self):
|
||||
'''Multiple connections to QProcess.finished(int)'''
|
||||
sender = QProcess()
|
||||
receivers = [BasicPySlotCase() for x in range(10)]
|
||||
|
||||
def start_proc(*args):
|
||||
sender.start(sys.executable, ['-c', '""'])
|
||||
sender.waitForFinished()
|
||||
|
||||
self.run_many(sender, 'finished(int)', start_proc, receivers, (0,))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue