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