From d4cf5045ab92d2b859e64b763bf8584e2ff47b9c Mon Sep 17 00:00:00 2001
From: Jay Kamat <jaygkamat@gmail.com>
Date: Sun, 2 Sep 2018 14:57:55 -0700
Subject: [PATCH] Fix tests for configcache

---
 qutebrowser/config/configcache.py     |  3 ---
 scripts/dev/check_coverage.py         |  2 ++
 tests/helpers/fixtures.py             |  5 ++++-
 tests/unit/config/test_configcache.py | 19 ++++++++++++++++---
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/qutebrowser/config/configcache.py b/qutebrowser/config/configcache.py
index c9e23ff66..471a42213 100644
--- a/qutebrowser/config/configcache.py
+++ b/qutebrowser/config/configcache.py
@@ -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
diff --git a/scripts/dev/check_coverage.py b/scripts/dev/check_coverage.py
index 32c5afc49..8d6f3ccae 100644
--- a/scripts/dev/check_coverage.py
+++ b/scripts/dev/check_coverage.py
@@ -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'),
diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py
index ec562c3b4..beb43f82b 100644
--- a/tests/helpers/fixtures.py
+++ b/tests/helpers/fixtures.py
@@ -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:
diff --git a/tests/unit/config/test_configcache.py b/tests/unit/config/test_configcache.py
index 1236cf8a7..982e0c3f1 100644
--- a/tests/unit/config/test_configcache.py
+++ b/tests/unit/config/test_configcache.py
@@ -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']