fix configfiles tests

- fix test_renamed_key()
- fix test_deleted_key()
- combine both test_merge_persist tests using @pytest.mark.parametrize
- fix _handle_migrations(): mark data dirty for renamed and deleted
This commit is contained in:
Marc Jauvin 2018-02-09 21:25:11 -05:00
parent 57fe674dc4
commit 504e29c004
2 changed files with 12 additions and 24 deletions

View File

@ -175,10 +175,10 @@ class YamlConfig(QObject):
new_name = configdata.MIGRATIONS.renamed[name]
log.config.debug("Renaming {} to {}".format(name, new_name))
self._values[new_name] = self._values[name]
del self._values[name]
self.unset(name)
elif name in configdata.MIGRATIONS.deleted:
log.config.debug("Removing {}".format(name))
del self._values[name]
self.unset(name)
persist = 'tabs.persist_mode_on_change'
if persist in self._values:
if self._values[persist]:

View File

@ -152,7 +152,7 @@ class TestYaml:
yaml._save()
lines = autoconfig.read_text('utf-8').splitlines()
assert ' hello:' not in lines
assert ' hello: world' not in lines
def test_renamed_key(self, monkeypatch, yaml, config_tmpdir):
"""A key marked as renamed should be renamed properly."""
@ -166,34 +166,22 @@ class TestYaml:
yaml._save()
lines = autoconfig.read_text('utf-8').splitlines()
assert ' old:' not in lines
assert ' new:' not in lines
assert ' old: value' not in lines
assert ' tabs.show: value' in lines
def test_merge_persist_false(self, monkeypatch, yaml, config_tmpdir):
"""Migration of tabs.persist_mode_on_change: False."""
@pytest.mark.parametrize('persist', [True, False])
def test_merge_persist(self, yaml, config_tmpdir, persist):
"""Tests for migration of tabs.persist_mode_on_change."""
autoconfig = config_tmpdir / 'autoconfig.yml'
autoconfig.write_text('global:\n tabs.persist_mode_on_change: False',
encoding='utf-8')
autoconfig.write_text('global:\n tabs.persist_mode_on_change: {}'.
format(persist), encoding='utf-8')
yaml.load()
yaml._save()
lines = autoconfig.read_text('utf-8').splitlines()
mode = 'persist' if persist else 'normal'
assert ' tabs.persist_mode_on_change:' not in lines
assert ' tabs.mode_on_change: normal' in lines
def test_merge_persist_true(self, monkeypatch, yaml, config_tmpdir):
"""Migration of tabs.persist_mode_on_change: True."""
autoconfig = config_tmpdir / 'autoconfig.yml'
autoconfig.write_text('global:\n tabs.persist_mode_on_change: True',
encoding='utf-8')
yaml.load()
yaml._save()
lines = autoconfig.read_text('utf-8').splitlines()
assert ' tabs.persist_mode_on_change:' not in lines
assert ' tabs.mode_on_change: persist' in lines
assert ' tabs.mode_on_change: {}'.format(mode) in lines
def test_renamed_key_unknown_target(self, monkeypatch, yaml,
config_tmpdir):