From 285b5343846929f38ac1284a6c9daee4847f4596 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Wed, 20 Sep 2017 10:04:34 +0200 Subject: [PATCH] make changed dirty and save on duplicate write --- qutebrowser/config/configfiles.py | 9 ++++----- tests/unit/config/test_configfiles.py | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index b187a6c08..06c3931f6 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -84,7 +84,7 @@ class YamlConfig: self._filename = os.path.join(standarddir.config(auto=True), 'autoconfig.yml') self._values = {} - self._changed = None + self._dirty = None def init_save_manager(self, save_manager): """Make sure the config gets saved properly. @@ -98,8 +98,7 @@ class YamlConfig: return self._values[name] def __setitem__(self, name, value): - if self._values.get(name) != value: - self._changed = True + self._dirty = True self._values[name] = value def __contains__(self, name): @@ -110,7 +109,7 @@ class YamlConfig: def _save(self): """Save the settings to the YAML file if they've changed.""" - if not self._changed: + if not self._dirty: return data = {'config_version': self.VERSION, 'global': self._values} @@ -155,7 +154,7 @@ class YamlConfig: raise configexc.ConfigFileErrors('autoconfig.yml', [desc]) self._values = global_obj - self._changed = False + self._dirty = False class ConfigAPI: diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 3680cf6b4..5736904c2 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -77,7 +77,6 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert): else: text = autoconfig.read_text('utf-8') lines = text.splitlines() - print(lines) if insert: assert lines[0].startswith('# DO NOT edit this file by hand,') @@ -85,6 +84,8 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert): assert 'global:' in lines + print(lines) + # WORKAROUND for https://github.com/PyCQA/pylint/issues/574 if 'magenta' in (old_config or ''): # pylint: disable=superfluous-parens assert ' colors.hints.fg: magenta' in lines