From a714f0b70cdc803e43375ac6326e87c81be9afed Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 17 Dec 2014 13:27:03 +0100 Subject: [PATCH] config: Set self._initialized before validating. With a setting with an interpolation this caused a ValueError because validate_all called get before self._initialized was True. --- qutebrowser/config/config.py | 5 +++-- qutebrowser/test/config/test_config.py | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 326682133..09ee8e751 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -225,11 +225,13 @@ class ConfigManager(QObject): self._fname = fname if configdir is None: self._configdir = None + self._initialized = True else: self._configdir = configdir parser = ini.ReadConfigParser(configdir, fname) self._from_cp(parser) - self._initialized = True + self._initialized = True + self._validate_all() def __getitem__(self, key): """Get a section from the config.""" @@ -357,7 +359,6 @@ class ConfigManager(QObject): if (sectname, k) in self.RENAMED_OPTIONS: k = self.RENAMED_OPTIONS[sectname, k] self.set('conf', sectname, k, v, validate=False) - self._validate_all() def _validate_all(self): """Validate all values set in self._from_cp.""" diff --git a/qutebrowser/test/config/test_config.py b/qutebrowser/test/config/test_config.py index f6dfe41fd..92e805037 100644 --- a/qutebrowser/test/config/test_config.py +++ b/qutebrowser/test/config/test_config.py @@ -73,15 +73,17 @@ class ConfigParserTests(unittest.TestCase): def test_invalid_value(self): """Test setting an invalid value.""" self.cp.read_dict({'general': {'ignore-case': 'invalid'}}) + self.cfg._from_cp(self.cp) with self.assertRaises(configexc.ValidationError): - self.cfg._from_cp(self.cp) + self.cfg._validate_all() def test_invalid_value_interpolated(self): """Test setting an invalid interpolated value.""" self.cp.read_dict({'general': {'ignore-case': 'smart', 'wrap-search': '${ignore-case}'}}) + self.cfg._from_cp(self.cp) with self.assertRaises(configexc.ValidationError): - self.cfg._from_cp(self.cp) + self.cfg._validate_all() def test_interpolation(self): """Test setting an interpolated value.""" @@ -106,8 +108,9 @@ class ConfigParserTests(unittest.TestCase): def test_invalid_interpolation(self): """Test an invalid interpolation.""" self.cp.read_dict({'general': {'ignore-case': '${foo}'}}) + self.cfg._from_cp(self.cp) with self.assertRaises(configparser.InterpolationError): - self.cfg._from_cp(self.cp) + self.cfg._validate_all() def test_invalid_interpolation_syntax(self): """Test an invalid interpolation syntax."""