Unit test setting value completion
This commit is contained in:
parent
f5b1019d4d
commit
8321c1a90f
@ -354,16 +354,38 @@ class FakeConfigSection:
|
|||||||
"""A stub for a KeyValue entry in configdata.DATA."""
|
"""A stub for a KeyValue entry in configdata.DATA."""
|
||||||
|
|
||||||
def __init__(self, *entries):
|
def __init__(self, *entries):
|
||||||
self.values = []
|
self.values = collections.OrderedDict()
|
||||||
self.descriptions = {}
|
self.descriptions = {}
|
||||||
for name, desc in entries:
|
for name, value, desc in entries:
|
||||||
self.values.append(name)
|
self.values[name] = value
|
||||||
self.descriptions[name] = desc
|
self.descriptions[name] = desc
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""Iterate over all set values."""
|
"""Iterate over all set values."""
|
||||||
return self.values.__iter__()
|
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):
|
class ConfigStub(QObject):
|
||||||
|
|
||||||
|
@ -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):
|
def _get_completions(model):
|
||||||
"""Collect all the completion entries of a model, organized by category.
|
"""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."""
|
"""Patch the configdata module to provide fake data."""
|
||||||
data = collections.OrderedDict([
|
data = collections.OrderedDict([
|
||||||
('general', stubs.FakeConfigSection(
|
('general', stubs.FakeConfigSection(
|
||||||
('time', 'Is an illusion.\n\nLunchtime doubly so.'),
|
('time',
|
||||||
('volume', 'Goes to 11'))),
|
stubs.FakeSettingValue(('fast', 'slow'), 'slow'),
|
||||||
|
'Is an illusion.\n\nLunchtime doubly so.'),
|
||||||
|
('volume',
|
||||||
|
stubs.FakeSettingValue(('0', '11'), '11'),
|
||||||
|
'Goes to 11'))),
|
||||||
('ui', stubs.FakeConfigSection(
|
('ui', stubs.FakeConfigSection(
|
||||||
('gesture', 'Waggle your hands to control qutebrowser'),
|
('gesture',
|
||||||
('mind', 'Enable mind-control ui (experimental)'),
|
stubs.FakeSettingValue(('on', 'off'), 'off'),
|
||||||
('voice', 'Whether to respond to voice commands'))),
|
'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)
|
monkeypatch.setattr(symbol, data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user