Add the option name to the backend error message

This commit is contained in:
Florian Bruhin 2017-11-24 09:23:35 +01:00
parent 28d7c5e204
commit 0afd6b23c9
4 changed files with 9 additions and 8 deletions

View File

@ -257,7 +257,7 @@ class Config(QObject):
"""Set the given option to the given value."""
if not isinstance(objects.backend, objects.NoBackend):
if objects.backend not in opt.backends:
raise configexc.BackendError(objects.backend)
raise configexc.BackendError(opt.name, objects.backend)
opt.typ.to_py(value) # for validation
self._values[opt.name] = opt.typ.from_obj(value)

View File

@ -35,9 +35,9 @@ class BackendError(Error):
"""Raised when this setting is unavailable with the current backend."""
def __init__(self, backend):
super().__init__("This setting is not available with the {} "
"backend!".format(backend.name))
def __init__(self, name, backend):
super().__init__("The {} setting is not available with the {} "
"backend!".format(name, backend.name))
class ValidationError(Error):

View File

@ -130,8 +130,8 @@ class TestSet:
def test_set_wrong_backend(self, commands, monkeypatch):
monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebEngine)
with pytest.raises(cmdexc.CommandError,
match="This setting is not available with the "
"QtWebEngine backend!"):
match="The content.cookies.accept setting is not "
"available with the QtWebEngine backend!"):
commands.set(0, 'content.cookies.accept', 'all')
@pytest.mark.parametrize('option', ['?', 'url.auto_search'])

View File

@ -49,8 +49,9 @@ def test_no_option_error_clash():
def test_backend_error():
e = configexc.BackendError(usertypes.Backend.QtWebKit)
assert str(e) == "This setting is not available with the QtWebKit backend!"
e = configexc.BackendError('foo', usertypes.Backend.QtWebKit)
expected = "The foo setting is not available with the QtWebKit backend!"
assert str(e) == expected
def test_desc_with_text():