Eliminate FakeSettingSection/Value.
Don't really need to mock these out for tests as the real classes are simple enough.
This commit is contained in:
parent
94ec712ea8
commit
d45acb0388
@ -349,39 +349,11 @@ class FakeTimer(QObject):
|
|||||||
return self._started
|
return self._started
|
||||||
|
|
||||||
|
|
||||||
class FakeConfigSection:
|
|
||||||
|
|
||||||
"""A stub for a KeyValue entry in configdata.DATA."""
|
|
||||||
|
|
||||||
def __init__(self, *entries):
|
|
||||||
self.values = collections.OrderedDict()
|
|
||||||
self.descriptions = {}
|
|
||||||
for name, value, desc in entries:
|
|
||||||
self.values[name] = value
|
|
||||||
self.descriptions[name] = desc
|
|
||||||
|
|
||||||
def __iter__(self):
|
|
||||||
"""Iterate over all set values."""
|
|
||||||
return iter(self.values)
|
|
||||||
|
|
||||||
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:
|
class FakeConfigType:
|
||||||
|
|
||||||
"""A stub for the typ attribute of a FakeSettingValue."""
|
"""A stub to provide valid_values for typ attribute of a SettingValue."""
|
||||||
|
|
||||||
def __init__(self, valid_values):
|
def __init__(self, *valid_values):
|
||||||
# normally valid_values would be a ValidValues, but for simplicity of
|
# normally valid_values would be a ValidValues, but for simplicity of
|
||||||
# testing this can be a simple list: [(val, desc), (val, desc), ...]
|
# testing this can be a simple list: [(val, desc), (val, desc), ...]
|
||||||
self.complete = lambda: [(val, '') for val in valid_values]
|
self.complete = lambda: [(val, '') for val in valid_values]
|
||||||
|
@ -28,6 +28,7 @@ from PyQt5.QtWidgets import QTreeView
|
|||||||
|
|
||||||
from qutebrowser.completion.models import miscmodels, urlmodel, configmodel
|
from qutebrowser.completion.models import miscmodels, urlmodel, configmodel
|
||||||
from qutebrowser.browser.webkit import history
|
from qutebrowser.browser.webkit import history
|
||||||
|
from qutebrowser.config import sections, value
|
||||||
|
|
||||||
|
|
||||||
def _get_completions(model):
|
def _get_completions(model):
|
||||||
@ -68,22 +69,27 @@ def _patch_cmdutils(monkeypatch, stubs, symbol):
|
|||||||
def _patch_configdata(monkeypatch, stubs, symbol):
|
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', sections.KeyValue(
|
||||||
('time',
|
('time',
|
||||||
stubs.FakeSettingValue(('fast', 'slow'), 'slow'),
|
value.SettingValue(stubs.FakeConfigType('fast', 'slow'),
|
||||||
|
default='slow'),
|
||||||
'Is an illusion.\n\nLunchtime doubly so.'),
|
'Is an illusion.\n\nLunchtime doubly so.'),
|
||||||
('volume',
|
('volume',
|
||||||
stubs.FakeSettingValue(('0', '11'), '11'),
|
value.SettingValue(stubs.FakeConfigType('0', '11'),
|
||||||
|
default='11'),
|
||||||
'Goes to 11'))),
|
'Goes to 11'))),
|
||||||
('ui', stubs.FakeConfigSection(
|
('ui', sections.KeyValue(
|
||||||
('gesture',
|
('gesture',
|
||||||
stubs.FakeSettingValue(('on', 'off'), 'off'),
|
value.SettingValue(stubs.FakeConfigType(('on', 'off')),
|
||||||
|
default='off'),
|
||||||
'Waggle your hands to control qutebrowser'),
|
'Waggle your hands to control qutebrowser'),
|
||||||
('mind',
|
('mind',
|
||||||
stubs.FakeSettingValue(('on', 'off'), 'off'),
|
value.SettingValue(stubs.FakeConfigType(('on', 'off')),
|
||||||
|
default='off'),
|
||||||
'Enable mind-control ui (experimental)'),
|
'Enable mind-control ui (experimental)'),
|
||||||
('voice',
|
('voice',
|
||||||
stubs.FakeSettingValue(('on', 'off'), 'off'),
|
value.SettingValue(stubs.FakeConfigType(('on', 'off')),
|
||||||
|
default='off'),
|
||||||
'Whether to respond to voice commands'))),
|
'Whether to respond to voice commands'))),
|
||||||
])
|
])
|
||||||
monkeypatch.setattr(symbol, data)
|
monkeypatch.setattr(symbol, data)
|
||||||
|
Loading…
Reference in New Issue
Block a user