<font face="Arial" size="2">Hi, <br><br>I'm using PyQt4
to develop a GUI and I would like to use QtTest module for my unit test<span>. However,</span> it doesn't work. </font><font face="Arial" size="2"><br>I would like to simulate a mouse click on my </font><span style="color: rgb(0, 0, 0);">
QtGui.QPushButton</span><font face="Arial" size="2"> but in the QTest class, the method's argument is a </font><font face="Arial" size="2">Qt.MouseButton.</font><font face="Arial" size="2"><br><br>QTest.mouseClick(QWidget widget,
<span style="font-weight: bold;">Qt.MouseButton button</span>,Qt.KeyboardModifiers stateKey = 0, QPoint pos = QPoint(), int delay = -1)</font><div id="mb_0"><br><font face="Arial" size="2">Is there any way to simulate a click on my QPushButton with this QTest class ?
<br></font>
<span style="color: rgb(0, 0, 0);"><p style="margin-bottom: 0cm;"><span style="color: rgb(0, 0, 0);">
<p style="margin-bottom: 0cm;">Thanks in advanced, <br>Sabrina.<br>
</p>
</span></p><p style="margin-bottom: 0cm;">--------------------------------------------------------------- CLASS TO TEST ---------------------------------------------------------------------------------------------------<br>
</p><p style="margin-bottom: 0cm;">import sys<br>from PyQt4 import QtCore, QtGui, Qt</p><p style="margin-bottom: 0cm;">class Dialog(QtGui.QDialog):<br> <br> def __init__(self, parent = None):<br> QtGui.QDialog.__init_
_(self, parent)<br> frameStyle = QtGui.QFrame.Sunken | QtGui.QFrame.Panel<br> self.textLabel = QtGui.QLabel()<br> self.textLabel.setFrameStyle(frameStyle)<br> self.textButton = <span style="font-weight: bold;">
QtGui.QPushButton</span>(self.tr("QInputDialog.get&Text()"))<br> self.connect(self.textButton, QtCore.SIGNAL("clicked()"), self.setText)<br> layout = QtGui.QGridLayout()<br> layout.setColumnStretch
(1, 1) <br> layout.setColumnMinimumWidth(1, 250)<br> layout.addWidget(self.textButton, 3, 0) <br> layout.addWidget(self.textLabel, 3, 1)<br> self.setLayout(layout)<br> self.setWindowTitle
(self.tr("Standard Dialogs"))<br><br> def setText(self):<br> text, ok = QtGui.QInputDialog.getText(self, self.tr("QInputDialog.getText()"), <br>
self.tr("User name:"),QtGui.QLineEdit.Normal, <br> QtCore.QDir.home().dirName())<br> if ok and not text.isEmpty():<br> self.textLabel.setText
(text)<br><br>if __name__ == '__main__':<br> app = QtGui.QApplication(sys.argv)<br> dialog = Dialog()<br> sys.exit(dialog.exec_())</p><br><p style="margin-bottom: 0cm;"><span style="color: rgb(0, 0, 0);">
<p style="margin-bottom: 0cm;"><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">
---------------------------------------------------------------------------</span></span></span><font face="Arial" size="2"> C</font><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">
</span></span></span><font face="Arial" size="2">LASS TEST </font><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">-------------------------------------------------------------------------------------
</span></span></span></p>
<p style="margin-bottom: 0cm;">import unittest, sys<br>
from PyQt4.QtTest import QTest<br>
from PyQt4 import QtCore, QtGui<br>
<span style="color: rgb(0, 0, 0);">from dialog import Dialog</span><br>
<br>
class DialogTestCase (unittest.TestCase):<br>
<br>
def setUp(self):<br>
self.app = QtGui.QApplication(sys.argv)<br>
self.dialog = Dialog() <br>
<br>
def test_setText(self):<br>
QTest.mouseClick(self.dialog, self.dialog.textButton)<br>
<br>
if __name__ == '__main__':<br>
unittest.main()</p><p style="margin-bottom: 0cm;"><br></p>-----------------------------------------------------------------------------<span style="color: rgb(0, 0, 0);"> ERROR MESSAGE --------</span></span><span style="color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0);">-------------------------------------------------------------------<span style="color: rgb(0, 0, 0);"></span></span></span></p><p style="margin-bottom: 0cm;">Importing test modules ... done.
<br><br>test_setText (test_dialog.DialogTestCase) ... ERROR<span style="color: rgb(0, 0, 0);"><br></span></p><p style="margin-bottom: 0cm;"><span style="color: rgb(0, 0, 0);"></span><br>======================================================================
<br>ERROR: test_setText (test_dialog.DialogTestCase)<br>----------------------------------------------------------------------<br>Traceback (most recent call last):<br> File "/home/master/fr59701/workspace/pyqt test/src/test_dialog.py", line 17, in test_setText
<br> QTest.mouseClick(self.dialog, self.dialog.textButton)<br>TypeError: argument 2 of mouseClick() has an invalid type<br><br>----------------------------------------------------------------------<br>Ran 1 test in 0.039s
<br><br>FAILED (errors=1)</p><br><br></span></div>