From 5078080bb00f9a8d40ace9810b18eeb751cd7fad Mon Sep 17 00:00:00 2001 From: Luca Benci Date: Tue, 10 Oct 2017 22:02:25 +0200 Subject: [PATCH] Add (not fully working) tests for use_best_match --- tests/unit/config/test_configcommands.py | 31 +++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index 21ec040f7..ed69e7c32 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -25,7 +25,7 @@ import pytest from PyQt5.QtCore import QUrl, QProcess from qutebrowser.config import configcommands -from qutebrowser.commands import cmdexc +from qutebrowser.commands import cmdexc, runners from qutebrowser.utils import usertypes from qutebrowser.misc import objects @@ -532,3 +532,32 @@ class TestBind: """ with pytest.raises(cmdexc.CommandError, match=expected): commands.unbind(key, mode=mode) + + +class TestCompletions: + + """Tests for completions.use_best_match.""" + + def test_dont_use_best_match(self, config_stub, monkeypatch): + """Test multiple completion options with use_best_match set to false. + + Should raise NoSuchCommandError + """ + config_stub.val.completion.use_best_match = False + monkeypatch.setattr('qutebrowser.config', config_stub) + parser = runners.CommandParser(partial_match=True) + + with pytest.raises(cmdexc.NoSuchCommandError): + result = parser.parse('do') + + def test_use_best_match(self, config_stub, monkeypatch): + """Test multiple completion options with use_best_match set to true. + + The resulting command should be the best match + """ + config_stub.val.completion.use_best_match = True + monkeypatch.setattr('qutebrowser.config', config_stub) + parser = runners.CommandParser(partial_match=True) + + result = parser.parse('do') + assert result.cmd.name == 'download'