Handle invalid keys in config.py
This commit is contained in:
parent
898f5c50c4
commit
8090d3e289
@ -333,6 +333,9 @@ class ConfigAPI:
|
||||
except urlmatch.ParseError as e:
|
||||
text = "While {} '{}' and parsing pattern".format(action, name)
|
||||
self.errors.append(configexc.ConfigErrorDesc(text, e))
|
||||
except keyutils.KeyParseError as e:
|
||||
text = "While {} '{}' and parsing key".format(action, name)
|
||||
self.errors.append(configexc.ConfigErrorDesc(text, e))
|
||||
|
||||
def finalize(self):
|
||||
"""Do work which needs to be done after reading config.py."""
|
||||
|
@ -29,6 +29,7 @@ from PyQt5.QtCore import QSettings
|
||||
from qutebrowser.config import (config, configfiles, configexc, configdata,
|
||||
configtypes)
|
||||
from qutebrowser.utils import utils, usertypes, urlmatch
|
||||
from qutebrowser.keyinput import keyutils
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@ -699,6 +700,20 @@ class TestConfigPy:
|
||||
message = "'ConfigAPI' object has no attribute 'val'"
|
||||
assert str(error.exception) == message
|
||||
|
||||
@pytest.mark.parametrize('line', [
|
||||
'config.bind("<blub>", "nop")',
|
||||
'config.bind("\U00010000", "nop")',
|
||||
'config.unbind("<blub>")',
|
||||
'config.unbind("\U00010000")',
|
||||
])
|
||||
def test_invalid_keys(self, confpy, line):
|
||||
confpy.write(line)
|
||||
error = confpy.read(error=True)
|
||||
assert error.text.endswith("and parsing key")
|
||||
assert isinstance(error.exception, keyutils.KeyParseError)
|
||||
assert str(error.exception).startswith("Could not parse")
|
||||
assert str(error.exception).endswith("Got unknown key!")
|
||||
|
||||
@pytest.mark.parametrize('line', ["c.foo = 42", "config.set('foo', 42)"])
|
||||
def test_config_error(self, confpy, line):
|
||||
confpy.write(line)
|
||||
|
Loading…
Reference in New Issue
Block a user