From 32cc6bea1d1ca97db97d68b96dd3ac4f50c3685f Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Thu, 11 Aug 2016 05:15:08 +0200 Subject: [PATCH] Add tests for the completion engine I tested everything that I thought was interesting enough to warrant a test: especially the ability to test multiple parameters deep, as well as testing :set --cycle and some involved example to make sure completion actually works and updates in realtime --- tests/end2end/features/completion.feature | 81 ++++++++++++++++++- tests/end2end/features/conftest.py | 26 +++++- tests/end2end/features/test_completion_bdd.py | 10 ++- tests/end2end/features/test_set_bdd.py | 6 -- tests/end2end/fixtures/quteprocess.py | 15 ++-- 5 files changed, 122 insertions(+), 16 deletions(-) diff --git a/tests/end2end/features/completion.feature b/tests/end2end/features/completion.feature index 4fec2d81b..1d39e6bff 100644 --- a/tests/end2end/features/completion.feature +++ b/tests/end2end/features/completion.feature @@ -1,4 +1,4 @@ -Feature: Command bar completion +Feature: Using completion Scenario: No warnings when completing with one entry (#1600) Given I open about:blank @@ -27,3 +27,82 @@ Feature: Command bar completion Given I open about:blank When I run :set-cmd-text -s :🌀 Then no crash should happen + + Scenario: Using command completion + When I run :set-cmd-text : + Then the completion model should be CommandCompletionModel + + Scenario: Using help completion + When I run :set-cmd-text -s :help + Then the completion model should be HelpCompletionModel + + Scenario: Using quickmark completion + When I run :set-cmd-text -s :quickmark-load + Then the completion model should be QuickmarkCompletionModel + + Scenario: Using bookmark completion + When I run :set-cmd-text -s :bookmark-load + Then the completion model should be BookmarkCompletionModel + + Scenario: Using bind completion + When I run :set-cmd-text -s :bind X + Then the completion model should be BindCompletionModel + + Scenario: Using session completion + Given I open data/hello.txt + And I run :session-save hello + When I run :set-cmd-text -s :session-load + And I run :completion-item-focus next + And I run :completion-item-focus next + And I run :session-delete hello + And I run :command-accept + Then the error "Session hello not found!" should be shown + + Scenario: Using option completion + When I run :set-cmd-text -s :set colors + Then the completion model should be SettingOptionCompletionModel + + Scenario: Using value completion + When I run :set-cmd-text -s :set colors statusbar.bg + Then the completion model should be SettingValueCompletionModel + + Scenario: Using value completion multiple times + When I run :set-cmd-text -s :set --cycle colors statusbar.bg black + Then the completion model should be SettingValueCompletionModel + + Scenario: Updating the completion in realtime + Given I have a fresh instance + And I set completion -> quick-complete to false + When I open data/hello.txt + And I run :set-cmd-text -s :buffer + And I run :completion-item-focus next + And I open data/hello2.txt in a new background tab + And I run :completion-item-focus next + And I open data/hello3.txt in a new background tab + And I run :completion-item-focus next + And I run :command-accept + Then the following tabs should be open: + - data/hello.txt + - data/hello2.txt + - data/hello3.txt (active) + + Scenario: Updating the value completion in realtime + Given I set colors -> statusbar.bg to green + When I run :set-cmd-text -s :set colors statusbar.bg + And I set colors -> statusbar.bg to yellow + And I run :completion-item-focus next + And I run :completion-item-focus next + And I set colors -> statusbar.bg to red + And I run :command-accept + Then colors -> statusbar.bg should be yellow + + Scenario: Deleting an open tab via the completion + Given I have a fresh instance + When I open data/hello.txt + And I open data/hello2.txt in a new tab + And I run :set-cmd-text -s :buffer + And I run :completion-item-focus next + And I run :completion-item-focus next + And I run :completion-item-del + Then the following tabs should be open: + - data/hello.txt (active) diff --git a/tests/end2end/features/conftest.py b/tests/end2end/features/conftest.py index 7dd42c2d0..ea6b96bbf 100644 --- a/tests/end2end/features/conftest.py +++ b/tests/end2end/features/conftest.py @@ -181,11 +181,13 @@ def open_path(quteproc, path): "... as a URL", it's opened according to new-instance-open-target. """ new_tab = False + new_bg_tab = False new_window = False as_url = False wait = True new_tab_suffix = ' in a new tab' + new_bg_tab_suffix = ' in a new background tab' new_window_suffix = ' in a new window' do_not_wait_suffix = ' without waiting' as_url_suffix = ' as a URL' @@ -206,8 +208,22 @@ def open_path(quteproc, path): else: break - quteproc.open_path(path, new_tab=new_tab, new_window=new_window, - as_url=as_url, wait=wait) + if path.endswith(new_tab_suffix): + path = path[:-len(new_tab_suffix)] + new_tab = True + elif path.endswith(new_bg_tab_suffix): + path = path[:-len(new_bg_tab_suffix)] + new_bg_tab = True + elif path.endswith(new_window_suffix): + path = path[:-len(new_window_suffix)] + new_window = True + + if path.endswith(do_not_wait_suffix): + path = path[:-len(do_not_wait_suffix)] + wait = False + + quteproc.open_path(path, new_tab=new_tab, new_bg_tab=new_bg_tab, + new_window=new_window, as_url=as_url, wait=wait) @bdd.when(bdd.parsers.parse("I set {sect} -> {opt} to {value}")) @@ -595,3 +611,9 @@ def check_not_scrolled(request, quteproc): x, y = _get_scroll_values(quteproc) assert x == 0 assert y == 0 + + +@bdd.then(bdd.parsers.parse("{section} -> {option} should be {value}")) +def check_option(quteproc, section, option, value): + actual_value = quteproc.get_setting(section, option) + assert actual_value == value diff --git a/tests/end2end/features/test_completion_bdd.py b/tests/end2end/features/test_completion_bdd.py index 4c2b43c8f..c8470441a 100644 --- a/tests/end2end/features/test_completion_bdd.py +++ b/tests/end2end/features/test_completion_bdd.py @@ -1,6 +1,6 @@ # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: -# Copyright 2016 Ryan Roden-Corrent (rcorre) +# Copyright 2015-2016 Florian Bruhin (The Compiler) # # This file is part of qutebrowser. # @@ -17,5 +17,13 @@ # You should have received a copy of the GNU General Public License # along with qutebrowser. If not, see . +import re import pytest_bdd as bdd bdd.scenarios('completion.feature') + + +@bdd.then(bdd.parsers.parse("the completion model should be {model}")) +def check_model(quteproc, model): + """Make sure the completion model was set to something.""" + pattern = "New completion [^:]*: {}".format(model) + quteproc.wait_for(message=re.compile(pattern)) diff --git a/tests/end2end/features/test_set_bdd.py b/tests/end2end/features/test_set_bdd.py index 30b33aedb..2eabd8c56 100644 --- a/tests/end2end/features/test_set_bdd.py +++ b/tests/end2end/features/test_set_bdd.py @@ -19,9 +19,3 @@ import pytest_bdd as bdd bdd.scenarios('set.feature') - - -@bdd.then(bdd.parsers.parse("{section} -> {option} should be {value}")) -def check_option(quteproc, section, option, value): - actual_value = quteproc.get_setting(section, option) - assert actual_value == value diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index 53f3bee88..cabc16954 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -475,15 +475,16 @@ class QuteProc(testprocess.Process): yield self.set_setting(sect, opt, old_value) - def open_path(self, path, *, new_tab=False, new_window=False, as_url=False, - port=None, https=False, wait=True): + def open_path(self, path, *, new_tab=False, new_bg_tab=False, + new_window=False, as_url=False, port=None, https=False, + wait=True): """Open the given path on the local webserver in qutebrowser.""" url = self.path_to_url(path, port=port, https=https) - self.open_url(url, new_tab=new_tab, new_window=new_window, - as_url=as_url, wait=wait) + self.open_url(url, new_tab=new_tab, new_bg_tab=new_bg_tab, + new_window=new_window, wait=wait) - def open_url(self, url, *, new_tab=False, new_window=False, as_url=False, - wait=True): + def open_url(self, url, *, new_tab=False, new_bg_tab=False, + new_window=False, as_url=False, wait=True): """Open the given url in qutebrowser.""" if new_tab and new_window: raise ValueError("new_tab and new_window given!") @@ -492,6 +493,8 @@ class QuteProc(testprocess.Process): self.send_cmd(url, invalid=True) elif new_tab: self.send_cmd(':open -t ' + url) + elif new_bg_tab: + self.send_cmd(':open -b ' + url) elif new_window: self.send_cmd(':open -w ' + url) else: