From 0afd6b23c9fdf62323a5b3b29d83bf9ead622041 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 24 Nov 2017 09:23:35 +0100 Subject: [PATCH] Add the option name to the backend error message --- qutebrowser/config/config.py | 2 +- qutebrowser/config/configexc.py | 6 +++--- tests/unit/config/test_configcommands.py | 4 ++-- tests/unit/config/test_configexc.py | 5 +++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 802695b8e..ff09e2a5b 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -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) diff --git a/qutebrowser/config/configexc.py b/qutebrowser/config/configexc.py index 1199a9864..28b269dd5 100644 --- a/qutebrowser/config/configexc.py +++ b/qutebrowser/config/configexc.py @@ -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): diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index c0142b09f..7137f50db 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -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']) diff --git a/tests/unit/config/test_configexc.py b/tests/unit/config/test_configexc.py index 03248731b..8fd99a9c7 100644 --- a/tests/unit/config/test_configexc.py +++ b/tests/unit/config/test_configexc.py @@ -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():