Consolidate invalid :bind/:unbind tests
This commit is contained in:
parent
7a27469ecd
commit
88b5007457
@ -19,6 +19,7 @@
|
|||||||
"""Tests for qutebrowser.config.configcommands."""
|
"""Tests for qutebrowser.config.configcommands."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import functools
|
||||||
import unittest.mock
|
import unittest.mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -543,23 +544,39 @@ class TestBind:
|
|||||||
msg = message_mock.getmsg(usertypes.MessageLevel.info)
|
msg = message_mock.getmsg(usertypes.MessageLevel.info)
|
||||||
assert msg.text == expected
|
assert msg.text == expected
|
||||||
|
|
||||||
def test_bind_invalid_mode(self, commands):
|
@pytest.mark.parametrize('command, args, kwargs, expected', [
|
||||||
"""Run ':bind --mode=wrongmode a nop'.
|
# :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.
|
Should show an error.
|
||||||
"""
|
"""
|
||||||
with pytest.raises(cmdexc.CommandError,
|
if command == 'bind':
|
||||||
match='Invalid mode wrongmode!'):
|
func = functools.partial(commands.bind, 0)
|
||||||
commands.bind(0, 'a', 'nop', mode='wrongmode')
|
elif command == 'unbind':
|
||||||
|
func = commands.unbind
|
||||||
|
|
||||||
def test_bind_print_invalid_mode(self, commands):
|
with pytest.raises(cmdexc.CommandError, match=expected):
|
||||||
"""Run ':bind --mode=wrongmode a'.
|
func(*args, **kwargs)
|
||||||
|
|
||||||
Should show an error.
|
|
||||||
"""
|
|
||||||
with pytest.raises(cmdexc.CommandError,
|
|
||||||
match='Invalid mode wrongmode!'):
|
|
||||||
commands.bind(0, 'a', mode='wrongmode')
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('key', ['a', 'b', '<Ctrl-X>'])
|
@pytest.mark.parametrize('key', ['a', 'b', '<Ctrl-X>'])
|
||||||
def test_bind_duplicate(self, commands, config_stub, key_config_stub, key):
|
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')
|
command = key_config_stub.get_command(keyseq('a'), mode='normal')
|
||||||
assert command == default_cmd
|
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):
|
def test_unbind_none(self, commands, config_stub):
|
||||||
config_stub.val.bindings.commands = None
|
config_stub.val.bindings.commands = None
|
||||||
commands.unbind('H')
|
commands.unbind('H')
|
||||||
@ -641,15 +646,3 @@ class TestBind:
|
|||||||
assert normalized not in yaml_bindings
|
assert normalized not in yaml_bindings
|
||||||
else:
|
else:
|
||||||
assert yaml_bindings[normalized] is None
|
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