diff options
author | Milo Gertjejansen <milo@milogert.com> | 2018-10-04 18:42:33 -0500 |
---|---|---|
committer | Milo Gertjejansen <milo@milogert.com> | 2018-10-04 18:42:33 -0500 |
commit | 7f0ae252cd5fd6223bf3119e2a21d4cd39e7c842 (patch) | |
tree | 3632a615e481c994057064ce9d3f483ebe1bfd4d /tests/unit/config/test_configcommands.py | |
parent | 876a2bdaa16c3beb40aa0f8afdb38e30dc1dfd0b (diff) | |
download | qutebrowser-7f0ae252cd5fd6223bf3119e2a21d4cd39e7c842.tar.gz qutebrowser-7f0ae252cd5fd6223bf3119e2a21d4cd39e7c842.zip |
New config: More powerful :config- commands: add #4283
Made requested changes:
- Separated list add and dict add commands.
- Separated list and dict completion models.
- Created tests for each command.
- Simplified the configmodel options by breaking them into a separate
function to do work that is similar.
- General simplification of both add commands.
Continues #2794
Diffstat (limited to 'tests/unit/config/test_configcommands.py')
-rw-r--r-- | tests/unit/config/test_configcommands.py | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index f70586152..c4906fcb7 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -25,7 +25,7 @@ import unittest.mock import pytest from PyQt5.QtCore import QUrl -from qutebrowser.config import configcommands, configutils +from qutebrowser.config import configcommands, configtypes, configutils from qutebrowser.commands import cmdexc from qutebrowser.utils import usertypes, urlmatch from qutebrowser.keyinput import keyutils @@ -282,6 +282,54 @@ class TestCycle: assert msg.text == 'auto_save.session = true' +class TestAdd: + + """Test :config-add-list and :config-add-dict.""" + + @pytest.mark.parametrize('name', ['content.host_blocking.whitelist', + 'history_gap_interval']) + @pytest.mark.parametrize('temp', [True, False]) + @pytest.mark.parametrize('value', ['test1', 'test2', '', None]) + def test_add_list(self, commands, config_stub, yaml_value, name, temp, value): + opt_type = config_stub.get_opt(name).typ + + try: + commands.config_add_list(name, value, temp=temp) + except cmdexc.CommandError: + # We attempted to add to the dictionary with replace as false. + valid_list_types = (configtypes.List, configtypes.ListOrValue) + assert not isinstance(opt_type, valid_list_types) or not value + return + + assert str(config_stub.get(name)[-1]) == value + if temp: + assert yaml_value(name) == configutils.UNSET + else: + assert yaml_value(name)[-1] == value + + @pytest.mark.parametrize('name', ['aliases', 'history_gap_interval']) + @pytest.mark.parametrize('key', ['w', 'missingkey']) + @pytest.mark.parametrize('value', ['test1', 'test2']) + @pytest.mark.parametrize('temp', [True, False]) + @pytest.mark.parametrize('replace', [True, False]) + def test_add_dict(self, commands, config_stub, yaml_value, name, key, + value, temp, replace): + opt_type = config_stub.get_opt(name).typ + + try: + commands.config_add_dict(name, key, value, temp=temp, replace=replace) + except cmdexc.CommandError: + # We attempted to add to the dictionary with replace as false. + assert not isinstance(opt_type, configtypes.Dict) or not replace + return + + assert str(config_stub.get(name)[key]) == value + if temp: + assert yaml_value(name) == configutils.UNSET + else: + assert yaml_value(name)[key] == value + + class TestUnsetAndClear: """Test :config-unset and :config-clear.""" |