tests: Get rid of duplicate key config stubs
This commit is contained in:
parent
012f79b244
commit
c63d16e2ea
@ -1,29 +0,0 @@
|
|||||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
||||||
# Copyright 2017 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
|
||||||
|
|
||||||
# This file is part of qutebrowser.
|
|
||||||
#
|
|
||||||
# qutebrowser is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# qutebrowser is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
"""Fixtures needed in various config test files."""
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from qutebrowser.config import config
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def keyconf(config_stub):
|
|
||||||
config_stub.val.aliases = {}
|
|
||||||
return config.KeyConfig(config_stub)
|
|
@ -93,11 +93,6 @@ class TestChangeFilter:
|
|||||||
|
|
||||||
class TestKeyConfig:
|
class TestKeyConfig:
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def keyconf(self, config_stub):
|
|
||||||
config_stub.val.aliases = {}
|
|
||||||
return config.KeyConfig(config_stub)
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def no_bindings(self):
|
def no_bindings(self):
|
||||||
"""Get a dict with no bindings."""
|
"""Get a dict with no bindings."""
|
||||||
@ -107,14 +102,14 @@ class TestKeyConfig:
|
|||||||
('A', 'A'),
|
('A', 'A'),
|
||||||
('<Ctrl-X>', '<ctrl+x>'),
|
('<Ctrl-X>', '<ctrl+x>'),
|
||||||
])
|
])
|
||||||
def test_prepare_valid(self, keyconf, key, expected):
|
def test_prepare_valid(self, key_config_stub, key, expected):
|
||||||
"""Make sure prepare normalizes the key."""
|
"""Make sure prepare normalizes the key."""
|
||||||
assert keyconf._prepare(key, 'normal') == expected
|
assert key_config_stub._prepare(key, 'normal') == expected
|
||||||
|
|
||||||
def test_prepare_invalid(self, keyconf):
|
def test_prepare_invalid(self, key_config_stub):
|
||||||
"""Make sure prepare checks the mode."""
|
"""Make sure prepare checks the mode."""
|
||||||
with pytest.raises(configexc.KeybindingError):
|
with pytest.raises(configexc.KeybindingError):
|
||||||
assert keyconf._prepare('x', 'abnormal')
|
assert key_config_stub._prepare('x', 'abnormal')
|
||||||
|
|
||||||
@pytest.mark.parametrize('commands, expected', [
|
@pytest.mark.parametrize('commands, expected', [
|
||||||
# Unbinding default key
|
# Unbinding default key
|
||||||
@ -126,7 +121,8 @@ class TestKeyConfig:
|
|||||||
# Unbinding unknown key
|
# Unbinding unknown key
|
||||||
({'x': None}, {'a': 'message-info foo', 'b': 'message-info bar'}),
|
({'x': None}, {'a': 'message-info foo', 'b': 'message-info bar'}),
|
||||||
])
|
])
|
||||||
def test_get_bindings_for_and_get_command(self, keyconf, config_stub,
|
def test_get_bindings_for_and_get_command(self, key_config_stub,
|
||||||
|
config_stub,
|
||||||
commands, expected):
|
commands, expected):
|
||||||
orig_default_bindings = {'normal': {'a': 'message-info foo',
|
orig_default_bindings = {'normal': {'a': 'message-info foo',
|
||||||
'b': 'message-info bar'},
|
'b': 'message-info bar'},
|
||||||
@ -139,18 +135,19 @@ class TestKeyConfig:
|
|||||||
'register': {}}
|
'register': {}}
|
||||||
config_stub.val.bindings.default = copy.deepcopy(orig_default_bindings)
|
config_stub.val.bindings.default = copy.deepcopy(orig_default_bindings)
|
||||||
config_stub.val.bindings.commands = {'normal': commands}
|
config_stub.val.bindings.commands = {'normal': commands}
|
||||||
bindings = keyconf.get_bindings_for('normal')
|
bindings = key_config_stub.get_bindings_for('normal')
|
||||||
|
|
||||||
# Make sure the code creates a copy and doesn't modify the setting
|
# Make sure the code creates a copy and doesn't modify the setting
|
||||||
assert config_stub.val.bindings.default == orig_default_bindings
|
assert config_stub.val.bindings.default == orig_default_bindings
|
||||||
assert bindings == expected
|
assert bindings == expected
|
||||||
for key, command in expected.items():
|
for key, command in expected.items():
|
||||||
assert keyconf.get_command(key, 'normal') == command
|
assert key_config_stub.get_command(key, 'normal') == command
|
||||||
|
|
||||||
def test_get_command_unbound(self, keyconf, config_stub, no_bindings):
|
def test_get_command_unbound(self, key_config_stub, config_stub,
|
||||||
|
no_bindings):
|
||||||
config_stub.val.bindings.default = no_bindings
|
config_stub.val.bindings.default = no_bindings
|
||||||
config_stub.val.bindings.commands = no_bindings
|
config_stub.val.bindings.commands = no_bindings
|
||||||
assert keyconf.get_command('foobar', 'normal') is None
|
assert key_config_stub.get_command('foobar', 'normal') is None
|
||||||
|
|
||||||
@pytest.mark.parametrize('bindings, expected', [
|
@pytest.mark.parametrize('bindings, expected', [
|
||||||
# Simple
|
# Simple
|
||||||
@ -166,46 +163,47 @@ class TestKeyConfig:
|
|||||||
({'a': 'message-info foo ;; message-info bar'},
|
({'a': 'message-info foo ;; message-info bar'},
|
||||||
{'message-info foo': ['a'], 'message-info bar': ['a']}),
|
{'message-info foo': ['a'], 'message-info bar': ['a']}),
|
||||||
])
|
])
|
||||||
def test_get_reverse_bindings_for(self, keyconf, config_stub, no_bindings,
|
def test_get_reverse_bindings_for(self, key_config_stub, config_stub,
|
||||||
bindings, expected):
|
no_bindings, bindings, expected):
|
||||||
config_stub.val.bindings.default = no_bindings
|
config_stub.val.bindings.default = no_bindings
|
||||||
config_stub.val.bindings.commands = {'normal': bindings}
|
config_stub.val.bindings.commands = {'normal': bindings}
|
||||||
assert keyconf.get_reverse_bindings_for('normal') == expected
|
assert key_config_stub.get_reverse_bindings_for('normal') == expected
|
||||||
|
|
||||||
@pytest.mark.parametrize('key', ['a', '<Ctrl-X>', 'b'])
|
@pytest.mark.parametrize('key', ['a', '<Ctrl-X>', 'b'])
|
||||||
def test_bind_duplicate(self, keyconf, config_stub, key):
|
def test_bind_duplicate(self, key_config_stub, config_stub, key):
|
||||||
config_stub.val.bindings.default = {'normal': {'a': 'nop',
|
config_stub.val.bindings.default = {'normal': {'a': 'nop',
|
||||||
'<Ctrl+x>': 'nop'}}
|
'<Ctrl+x>': 'nop'}}
|
||||||
config_stub.val.bindings.commands = {'normal': {'b': 'nop'}}
|
config_stub.val.bindings.commands = {'normal': {'b': 'nop'}}
|
||||||
keyconf.bind(key, 'message-info foo', mode='normal')
|
key_config_stub.bind(key, 'message-info foo', mode='normal')
|
||||||
assert keyconf.get_command(key, 'normal') == 'message-info foo'
|
assert key_config_stub.get_command(key, 'normal') == 'message-info foo'
|
||||||
|
|
||||||
@pytest.mark.parametrize('mode', ['normal', 'caret'])
|
@pytest.mark.parametrize('mode', ['normal', 'caret'])
|
||||||
@pytest.mark.parametrize('command', [
|
@pytest.mark.parametrize('command', [
|
||||||
'message-info foo',
|
'message-info foo',
|
||||||
'nop ;; wq', # https://github.com/qutebrowser/qutebrowser/issues/3002
|
'nop ;; wq', # https://github.com/qutebrowser/qutebrowser/issues/3002
|
||||||
])
|
])
|
||||||
def test_bind(self, keyconf, config_stub, qtbot, no_bindings,
|
def test_bind(self, key_config_stub, config_stub, qtbot, no_bindings,
|
||||||
mode, command):
|
mode, command):
|
||||||
config_stub.val.bindings.default = no_bindings
|
config_stub.val.bindings.default = no_bindings
|
||||||
config_stub.val.bindings.commands = no_bindings
|
config_stub.val.bindings.commands = no_bindings
|
||||||
|
|
||||||
with qtbot.wait_signal(config_stub.changed):
|
with qtbot.wait_signal(config_stub.changed):
|
||||||
keyconf.bind('a', command, mode=mode)
|
key_config_stub.bind('a', command, mode=mode)
|
||||||
|
|
||||||
assert config_stub.val.bindings.commands[mode]['a'] == command
|
assert config_stub.val.bindings.commands[mode]['a'] == command
|
||||||
assert keyconf.get_bindings_for(mode)['a'] == command
|
assert key_config_stub.get_bindings_for(mode)['a'] == command
|
||||||
assert keyconf.get_command('a', mode) == command
|
assert key_config_stub.get_command('a', mode) == command
|
||||||
|
|
||||||
def test_bind_mode_changing(self, keyconf, config_stub, no_bindings):
|
def test_bind_mode_changing(self, key_config_stub, config_stub,
|
||||||
|
no_bindings):
|
||||||
"""Make sure we can bind to a command which changes the mode.
|
"""Make sure we can bind to a command which changes the mode.
|
||||||
|
|
||||||
https://github.com/qutebrowser/qutebrowser/issues/2989
|
https://github.com/qutebrowser/qutebrowser/issues/2989
|
||||||
"""
|
"""
|
||||||
config_stub.val.bindings.default = no_bindings
|
config_stub.val.bindings.default = no_bindings
|
||||||
config_stub.val.bindings.commands = no_bindings
|
config_stub.val.bindings.commands = no_bindings
|
||||||
keyconf.bind('a', 'set-cmd-text :nop ;; rl-beginning-of-line',
|
key_config_stub.bind('a', 'set-cmd-text :nop ;; rl-beginning-of-line',
|
||||||
mode='normal')
|
mode='normal')
|
||||||
|
|
||||||
@pytest.mark.parametrize('key, normalized', [
|
@pytest.mark.parametrize('key, normalized', [
|
||||||
('a', 'a'), # default bindings
|
('a', 'a'), # default bindings
|
||||||
@ -213,7 +211,8 @@ class TestKeyConfig:
|
|||||||
('<Ctrl-X>', '<ctrl+x>')
|
('<Ctrl-X>', '<ctrl+x>')
|
||||||
])
|
])
|
||||||
@pytest.mark.parametrize('mode', ['normal', 'caret', 'prompt'])
|
@pytest.mark.parametrize('mode', ['normal', 'caret', 'prompt'])
|
||||||
def test_unbind(self, keyconf, config_stub, qtbot, key, normalized, mode):
|
def test_unbind(self, key_config_stub, config_stub, qtbot,
|
||||||
|
key, normalized, mode):
|
||||||
default_bindings = {
|
default_bindings = {
|
||||||
'normal': {'a': 'nop', '<ctrl+x>': 'nop'},
|
'normal': {'a': 'nop', '<ctrl+x>': 'nop'},
|
||||||
'caret': {'a': 'nop', '<ctrl+x>': 'nop'},
|
'caret': {'a': 'nop', '<ctrl+x>': 'nop'},
|
||||||
@ -228,9 +227,9 @@ class TestKeyConfig:
|
|||||||
}
|
}
|
||||||
|
|
||||||
with qtbot.wait_signal(config_stub.changed):
|
with qtbot.wait_signal(config_stub.changed):
|
||||||
keyconf.unbind(key, mode=mode)
|
key_config_stub.unbind(key, mode=mode)
|
||||||
|
|
||||||
assert keyconf.get_command(key, mode) is None
|
assert key_config_stub.get_command(key, mode) is None
|
||||||
|
|
||||||
mode_bindings = config_stub.val.bindings.commands[mode]
|
mode_bindings = config_stub.val.bindings.commands[mode]
|
||||||
if key == 'b' and mode != 'prompt':
|
if key == 'b' and mode != 'prompt':
|
||||||
@ -241,13 +240,13 @@ class TestKeyConfig:
|
|||||||
assert default_bindings[mode] == old_default_bindings[mode]
|
assert default_bindings[mode] == old_default_bindings[mode]
|
||||||
assert mode_bindings[normalized] is None
|
assert mode_bindings[normalized] is None
|
||||||
|
|
||||||
def test_unbind_unbound(self, keyconf, config_stub, no_bindings):
|
def test_unbind_unbound(self, key_config_stub, config_stub, no_bindings):
|
||||||
"""Try unbinding a key which is not bound."""
|
"""Try unbinding a key which is not bound."""
|
||||||
config_stub.val.bindings.default = no_bindings
|
config_stub.val.bindings.default = no_bindings
|
||||||
config_stub.val.bindings.commands = no_bindings
|
config_stub.val.bindings.commands = no_bindings
|
||||||
with pytest.raises(configexc.KeybindingError,
|
with pytest.raises(configexc.KeybindingError,
|
||||||
match="Can't find binding 'foobar' in normal mode"):
|
match="Can't find binding 'foobar' in normal mode"):
|
||||||
keyconf.unbind('foobar', mode='normal')
|
key_config_stub.unbind('foobar', mode='normal')
|
||||||
|
|
||||||
|
|
||||||
class TestConfig:
|
class TestConfig:
|
||||||
|
@ -31,8 +31,8 @@ from qutebrowser.misc import objects
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def commands(config_stub, keyconf):
|
def commands(config_stub, key_config_stub):
|
||||||
return configcommands.ConfigCommands(config_stub, keyconf)
|
return configcommands.ConfigCommands(config_stub, key_config_stub)
|
||||||
|
|
||||||
|
|
||||||
class TestSet:
|
class TestSet:
|
||||||
@ -353,10 +353,10 @@ class TestWritePy:
|
|||||||
|
|
||||||
"""Tests for :config-write-py."""
|
"""Tests for :config-write-py."""
|
||||||
|
|
||||||
def test_custom(self, commands, config_stub, keyconf, tmpdir):
|
def test_custom(self, commands, config_stub, key_config_stub, tmpdir):
|
||||||
confpy = tmpdir / 'config.py'
|
confpy = tmpdir / 'config.py'
|
||||||
config_stub.val.content.javascript.enabled = True
|
config_stub.val.content.javascript.enabled = True
|
||||||
keyconf.bind(',x', 'message-info foo', mode='normal')
|
key_config_stub.bind(',x', 'message-info foo', mode='normal')
|
||||||
|
|
||||||
commands.config_write_py(str(confpy))
|
commands.config_write_py(str(confpy))
|
||||||
|
|
||||||
@ -408,14 +408,15 @@ class TestBind:
|
|||||||
return {'normal': {}}
|
return {'normal': {}}
|
||||||
|
|
||||||
@pytest.mark.parametrize('command', ['nop', 'nope'])
|
@pytest.mark.parametrize('command', ['nop', 'nope'])
|
||||||
def test_bind(self, commands, config_stub, no_bindings, keyconf, command):
|
def test_bind(self, commands, config_stub, no_bindings, key_config_stub,
|
||||||
|
command):
|
||||||
"""Simple :bind test (and aliases)."""
|
"""Simple :bind test (and aliases)."""
|
||||||
config_stub.val.aliases = {'nope': 'nop'}
|
config_stub.val.aliases = {'nope': 'nop'}
|
||||||
config_stub.val.bindings.default = no_bindings
|
config_stub.val.bindings.default = no_bindings
|
||||||
config_stub.val.bindings.commands = no_bindings
|
config_stub.val.bindings.commands = no_bindings
|
||||||
|
|
||||||
commands.bind('a', command)
|
commands.bind('a', command)
|
||||||
assert keyconf.get_command('a', 'normal') == command
|
assert key_config_stub.get_command('a', 'normal') == command
|
||||||
yaml_bindings = config_stub._yaml['bindings.commands']['normal']
|
yaml_bindings = config_stub._yaml['bindings.commands']['normal']
|
||||||
assert yaml_bindings['a'] == command
|
assert yaml_bindings['a'] == command
|
||||||
|
|
||||||
@ -466,7 +467,7 @@ class TestBind:
|
|||||||
commands.bind('a', 'nop', mode='wrongmode')
|
commands.bind('a', 'nop', 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, keyconf, key):
|
def test_bind_duplicate(self, commands, config_stub, key_config_stub, key):
|
||||||
"""Run ':bind' with a key which already has been bound.'.
|
"""Run ':bind' with a key which already has been bound.'.
|
||||||
|
|
||||||
Also tests for https://github.com/qutebrowser/qutebrowser/issues/1544
|
Also tests for https://github.com/qutebrowser/qutebrowser/issues/1544
|
||||||
@ -479,7 +480,7 @@ class TestBind:
|
|||||||
}
|
}
|
||||||
|
|
||||||
commands.bind(key, 'message-info foo', mode='normal')
|
commands.bind(key, 'message-info foo', mode='normal')
|
||||||
assert keyconf.get_command(key, 'normal') == 'message-info foo'
|
assert key_config_stub.get_command(key, 'normal') == 'message-info foo'
|
||||||
|
|
||||||
def test_bind_none(self, commands, config_stub):
|
def test_bind_none(self, commands, config_stub):
|
||||||
config_stub.val.bindings.commands = None
|
config_stub.val.bindings.commands = None
|
||||||
@ -495,7 +496,8 @@ class TestBind:
|
|||||||
('c', 'c'), # :bind then :unbind
|
('c', 'c'), # :bind then :unbind
|
||||||
('<Ctrl-X>', '<ctrl+x>') # normalized special binding
|
('<Ctrl-X>', '<ctrl+x>') # normalized special binding
|
||||||
])
|
])
|
||||||
def test_unbind(self, commands, keyconf, config_stub, key, normalized):
|
def test_unbind(self, commands, key_config_stub, config_stub,
|
||||||
|
key, normalized):
|
||||||
config_stub.val.bindings.default = {
|
config_stub.val.bindings.default = {
|
||||||
'normal': {'a': 'nop', '<ctrl+x>': 'nop'},
|
'normal': {'a': 'nop', '<ctrl+x>': 'nop'},
|
||||||
'caret': {'a': 'nop', '<ctrl+x>': 'nop'},
|
'caret': {'a': 'nop', '<ctrl+x>': 'nop'},
|
||||||
@ -509,7 +511,7 @@ class TestBind:
|
|||||||
commands.bind(key, 'nop')
|
commands.bind(key, 'nop')
|
||||||
|
|
||||||
commands.unbind(key)
|
commands.unbind(key)
|
||||||
assert keyconf.get_command(key, 'normal') is None
|
assert key_config_stub.get_command(key, 'normal') is None
|
||||||
|
|
||||||
yaml_bindings = config_stub._yaml['bindings.commands']['normal']
|
yaml_bindings = config_stub._yaml['bindings.commands']['normal']
|
||||||
if key in 'bc':
|
if key in 'bc':
|
||||||
|
Loading…
Reference in New Issue
Block a user