diff options
author | Florian Bruhin <me@the-compiler.org> | 2018-11-29 14:09:06 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2018-11-29 14:18:11 +0100 |
commit | b7de287e7bf053072eab47551e593d948fa8ced7 (patch) | |
tree | cdfc159315deaaaa6d229625c126e76c739c1d7d /tests | |
parent | f9858733c1ba7d4500ad8b20bef281341dc12f12 (diff) | |
download | qutebrowser-b7de287e7bf053072eab47551e593d948fa8ced7.tar.gz qutebrowser-b7de287e7bf053072eab47551e593d948fa8ced7.zip |
Move CommandError to api.cmdutils
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/api/test_cmdutils.py (renamed from tests/unit/commands/test_cmdutils.py) | 9 | ||||
-rw-r--r-- | tests/unit/browser/test_history.py | 4 | ||||
-rw-r--r-- | tests/unit/completion/test_completer.py | 3 | ||||
-rw-r--r-- | tests/unit/completion/test_completionmodel.py | 4 | ||||
-rw-r--r-- | tests/unit/completion/test_completionwidget.py | 4 | ||||
-rw-r--r-- | tests/unit/config/test_configcommands.py | 50 | ||||
-rw-r--r-- | tests/unit/misc/test_utilcmds.py | 8 | ||||
-rw-r--r-- | tests/unit/utils/test_urlutils.py | 4 |
8 files changed, 44 insertions, 42 deletions
diff --git a/tests/unit/commands/test_cmdutils.py b/tests/unit/api/test_cmdutils.py index 4d7877e69..f2318ab46 100644 --- a/tests/unit/commands/test_cmdutils.py +++ b/tests/unit/api/test_cmdutils.py @@ -19,7 +19,7 @@ # pylint: disable=unused-variable -"""Tests for qutebrowser.commands.cmdutils.""" +"""Tests for qutebrowser.api.cmdutils.""" import sys import logging @@ -30,7 +30,8 @@ import enum import pytest from qutebrowser.misc import objects -from qutebrowser.commands import cmdexc, argparser, command, cmdutils +from qutebrowser.commands import cmdexc, argparser, command +from qutebrowser.api import cmdutils from qutebrowser.utils import usertypes @@ -59,7 +60,7 @@ class TestCheckOverflow: def test_bad(self): int32_max = 2 ** 31 - 1 - with pytest.raises(cmdexc.CommandError, match="Numeric argument is " + with pytest.raises(cmdutils.CommandError, match="Numeric argument is " "too large for internal int representation."): cmdutils.check_overflow(int32_max + 1, 'int') @@ -71,7 +72,7 @@ class TestCheckExclusive: cmdutils.check_exclusive(flags, []) def test_bad(self): - with pytest.raises(cmdexc.CommandError, + with pytest.raises(cmdutils.CommandError, match="Only one of -x/-y/-z can be given!"): cmdutils.check_exclusive([True, True], 'xyz') diff --git a/tests/unit/browser/test_history.py b/tests/unit/browser/test_history.py index 5b84eac4c..715b597b0 100644 --- a/tests/unit/browser/test_history.py +++ b/tests/unit/browser/test_history.py @@ -26,7 +26,7 @@ from PyQt5.QtCore import QUrl from qutebrowser.browser import history from qutebrowser.utils import objreg, urlutils, usertypes -from qutebrowser.commands import cmdexc +from qutebrowser.api import cmdutils from qutebrowser.misc import sql @@ -324,7 +324,7 @@ class TestDump: def test_nonexistent(self, web_history, tmpdir): histfile = tmpdir / 'nonexistent' / 'history' - with pytest.raises(cmdexc.CommandError): + with pytest.raises(cmdutils.CommandError): web_history.debug_dump_history(str(histfile)) diff --git a/tests/unit/completion/test_completer.py b/tests/unit/completion/test_completer.py index 59291cdd6..16ebb95dc 100644 --- a/tests/unit/completion/test_completer.py +++ b/tests/unit/completion/test_completer.py @@ -26,7 +26,8 @@ from PyQt5.QtCore import QObject from PyQt5.QtGui import QStandardItemModel from qutebrowser.completion import completer -from qutebrowser.commands import command, cmdutils +from qutebrowser.commands import command +from qutebrowser.api import cmdutils class FakeCompletionModel(QStandardItemModel): diff --git a/tests/unit/completion/test_completionmodel.py b/tests/unit/completion/test_completionmodel.py index e0e044ffb..24f5bdf0d 100644 --- a/tests/unit/completion/test_completionmodel.py +++ b/tests/unit/completion/test_completionmodel.py @@ -28,7 +28,7 @@ from PyQt5.QtCore import QModelIndex from qutebrowser.completion.models import completionmodel, listcategory from qutebrowser.utils import qtutils -from qutebrowser.commands import cmdexc +from qutebrowser.api import cmdutils @hypothesis.given(strategies.lists( @@ -102,7 +102,7 @@ def test_delete_cur_item_no_func(): model.rowsRemoved.connect(callback) model.add_category(cat) parent = model.index(0, 0) - with pytest.raises(cmdexc.CommandError): + with pytest.raises(cmdutils.CommandError): model.delete_cur_item(model.index(0, 0, parent)) callback.assert_not_called() diff --git a/tests/unit/completion/test_completionwidget.py b/tests/unit/completion/test_completionwidget.py index 01bd3ec03..3d66e1145 100644 --- a/tests/unit/completion/test_completionwidget.py +++ b/tests/unit/completion/test_completionwidget.py @@ -25,7 +25,7 @@ import pytest from qutebrowser.completion import completionwidget from qutebrowser.completion.models import completionmodel, listcategory -from qutebrowser.commands import cmdexc +from qutebrowser.api import cmdutils @pytest.fixture @@ -241,7 +241,7 @@ def test_completion_item_del_no_selection(completionview): cat = listcategory.ListCategory('', [('foo',)], delete_func=func) model.add_category(cat) completionview.set_model(model) - with pytest.raises(cmdexc.CommandError, match='No item selected!'): + with pytest.raises(cmdutils.CommandError, match='No item selected!'): completionview.completion_item_del() func.assert_not_called() diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index 47bcaaa74..001d55899 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -26,7 +26,7 @@ import pytest from PyQt5.QtCore import QUrl from qutebrowser.config import configcommands, configutils -from qutebrowser.commands import cmdexc +from qutebrowser.api import cmdutils from qutebrowser.utils import usertypes, urlmatch from qutebrowser.keyinput import keyutils from qutebrowser.misc import objects @@ -108,7 +108,7 @@ class TestSet: monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebKit) option = 'content.javascript.enabled' - with pytest.raises(cmdexc.CommandError, + with pytest.raises(cmdutils.CommandError, match=('Error while parsing http://: Pattern ' 'without host')): commands.set(0, option, 'false', pattern='http://') @@ -118,7 +118,7 @@ class TestSet: Should show an error as patterns are unsupported. """ - with pytest.raises(cmdexc.CommandError, + with pytest.raises(cmdutils.CommandError, match='does not support URL patterns'): commands.set(0, 'colors.statusbar.normal.bg', '#abcdef', pattern='*://*') @@ -165,7 +165,7 @@ class TestSet: Should show an error. """ - with pytest.raises(cmdexc.CommandError, match="No option 'foo'"): + with pytest.raises(cmdutils.CommandError, match="No option 'foo'"): commands.set(0, 'foo', 'bar') def test_set_invalid_value(self, commands): @@ -173,13 +173,13 @@ class TestSet: Should show an error. """ - with pytest.raises(cmdexc.CommandError, + with pytest.raises(cmdutils.CommandError, match="Invalid value 'blah' - must be a boolean!"): commands.set(0, 'auto_save.session', 'blah') def test_set_wrong_backend(self, commands, monkeypatch): monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebEngine) - with pytest.raises(cmdexc.CommandError, + with pytest.raises(cmdutils.CommandError, match="The hints.find_implementation setting is " "not available with the QtWebEngine backend!"): commands.set(0, 'hints.find_implementation', 'javascript') @@ -190,7 +190,7 @@ class TestSet: Should show an error. See https://github.com/qutebrowser/qutebrowser/issues/1109 """ - with pytest.raises(cmdexc.CommandError, match="No option '?'"): + with pytest.raises(cmdutils.CommandError, match="No option '?'"): commands.set(win_id=0, option='?') def test_toggle(self, commands): @@ -198,7 +198,7 @@ class TestSet: Should show an nicer error. """ - with pytest.raises(cmdexc.CommandError, + with pytest.raises(cmdutils.CommandError, match="Toggling values was moved to the " ":config-cycle command"): commands.set(win_id=0, option='javascript.enabled!') @@ -208,7 +208,7 @@ class TestSet: Should show an error. """ - with pytest.raises(cmdexc.CommandError, match="No option 'foo'"): + with pytest.raises(cmdutils.CommandError, match="No option 'foo'"): commands.set(win_id=0, option='foo?') @@ -267,7 +267,7 @@ class TestCycle: Should show an error. """ assert config_stub.val.url.auto_search == 'naive' - with pytest.raises(cmdexc.CommandError, match="Need at least " + with pytest.raises(cmdutils.CommandError, match="Need at least " "two values for non-boolean settings."): commands.config_cycle(*args) assert config_stub.val.url.auto_search == 'naive' @@ -301,14 +301,14 @@ class TestAdd: def test_list_add_non_list(self, commands): with pytest.raises( - cmdexc.CommandError, + cmdutils.CommandError, match=":config-list-add can only be used for lists"): commands.config_list_add('history_gap_interval', 'value') @pytest.mark.parametrize('value', ['', None, 42]) def test_list_add_invalid_values(self, commands, value): with pytest.raises( - cmdexc.CommandError, + cmdutils.CommandError, match="Invalid value '{}'".format(value)): commands.config_list_add('content.host_blocking.whitelist', value) @@ -337,20 +337,20 @@ class TestAdd: assert str(config_stub.get(name)[key]) == value else: with pytest.raises( - cmdexc.CommandError, + cmdutils.CommandError, match="w already exists in aliases - use --replace to " "overwrite!"): commands.config_dict_add(name, key, value, replace=False) def test_dict_add_non_dict(self, commands): with pytest.raises( - cmdexc.CommandError, + cmdutils.CommandError, match=":config-dict-add can only be used for dicts"): commands.config_dict_add('history_gap_interval', 'key', 'value') @pytest.mark.parametrize('value', ['', None, 42]) def test_dict_add_invalid_values(self, commands, value): - with pytest.raises(cmdexc.CommandError, + with pytest.raises(cmdutils.CommandError, match="Invalid value '{}'".format(value)): commands.config_dict_add('aliases', 'missingkey', value) @@ -373,14 +373,14 @@ class TestRemove: def test_list_remove_non_list(self, commands): with pytest.raises( - cmdexc.CommandError, + cmdutils.CommandError, match=":config-list-remove can only be used for lists"): commands.config_list_remove('content.javascript.enabled', 'never') def test_list_remove_no_value(self, commands): with pytest.raises( - cmdexc.CommandError, + cmdutils.CommandError, match="never is not in colors.completion.fg!"): commands.config_list_remove('colors.completion.fg', 'never') @@ -398,14 +398,14 @@ class TestRemove: def test_dict_remove_non_dict(self, commands): with pytest.raises( - cmdexc.CommandError, + cmdutils.CommandError, match=":config-dict-remove can only be used for dicts"): commands.config_dict_remove('content.javascript.enabled', 'never') def test_dict_remove_no_value(self, commands): with pytest.raises( - cmdexc.CommandError, + cmdutils.CommandError, match="never is not in aliases!"): commands.config_dict_remove('aliases', 'never') @@ -425,7 +425,7 @@ class TestUnsetAndClear: assert yaml_value(name) == ('never' if temp else configutils.UNSET) def test_unset_unknown_option(self, commands): - with pytest.raises(cmdexc.CommandError, match="No option 'tabs'"): + with pytest.raises(cmdutils.CommandError, match="No option 'tabs'"): commands.config_unset('tabs') @pytest.mark.parametrize('save', [True, False]) @@ -472,7 +472,7 @@ class TestSource: pyfile = config_tmpdir / 'config.py' pyfile.write_text('c.foo = 42', encoding='utf-8') - with pytest.raises(cmdexc.CommandError) as excinfo: + with pytest.raises(cmdutils.CommandError) as excinfo: commands.config_source() expected = ("Errors occurred while reading config.py:\n" @@ -483,7 +483,7 @@ class TestSource: pyfile = config_tmpdir / 'config.py' pyfile.write_text('1/0', encoding='utf-8') - with pytest.raises(cmdexc.CommandError) as excinfo: + with pytest.raises(cmdutils.CommandError) as excinfo: commands.config_source() expected = ("Errors occurred while reading config.py:\n" @@ -582,7 +582,7 @@ class TestWritePy: confpy = tmpdir / 'config.py' confpy.ensure() - with pytest.raises(cmdexc.CommandError) as excinfo: + with pytest.raises(cmdutils.CommandError) as excinfo: commands.config_write_py(str(confpy)) expected = " already exists - use --force to overwrite!" @@ -599,7 +599,7 @@ class TestWritePy: def test_oserror(self, commands, tmpdir): """Test writing to a directory which does not exist.""" - with pytest.raises(cmdexc.CommandError): + with pytest.raises(cmdutils.CommandError): commands.config_write_py(str(tmpdir / 'foo' / 'config.py')) @@ -709,7 +709,7 @@ class TestBind: elif command == 'unbind': func = commands.unbind - with pytest.raises(cmdexc.CommandError, match=expected): + with pytest.raises(cmdutils.CommandError, match=expected): func(*args, **kwargs) @pytest.mark.parametrize('key', ['a', 'b', '<Ctrl-X>']) diff --git a/tests/unit/misc/test_utilcmds.py b/tests/unit/misc/test_utilcmds.py index cfa115412..73f97095f 100644 --- a/tests/unit/misc/test_utilcmds.py +++ b/tests/unit/misc/test_utilcmds.py @@ -28,7 +28,7 @@ import pytest from PyQt5.QtCore import QUrl from qutebrowser.misc import utilcmds -from qutebrowser.commands import cmdexc +from qutebrowser.api import cmdutils from qutebrowser.utils import utils, objreg @@ -83,14 +83,14 @@ def test_debug_trace_exception(mocker): hunter_mock = mocker.patch('qutebrowser.misc.utilcmds.hunter') hunter_mock.trace.side_effect = _mock_exception - with pytest.raises(cmdexc.CommandError, match='Exception: message'): + with pytest.raises(cmdutils.CommandError, match='Exception: message'): utilcmds.debug_trace() def test_debug_trace_no_hunter(monkeypatch): """Test that an error is shown if debug_trace is called without hunter.""" monkeypatch.setattr(utilcmds, 'hunter', None) - with pytest.raises(cmdexc.CommandError, match="You need to install " + with pytest.raises(cmdutils.CommandError, match="You need to install " "'hunter' to use this command!"): utilcmds.debug_trace() @@ -103,7 +103,7 @@ def test_repeat_command_initial(mocker, mode_manager): """ objreg_mock = mocker.patch('qutebrowser.misc.utilcmds.objreg') objreg_mock.get.return_value = mode_manager - with pytest.raises(cmdexc.CommandError, + with pytest.raises(cmdutils.CommandError, match="You didn't do anything yet."): utilcmds.repeat_command(win_id=0) diff --git a/tests/unit/utils/test_urlutils.py b/tests/unit/utils/test_urlutils.py index 26b063456..1c1efffab 100644 --- a/tests/unit/utils/test_urlutils.py +++ b/tests/unit/utils/test_urlutils.py @@ -27,7 +27,7 @@ from PyQt5.QtCore import QUrl from PyQt5.QtNetwork import QNetworkProxy import pytest -from qutebrowser.commands import cmdexc +from qutebrowser.api import cmdutils from qutebrowser.browser.network import pac from qutebrowser.utils import utils, urlutils, qtutils, usertypes from helpers import utils as testutils @@ -495,7 +495,7 @@ def test_raise_cmdexc_if_invalid(url, valid, has_err_string): expected_text = "Invalid URL - " + qurl.errorString() else: expected_text = "Invalid URL" - with pytest.raises(cmdexc.CommandError, match=expected_text): + with pytest.raises(cmdutils.CommandError, match=expected_text): urlutils.raise_cmdexc_if_invalid(qurl) |