Fix test_configinit.py
This commit is contained in:
parent
c89e804653
commit
19f7b92abb
@ -100,14 +100,15 @@ class TestEarlyInit:
|
|||||||
|
|
||||||
# Check config values
|
# Check config values
|
||||||
if config_py:
|
if config_py:
|
||||||
assert config.instance._values == {'colors.hints.bg': 'red'}
|
expected = 'colors.hints.bg = red'
|
||||||
else:
|
else:
|
||||||
assert config.instance._values == {}
|
expected = '<Default configuration>'
|
||||||
|
assert config.instance.dump_userconfig() == expected
|
||||||
|
|
||||||
@pytest.mark.parametrize('load_autoconfig', [True, False]) # noqa
|
@pytest.mark.parametrize('load_autoconfig', [True, False]) # noqa
|
||||||
@pytest.mark.parametrize('config_py', [True, 'error', False])
|
@pytest.mark.parametrize('config_py', [True, 'error', False])
|
||||||
@pytest.mark.parametrize('invalid_yaml', ['42', 'unknown', 'wrong-type',
|
@pytest.mark.parametrize('invalid_yaml', ['42', 'list', 'unknown',
|
||||||
False])
|
'wrong-type', False])
|
||||||
def test_autoconfig_yml(self, init_patch, config_tmpdir, caplog, args,
|
def test_autoconfig_yml(self, init_patch, config_tmpdir, caplog, args,
|
||||||
load_autoconfig, config_py, invalid_yaml):
|
load_autoconfig, config_py, invalid_yaml):
|
||||||
"""Test interaction between config.py and autoconfig.yml."""
|
"""Test interaction between config.py and autoconfig.yml."""
|
||||||
@ -115,14 +116,30 @@ class TestEarlyInit:
|
|||||||
autoconfig_file = config_tmpdir / 'autoconfig.yml'
|
autoconfig_file = config_tmpdir / 'autoconfig.yml'
|
||||||
config_py_file = config_tmpdir / 'config.py'
|
config_py_file = config_tmpdir / 'config.py'
|
||||||
|
|
||||||
yaml_text = {
|
yaml_lines = {
|
||||||
'42': '42',
|
'42': '42',
|
||||||
'unknown': 'global:\n colors.foobar: magenta\n',
|
'list': '[1, 2]',
|
||||||
'wrong-type': 'global:\n tabs.position: true\n',
|
'unknown': [
|
||||||
False: 'global:\n colors.hints.fg: magenta\n',
|
'settings:',
|
||||||
|
' colors.foobar:',
|
||||||
|
' global: magenta',
|
||||||
|
'config_version: 1',
|
||||||
|
],
|
||||||
|
'wrong-type': [
|
||||||
|
'settings:',
|
||||||
|
' tabs.position:',
|
||||||
|
' global: true',
|
||||||
|
'config_version: 1',
|
||||||
|
],
|
||||||
|
False: [
|
||||||
|
'settings:',
|
||||||
|
' colors.hints.fg:',
|
||||||
|
' global: magenta',
|
||||||
|
'config_version: 1',
|
||||||
|
],
|
||||||
}
|
}
|
||||||
autoconfig_file.write_text(yaml_text[invalid_yaml], 'utf-8',
|
text = '\n'.join(yaml_lines[invalid_yaml])
|
||||||
ensure=True)
|
autoconfig_file.write_text(text, 'utf-8', ensure=True)
|
||||||
|
|
||||||
if config_py:
|
if config_py:
|
||||||
config_py_lines = ['c.colors.hints.bg = "red"']
|
config_py_lines = ['c.colors.hints.bg = "red"']
|
||||||
@ -141,7 +158,7 @@ class TestEarlyInit:
|
|||||||
|
|
||||||
if load_autoconfig or not config_py:
|
if load_autoconfig or not config_py:
|
||||||
suffix = ' (autoconfig.yml)' if config_py else ''
|
suffix = ' (autoconfig.yml)' if config_py else ''
|
||||||
if invalid_yaml == '42':
|
if invalid_yaml in ['42', 'list']:
|
||||||
error = ("While loading data{}: Toplevel object is not a dict"
|
error = ("While loading data{}: Toplevel object is not a dict"
|
||||||
.format(suffix))
|
.format(suffix))
|
||||||
expected_errors.append(error)
|
expected_errors.append(error)
|
||||||
@ -165,17 +182,21 @@ class TestEarlyInit:
|
|||||||
assert actual_errors == expected_errors
|
assert actual_errors == expected_errors
|
||||||
|
|
||||||
# Check config values
|
# Check config values
|
||||||
|
dump = config.instance.dump_userconfig()
|
||||||
|
|
||||||
if config_py and load_autoconfig and not invalid_yaml:
|
if config_py and load_autoconfig and not invalid_yaml:
|
||||||
assert config.instance._values == {
|
expected = [
|
||||||
'colors.hints.bg': 'red',
|
'colors.hints.fg = magenta',
|
||||||
'colors.hints.fg': 'magenta',
|
'colors.hints.bg = red',
|
||||||
}
|
]
|
||||||
elif config_py:
|
elif config_py:
|
||||||
assert config.instance._values == {'colors.hints.bg': 'red'}
|
expected = ['colors.hints.bg = red']
|
||||||
elif invalid_yaml:
|
elif invalid_yaml:
|
||||||
assert config.instance._values == {}
|
expected = ['<Default configuration>']
|
||||||
else:
|
else:
|
||||||
assert config.instance._values == {'colors.hints.fg': 'magenta'}
|
expected = ['colors.hints.fg = magenta']
|
||||||
|
|
||||||
|
assert dump == '\n'.join(expected)
|
||||||
|
|
||||||
def test_invalid_change_filter(self, init_patch, args):
|
def test_invalid_change_filter(self, init_patch, args):
|
||||||
config.change_filter('foobar')
|
config.change_filter('foobar')
|
||||||
@ -185,7 +206,7 @@ class TestEarlyInit:
|
|||||||
def test_temp_settings_valid(self, init_patch, args):
|
def test_temp_settings_valid(self, init_patch, args):
|
||||||
args.temp_settings = [('colors.completion.fg', 'magenta')]
|
args.temp_settings = [('colors.completion.fg', 'magenta')]
|
||||||
configinit.early_init(args)
|
configinit.early_init(args)
|
||||||
assert config.instance._values['colors.completion.fg'] == 'magenta'
|
assert config.instance.get_obj('colors.completion.fg') == 'magenta'
|
||||||
|
|
||||||
def test_temp_settings_invalid(self, caplog, init_patch, message_mock,
|
def test_temp_settings_invalid(self, caplog, init_patch, message_mock,
|
||||||
args):
|
args):
|
||||||
@ -198,7 +219,6 @@ class TestEarlyInit:
|
|||||||
msg = message_mock.getmsg()
|
msg = message_mock.getmsg()
|
||||||
assert msg.level == usertypes.MessageLevel.error
|
assert msg.level == usertypes.MessageLevel.error
|
||||||
assert msg.text == "set: NoOptionError - No option 'foo'"
|
assert msg.text == "set: NoOptionError - No option 'foo'"
|
||||||
assert 'colors.completion.fg' not in config.instance._values
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('settings, size, family', [
|
@pytest.mark.parametrize('settings, size, family', [
|
||||||
# Only fonts.monospace customized
|
# Only fonts.monospace customized
|
||||||
@ -220,8 +240,9 @@ class TestEarlyInit:
|
|||||||
args.temp_settings = settings
|
args.temp_settings = settings
|
||||||
elif method == 'auto':
|
elif method == 'auto':
|
||||||
autoconfig_file = config_tmpdir / 'autoconfig.yml'
|
autoconfig_file = config_tmpdir / 'autoconfig.yml'
|
||||||
lines = ["global:"] + [" {}: '{}'".format(k, v)
|
lines = (["config_version: 1", "settings:"] +
|
||||||
for k, v in settings]
|
[" {}:\n global:\n '{}'".format(k, v)
|
||||||
|
for k, v in settings])
|
||||||
autoconfig_file.write_text('\n'.join(lines), 'utf-8', ensure=True)
|
autoconfig_file.write_text('\n'.join(lines), 'utf-8', ensure=True)
|
||||||
elif method == 'py':
|
elif method == 'py':
|
||||||
config_py_file = config_tmpdir / 'config.py'
|
config_py_file = config_tmpdir / 'config.py'
|
||||||
|
Loading…
Reference in New Issue
Block a user