Make sure multiple wrong keys are reported

This commit is contained in:
Florian Bruhin 2018-02-08 22:02:22 +01:00
parent 1a88b64c67
commit 1a81f7231b
2 changed files with 20 additions and 6 deletions

View File

@ -182,12 +182,12 @@ class YamlConfig(QObject):
def _validate(self):
"""Make sure all settings exist."""
for name in self._values:
if name not in configdata.DATA:
desc = configexc.ConfigErrorDesc(
"While loading options",
"Unknown option {}".format(name))
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
unknown = set(self._values) - set(configdata.DATA)
if unknown:
errors = [configexc.ConfigErrorDesc("While loading options",
"Unknown option {}".format(e))
for e in sorted(unknown)]
raise configexc.ConfigFileErrors('autoconfig.yml', errors)
def unset(self, name):
"""Remove the given option name if it's configured."""

View File

@ -127,6 +127,20 @@ class TestYaml:
assert error.text == "While loading options"
assert str(error.exception) == "Unknown option hello"
def test_multiple_unknown_keys(self, yaml, config_tmpdir):
"""With multiple unknown settings, all should be shown."""
autoconfig = config_tmpdir / 'autoconfig.yml'
autoconfig.write_text('global:\n one: 1\n two: 2', encoding='utf-8')
with pytest.raises(configexc.ConfigFileErrors) as excinfo:
yaml.load()
assert len(excinfo.value.errors) == 2
error1, error2 = excinfo.value.errors
assert error1.text == error2.text == "While loading options"
assert str(error1.exception) == "Unknown option one"
assert str(error2.exception) == "Unknown option two"
def test_deleted_key(self, monkeypatch, yaml, config_tmpdir):
"""A key marked as deleted should be removed."""
autoconfig = config_tmpdir / 'autoconfig.yml'