Skip to main content

Authors: Jan Kotański <jan.kotanski at desy.de>

Introduction

This is a simple helper module to perform PyQt GUI tests.

With the qtchecker module its user

  1. creates QtChecker object with the global QApplication object and a given tested QWidget dialog parameters

  2. defines a sequence of checks with setChecks() method and the following helper classes:

  • AttrCheck - read a tested dialog attribute value

  • CmdCheck - execute a tested dialog command and read its result value

  • WrapAttrCheck - execute a wrapper command on a tested dialog attribute

  • WrapCmdCheck - execute a wrapper command on a result value of a tested dialog command

  • ExtAttrCheck - read an external attribute value defined outside the dialog

  • ExtCmdCheck - execute an external command defined outside the dialog and read its result value

  1. starts event loop and performs checkes with executeChecks() or executeChecksAndClose() method

  2. compare results by reading results attribute of executing

for example

import unittest

from PyQt5 import QtGui
from PyQt5 import QtCore
from PyQt5 import QtTest

from qtchecker.qtChecker import QtChecker, CmdCheck, WrapAttrCheck, ExtCmdCheck

# import my dialog module
from lavuelib import liveViewer


# QApplication object should be one for all tess
app = QtGui.QApplication([])


class GuiTest(unittest.TestCase):

    def __init__(self, methodName):
        unittest.TestCase.__init__(self, methodName)

    def test_run(self):

        # my tested MainWindow dialog
        dialog = liveViewer.MainWindow()
        dialog.show()

        # create QtChecker object
        qtck = QtChecker(app, dialog)

        # define a sequence of action of the dialog
        qtck.setChecks([
            # read return value of execute isConnected command
            CmdCheck(
                # a python path to a method executed in the first action
                "_MainWindow__lavue._LiveViewer__sourcewg.isConnected"
            ),
            # click pushButton with the left-mouse-click
            WrapAttrCheck(
                # a python path to an pushButton object
                "_MainWindow__lavue._LiveViewer__sourcewg._SourceTabWidget__sourcetabs[],0._ui.pushButton",
                # Wrapper command to be executed on the action object
                QtTest.QTest.mouseClick,
                # additional parameters of the wrapper command
                [QtCore.Qt.LeftButton]
            ),
            # read a result of external "getLAvueState" command
            ExtCmdCheck(
                # parent object of the external command
                self,
                # external command name
                "getLavueState"
            ),
        ])

        # execute the check actions and close the dialog
        status = qtck.executeChecksAndClose()
        self.assertEqual(status, 0)

        # compare results returned by each action
        qtck.compareResults(self,
            [
                # a result of isConnected() command
                True,
                # a result of the mouseClick on the pushButton
                None,
                # a result of getLavueState() command
                '{"connected": false}'
            ]
        )

   def getLavueState(self):
       """ an external command """

       import tango
       return tango.DeviceProxy("po/lavuecontroller/1").LavueState

More examples can be found at like LavueTests or LavueStateTests.

Installation

QtChecker requires the following python packages: qt4 or qt5 or pyqtgraph.

From sources

Download the latest QtChecker version from https://github.com/jkotan/qtchecker

Extract sources and run

$ python setup.py install

The setup.py script may need: setuptools sphinx python packages as well as qtbase5-dev-tools or libqt4-dev-bin.

Debian packages

Debian buster and stretch or Ubuntu focal, eoan, bionic packages can be found in the HDRI repository.

To install the debian packages, add the PGP repository key

$ sudo su
$ wget -q -O - http://repos.pni-hdri.de/debian_repo.pub.gpg | apt-key add -

and then download the corresponding source list, e.g.

$ cd /etc/apt/sources.list.d

and

$ wget http://repos.pni-hdri.de/buster-pni-hdri.list

or

$ wget http://repos.pni-hdri.de/stretch-pni-hdri.list

or

$ wget http://repos.pni-hdri.de/focal-pni-hdri.list

respectively.

Finally,

$ apt-get update
$ apt-get install python-qtchecker
$ apt-get update
$ apt-get install python3-qtchecker

for python 3 version.

From pip

To install it from pip you need to install pyqt5 in advance, e.g.

$ python3 -m venv myvenv
$ . myvenv/bin/activate

$ pip install pyqt5

$ pip install qtchecker

Release files for qtchecker 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qtchecker 0.4.0
File Size Uploaded
qtchecker-0.4.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qtchecker 0.4.0
File Interpreter ABI Platform
qtchecker-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.9 kB

Release files / qtchecker-0.4.0.tar.gz

Download URL qtchecker-0.4.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c7d5f5119102105a19b75e6f008c9459dcef7484d263eddc8ce5769fa437cdf3
BLAKE2b-256 checksum
How to use checksums
85e4fe701237a20a63eb1ffd063cad28fa76a39f29d53b82f46a869b3b7e1dd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

Release files / qtchecker-0.4.0-py3-none-any.whl

Download URL qtchecker-0.4.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24bcf6b59346846a9df18b3247d32c674c5d53e5d93e1facf8b88d3c79c27153
BLAKE2b-256 checksum
How to use checksums
e1d765b15212c2cc55f264f8f82a74d50ae2cf300e6f08f777cdd38e4bddb81b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page