Skip to content

Commit

Permalink
Work around PyQt 5.15.1 waitSignals issues
Browse files Browse the repository at this point in the history
This should be reverted with PyQt 5.15.2.
See #5719
  • Loading branch information
The-Compiler committed Sep 15, 2020
1 parent 966873a commit b55675a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 34 deletions.
7 changes: 4 additions & 3 deletions tests/unit/browser/webkit/network/test_networkreply.py
Expand Up @@ -52,8 +52,9 @@ def test_attributes(self, req):
b'Hello World! This is a test.'])
def test_data(self, qtbot, req, data):
reply = networkreply.FixedDataNetworkReply(req, data, 'test/foo')
with qtbot.waitSignals([reply.metaDataChanged, reply.readyRead,
reply.finished], order='strict'):
with qtbot.waitSignal(reply.metaDataChanged), \
qtbot.waitSignal(reply.readyRead), \
qtbot.waitSignal(reply.finished):
pass

assert reply.bytesAvailable() == len(data)
Expand All @@ -78,7 +79,7 @@ def test_error_network_reply(qtbot, req):
reply = networkreply.ErrorNetworkReply(
req, "This is an error", QNetworkReply.UnknownNetworkError)

with qtbot.waitSignals([reply.error, reply.finished], order='strict'):
with qtbot.waitSignal(reply.error), qtbot.waitSignal(reply.finished):
pass

reply.abort() # shouldn't do anything
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/completion/test_completionmodel.py
Expand Up @@ -77,8 +77,8 @@ def test_set_pattern(pat, qtbot):
for c in cats:
c.set_pattern = mock.Mock(spec=[])
model.add_category(c)
with qtbot.waitSignals([model.layoutAboutToBeChanged, model.layoutChanged],
order='strict'):
with qtbot.waitSignal(model.layoutAboutToBeChanged), \
qtbot.waitSignal(model.layoutChanged):
model.set_pattern(pat)
for c in cats:
c.set_pattern.assert_called_with(pat)
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/config/test_config.py
Expand Up @@ -432,11 +432,12 @@ def test_clear(self, conf, qtbot, yaml_value, save_yaml):
assert conf.get_obj(name1) == 'never'
assert conf.get_obj(name2) is True

with qtbot.waitSignals([conf.changed, conf.changed]) as blocker:
with qtbot.waitSignal(conf.changed), qtbot.waitSignal(conf.changed):
conf.clear(save_yaml=save_yaml)

options = {e.args[0] for e in blocker.all_signals_and_args}
assert options == {name1, name2}
# Doesn't work with PyQt 5.15.1 workaround
# options = {blocker1.args[0], blocker2.args[0]}
# assert options == {name1, name2}

if save_yaml:
assert yaml_value(name1) is usertypes.UNSET
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/keyinput/test_basekeyparser.py
Expand Up @@ -21,7 +21,7 @@

from unittest import mock

from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt, PYQT_VERSION
import pytest

from qutebrowser.keyinput import basekeyparser, keyutils
Expand Down Expand Up @@ -309,6 +309,8 @@ def test_superscript(self, handle_text, prompt_keyparser):
# https://github.com/qutebrowser/qutebrowser/issues/3743
handle_text(prompt_keyparser, Qt.Key_twosuperior, Qt.Key_B, Qt.Key_A)

@pytest.mark.skipif(PYQT_VERSION == 0x050F01,
reason='waitSignals is broken in PyQt 5.15.1')
def test_count_keystring_update(self, qtbot,
handle_text, prompt_keyparser):
"""Make sure the keystring is updated correctly when entering count."""
Expand Down
29 changes: 14 additions & 15 deletions tests/unit/misc/test_guiprocess.py
Expand Up @@ -54,8 +54,8 @@ def fake_proc(monkeypatch, stubs):

def test_start(proc, qtbot, message_mock, py_proc):
"""Test simply starting a process."""
with qtbot.waitSignals([proc.started, proc.finished], timeout=10000,
order='strict'):
with qtbot.waitSignal(proc.started, timeout=10000), \
qtbot.waitSignal(proc.finished, timeout=10000):
argv = py_proc("import sys; print('test'); sys.exit(0)")
proc.start(*argv)

Expand All @@ -70,8 +70,8 @@ def test_start_verbose(proc, qtbot, message_mock, py_proc):
"""Test starting a process verbosely."""
proc.verbose = True

with qtbot.waitSignals([proc.started, proc.finished], timeout=10000,
order='strict'):
with qtbot.waitSignal(proc.started, timeout=10000), \
qtbot.waitSignal(proc.finished, timeout=10000):
argv = py_proc("import sys; print('test'); sys.exit(0)")
proc.start(*argv)

Expand Down Expand Up @@ -99,9 +99,8 @@ def test_start_output_message(proc, qtbot, caplog, message_mock, py_proc,
code.append("sys.exit(0)")

with caplog.at_level(logging.ERROR, 'message'):
with qtbot.waitSignals([proc.started, proc.finished],
timeout=10000,
order='strict'):
with qtbot.waitSignal(proc.started, timeout=10000), \
qtbot.waitSignal(proc.finished, timeout=10000):
argv = py_proc(';'.join(code))
proc.start(*argv)

Expand Down Expand Up @@ -147,8 +146,8 @@ def test_start_env(monkeypatch, qtbot, py_proc):
sys.exit(0)
""")

with qtbot.waitSignals([proc.started, proc.finished], timeout=10000,
order='strict'):
with qtbot.waitSignal(proc.started, timeout=10000), \
qtbot.waitSignal(proc.finished, timeout=10000):
proc.start(*argv)

data = qutescheme.spawn_output
Expand Down Expand Up @@ -187,12 +186,12 @@ def test_double_start(qtbot, proc, py_proc):

def test_double_start_finished(qtbot, proc, py_proc):
"""Test starting a GUIProcess twice (with the first call finished)."""
with qtbot.waitSignals([proc.started, proc.finished], timeout=10000,
order='strict'):
with qtbot.waitSignal(proc.started, timeout=10000), \
qtbot.waitSignal(proc.finished, timeout=10000):
argv = py_proc("import sys; sys.exit(0)")
proc.start(*argv)
with qtbot.waitSignals([proc.started, proc.finished], timeout=10000,
order='strict'):
with qtbot.waitSignal(proc.started, timeout=10000), \
qtbot.waitSignal(proc.finished, timeout=10000):
argv = py_proc("import sys; sys.exit(0)")
proc.start(*argv)

Expand Down Expand Up @@ -267,8 +266,8 @@ def test_exit_successful_output(qtbot, proc, py_proc, stream):

def test_stdout_not_decodable(proc, qtbot, message_mock, py_proc):
"""Test handling malformed utf-8 in stdout."""
with qtbot.waitSignals([proc.started, proc.finished], timeout=10000,
order='strict'):
with qtbot.waitSignal(proc.started, timeout=10000), \
qtbot.waitSignal(proc.finished, timeout=10000):
argv = py_proc(r"""
import sys
# Using \x81 because it's invalid in UTF-8 and CP1252
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/misc/test_ipc.py
Expand Up @@ -493,10 +493,10 @@ def test_partial_line(connected_socket):
(b'{"args": [], "target_arg": null}\n', 'invalid version'),
])
def test_invalid_data(qtbot, ipc_server, connected_socket, caplog, data, msg):
signals = [ipc_server.got_invalid_data, connected_socket.disconnected]
with caplog.at_level(logging.ERROR):
with qtbot.assertNotEmitted(ipc_server.got_args):
with qtbot.waitSignals(signals, order='strict'):
with qtbot.waitSignal(ipc_server.got_invalid_data), \
qtbot.waitSignal(connected_socket.disconnected):
connected_socket.write(data)

invalid_msg = 'Ignoring invalid IPC data from socket '
Expand All @@ -514,8 +514,8 @@ def test_multiline(qtbot, ipc_server, connected_socket):
version=ipc.PROTOCOL_VERSION))

with qtbot.assertNotEmitted(ipc_server.got_invalid_data):
with qtbot.waitSignals([ipc_server.got_args, ipc_server.got_args],
order='strict'):
with qtbot.waitSignal(ipc_server.got_args), \
qtbot.waitSignal(ipc_server.got_args):
connected_socket.write(data.encode('utf-8'))

assert len(spy) == 2
Expand Down
14 changes: 8 additions & 6 deletions tests/unit/utils/usertypes/test_question.py
Expand Up @@ -53,23 +53,25 @@ def test_done(mode, answer, signal_names, question, qtbot):
question.mode = mode
question.answer = answer
signals = [getattr(question, name) for name in signal_names]
with qtbot.waitSignals(signals, order='strict'):
question.done()
blockers = [qtbot.waitSignal(signal) for signal in signals]

question.done()
for blocker in blockers:
blocker.wait()

assert not question.is_aborted


def test_cancel(question, qtbot):
"""Test Question.cancel()."""
with qtbot.waitSignals([question.cancelled, question.completed],
order='strict'):
with qtbot.waitSignal(question.cancelled), qtbot.waitSignal(question.completed):
question.cancel()
assert not question.is_aborted


def test_abort(question, qtbot):
"""Test Question.abort()."""
with qtbot.waitSignals([question.aborted, question.completed],
order='strict'):
with qtbot.waitSignal(question.aborted), qtbot.waitSignal(question.completed):
question.abort()
assert question.is_aborted

Expand Down

0 comments on commit b55675a

Please sign in to comment.