Remove unknown YAML data from config
I considered introducing another list of deleted options (or a "deleted: True" in configdata.yml), similar to what we had with the old config. However, let's take the easier route and just delete everything we don't know from configdata.yml. If someone edits it by hand, it's their fault :P See #2772, #2847
This commit is contained in:
parent
cb57525f69
commit
7cad8f41f2
@ -30,7 +30,7 @@ import yaml
|
|||||||
from PyQt5.QtCore import QSettings
|
from PyQt5.QtCore import QSettings
|
||||||
|
|
||||||
import qutebrowser
|
import qutebrowser
|
||||||
from qutebrowser.config import configexc, config
|
from qutebrowser.config import configexc, config, configdata
|
||||||
from qutebrowser.utils import standarddir, utils, qtutils
|
from qutebrowser.utils import standarddir, utils, qtutils
|
||||||
|
|
||||||
|
|
||||||
@ -153,6 +153,12 @@ class YamlConfig:
|
|||||||
"'global' object is not a dict")
|
"'global' object is not a dict")
|
||||||
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
|
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
|
||||||
|
|
||||||
|
# Delete unknown values
|
||||||
|
# (e.g. options which were removed from configdata.yml)
|
||||||
|
for name in list(global_obj):
|
||||||
|
if name not in configdata.DATA:
|
||||||
|
del global_obj[name]
|
||||||
|
|
||||||
self._values = global_obj
|
self._values = global_obj
|
||||||
self._dirty = False
|
self._dirty = False
|
||||||
|
|
||||||
|
@ -932,14 +932,9 @@ def test_early_init(init_patch, config_tmpdir, caplog, fake_args,
|
|||||||
expected_errors.append(
|
expected_errors.append(
|
||||||
"Errors occurred while reading config.py:\n"
|
"Errors occurred while reading config.py:\n"
|
||||||
" While setting 'foo': No option 'foo'")
|
" While setting 'foo': No option 'foo'")
|
||||||
if invalid_yaml and (load_autoconfig or not config_py):
|
if invalid_yaml == '42' and (load_autoconfig or not config_py):
|
||||||
error = "Errors occurred while reading autoconfig.yml:\n"
|
error = "Errors occurred while reading autoconfig.yml:\n"
|
||||||
if invalid_yaml == '42':
|
error += " While loading data: Toplevel object is not a dict"
|
||||||
error += " While loading data: Toplevel object is not a dict"
|
|
||||||
elif invalid_yaml == 'unknown':
|
|
||||||
error += " Error: No option 'colors.foobar'"
|
|
||||||
else:
|
|
||||||
assert False, invalid_yaml
|
|
||||||
expected_errors.append(error)
|
expected_errors.append(error)
|
||||||
|
|
||||||
actual_errors = [str(err) for err in config._init_errors]
|
actual_errors = [str(err) for err in config._init_errors]
|
||||||
|
@ -57,6 +57,8 @@ def test_state_config(fake_save_manager, data_tmpdir,
|
|||||||
@pytest.mark.parametrize('old_config', [
|
@pytest.mark.parametrize('old_config', [
|
||||||
None,
|
None,
|
||||||
'global:\n colors.hints.fg: magenta',
|
'global:\n colors.hints.fg: magenta',
|
||||||
|
# Unknown key
|
||||||
|
'global:\n hello: world',
|
||||||
])
|
])
|
||||||
@pytest.mark.parametrize('insert', [True, False])
|
@pytest.mark.parametrize('insert', [True, False])
|
||||||
def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
||||||
@ -91,6 +93,7 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
|||||||
assert ' colors.hints.fg: magenta' in lines
|
assert ' colors.hints.fg: magenta' in lines
|
||||||
if insert:
|
if insert:
|
||||||
assert ' tabs.show: never' in lines
|
assert ' tabs.show: never' in lines
|
||||||
|
assert ' hello:' not in lines
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('old_config', [
|
@pytest.mark.parametrize('old_config', [
|
||||||
|
Loading…
Reference in New Issue
Block a user