summaryrefslogtreecommitdiff
path: root/tests/unit/config/test_configcommands.py
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2018-02-27 12:54:11 +0100
committerFlorian Bruhin <git@the-compiler.org>2018-02-27 13:02:32 +0100
commit88b50074570a8abcdb5d64ffe18a68923c1b7a11 (patch)
tree8088e9cf5c579d34f31f276aa9c0b690e368e76b /tests/unit/config/test_configcommands.py
parent7a27469ecdfe7db5e8f3519824c8191b0acc0f10 (diff)
downloadqutebrowser-88b50074570a8abcdb5d64ffe18a68923c1b7a11.tar.gz
qutebrowser-88b50074570a8abcdb5d64ffe18a68923c1b7a11.zip
Consolidate invalid :bind/:unbind tests
Diffstat (limited to 'tests/unit/config/test_configcommands.py')
-rw-r--r--tests/unit/config/test_configcommands.py67
1 files changed, 30 insertions, 37 deletions
diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py
index 320eb2bd4..0e2427c06 100644
--- a/tests/unit/config/test_configcommands.py
+++ b/tests/unit/config/test_configcommands.py
@@ -19,6 +19,7 @@
"""Tests for qutebrowser.config.configcommands."""
import logging
+import functools
import unittest.mock
import pytest
@@ -543,23 +544,39 @@ class TestBind:
msg = message_mock.getmsg(usertypes.MessageLevel.info)
assert msg.text == expected
- def test_bind_invalid_mode(self, commands):
- """Run ':bind --mode=wrongmode a nop'.
+ @pytest.mark.parametrize('command, args, kwargs, expected', [
+ # :bind --mode=wrongmode a nop
+ ('bind', ['a', 'nop'], {'mode': 'wrongmode'},
+ 'Invalid mode wrongmode!'),
+ # :bind --mode=wrongmode a
+ ('bind', ['a'], {'mode': 'wrongmode'},
+ 'Invalid mode wrongmode!'),
+ # :bind --default --mode=wrongmode a
+ ('bind', ['a'], {'mode': 'wrongmode', 'default': True},
+ 'Invalid mode wrongmode!'),
+ # :bind --default foobar
+ ('bind', ['foobar'], {'default': True},
+ "Can't find binding 'foobar' in normal mode"),
+ # :unbind foobar
+ ('unbind', ['foobar'], {},
+ "Can't find binding 'foobar' in normal mode"),
+ # :unbind --mode=wrongmode x
+ ('unbind', ['x'], {'mode': 'wrongmode'},
+ 'Invalid mode wrongmode!'),
+ ])
+ def test_bind_invalid(self, commands,
+ command, args, kwargs, expected):
+ """Run various wrong :bind/:unbind invocations.
Should show an error.
"""
- with pytest.raises(cmdexc.CommandError,
- match='Invalid mode wrongmode!'):
- commands.bind(0, 'a', 'nop', mode='wrongmode')
-
- def test_bind_print_invalid_mode(self, commands):
- """Run ':bind --mode=wrongmode a'.
+ if command == 'bind':
+ func = functools.partial(commands.bind, 0)
+ elif command == 'unbind':
+ func = commands.unbind
- Should show an error.
- """
- with pytest.raises(cmdexc.CommandError,
- match='Invalid mode wrongmode!'):
- commands.bind(0, 'a', mode='wrongmode')
+ with pytest.raises(cmdexc.CommandError, match=expected):
+ func(*args, **kwargs)
@pytest.mark.parametrize('key', ['a', 'b', '<Ctrl-X>'])
def test_bind_duplicate(self, commands, config_stub, key_config_stub, key):
@@ -596,18 +613,6 @@ class TestBind:
command = key_config_stub.get_command(keyseq('a'), mode='normal')
assert command == default_cmd
- @pytest.mark.parametrize('key, mode, expected', [
- ('foobar', 'normal', "Can't find binding 'foobar' in normal mode"),
- ('x', 'wrongmode', "Invalid mode wrongmode!"),
- ])
- def test_bind_default_invalid(self, commands, key, mode, expected):
- """Run ':bind --default foobar' / ':bind --default x wrongmode'.
-
- Should show an error.
- """
- with pytest.raises(cmdexc.CommandError, match=expected):
- commands.bind(0, key, mode=mode, default=True)
-
def test_unbind_none(self, commands, config_stub):
config_stub.val.bindings.commands = None
commands.unbind('H')
@@ -641,15 +646,3 @@ class TestBind:
assert normalized not in yaml_bindings
else:
assert yaml_bindings[normalized] is None
-
- @pytest.mark.parametrize('key, mode, expected', [
- ('foobar', 'normal', "Can't find binding 'foobar' in normal mode"),
- ('x', 'wrongmode', "Invalid mode wrongmode!"),
- ])
- def test_unbind_invalid(self, commands, key, mode, expected):
- """Run ':unbind foobar' / ':unbind x wrongmode'.
-
- Should show an error.
- """
- with pytest.raises(cmdexc.CommandError, match=expected):
- commands.unbind(key, mode=mode)