add unit test and fix issues with it
This commit is contained in:
parent
0e743f0e09
commit
7b192d426e
@ -85,6 +85,7 @@ class YamlConfig:
|
|||||||
self._filename = os.path.join(standarddir.config(auto=True),
|
self._filename = os.path.join(standarddir.config(auto=True),
|
||||||
'autoconfig.yml')
|
'autoconfig.yml')
|
||||||
self.values = {}
|
self.values = {}
|
||||||
|
self._initial_values = {}
|
||||||
|
|
||||||
def init_save_manager(self, save_manager):
|
def init_save_manager(self, save_manager):
|
||||||
"""Make sure the config gets saved properly.
|
"""Make sure the config gets saved properly.
|
||||||
@ -119,7 +120,7 @@ class YamlConfig:
|
|||||||
with open(self._filename, 'r', encoding='utf-8') as f:
|
with open(self._filename, 'r', encoding='utf-8') as f:
|
||||||
yaml_data = utils.yaml_load(f)
|
yaml_data = utils.yaml_load(f)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return
|
return {}
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
desc = configexc.ConfigErrorDesc("While reading", e)
|
desc = configexc.ConfigErrorDesc("While reading", e)
|
||||||
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
|
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
|
||||||
|
@ -72,16 +72,17 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
|||||||
|
|
||||||
yaml._save()
|
yaml._save()
|
||||||
|
|
||||||
text = autoconfig.read_text('utf-8')
|
if not insert and old_config is None:
|
||||||
lines = text.splitlines()
|
lines = []
|
||||||
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 'global: {}' in lines
|
|
||||||
else:
|
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,')
|
||||||
|
assert 'config_version: {}'.format(yaml.VERSION) in lines
|
||||||
|
|
||||||
assert 'global:' in lines
|
assert 'global:' in lines
|
||||||
|
|
||||||
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
|
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
|
||||||
@ -91,6 +92,27 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
|||||||
assert ' tabs.show: never' in lines
|
assert ' tabs.show: never' in lines
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('old_config', [
|
||||||
|
None,
|
||||||
|
'global:\n colors.hints.fg: magenta',
|
||||||
|
])
|
||||||
|
def test_yaml_config_unchanged(fake_save_manager, config_tmpdir, old_config):
|
||||||
|
autoconfig = config_tmpdir / 'autoconfig.yml'
|
||||||
|
mtime = None
|
||||||
|
if old_config is not None:
|
||||||
|
autoconfig.write_text(old_config, 'utf-8')
|
||||||
|
mtime = autoconfig.stat().mtime
|
||||||
|
|
||||||
|
yaml = configfiles.YamlConfig()
|
||||||
|
yaml.load()
|
||||||
|
yaml._save()
|
||||||
|
|
||||||
|
if old_config is None:
|
||||||
|
assert not autoconfig.exists()
|
||||||
|
else:
|
||||||
|
assert autoconfig.stat().mtime == mtime
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('line, text, exception', [
|
@pytest.mark.parametrize('line, text, exception', [
|
||||||
('%', 'While parsing', 'while scanning a directive'),
|
('%', 'While parsing', 'while scanning a directive'),
|
||||||
('global: 42', 'While loading data', "'global' object is not a dict"),
|
('global: 42', 'While loading data', "'global' object is not a dict"),
|
||||||
|
Loading…
Reference in New Issue
Block a user