Merge remote-tracking branch 'origin/pr/4178'

This commit is contained in:
Florian Bruhin 2018-09-02 15:45:48 +02:00
commit 8a42256cff
3 changed files with 14 additions and 17 deletions

View File

@ -1139,7 +1139,7 @@ Syntax: +:set [*--temp*] [*--print*] [*--pattern* 'pattern'] ['option'] ['value'
Set an option. Set an option.
If the option name ends with '?', the value of the option is shown instead. Using :set without any arguments opens a page where settings can be changed interactively. If the option name ends with '?' or no value is provided, the value of the option is shown instead. Using :set without any arguments opens a page where settings can be changed interactively.
==== positional arguments ==== positional arguments
* +'option'+: The name of the option. * +'option'+: The name of the option.

View File

@ -85,8 +85,8 @@ class ConfigCommands:
*, pattern=None): *, pattern=None):
"""Set an option. """Set an option.
If the option name ends with '?', the value of the option is shown If the option name ends with '?' or no value is provided, the
instead. value of the option is shown instead.
Using :set without any arguments opens a page where settings can be Using :set without any arguments opens a page where settings can be
changed interactively. changed interactively.
@ -97,6 +97,7 @@ class ConfigCommands:
pattern: The URL pattern to use. pattern: The URL pattern to use.
temp: Set value temporarily until qutebrowser is closed. temp: Set value temporarily until qutebrowser is closed.
print_: Print the value after setting. print_: Print the value after setting.
""" """
if option is None: if option is None:
tabbed_browser = objreg.get('tabbed-browser', scope='window', tabbed_browser = objreg.get('tabbed-browser', scope='window',
@ -116,8 +117,7 @@ class ConfigCommands:
with self._handle_config_error(): with self._handle_config_error():
if value is None: if value is None:
raise cmdexc.CommandError("set: The following arguments " self._print_value(option, pattern=pattern)
"are required: value")
else: else:
self._config.set_str(option, value, pattern=pattern, self._config.set_str(option, value, pattern=pattern,
save_yaml=not temp) save_yaml=not temp)

View File

@ -61,13 +61,14 @@ class TestSet:
commands.set(win_id=0) commands.set(win_id=0)
assert tabbed_browser_stubs[0].opened_url == QUrl('qute://settings') assert tabbed_browser_stubs[0].opened_url == QUrl('qute://settings')
def test_get(self, config_stub, commands, message_mock): @pytest.mark.parametrize('option', ['url.auto_search?', 'url.auto_search'])
"""Run ':set url.auto_search?'. def test_get(self, config_stub, commands, message_mock, option):
"""Run ':set url.auto_search?' / ':set url.auto_search?'.
Should show the value. Should show the value.
""" """
config_stub.val.url.auto_search = 'never' config_stub.val.url.auto_search = 'never'
commands.set(win_id=0, option='url.auto_search?') commands.set(win_id=0, option=option)
msg = message_mock.getmsg(usertypes.MessageLevel.info) msg = message_mock.getmsg(usertypes.MessageLevel.info)
assert msg.text == 'url.auto_search = never' assert msg.text == 'url.auto_search = never'
@ -183,17 +184,13 @@ class TestSet:
"not available with the QtWebEngine backend!"): "not available with the QtWebEngine backend!"):
commands.set(0, 'hints.find_implementation', 'javascript') commands.set(0, 'hints.find_implementation', 'javascript')
@pytest.mark.parametrize('option', ['?', 'url.auto_search']) def test_empty(self, commands):
def test_empty(self, commands, option): """Run ':set ?'.
"""Run ':set ?' / ':set url.auto_search'. Should show an error.
Should show an error.
See https://github.com/qutebrowser/qutebrowser/issues/1109 See https://github.com/qutebrowser/qutebrowser/issues/1109
""" """
with pytest.raises(cmdexc.CommandError, with pytest.raises(cmdexc.CommandError, match="No option '?'"):
match="The following arguments are required: " commands.set(win_id=0, option='?')
"value"):
commands.set(win_id=0, option=option)
def test_toggle(self, commands): def test_toggle(self, commands):
"""Try toggling a value. """Try toggling a value.