diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index 11078ca8f..4c504af34 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -354,16 +354,38 @@ class FakeConfigSection: """A stub for a KeyValue entry in configdata.DATA.""" def __init__(self, *entries): - self.values = [] + self.values = collections.OrderedDict() self.descriptions = {} - for name, desc in entries: - self.values.append(name) + for name, value, desc in entries: + self.values[name] = value self.descriptions[name] = desc def __iter__(self): """Iterate over all set values.""" return self.values.__iter__() + def __getitem__(self, key): + return self.values[key] + + +class FakeSettingValue: + + """A stub for a SettingValue entry in configdata.DATA[section].""" + + def __init__(self, valid_values, default=None): + self.typ = FakeConfigType(valid_values) + self.default = lambda: default + + +class FakeConfigType: + + """A stub for the typ attribute of a FakeSettingValue.""" + + def __init__(self, valid_values): + # normally valid_values would be a ValidValues, but for simplicity of + # testing this can be a simple list: [(val, desc), (val, desc), ...] + self.complete = lambda: [(val, '') for val in valid_values] + class ConfigStub(QObject): diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 0fd1a1bbc..4f3e61b6c 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -231,6 +231,24 @@ def test_setting_option_completion(monkeypatch, stubs, config_stub): ] +def test_setting_value_completion(monkeypatch, stubs, config_stub): + module = 'qutebrowser.completion.models.configmodel' + _patch_configdata(monkeypatch, stubs, module + '.configdata.DATA') + config_stub.data = {'general': { 'volume': '0' }} + model = configmodel.SettingValueCompletionModel('general', 'volume') + actual = _get_completions(model) + assert actual == [ + ("Current/Default", [ + ('0', 'Current value', ''), + ('11', 'Default value', ''), + ]), + ("Completions", [ + ('0', '', ''), + ('11', '', ''), + ]) + ] + + def _get_completions(model): """Collect all the completion entries of a model, organized by category. @@ -270,12 +288,22 @@ def _patch_configdata(monkeypatch, stubs, symbol): """Patch the configdata module to provide fake data.""" data = collections.OrderedDict([ ('general', stubs.FakeConfigSection( - ('time', 'Is an illusion.\n\nLunchtime doubly so.'), - ('volume', 'Goes to 11'))), + ('time', + stubs.FakeSettingValue(('fast', 'slow'), 'slow'), + 'Is an illusion.\n\nLunchtime doubly so.'), + ('volume', + stubs.FakeSettingValue(('0', '11'), '11'), + 'Goes to 11'))), ('ui', stubs.FakeConfigSection( - ('gesture', 'Waggle your hands to control qutebrowser'), - ('mind', 'Enable mind-control ui (experimental)'), - ('voice', 'Whether to respond to voice commands'))), + ('gesture', + stubs.FakeSettingValue(('on', 'off'), 'off'), + 'Waggle your hands to control qutebrowser'), + ('mind', + stubs.FakeSettingValue(('on', 'off'), 'off'), + 'Enable mind-control ui (experimental)'), + ('voice', + stubs.FakeSettingValue(('on', 'off'), 'off'), + 'Whether to respond to voice commands'))), ]) monkeypatch.setattr(symbol, data)