[PyQt] PyQt4 : problem with QtTest

Sabrina Demagny sabrina.demagny at gmail.com
Thu Mar 29 16:41:01 BST 2007


Hi,

I'm using PyQt4 to develop a GUI and I would like to use QtTest module for
my unit test. However, it doesn't work.
I would like to simulate a mouse click on my QtGui.QPushButton but in the
QTest class, the method's argument is a Qt.MouseButton.

QTest.mouseClick(QWidget widget, Qt.MouseButton
button,Qt.KeyboardModifiersstateKey = 0, QPoint pos = QPoint(), int
delay = -1)
Is there any way to simulate a click on my QPushButton with this QTest class
?

Thanks in advanced,
Sabrina.

--------------------------------------------------------------- CLASS TO
TEST
---------------------------------------------------------------------------------------------------

import sys
from PyQt4 import QtCore, QtGui, Qt

class Dialog(QtGui.QDialog):

    def __init__(self, parent = None):
        QtGui.QDialog.__init__(self, parent)
        frameStyle = QtGui.QFrame.Sunken | QtGui.QFrame.Panel
        self.textLabel = QtGui.QLabel()
        self.textLabel.setFrameStyle(frameStyle)
        self.textButton = QtGui.QPushButton(self.tr("QInputDialog.get&Text
()"))
        self.connect(self.textButton, QtCore.SIGNAL("clicked()"),
self.setText)
        layout = QtGui.QGridLayout()
        layout.setColumnStretch(1, 1)
        layout.setColumnMinimumWidth(1, 250)
        layout.addWidget(self.textButton, 3, 0)
        layout.addWidget(self.textLabel, 3, 1)
        self.setLayout(layout)
        self.setWindowTitle(self.tr("Standard Dialogs"))

    def setText(self):
        text, ok = QtGui.QInputDialog.getText(self, self.tr("
QInputDialog.getText()"),
                                                               self.tr("User
name:"),QtGui.QLineEdit.Normal,

QtCore.QDir.home().dirName())
        if ok and not text.isEmpty():
            self.textLabel.setText(text)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    dialog = Dialog()
    sys.exit(dialog.exec_())

 ---------------------------------------------------------------------------CLASS
TEST
-------------------------------------------------------------------------------------

import unittest, sys
from PyQt4.QtTest import QTest
from PyQt4 import QtCore, QtGui
from dialog import Dialog

class DialogTestCase (unittest.TestCase):

    def setUp(self):
        self.app = QtGui.QApplication(sys.argv)
        self.dialog = Dialog()

    def test_setText(self):
        QTest.mouseClick(self.dialog, self.dialog.textButton)

if __name__ == '__main__':
    unittest.main()


-----------------------------------------------------------------------------ERROR
MESSAGE --------
-------------------------------------------------------------------

Importing test modules ... done.

test_setText (test_dialog.DialogTestCase) ... ERROR


======================================================================
ERROR: test_setText (test_dialog.DialogTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/master/fr59701/workspace/pyqt test/src/test_dialog.py", line
17, in test_setText
    QTest.mouseClick(self.dialog, self.dialog.textButton)
TypeError: argument 2 of mouseClick() has an invalid type

----------------------------------------------------------------------
Ran 1 test in 0.039s

FAILED (errors=1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20070329/34af5757/attachment.html


More information about the PyQt mailing list