Add a config version to the YAML file

This commit is contained in:
Florian Bruhin 2017-07-19 08:22:00 +02:00
parent cbf9da0b7e
commit 0f85898137
2 changed files with 11 additions and 4 deletions

View File

@ -54,7 +54,13 @@ class StateConfig(configparser.ConfigParser):
class YamlConfig:
"""A config stored on disk as YAML file."""
"""A config stored on disk as YAML file.
Class attributes:
VERSION: The current version number of the config file.
"""
VERSION = 1
def __init__(self):
save_manager = objreg.get('save-manager')
@ -64,7 +70,7 @@ class YamlConfig:
def _save(self):
"""Save the changed settings to the YAML file."""
data = {'global': self.values}
data = {'config_version': self.VERSION, 'global': self.values}
with qtutils.savefile_open(self._filename) as f:
f.write(textwrap.dedent("""
# DO NOT edit this file by hand, qutebrowser will overwrite it.

View File

@ -77,11 +77,12 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
print(lines)
assert lines[0].startswith('# DO NOT edit this file by hand,')
assert 'config_version: {}'.format(yaml.VERSION) in lines
if old_config is None and not insert:
assert lines[3] == 'global: {}'
assert 'global: {}' in lines
else:
assert lines[3] == 'global:'
assert 'global:' in lines
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
if 'magenta' in (old_config or ''): # pylint: disable=superfluous-parens