Fix tests for configcache

This commit is contained in:
Jay Kamat 2018-09-02 14:57:55 -07:00
parent cc09f6c962
commit d4cf5045ab
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5
4 changed files with 22 additions and 7 deletions

View File

@ -42,9 +42,6 @@ class ConfigCache():
if attr in self.cache:
self.cache[attr] = config.instance.get(attr)
def __setitem__(self, attr, _value):
raise Exception("ConfigCache cannot be used to set values.")
def __getitem__(self, attr: str):
if attr not in self.cache:
assert not config.instance.get_opt(attr).supports_pattern

View File

@ -147,6 +147,8 @@ PERFECT_FILES = [
'config/configcommands.py'),
('tests/unit/config/test_configutils.py',
'config/configutils.py'),
('tests/unit/config/test_configcache.py',
'config/configcache.py'),
('tests/unit/utils/test_qtutils.py',
'utils/qtutils.py'),

View File

@ -42,7 +42,7 @@ from PyQt5.QtNetwork import QNetworkCookieJar
import helpers.stubs as stubsmod
import helpers.utils
from qutebrowser.config import (config, configdata, configtypes, configexc,
configfiles)
configfiles, configcache)
from qutebrowser.utils import objreg, standarddir, utils, usertypes
from qutebrowser.browser import greasemonkey
from qutebrowser.browser.webkit import cookies
@ -253,6 +253,9 @@ def config_stub(stubs, monkeypatch, configdata_init, yaml_config_stub):
container = config.ConfigContainer(conf)
monkeypatch.setattr(config, 'val', container)
cache = configcache.ConfigCache()
monkeypatch.setattr(config, 'configcache', cache)
try:
configtypes.Font.monospace_fonts = container.fonts.monospace
except configexc.NoOptionError:

View File

@ -21,15 +21,28 @@
import pytest
from qutebrowser.config import configcache, config
from qutebrowser.config import config
class TestConfigCache:
@pytest.fixture
def ccache(self, config_stub):
return configcache.ConfigCache()
return config.configcache
def test_configcache_except_pattern(self, ccache):
with pytest.raises(AssertionError):
ccache['content.javascript.enabled']
assert ccache['content.javascript.enabled']
def test_configcache_error_set(self, ccache):
with pytest.raises(TypeError):
ccache['content.javascript.enabled'] = True
def test_configcache_get(self, ccache):
assert not ccache['auto_save.session']
assert not ccache['auto_save.session']
def test_configcache_get_after_set(self, ccache):
assert not ccache['auto_save.session']
config.val.auto_save.session = True
assert ccache['auto_save.session']