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
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
'''Connecting lambda to signals'''
|
'''Connecting lambda to signals'''
|
||||||
|
|
||||||
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from PySide.QtCore import QObject, SIGNAL
|
from PySide.QtCore import QObject, SIGNAL, QProcess
|
||||||
from PySide.QtGui import QApplication, QSpinBox, QPushButton
|
from PySide.QtGui import QApplication, QSpinBox, QPushButton
|
||||||
|
|
||||||
from helper import UsesQApplication
|
from helper import UsesQApplication
|
||||||
|
|
@ -34,6 +35,24 @@ class QtSigLambda(UsesQApplication):
|
||||||
|
|
||||||
qapplication = True
|
qapplication = True
|
||||||
|
|
||||||
|
def testNoArgs(self):
|
||||||
|
'''Connecting a lambda to a signal without arguments'''
|
||||||
|
proc = QProcess()
|
||||||
|
dummy = Dummy()
|
||||||
|
QObject.connect(proc, SIGNAL('started()'), lambda : setattr(dummy, 'called', True))
|
||||||
|
proc.start(sys.executable, ['-c', '""'])
|
||||||
|
proc.waitForFinished()
|
||||||
|
self.assert_(dummy.called)
|
||||||
|
|
||||||
|
def testWithArgs(self):
|
||||||
|
'''Connecting a lambda to a signal with arguments'''
|
||||||
|
proc = QProcess()
|
||||||
|
dummy = Dummy()
|
||||||
|
QObject.connect(proc, SIGNAL('finished(int)'), lambda x: setattr(dummy, 'called', x))
|
||||||
|
proc.start(sys.executable, ['-c', '""'])
|
||||||
|
proc.waitForFinished()
|
||||||
|
self.assertEqual(dummy.called, proc.exitCode())
|
||||||
|
|
||||||
def testButton(self):
|
def testButton(self):
|
||||||
#Connecting a lambda to a QPushButton.clicked()
|
#Connecting a lambda to a QPushButton.clicked()
|
||||||
obj = QPushButton('label')
|
obj = QPushButton('label')
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,27 @@
|
||||||
|
|
||||||
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import random
|
import random
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PySide.QtCore import QObject, SIGNAL
|
from PySide.QtCore import QObject, SIGNAL, QProcess
|
||||||
from PySide.QtGui import QPushButton, QSpinBox, QApplication
|
|
||||||
|
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):
|
def random_gen(count=100, largest=99, lowest=0):
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
yield random.randint(lowest, largest)
|
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):
|
def run_many(self, sender, signal, emitter, receivers, args=None):
|
||||||
"""Utility method to connect a list of receivers to a signal.
|
"""Utility method to connect a list of receivers to a signal.
|
||||||
|
|
@ -38,6 +45,10 @@ class MultipleSignalConnections(UsesQApplication):
|
||||||
for rec in receivers:
|
for rec in receivers:
|
||||||
self.assert_(rec.called)
|
self.assert_(rec.called)
|
||||||
|
|
||||||
|
|
||||||
|
class QtGuiMultipleSlots(UsesQApplication, MultipleSignalConnections):
|
||||||
|
'''Multiple connections to QtGui signals'''
|
||||||
|
|
||||||
def testButtonClick(self):
|
def testButtonClick(self):
|
||||||
"""Multiple connections to QPushButton.clicked()"""
|
"""Multiple connections to QPushButton.clicked()"""
|
||||||
sender = QPushButton('button')
|
sender = QPushButton('button')
|
||||||
|
|
@ -53,8 +64,13 @@ class MultipleSignalConnections(UsesQApplication):
|
||||||
self.run_many(sender, 'valueChanged(int)', sender.setValue,
|
self.run_many(sender, 'valueChanged(int)', sender.setValue,
|
||||||
receivers, (test,))
|
receivers, (test,))
|
||||||
|
|
||||||
|
|
||||||
|
class PythonMultipleSlots(UsesQCoreApplication, MultipleSignalConnections):
|
||||||
|
'''Multiple connections to python signals'''
|
||||||
|
|
||||||
def testPythonSignal(self):
|
def testPythonSignal(self):
|
||||||
"""Multiple connections to a python signal (short-circuit)"""
|
"""Multiple connections to a python signal (short-circuit)"""
|
||||||
|
|
||||||
class Dummy(QObject):
|
class Dummy(QObject):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -64,6 +80,31 @@ class MultipleSignalConnections(UsesQApplication):
|
||||||
self.run_many(sender, 'foobar', partial(sender.emit,
|
self.run_many(sender, 'foobar', partial(sender.emit,
|
||||||
SIGNAL('foobar')), receivers, (test, ))
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue