tests: Default to raising=True for qtbot.

- qtbot.waitSignal with raising=True is the default this way, so we remove the
  raising=True.
- qtbot.waitSignal with raising=False stay untouched
- Some qtbot.waitSignal without raising had one added (because we don't want it
  to raise)
- Some qtbot.waitSignal without raising actually should've raised, which they
  do now.
This commit is contained in:
Florian Bruhin 2016-01-08 09:49:06 +01:00
parent a0a6b488e6
commit 1fb34331e5
19 changed files with 61 additions and 79 deletions

View File

@ -40,3 +40,4 @@ qt_log_ignore =
^QXcbXSettings::QXcbXSettings\(QXcbScreen\*\) Failed to get selection owner for XSETTINGS_S atom
^QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to .*
^QXcbClipboard: SelectionRequest too old
qt_wait_signal_raising = true

View File

@ -143,7 +143,7 @@ def run_command(quteproc, httpbin, command):
@bdd.when(bdd.parsers.parse("I reload"))
def reload(qtbot, httpbin, quteproc, command):
"""Reload and wait until a new request is received."""
with qtbot.waitSignal(httpbin.new_request, raising=True):
with qtbot.waitSignal(httpbin.new_request):
quteproc.send_cmd(':reload')
@ -398,7 +398,7 @@ def _wait_for_clipboard(qtbot, clipboard, mode, expected):
# We need to poll the clipboard, as for some reason it can change with
# emitting changed (?).
with qtbot.waitSignal(clipboard.changed, timeout=100) as blocker:
with qtbot.waitSignal(clipboard.changed, timeout=100, raising=False) as blocker:
pass
if timer.hasExpired(timeout):

View File

@ -33,7 +33,7 @@ def skip_with_broken_clipboard(qtbot, qapp):
"""
clipboard = qapp.clipboard()
with qtbot.waitSignal(clipboard.changed):
with qtbot.waitSignal(clipboard.changed, raising=False):
clipboard.setText("Does this work?")
if clipboard.text() != "Does this work?":

View File

@ -31,7 +31,7 @@ from qutebrowser.utils import log
def test_quteproc_error_message(qtbot, quteproc):
"""Make sure the test fails with an unexpected error message."""
with qtbot.waitSignal(quteproc.got_error, raising=True):
with qtbot.waitSignal(quteproc.got_error):
quteproc.send_cmd(':message-error test')
# Usually we wouldn't call this from inside a test, but here we force the
# error to occur during the test rather than at teardown time.
@ -41,7 +41,7 @@ def test_quteproc_error_message(qtbot, quteproc):
def test_qt_log_ignore(qtbot, quteproc):
"""Make sure the test passes when logging a qt_log_ignore message."""
with qtbot.waitSignal(quteproc.got_error, raising=True):
with qtbot.waitSignal(quteproc.got_error):
quteproc.send_cmd(':message-error "SpellCheck: test"')

View File

@ -33,7 +33,7 @@ import pytest
('/data/hello.txt', 'Hello World!', True),
])
def test_httpbin(httpbin, qtbot, path, content, expected):
with qtbot.waitSignal(httpbin.new_request, raising=True, timeout=100):
with qtbot.waitSignal(httpbin.new_request, timeout=100):
url = 'http://localhost:{}{}'.format(httpbin.port, path)
try:
response = urllib.request.urlopen(url)

View File

@ -172,7 +172,7 @@ class Process(QObject):
self.read_log()
return self._data
def _wait_signal(self, signal, timeout=5000, raising=True):
def _wait_signal(self, signal, timeout=5000, raising=None):
"""Wait for a signal to be emitted.
Should be used in a contextmanager.

View File

@ -53,7 +53,7 @@ class TestFixedDataNetworkReply:
def test_data(self, qtbot, req, data):
reply = networkreply.FixedDataNetworkReply(req, data, 'test/foo')
with qtbot.waitSignals([reply.metaDataChanged, reply.readyRead,
reply.finished], raising=True):
reply.finished]):
pass
assert reply.bytesAvailable() == len(data)
@ -78,7 +78,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], raising=True):
with qtbot.waitSignals([reply.error, reply.finished]):
pass
reply.abort() # shouldn't do anything

View File

@ -79,7 +79,7 @@ def test_set_cookies_accept(config_stub, qtbot, monkeypatch):
ram_jar = cookies.RAMCookieJar()
cookie = QNetworkCookie(b'foo', b'bar')
url = QUrl('http://example.com/')
with qtbot.waitSignal(ram_jar.changed, raising=True):
with qtbot.waitSignal(ram_jar.changed):
assert ram_jar.setCookiesFromUrl([cookie], url)
# assert the cookies are added correctly
@ -151,7 +151,7 @@ def test_cookies_changed_emit(config_stub, fake_save_manager,
'LineParser', LineparserSaveStub)
jar = cookies.CookieJar()
with qtbot.waitSignal(jar.changed, raising=True):
with qtbot.waitSignal(jar.changed):
config_stub.set('content', 'cookies-store', False)

View File

@ -628,7 +628,7 @@ class TestJavascriptEscape:
with open(path, encoding='utf-8') as f:
html_source = f.read().replace('%INPUT%', escaped)
with qtbot.waitSignal(webframe.loadFinished, raising=True) as blocker:
with qtbot.waitSignal(webframe.loadFinished) as blocker:
webframe.setHtml(html_source)
assert blocker.args == [True]

View File

@ -79,8 +79,7 @@ def test_command(qtbot, py_proc, runner):
with open(os.environ['QUTE_FIFO'], 'w') as f:
f.write('foo\n')
""")
with qtbot.waitSignal(runner.got_cmd, raising=True,
timeout=10000) as blocker:
with qtbot.waitSignal(runner.got_cmd, timeout=10000) as blocker:
runner.run(cmd, *args)
assert blocker.args == ['foo']
@ -100,8 +99,7 @@ def test_custom_env(qtbot, monkeypatch, py_proc, runner):
f.write('\n')
""")
with qtbot.waitSignal(runner.got_cmd, raising=True,
timeout=10000) as blocker:
with qtbot.waitSignal(runner.got_cmd, timeout=10000) as blocker:
runner.run(cmd, *args, env=env)
data = blocker.args[0]
@ -136,9 +134,8 @@ def test_temporary_files(qtbot, tmpdir, py_proc, runner):
f.write('\n')
""")
with qtbot.waitSignal(runner.finished, raising=True, timeout=10000):
with qtbot.waitSignal(runner.got_cmd, raising=True,
timeout=10000) as blocker:
with qtbot.waitSignal(runner.finished, timeout=10000):
with qtbot.waitSignal(runner.got_cmd, timeout=10000) as blocker:
runner.run(cmd, *args, env=env)
data = blocker.args[0]
@ -160,7 +157,7 @@ def test_command_with_error(qtbot, tmpdir, py_proc, runner):
sys.exit(1)
""")
with qtbot.waitSignal(runner.finished, raising=True, timeout=10000):
with qtbot.waitSignal(runner.finished, timeout=10000):
runner.run(cmd, *args, env=env)
assert not text_file.exists()
@ -191,14 +188,13 @@ def test_killed_command(qtbot, tmpdir, py_proc, runner):
""")
args.append(str(pidfile))
with qtbot.waitSignal(watcher.directoryChanged, raising=True,
timeout=10000):
with qtbot.waitSignal(watcher.directoryChanged, timeout=10000):
runner.run(cmd, *args, env=env)
# Make sure the PID was written to the file, not just the file created
time.sleep(0.5)
with qtbot.waitSignal(runner.finished, raising=True):
with qtbot.waitSignal(runner.finished):
os.kill(int(pidfile.read()), signal.SIGTERM)
assert not text_file.exists()
@ -216,7 +212,7 @@ def test_temporary_files_failed_cleanup(caplog, qtbot, tmpdir, py_proc,
""")
with caplog.at_level(logging.ERROR):
with qtbot.waitSignal(runner.finished, raising=True, timeout=10000):
with qtbot.waitSignal(runner.finished, timeout=10000):
runner.run(cmd, *args, env={'QUTE_HTML': str(test_file)})
assert len(caplog.records) == 1

View File

@ -94,8 +94,7 @@ class JSTester:
**kwargs: Passed to jinja's template.render().
"""
template = self._jinja_env.get_template(path)
with self._qtbot.waitSignal(self.webview.loadFinished,
raising=True) as blocker:
with self._qtbot.waitSignal(self.webview.loadFinished) as blocker:
self.webview.setHtml(template.render(**kwargs))
assert blocker.args == [True]

View File

@ -282,7 +282,7 @@ class TestKeyChain:
assert not keyparser.execute.called
assert keyparser._ambiguous_timer.isActive()
# We wait for the timeout to occur.
with qtbot.waitSignal(keyparser.keystring_updated, raising=True):
with qtbot.waitSignal(keyparser.keystring_updated):
pass
assert keyparser.execute.called

View File

@ -66,7 +66,7 @@ def test_get_version_success(qtbot):
# Use a spy to inspect the signal
error_spy = QSignalSpy(client.error)
with qtbot.waitSignal(client.success, raising=True):
with qtbot.waitSignal(client.success):
client.get_version('test')
assert len(error_spy) == 0
@ -82,7 +82,7 @@ def test_get_version_error(qtbot):
# Use a spy to inspect the signal
success_spy = QSignalSpy(client.success)
with qtbot.waitSignal(client.error, raising=True):
with qtbot.waitSignal(client.error):
client.get_version('test')
assert len(success_spy) == 0
@ -98,7 +98,7 @@ def test_invalid_json(qtbot, json):
# Use a spy to inspect the signal
success_spy = QSignalSpy(client.success)
with qtbot.waitSignal(client.error, raising=True):
with qtbot.waitSignal(client.error):
client.get_version('test')
assert len(success_spy) == 0

View File

@ -40,7 +40,8 @@ def proc(qtbot):
p = guiprocess.GUIProcess(0, 'testprocess')
yield p
if p._proc.state() == QProcess.Running:
with qtbot.waitSignal(p.finished, timeout=10000) as blocker:
with qtbot.waitSignal(p.finished, timeout=10000,
raising=False) as blocker:
p._proc.terminate()
if not blocker.signal_triggered:
p._proc.kill()
@ -56,8 +57,7 @@ def fake_proc(monkeypatch, stubs):
def test_start(proc, qtbot, guiprocess_message_mock, py_proc):
"""Test simply starting a process."""
with qtbot.waitSignals([proc.started, proc.finished], raising=True,
timeout=10000):
with qtbot.waitSignals([proc.started, proc.finished], timeout=10000):
argv = py_proc("import sys; print('test'); sys.exit(0)")
proc.start(*argv)
@ -69,8 +69,7 @@ def test_start_verbose(proc, qtbot, guiprocess_message_mock, py_proc):
"""Test starting a process verbosely."""
proc.verbose = True
with qtbot.waitSignals([proc.started, proc.finished], raising=True,
timeout=10000):
with qtbot.waitSignals([proc.started, proc.finished], timeout=10000):
argv = py_proc("import sys; print('test'); sys.exit(0)")
proc.start(*argv)
@ -97,8 +96,7 @@ def test_start_env(monkeypatch, qtbot, py_proc):
sys.exit(0)
""")
with qtbot.waitSignals([proc.started, proc.finished], raising=True,
timeout=10000):
with qtbot.waitSignals([proc.started, proc.finished], timeout=10000):
proc.start(*argv)
data = bytes(proc._proc.readAll()).decode('utf-8')
@ -110,8 +108,7 @@ def test_start_env(monkeypatch, qtbot, py_proc):
@pytest.mark.qt_log_ignore('QIODevice::read.*: WriteOnly device', extend=True)
def test_start_mode(proc, qtbot, py_proc):
"""Test simply starting a process with mode parameter."""
with qtbot.waitSignals([proc.started, proc.finished], raising=True,
timeout=10000):
with qtbot.waitSignals([proc.started, proc.finished], timeout=10000):
argv = py_proc("import sys; print('test'); sys.exit(0)")
proc.start(*argv, mode=QIODevice.NotOpen)
@ -139,7 +136,7 @@ def test_start_detached_error(fake_proc, guiprocess_message_mock):
def test_double_start(qtbot, proc, py_proc):
"""Test starting a GUIProcess twice."""
with qtbot.waitSignal(proc.started, raising=True, timeout=10000):
with qtbot.waitSignal(proc.started, timeout=10000):
argv = py_proc("import time; time.sleep(10)")
proc.start(*argv)
with pytest.raises(ValueError):
@ -148,12 +145,10 @@ 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], raising=True,
timeout=10000):
with qtbot.waitSignals([proc.started, proc.finished], timeout=10000):
argv = py_proc("import sys; sys.exit(0)")
proc.start(*argv)
with qtbot.waitSignals([proc.started, proc.finished], raising=True,
timeout=10000):
with qtbot.waitSignals([proc.started, proc.finished], timeout=10000):
argv = py_proc("import sys; sys.exit(0)")
proc.start(*argv)
@ -180,7 +175,7 @@ def test_start_logging(fake_proc, caplog):
def test_error(qtbot, proc, caplog, guiprocess_message_mock):
"""Test the process emitting an error."""
with caplog.at_level(logging.ERROR, 'message'):
with qtbot.waitSignal(proc.error, raising=True, timeout=5000):
with qtbot.waitSignal(proc.error, timeout=5000):
proc.start('this_does_not_exist_either', [])
msg = guiprocess_message_mock.getmsg(guiprocess_message_mock.Level.error,
@ -191,7 +186,7 @@ def test_error(qtbot, proc, caplog, guiprocess_message_mock):
def test_exit_unsuccessful(qtbot, proc, guiprocess_message_mock, py_proc):
with qtbot.waitSignal(proc.finished, raising=True, timeout=10000):
with qtbot.waitSignal(proc.finished, timeout=10000):
proc.start(*py_proc('import sys; sys.exit(1)'))
msg = guiprocess_message_mock.getmsg(guiprocess_message_mock.Level.error)
@ -202,7 +197,7 @@ def test_exit_unsuccessful(qtbot, proc, guiprocess_message_mock, py_proc):
def test_exit_unsuccessful_output(qtbot, proc, caplog, py_proc, stream):
"""When a process fails, its output should be logged."""
with caplog.at_level(logging.ERROR):
with qtbot.waitSignal(proc.finished, raising=True, timeout=10000):
with qtbot.waitSignal(proc.finished, timeout=10000):
proc.start(*py_proc("""
import sys
print("test", file=sys.{})
@ -219,7 +214,7 @@ def test_exit_successful_output(qtbot, proc, py_proc, stream):
The test doesn't actually check the log as it'd fail because of the error
logging.
"""
with qtbot.waitSignal(proc.finished, raising=True, timeout=10000):
with qtbot.waitSignal(proc.finished, timeout=10000):
proc.start(*py_proc("""
import sys
print("test", file=sys.{})

View File

@ -343,13 +343,11 @@ class TestListen:
ipc_server.listen()
old_atime = os.stat(ipc_server._server.fullServerName()).st_atime_ns
with qtbot.waitSignal(ipc_server._atime_timer.timeout, timeout=2000,
raising=True):
with qtbot.waitSignal(ipc_server._atime_timer.timeout, timeout=2000):
pass
# Make sure the timer is not singleShot
with qtbot.waitSignal(ipc_server._atime_timer.timeout, timeout=2000,
raising=True):
with qtbot.waitSignal(ipc_server._atime_timer.timeout, timeout=2000):
pass
new_atime = os.stat(ipc_server._server.fullServerName()).st_atime_ns
@ -444,7 +442,7 @@ class TestHandleConnection:
ipc_server._server = FakeServer(socket)
with qtbot.waitSignal(ipc_server.got_args, raising=True) as blocker:
with qtbot.waitSignal(ipc_server.got_args) as blocker:
ipc_server.handle_connection()
assert blocker.args == [['foo'], 'tab', '']
@ -458,7 +456,7 @@ def connected_socket(qtbot, qlocalsocket, ipc_server):
pytest.skip("Skipping connected_socket test - "
"https://github.com/The-Compiler/qutebrowser/issues/1045")
ipc_server.listen()
with qtbot.waitSignal(ipc_server._server.newConnection, raising=True):
with qtbot.waitSignal(ipc_server._server.newConnection):
qlocalsocket.connectToServer('qute-test')
yield qlocalsocket
qlocalsocket.disconnectFromServer()
@ -500,7 +498,7 @@ 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.waitSignals(signals, raising=True):
with qtbot.waitSignals(signals):
connected_socket.write(data)
messages = [r.message for r in caplog.records]
@ -519,8 +517,7 @@ def test_multiline(qtbot, ipc_server, connected_socket):
' "protocol_version": {version}}}\n'.format(
version=ipc.PROTOCOL_VERSION))
with qtbot.waitSignals([ipc_server.got_args, ipc_server.got_args],
raising=True):
with qtbot.waitSignals([ipc_server.got_args, ipc_server.got_args]):
connected_socket.write(data.encode('utf-8'))
assert not error_spy
@ -544,8 +541,7 @@ class TestSendToRunningInstance:
raw_spy = QSignalSpy(ipc_server.got_raw)
error_spy = QSignalSpy(ipc_server.got_invalid_data)
with qtbot.waitSignal(ipc_server.got_args, raising=True,
timeout=5000) as blocker:
with qtbot.waitSignal(ipc_server.got_args, timeout=5000) as blocker:
with tmpdir.as_cwd():
if not has_cwd:
m = mocker.patch('qutebrowser.misc.ipc.os')
@ -598,12 +594,11 @@ def test_timeout(qtbot, caplog, qlocalsocket, ipc_server):
ipc_server._timer.setInterval(100)
ipc_server.listen()
with qtbot.waitSignal(ipc_server._server.newConnection, raising=True):
with qtbot.waitSignal(ipc_server._server.newConnection):
qlocalsocket.connectToServer('qute-test')
with caplog.at_level(logging.ERROR):
with qtbot.waitSignal(qlocalsocket.disconnected, raising=True,
timeout=5000):
with qtbot.waitSignal(qlocalsocket.disconnected, timeout=5000):
pass
assert caplog.records[-1].message == "IPC connection timed out."
@ -679,14 +674,14 @@ class TestSendOrListen:
objreg_server = objreg.get('ipc-server')
assert objreg_server is ret_server
with qtbot.waitSignal(ret_server.got_args, raising=True):
with qtbot.waitSignal(ret_server.got_args):
ret_client = ipc.send_or_listen(args)
assert ret_client is None
@pytest.mark.posix(reason="Unneeded on Windows")
def test_legacy_name(self, caplog, qtbot, args, legacy_server):
with qtbot.waitSignal(legacy_server.got_args, raising=True):
with qtbot.waitSignal(legacy_server.got_args):
ret = ipc.send_or_listen(args)
assert ret is None
msgs = [e.message for e in caplog.records]
@ -727,7 +722,7 @@ class TestSendOrListen:
assert isinstance(ret_server, ipc.IPCServer)
logging.debug('== Connecting ==')
with qtbot.waitSignal(ret_server.got_args, raising=True):
with qtbot.waitSignal(ret_server.got_args):
ret_client = ipc.send_or_listen(args)
assert ret_client is None

View File

@ -74,7 +74,7 @@ def test_finished_signal(qtbot):
qtbot.add_widget(box)
with qtbot.waitSignal(box.finished, raising=True):
with qtbot.waitSignal(box.finished):
box.accept()
assert signal_triggered

View File

@ -439,9 +439,8 @@ class TestSave:
def test_update_completion_signal(self, sess_man, tmpdir, qtbot):
session_path = tmpdir / 'foo.yml'
blocker = qtbot.waitSignal(sess_man.update_completion)
sess_man.save(str(session_path))
assert blocker.signal_triggered
with qtbot.waitSignal(sess_man.update_completion):
sess_man.save(str(session_path))
def test_no_state_config(self, sess_man, tmpdir, state_config):
session_path = tmpdir / 'foo.yml'
@ -691,9 +690,8 @@ class TestDelete:
sess = tmpdir / 'foo.yml'
sess.ensure()
blocker = qtbot.waitSignal(sess_man.update_completion)
sess_man.delete(str(sess))
assert blocker.signal_triggered
with qtbot.waitSignal(sess_man.update_completion):
sess_man.delete(str(sess))
def test_not_existing(self, sess_man, qtbot, tmpdir):
sess = tmpdir / 'foo.yml'

View File

@ -61,23 +61,21 @@ 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, raising=True):
with qtbot.waitSignals(signals):
question.done()
assert not question.is_aborted
def test_cancel(question, qtbot):
"""Test Question.cancel()."""
with qtbot.waitSignals([question.cancelled, question.completed],
raising=True):
with qtbot.waitSignals([question.cancelled, question.completed]):
question.cancel()
assert not question.is_aborted
def test_abort(question, qtbot):
"""Test Question.abort()."""
with qtbot.waitSignals([question.aborted, question.completed],
raising=True):
with qtbot.waitSignals([question.aborted, question.completed]):
question.abort()
assert question.is_aborted

View File

@ -72,13 +72,13 @@ def test_start_overflow():
def test_timeout_start(qtbot):
"""Make sure the timer works with start()."""
t = usertypes.Timer()
with qtbot.waitSignal(t.timeout, timeout=3000, raising=True):
with qtbot.waitSignal(t.timeout, timeout=3000):
t.start(200)
def test_timeout_set_interval(qtbot):
"""Make sure the timer works with setInterval()."""
t = usertypes.Timer()
with qtbot.waitSignal(t.timeout, timeout=3000, raising=True):
with qtbot.waitSignal(t.timeout, timeout=3000):
t.setInterval(200)
t.start()