Update config_stub for tests
This commit is contained in:
parent
0dc95aceed
commit
a5c8a52dd5
@ -203,31 +203,53 @@ def cmdline_test(request):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_stub(stubs):
|
||||
def config_stub(stubs, monkeypatch):
|
||||
"""Fixture which provides a fake config object."""
|
||||
stub = stubs.ConfigStub()
|
||||
objreg.register('config', stub)
|
||||
yield stub
|
||||
objreg.delete('config')
|
||||
conf = stubs.ConfigStub()
|
||||
monkeypatch.setattr(config, 'instance', conf)
|
||||
|
||||
container = config.ConfigContainer(conf)
|
||||
monkeypatch.setattr(config, 'val', container)
|
||||
|
||||
conf.val = container
|
||||
return conf
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def default_config():
|
||||
"""Fixture that provides and registers an empty default config object."""
|
||||
config_obj = config.ConfigManager()
|
||||
config_obj.read(configdir=None, fname=None, relaxed=True)
|
||||
objreg.register('config', config_obj)
|
||||
yield config_obj
|
||||
objreg.delete('config')
|
||||
# FIXME:conf
|
||||
return None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def key_config_stub(stubs):
|
||||
"""Fixture which provides a fake key config object."""
|
||||
stub = stubs.KeyConfigStub()
|
||||
objreg.register('key-config', stub)
|
||||
yield stub
|
||||
objreg.delete('key-config')
|
||||
# FIXME:conf
|
||||
# class KeyConfigStub:
|
||||
#
|
||||
# """Stub for the key-config object."""
|
||||
#
|
||||
# def __init__(self):
|
||||
# self.bindings = {}
|
||||
#
|
||||
# def get_bindings_for(self, section):
|
||||
# return self.bindings.get(section)
|
||||
#
|
||||
# def set_bindings_for(self, section, bindings):
|
||||
# self.bindings[section] = bindings
|
||||
#
|
||||
# def get_reverse_bindings_for(self, section):
|
||||
# """Get a dict of commands to a list of bindings for the section."""
|
||||
# cmd_to_keys = collections.defaultdict(list)
|
||||
# for key, cmd in self.bindings[section].items():
|
||||
# # put special bindings last
|
||||
# if utils.is_special_key(key):
|
||||
# cmd_to_keys[cmd].append(key)
|
||||
# else:
|
||||
# cmd_to_keys[cmd].insert(0, key)
|
||||
# return cmd_to_keys
|
||||
return None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -418,76 +418,33 @@ class ConfigStub(QObject):
|
||||
|
||||
Attributes:
|
||||
data: The config data to return.
|
||||
val: A ConfigContainer
|
||||
"""
|
||||
|
||||
# FIXME:conf refactor...
|
||||
|
||||
changed = pyqtSignal(str, str)
|
||||
changed = pyqtSignal(str)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
"""Constructor.
|
||||
|
||||
Args:
|
||||
signal: The signal to use for self.changed.
|
||||
"""
|
||||
super().__init__(parent)
|
||||
self.data = {}
|
||||
self.val = None
|
||||
|
||||
def __getitem__(self, name):
|
||||
return self.section(name)
|
||||
|
||||
def section(self, name):
|
||||
"""Get a section from the config.
|
||||
|
||||
Args:
|
||||
name: The section name to get.
|
||||
|
||||
Return:
|
||||
The section as dict.
|
||||
"""
|
||||
return self.data[name]
|
||||
|
||||
def get(self, sect, opt, raw=True):
|
||||
def get(self, name):
|
||||
"""Get a value from the config."""
|
||||
data = self.data[sect]
|
||||
try:
|
||||
return data[opt]
|
||||
return self.data[name]
|
||||
except KeyError:
|
||||
raise configexc.NoOptionError(opt, sect)
|
||||
raise configexc.NoOptionError(name)
|
||||
|
||||
def set(self, sect, opt, value):
|
||||
def set_obj(self, name, value):
|
||||
"""Set a value in the config."""
|
||||
data = self.data[sect]
|
||||
try:
|
||||
data[opt] = value
|
||||
self.changed.emit(sect, opt)
|
||||
self.data[name] = value
|
||||
self.changed.emit(name)
|
||||
except KeyError:
|
||||
raise configexc.NoOptionError(opt, sect)
|
||||
|
||||
|
||||
class KeyConfigStub:
|
||||
|
||||
"""Stub for the key-config object."""
|
||||
|
||||
def __init__(self):
|
||||
self.bindings = {}
|
||||
|
||||
def get_bindings_for(self, section):
|
||||
return self.bindings.get(section)
|
||||
|
||||
def set_bindings_for(self, section, bindings):
|
||||
self.bindings[section] = bindings
|
||||
|
||||
def get_reverse_bindings_for(self, section):
|
||||
"""Get a dict of commands to a list of bindings for the section."""
|
||||
cmd_to_keys = collections.defaultdict(list)
|
||||
for key, cmd in self.bindings[section].items():
|
||||
# put special bindings last
|
||||
if utils.is_special_key(key):
|
||||
cmd_to_keys[cmd].append(key)
|
||||
else:
|
||||
cmd_to_keys[cmd].insert(0, key)
|
||||
return cmd_to_keys
|
||||
raise configexc.NoOptionError(name)
|
||||
|
||||
|
||||
class UrlMarkManagerStub(QObject):
|
||||
|
@ -19,23 +19,19 @@
|
||||
"""Tests for qutebrowser.config.configdata."""
|
||||
|
||||
import textwrap
|
||||
import types
|
||||
|
||||
import yaml
|
||||
import pytest
|
||||
|
||||
# To run cmdutils.register decorators
|
||||
from qutebrowser import app
|
||||
from qutebrowser.config import config, configdata, configtypes
|
||||
from qutebrowser.config import configdata, configtypes
|
||||
from qutebrowser.utils import usertypes
|
||||
|
||||
|
||||
def test_init(monkeypatch):
|
||||
def test_init(config_stub):
|
||||
"""Test reading the default yaml file and validating the values."""
|
||||
# FIXME:conf use some kind of config_stub here
|
||||
ns = types.SimpleNamespace()
|
||||
ns.aliases = {}
|
||||
monkeypatch.setattr('qutebrowser.config.config.val', ns)
|
||||
config_stub.val.aliases = {}
|
||||
configdata.init()
|
||||
assert isinstance(configdata.DATA, dict)
|
||||
assert 'ignore_case' in configdata.DATA
|
||||
|
@ -27,7 +27,6 @@ import collections
|
||||
import itertools
|
||||
import warnings
|
||||
import inspect
|
||||
import types
|
||||
import functools
|
||||
|
||||
import pytest
|
||||
@ -209,12 +208,9 @@ class TestAll:
|
||||
yield member
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def patch(self, monkeypatch):
|
||||
def patch_aliases(self, config_stub):
|
||||
"""Patch aliases so Command works."""
|
||||
# FIXME:conf use some kind of config_stub here
|
||||
ns = types.SimpleNamespace()
|
||||
ns.aliases = {}
|
||||
monkeypatch.setattr('qutebrowser.config.config.val', ns)
|
||||
config_stub.val.aliases = {}
|
||||
|
||||
@pytest.fixture(params=list(gen_classes()))
|
||||
def klass(self, request):
|
||||
@ -1037,13 +1033,10 @@ class TestCommand:
|
||||
monkeypatch.setattr('qutebrowser.commands.runners.cmdutils', cmd_utils)
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def patch_aliases(self, monkeypatch):
|
||||
def patch_aliases(self, config_stub):
|
||||
"""Patch the aliases setting."""
|
||||
# FIXME:conf use some kind of config_stub here
|
||||
# also remove the no branch pragma from configtypes.Command then
|
||||
ns = types.SimpleNamespace()
|
||||
ns.aliases = {'alias': 'cmd1'}
|
||||
monkeypatch.setattr('qutebrowser.config.config.val', ns)
|
||||
# FIXME:conf use the real config so we can test the RecursionError
|
||||
config_stub.val.aliases = {'alias': 'cmd1'}
|
||||
|
||||
@pytest.fixture
|
||||
def klass(self):
|
||||
|
Loading…
Reference in New Issue
Block a user