diff --git a/.flake8 b/.flake8 index d967a505b..b87fef8b2 100644 --- a/.flake8 +++ b/.flake8 @@ -11,6 +11,7 @@ exclude = .*,__pycache__,resources.py # (for pytest's __tracebackhide__) # F401: Unused import # N802: function name should be lowercase +# N806: variable in function should be lowercase # P101: format string does contain unindexed parameters # P102: docstring does contain unindexed parameters # P103: other string does contain unindexed parameters @@ -27,7 +28,7 @@ exclude = .*,__pycache__,resources.py ignore = E128,E226,E265,E501,E402,E266,E722,E731, F401, - N802, + N802,N806 P101,P102,P103, D102,D103,D104,D105,D209,D211,D402,D403 min-version = 3.4.0 diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py index 9b8d31ad6..68466630a 100644 --- a/qutebrowser/completion/completionwidget.py +++ b/qutebrowser/completion/completionwidget.py @@ -290,6 +290,8 @@ class CompletionView(QTreeView): self.expand(model.index(i, 0)) def set_pattern(self, pattern): + if not self.model(): + return self.pattern = pattern with debug.log_time(log.completion, 'Set pattern {}'.format(pattern)): self.model().set_pattern(pattern) diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index e38a3ce49..74c63f251 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -490,6 +490,7 @@ class ModelValidator: def __init__(self, modeltester): modeltester.data_display_may_return_none = True + self._model = None self._modeltester = modeltester def set_model(self, model): diff --git a/tests/unit/browser/test_history.py b/tests/unit/browser/test_history.py index 0b5e6eb41..5a8425646 100644 --- a/tests/unit/browser/test_history.py +++ b/tests/unit/browser/test_history.py @@ -20,7 +20,6 @@ """Tests for the global page history.""" import logging -import os import pytest from PyQt5.QtCore import QUrl diff --git a/tests/unit/completion/test_completionwidget.py b/tests/unit/completion/test_completionwidget.py index cad45b5c1..207e557a8 100644 --- a/tests/unit/completion/test_completionwidget.py +++ b/tests/unit/completion/test_completionwidget.py @@ -89,6 +89,11 @@ def test_set_pattern(completionview): model.set_pattern.assert_called_with('foo') +def test_set_pattern_no_model(completionview): + """Ensure that setting a pattern with no model does not fail.""" + completionview.set_pattern('foo') + + def test_maybe_update_geometry(completionview, config_stub, qtbot): """Ensure completion is resized only if shrink is True.""" with qtbot.assertNotEmitted(completionview.update_geometry): @@ -233,4 +238,4 @@ def test_completion_item_del_no_selection(completionview): completionview.set_model(model) with pytest.raises(cmdexc.CommandError, match='No item selected!'): completionview.completion_item_del() - func.assert_not_called() + assert not func.called