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.
This commit is contained in:
Florian Bruhin 2014-12-17 13:27:03 +01:00
parent 512d7c4448
commit a714f0b70c
2 changed files with 9 additions and 5 deletions

View File

@ -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."""

View File

@ -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."""