Consolidate invalid :bind/:unbind tests
This commit is contained in:
parent
7a27469ecd
commit
88b5007457
@ -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')
|
||||
if command == 'bind':
|
||||
func = functools.partial(commands.bind, 0)
|
||||
elif command == 'unbind':
|
||||
func = commands.unbind
|
||||
|
||||
def test_bind_print_invalid_mode(self, commands):
|
||||
"""Run ':bind --mode=wrongmode a'.
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user