Fix test_configfiles.py
This commit is contained in:
parent
ab119975e7
commit
7d80825853
@ -27,7 +27,7 @@ import pytest
|
|||||||
from PyQt5.QtCore import QSettings
|
from PyQt5.QtCore import QSettings
|
||||||
|
|
||||||
from qutebrowser.config import (config, configfiles, configexc, configdata,
|
from qutebrowser.config import (config, configfiles, configexc, configdata,
|
||||||
configtypes)
|
configtypes, configutils)
|
||||||
from qutebrowser.utils import utils, usertypes
|
from qutebrowser.utils import utils, usertypes
|
||||||
|
|
||||||
|
|
||||||
@ -200,12 +200,12 @@ class TestYaml:
|
|||||||
data = autoconfig.read()
|
data = autoconfig.read()
|
||||||
assert 'tabs.persist_mode_on_change' not in data
|
assert 'tabs.persist_mode_on_change' not in data
|
||||||
mode = 'persist' if persist else 'normal'
|
mode = 'persist' if persist else 'normal'
|
||||||
assert data['tabs.mode_on_change'] == mode
|
assert data['tabs.mode_on_change']['global'] == mode
|
||||||
|
|
||||||
def test_renamed_key_unknown_target(self, monkeypatch, yaml,
|
def test_renamed_key_unknown_target(self, monkeypatch, yaml,
|
||||||
autoconfig):
|
autoconfig):
|
||||||
"""A key marked as renamed with invalid name should raise an error."""
|
"""A key marked as renamed with invalid name should raise an error."""
|
||||||
autoconfig.write_text({'old': {'global': 'value'}})
|
autoconfig.write({'old': {'global': 'value'}})
|
||||||
|
|
||||||
monkeypatch.setattr(configdata.MIGRATIONS, 'renamed',
|
monkeypatch.setattr(configdata.MIGRATIONS, 'renamed',
|
||||||
{'old': 'new'})
|
{'old': 'new'})
|
||||||
@ -238,7 +238,6 @@ class TestYaml:
|
|||||||
with qtbot.wait_signal(yaml.changed):
|
with qtbot.wait_signal(yaml.changed):
|
||||||
yaml.set_obj(key, value)
|
yaml.set_obj(key, value)
|
||||||
|
|
||||||
assert key in yaml
|
|
||||||
assert yaml._values[key].get_for_url(fallback=False) == value
|
assert yaml._values[key].get_for_url(fallback=False) == value
|
||||||
|
|
||||||
yaml._save()
|
yaml._save()
|
||||||
@ -246,13 +245,10 @@ class TestYaml:
|
|||||||
yaml = configfiles.YamlConfig()
|
yaml = configfiles.YamlConfig()
|
||||||
yaml.load()
|
yaml.load()
|
||||||
|
|
||||||
assert key in yaml
|
|
||||||
assert yaml._values[key].get_for_url(fallback=False) == value
|
assert yaml._values[key].get_for_url(fallback=False) == value
|
||||||
|
|
||||||
def test_iter(self, yaml):
|
def test_iter(self, yaml):
|
||||||
yaml.set_obj('foo', 23)
|
assert list(iter(yaml)) == list(iter(yaml._values.values()))
|
||||||
yaml.set_obj('bar', 42)
|
|
||||||
assert list(iter(yaml)) == [('bar', 42), ('foo', 23)]
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('old_config', [
|
@pytest.mark.parametrize('old_config', [
|
||||||
None,
|
None,
|
||||||
@ -274,9 +270,12 @@ class TestYaml:
|
|||||||
|
|
||||||
@pytest.mark.parametrize('line, text, exception', [
|
@pytest.mark.parametrize('line, text, exception', [
|
||||||
('%', 'While parsing', 'while scanning a directive'),
|
('%', 'While parsing', 'while scanning a directive'),
|
||||||
('settings: 42', 'While loading data', "'settings' object is not a dict"),
|
('settings: 42\nconfig_version: 1',
|
||||||
('foo: 42', 'While loading data',
|
'While loading data', "'settings' object is not a dict"),
|
||||||
|
('foo: 42\nconfig_version: 1', 'While loading data',
|
||||||
"Toplevel object does not contain 'settings' key"),
|
"Toplevel object does not contain 'settings' key"),
|
||||||
|
('settings: {}', 'While loading data',
|
||||||
|
"Toplevel object does not contain 'config_version' key"),
|
||||||
('42', 'While loading data', "Toplevel object is not a dict"),
|
('42', 'While loading data', "Toplevel object is not a dict"),
|
||||||
])
|
])
|
||||||
def test_invalid(self, yaml, autoconfig, line, text, exception):
|
def test_invalid(self, yaml, autoconfig, line, text, exception):
|
||||||
@ -385,7 +384,7 @@ class TestConfigPyModules:
|
|||||||
confpy.write_qbmodule()
|
confpy.write_qbmodule()
|
||||||
confpy.read()
|
confpy.read()
|
||||||
expected = {'normal': {',a': 'message-info foo'}}
|
expected = {'normal': {',a': 'message-info foo'}}
|
||||||
assert config.instance._values['bindings.commands'] == expected
|
assert config.instance.get_obj('bindings.commands') == expected
|
||||||
assert "qbmodule" not in sys.modules.keys()
|
assert "qbmodule" not in sys.modules.keys()
|
||||||
assert tmpdir not in sys.path
|
assert tmpdir not in sys.path
|
||||||
|
|
||||||
@ -451,7 +450,7 @@ class TestConfigPy:
|
|||||||
def test_set(self, confpy, line):
|
def test_set(self, confpy, line):
|
||||||
confpy.write(line)
|
confpy.write(line)
|
||||||
confpy.read()
|
confpy.read()
|
||||||
assert config.instance._values['colors.hints.bg'] == 'red'
|
assert config.instance.get_obj('colors.hints.bg') == 'red'
|
||||||
|
|
||||||
@pytest.mark.parametrize('set_first', [True, False])
|
@pytest.mark.parametrize('set_first', [True, False])
|
||||||
@pytest.mark.parametrize('get_line', [
|
@pytest.mark.parametrize('get_line', [
|
||||||
@ -478,7 +477,7 @@ class TestConfigPy:
|
|||||||
confpy.write(line)
|
confpy.write(line)
|
||||||
confpy.read()
|
confpy.read()
|
||||||
expected = {mode: {',a': 'message-info foo'}}
|
expected = {mode: {',a': 'message-info foo'}}
|
||||||
assert config.instance._values['bindings.commands'] == expected
|
assert config.instance.get_obj('bindings.commands') == expected
|
||||||
|
|
||||||
def test_bind_freshly_defined_alias(self, confpy):
|
def test_bind_freshly_defined_alias(self, confpy):
|
||||||
"""Make sure we can bind to a new alias.
|
"""Make sure we can bind to a new alias.
|
||||||
@ -494,14 +493,14 @@ class TestConfigPy:
|
|||||||
confpy.write("config.bind('H', 'message-info back')")
|
confpy.write("config.bind('H', 'message-info back')")
|
||||||
confpy.read()
|
confpy.read()
|
||||||
expected = {'normal': {'H': 'message-info back'}}
|
expected = {'normal': {'H': 'message-info back'}}
|
||||||
assert config.instance._values['bindings.commands'] == expected
|
assert config.instance.get_obj('bindings.commands') == expected
|
||||||
|
|
||||||
def test_bind_none(self, confpy):
|
def test_bind_none(self, confpy):
|
||||||
confpy.write("c.bindings.commands = None",
|
confpy.write("c.bindings.commands = None",
|
||||||
"config.bind(',x', 'nop')")
|
"config.bind(',x', 'nop')")
|
||||||
confpy.read()
|
confpy.read()
|
||||||
expected = {'normal': {',x': 'nop'}}
|
expected = {'normal': {',x': 'nop'}}
|
||||||
assert config.instance._values['bindings.commands'] == expected
|
assert config.instance.get_obj('bindings.commands') == expected
|
||||||
|
|
||||||
@pytest.mark.parametrize('line, key, mode', [
|
@pytest.mark.parametrize('line, key, mode', [
|
||||||
('config.unbind("o")', 'o', 'normal'),
|
('config.unbind("o")', 'o', 'normal'),
|
||||||
@ -511,14 +510,14 @@ class TestConfigPy:
|
|||||||
confpy.write(line)
|
confpy.write(line)
|
||||||
confpy.read()
|
confpy.read()
|
||||||
expected = {mode: {key: None}}
|
expected = {mode: {key: None}}
|
||||||
assert config.instance._values['bindings.commands'] == expected
|
assert config.instance.get_obj('bindings.commands') == expected
|
||||||
|
|
||||||
def test_mutating(self, confpy):
|
def test_mutating(self, confpy):
|
||||||
confpy.write('c.aliases["foo"] = "message-info foo"',
|
confpy.write('c.aliases["foo"] = "message-info foo"',
|
||||||
'c.aliases["bar"] = "message-info bar"')
|
'c.aliases["bar"] = "message-info bar"')
|
||||||
confpy.read()
|
confpy.read()
|
||||||
assert config.instance._values['aliases']['foo'] == 'message-info foo'
|
assert config.instance.get_obj('aliases')['foo'] == 'message-info foo'
|
||||||
assert config.instance._values['aliases']['bar'] == 'message-info bar'
|
assert config.instance.get_obj('aliases')['bar'] == 'message-info bar'
|
||||||
|
|
||||||
@pytest.mark.parametrize('option, value', [
|
@pytest.mark.parametrize('option, value', [
|
||||||
('content.user_stylesheets', 'style.css'),
|
('content.user_stylesheets', 'style.css'),
|
||||||
@ -532,7 +531,7 @@ class TestConfigPy:
|
|||||||
(config_tmpdir / 'style.css').ensure()
|
(config_tmpdir / 'style.css').ensure()
|
||||||
confpy.write('c.{}.append("{}")'.format(option, value))
|
confpy.write('c.{}.append("{}")'.format(option, value))
|
||||||
confpy.read()
|
confpy.read()
|
||||||
assert config.instance._values[option][-1] == value
|
assert config.instance.get_obj(option)[-1] == value
|
||||||
|
|
||||||
def test_oserror(self, tmpdir, data_tmpdir, config_tmpdir):
|
def test_oserror(self, tmpdir, data_tmpdir, config_tmpdir):
|
||||||
with pytest.raises(configexc.ConfigFileErrors) as excinfo:
|
with pytest.raises(configexc.ConfigFileErrors) as excinfo:
|
||||||
@ -653,7 +652,7 @@ class TestConfigPy:
|
|||||||
confpy.write("config.source({!r})".format(arg))
|
confpy.write("config.source({!r})".format(arg))
|
||||||
confpy.read()
|
confpy.read()
|
||||||
|
|
||||||
assert not config.instance._values['content.javascript.enabled']
|
assert not config.instance.get_obj('content.javascript.enabled')
|
||||||
|
|
||||||
def test_source_errors(self, tmpdir, confpy):
|
def test_source_errors(self, tmpdir, confpy):
|
||||||
subfile = tmpdir / 'config' / 'subfile.py'
|
subfile = tmpdir / 'config' / 'subfile.py'
|
||||||
@ -697,7 +696,7 @@ class TestConfigPyWriter:
|
|||||||
name='opt', typ=configtypes.Int(), default='def',
|
name='opt', typ=configtypes.Int(), default='def',
|
||||||
backends=[usertypes.Backend.QtWebEngine], raw_backends=None,
|
backends=[usertypes.Backend.QtWebEngine], raw_backends=None,
|
||||||
description=desc)
|
description=desc)
|
||||||
options = [(opt, 'val')]
|
options = [(None, opt, 'val')]
|
||||||
bindings = {'normal': {',x': 'message-info normal'},
|
bindings = {'normal': {',x': 'message-info normal'},
|
||||||
'caret': {',y': 'message-info caret'}}
|
'caret': {',y': 'message-info caret'}}
|
||||||
|
|
||||||
@ -729,8 +728,8 @@ class TestConfigPyWriter:
|
|||||||
def test_binding_options_hidden(self):
|
def test_binding_options_hidden(self):
|
||||||
opt1 = configdata.DATA['bindings.default']
|
opt1 = configdata.DATA['bindings.default']
|
||||||
opt2 = configdata.DATA['bindings.commands']
|
opt2 = configdata.DATA['bindings.commands']
|
||||||
options = [(opt1, {'normal': {'x': 'message-info x'}}),
|
options = [(None, opt1, {'normal': {'x': 'message-info x'}}),
|
||||||
(opt2, {})]
|
(None, opt2, {})]
|
||||||
writer = configfiles.ConfigPyWriter(options, bindings={},
|
writer = configfiles.ConfigPyWriter(options, bindings={},
|
||||||
commented=False)
|
commented=False)
|
||||||
text = '\n'.join(writer._gen_lines())
|
text = '\n'.join(writer._gen_lines())
|
||||||
@ -742,7 +741,7 @@ class TestConfigPyWriter:
|
|||||||
name='opt', typ=configtypes.Int(), default='def',
|
name='opt', typ=configtypes.Int(), default='def',
|
||||||
backends=[usertypes.Backend.QtWebEngine], raw_backends=None,
|
backends=[usertypes.Backend.QtWebEngine], raw_backends=None,
|
||||||
description='Hello World')
|
description='Hello World')
|
||||||
options = [(opt, 'val')]
|
options = [(None, opt, 'val')]
|
||||||
bindings = {'normal': {',x': 'message-info normal'},
|
bindings = {'normal': {',x': 'message-info normal'},
|
||||||
'caret': {',y': 'message-info caret'}}
|
'caret': {',y': 'message-info caret'}}
|
||||||
|
|
||||||
@ -768,7 +767,7 @@ class TestConfigPyWriter:
|
|||||||
backends=[usertypes.Backend.QtWebEngine], raw_backends=None,
|
backends=[usertypes.Backend.QtWebEngine], raw_backends=None,
|
||||||
description='All colors are beautiful!')
|
description='All colors are beautiful!')
|
||||||
|
|
||||||
options = [(opt1, 'ask'), (opt2, 'rgb')]
|
options = [(None, opt1, 'ask'), (None, opt2, 'rgb')]
|
||||||
|
|
||||||
writer = configfiles.ConfigPyWriter(options, bindings={},
|
writer = configfiles.ConfigPyWriter(options, bindings={},
|
||||||
commented=False)
|
commented=False)
|
||||||
@ -819,7 +818,7 @@ class TestConfigPyWriter:
|
|||||||
|
|
||||||
def test_defaults_work(self, confpy):
|
def test_defaults_work(self, confpy):
|
||||||
"""Get a config.py with default values and run it."""
|
"""Get a config.py with default values and run it."""
|
||||||
options = [(opt, opt.default)
|
options = [(None, opt, opt.default)
|
||||||
for _name, opt in sorted(configdata.DATA.items())]
|
for _name, opt in sorted(configdata.DATA.items())]
|
||||||
bindings = dict(configdata.DATA['bindings.default'].default)
|
bindings = dict(configdata.DATA['bindings.default'].default)
|
||||||
writer = configfiles.ConfigPyWriter(options, bindings, commented=False)
|
writer = configfiles.ConfigPyWriter(options, bindings, commented=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user