From 48fe309a48be7e71b8681d5c23db69e9e4ecec79 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 31 Aug 2016 12:43:23 -0400 Subject: [PATCH 1/2] Regression test for repeated completion. Add a completionwidget unit test for #1812: help completion repeatedly completes. Addresses #1899. --- .../unit/completion/test_completionwidget.py | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tests/unit/completion/test_completionwidget.py b/tests/unit/completion/test_completionwidget.py index 2f82799f2..c5a5951e7 100644 --- a/tests/unit/completion/test_completionwidget.py +++ b/tests/unit/completion/test_completionwidget.py @@ -145,7 +145,8 @@ def test_maybe_resize_completion(completionview, config_stub, qtbot): ('next-category', [[]], 1, None), ('prev-category', [[]], 1, None), ]) -def test_completion_item_focus(which, tree, count, expected, completionview): +def test_completion_item_focus(which, tree, count, expected, completionview, + qtbot): """Test that on_next_prev_item moves the selection properly. Args: @@ -163,12 +164,34 @@ def test_completion_item_focus(which, tree, count, expected, completionview): filtermodel = sortfilter.CompletionFilterModel(model, parent=completionview) completionview.set_model(filtermodel) - for _ in range(count): - completionview.completion_item_focus(which) + if expected is None: + for _ in range(count): + completionview.completion_item_focus(which) + else: + with qtbot.waitSignal(completionview.selection_changed): + for _ in range(count): + completionview.completion_item_focus(which) idx = completionview.selectionModel().currentIndex() assert filtermodel.data(idx) == expected +@pytest.mark.parametrize('which', ['next', 'prev', 'next-category', + 'prev-category']) +def test_completion_item_focus_no_model(which, completionview, qtbot): + """Test that selectionChanged is not fired when the model is None. + + Validates #1812: help completion repeatedly completes + """ + with qtbot.assertNotEmitted(completionview.selection_changed): + completionview.completion_item_focus(which) + model = base.BaseCompletionModel() + filtermodel = sortfilter.CompletionFilterModel(model, + parent=completionview) + completionview.set_model(filtermodel) + completionview.set_model(None) + with qtbot.assertNotEmitted(completionview.selection_changed): + completionview.completion_item_focus(which) + @pytest.mark.parametrize('show', ['always', 'auto', 'never']) @pytest.mark.parametrize('rows', [[], ['Aa'], ['Aa', 'Bb']]) @pytest.mark.parametrize('quick_complete', [True, False]) From 24a5bffbd81a004dfe9a6c0acfae759d26999c12 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 31 Aug 2016 22:25:34 -0400 Subject: [PATCH 2/2] Test for completion warnings with 1 item. Add a regression test for #1600: Warnings from completionwidget when it only has 1 item. Addresses #1899. --- tests/end2end/features/completion.feature | 7 +++++++ tests/end2end/features/test_completion_bdd.py | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/end2end/features/completion.feature create mode 100644 tests/end2end/features/test_completion_bdd.py diff --git a/tests/end2end/features/completion.feature b/tests/end2end/features/completion.feature new file mode 100644 index 000000000..f3a343585 --- /dev/null +++ b/tests/end2end/features/completion.feature @@ -0,0 +1,7 @@ +Feature: Command bar completion + + Scenario: No warnings when completing with one entry (#1600) + Given I open about:blank + When I run :set-cmd-text -s :open + And I run :completion-item-focus next + Then no crash should happen diff --git a/tests/end2end/features/test_completion_bdd.py b/tests/end2end/features/test_completion_bdd.py new file mode 100644 index 000000000..4c2b43c8f --- /dev/null +++ b/tests/end2end/features/test_completion_bdd.py @@ -0,0 +1,21 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2016 Ryan Roden-Corrent (rcorre) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +import pytest_bdd as bdd +bdd.scenarios('completion.feature')