File: test_qtest.py

package info (click to toggle)
python-anyqt 0.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: python: 4,087; makefile: 192; sh: 3
file content (39 lines) | stat: -rw-r--r-- 992 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import unittest
from itertools import count

from AnyQt.QtCore import QObject, isdeleted
from AnyQt.QtWidgets import QApplication
from AnyQt.QtTest import QTest


class TestQtTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        super().setUpClass()
        app = QApplication.instance()
        if app is None:
            app = QApplication([])
        cls.app = app

    @classmethod
    def tearDownClass(cls) -> None:
        cls.app = None
        super().tearDownClass()

    def test_qwait(self):
        obj = QObject()
        obj.deleteLater()
        QTest.qWait(0)
        self.assertTrue(isdeleted(obj))

    def test_qwaitfor(self):
        counter = count()
        current = 0

        def pred():
            nonlocal current
            current = next(counter)
            return current > 4
        self.assertTrue(QTest.qWaitFor(pred, 100000))
        self.assertTrue(current == 5)
        self.assertFalse(QTest.qWaitFor(lambda: False, 10))