From d641652a922cc6357090ee987034aba549316a7c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 3 Jul 2017 15:13:38 +0200 Subject: [PATCH] More test_config improvements --- qutebrowser/config/configtypes.py | 4 +--- tests/unit/config/test_config.py | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 484f5abcf..24722f510 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -739,9 +739,7 @@ class Command(BaseType): # leading to an endless recursion. # To fix that, we turn off validating other commands (alias values) # while validating a command. - # FIXME:conf Can't test this because we don't have a real config in - # TestCommand - if not Command.unvalidated: # pragma: no branch + if not Command.unvalidated: Command.unvalidated = True try: from qutebrowser.commands import runners, cmdexc diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index eacd5b4c3..79a7f7870 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -613,6 +613,13 @@ class TestConfig: """Test conf.get() with a QColor (where get/get_obj is different).""" assert conf.get('colors.completion.fg') == QColor('white') + @pytest.mark.parametrize('value', [{}, {'normal': {'a': 'nop'}}]) + def test_get_bindings(self, config_stub, conf, value): + """Test conf.get() with bindings which have missing keys.""" + config_stub.val.aliases = {} + conf._values['bindings.commands'] = value + assert conf.get('bindings.commands')['prompt'] == {} + def test_get_mutable(self, conf): """Make sure we don't observe everything for mutations.""" conf.get('content.headers.custom') @@ -622,11 +629,12 @@ class TestConfig: assert conf.get_obj('colors.completion.fg') == 'white' @pytest.mark.parametrize('option', ['content.headers.custom', - 'keyhint.blacklist']) + 'keyhint.blacklist', + 'bindings.commands']) @pytest.mark.parametrize('mutable', [True, False]) @pytest.mark.parametrize('mutated', [True, False]) - def test_get_obj_mutable(self, conf, qtbot, caplog, option, mutable, - mutated): + def test_get_obj_mutable(self, conf, config_stub, qtbot, caplog, + option, mutable, mutated): """Make sure mutables are handled correctly. When we get a mutable object from the config, some invariants should be @@ -652,8 +660,7 @@ class TestConfig: if mutable: new = {'X-Answer': '42'} assert obj == new - else: - assert option == 'keyhint.blacklist' + elif option == 'keyhint.blacklist': old = [] new = [] assert obj == old @@ -662,6 +669,18 @@ class TestConfig: if mutable: new = ['foo'] assert obj == new + else: + assert option == 'bindings.commands' + config_stub.val.aliases = {} + old = {} + new = {} + assert obj == old + if mutated: + obj['prompt'] = {} + obj['prompt']['foobar'] = 'nop' + if mutable: + new = {'prompt': {'foobar': 'nop'}} + assert obj == new if mutable: assert conf._mutables == [(option, old, new)]