Skip to content

Commit 7fa4298

Browse files
authored
test: remove Qt application and debouncer timing assumptions (#1425)
1 parent eead59b commit 7fa4298

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

‎phy/gui/tests/test_qt.py‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,23 @@
3737
# ------------------------------------------------------------------------------
3838

3939

40-
def test_require_qt_with_app():
40+
def test_require_qt_with_app(monkeypatch):
41+
calls = []
42+
43+
class NoApplication:
44+
@staticmethod
45+
def instance():
46+
return None
47+
48+
monkeypatch.setattr('phy.gui.qt.QApplication', NoApplication)
49+
monkeypatch.setattr('phy.gui.qt.create_app', lambda: calls.append('create'))
50+
4151
@require_qt
4252
def f():
43-
pass
53+
calls.append('call')
4454

45-
if not QApplication.instance():
46-
with raises(RuntimeError): # pragma: no cover
47-
f()
55+
f()
56+
assert calls == ['create', 'call']
4857

4958

5059
def test_require_qt_without_app(qapp):
@@ -81,17 +90,22 @@ def f(): # pragma: no cover
8190
assert _l == [0]
8291

8392

84-
def test_debouncer_1(qtbot):
93+
def test_debouncer_1(qtbot, monkeypatch):
94+
now = [100.0]
95+
monkeypatch.setattr('phy.gui.qt.default_timer', lambda: now[0])
8596
d = Debouncer(delay=50)
8697
_l = []
8798

8899
def f(i):
89100
_l.append(i)
90101

91102
for i in range(10):
92-
qtbot.wait(10)
103+
now[0] += 0.01
93104
d.submit(f, i)
94-
qtbot.wait(500)
105+
d._timer_callback()
106+
assert _l == [0]
107+
now[0] += 0.5
108+
d._timer_callback()
95109
assert _l == [0, 9]
96110

97111

0 commit comments

Comments
 (0)