Use .assert_not_called() for mocks

This commit is contained in:
Florian Bruhin 2017-09-22 19:58:38 +02:00
parent e27c54a5c1
commit 4e46c34e5a
6 changed files with 17 additions and 17 deletions

View File

@ -36,8 +36,8 @@ def test_timeout(timer):
func2 = mock.Mock() func2 = mock.Mock()
timer.timeout.connect(func) timer.timeout.connect(func)
timer.timeout.connect(func2) timer.timeout.connect(func2)
assert not func.called func.assert_not_called()
assert not func2.called func2.assert_not_called()
timer.timeout.emit() timer.timeout.emit()
func.assert_called_once_with() func.assert_called_once_with()
func2.assert_called_once_with() func2.assert_called_once_with()
@ -49,7 +49,7 @@ def test_disconnect_all(timer):
timer.timeout.connect(func) timer.timeout.connect(func)
timer.timeout.disconnect() timer.timeout.disconnect()
timer.timeout.emit() timer.timeout.emit()
assert not func.called func.assert_not_called()
def test_disconnect_one(timer): def test_disconnect_one(timer):
@ -58,7 +58,7 @@ def test_disconnect_one(timer):
timer.timeout.connect(func) timer.timeout.connect(func)
timer.timeout.disconnect(func) timer.timeout.disconnect(func)
timer.timeout.emit() timer.timeout.emit()
assert not func.called func.assert_not_called()
def test_disconnect_all_invalid(timer): def test_disconnect_all_invalid(timer):
@ -74,8 +74,8 @@ def test_disconnect_one_invalid(timer):
timer.timeout.connect(func1) timer.timeout.connect(func1)
with pytest.raises(TypeError): with pytest.raises(TypeError):
timer.timeout.disconnect(func2) timer.timeout.disconnect(func2)
assert not func1.called func1.assert_not_called()
assert not func2.called func2.assert_not_called()
timer.timeout.emit() timer.timeout.emit()
func1.assert_called_once_with() func1.assert_called_once_with()

View File

@ -103,7 +103,7 @@ def test_delete_cur_item_no_func():
parent = model.index(0, 0) parent = model.index(0, 0)
with pytest.raises(cmdexc.CommandError): with pytest.raises(cmdexc.CommandError):
model.delete_cur_item(model.index(0, 0, parent)) model.delete_cur_item(model.index(0, 0, parent))
assert not callback.called callback.assert_not_called()
def test_delete_cur_item_no_cat(): def test_delete_cur_item_no_cat():
@ -114,4 +114,4 @@ def test_delete_cur_item_no_cat():
model.rowsRemoved.connect(callback) model.rowsRemoved.connect(callback)
with pytest.raises(qtutils.QtValueError): with pytest.raises(qtutils.QtValueError):
model.delete_cur_item(QModelIndex()) model.delete_cur_item(QModelIndex())
assert not callback.called callback.assert_not_called()

View File

@ -242,7 +242,7 @@ def test_completion_item_del_no_selection(completionview):
completionview.set_model(model) completionview.set_model(model)
with pytest.raises(cmdexc.CommandError, match='No item selected!'): with pytest.raises(cmdexc.CommandError, match='No item selected!'):
completionview.completion_item_del() completionview.completion_item_del()
assert not func.called func.assert_not_called()
def test_resize_no_model(completionview, qtbot): def test_resize_no_model(completionview, qtbot):

View File

@ -151,7 +151,7 @@ def test_late_init(init_patch, monkeypatch, fake_save_manager, fake_args,
assert text.startswith('Errors occurred while reading config.py:') assert text.startswith('Errors occurred while reading config.py:')
assert '<b>Error text</b>: Exception' in text assert '<b>Error text</b>: Exception' in text
else: else:
assert not msgbox_mock.called msgbox_mock.assert_not_called()
class TestQtArgs: class TestQtArgs:

View File

@ -380,7 +380,7 @@ class TestHandleConnection:
monkeypatch.setattr(ipc_server._server, 'nextPendingConnection', m) monkeypatch.setattr(ipc_server._server, 'nextPendingConnection', m)
ipc_server.ignored = True ipc_server.ignored = True
ipc_server.handle_connection() ipc_server.handle_connection()
assert not m.called m.assert_not_called()
def test_no_connection(self, ipc_server, caplog): def test_no_connection(self, ipc_server, caplog):
ipc_server.handle_connection() ipc_server.handle_connection()

View File

@ -494,17 +494,17 @@ def test_init(mocker, tmpdir, args_kind):
assert standarddir._locations != {} assert standarddir._locations != {}
if args_kind == 'normal': if args_kind == 'normal':
if utils.is_mac: if utils.is_mac:
assert not m_windows.called m_windows.assert_not_called()
assert m_mac.called assert m_mac.called
elif utils.is_windows: elif utils.is_windows:
assert m_windows.called assert m_windows.called
assert not m_mac.called m_mac.assert_not_called()
else: else:
assert not m_windows.called m_windows.assert_not_called()
assert not m_mac.called m_mac.assert_not_called()
else: else:
assert not m_windows.called m_windows.assert_not_called()
assert not m_mac.called m_mac.assert_not_called()
@pytest.mark.linux @pytest.mark.linux