Add TestYaml class to test_configfiles
This commit is contained in:
parent
f821fb793a
commit
3e0d49a4b3
@ -61,6 +61,8 @@ def test_state_config(fake_save_manager, data_tmpdir,
|
|||||||
assert statefile.read_text('utf-8') == new_data
|
assert statefile.read_text('utf-8') == new_data
|
||||||
|
|
||||||
|
|
||||||
|
class TestYaml:
|
||||||
|
|
||||||
@pytest.mark.parametrize('old_config', [
|
@pytest.mark.parametrize('old_config', [
|
||||||
None,
|
None,
|
||||||
'global:\n colors.hints.fg: magenta',
|
'global:\n colors.hints.fg: magenta',
|
||||||
@ -68,7 +70,8 @@ def test_state_config(fake_save_manager, data_tmpdir,
|
|||||||
'global:\n hello: world',
|
'global:\n hello: world',
|
||||||
])
|
])
|
||||||
@pytest.mark.parametrize('insert', [True, False])
|
@pytest.mark.parametrize('insert', [True, False])
|
||||||
def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
def test_yaml_config(self, fake_save_manager, config_tmpdir,
|
||||||
|
old_config, insert):
|
||||||
autoconfig = config_tmpdir / 'autoconfig.yml'
|
autoconfig = config_tmpdir / 'autoconfig.yml'
|
||||||
if old_config is not None:
|
if old_config is not None:
|
||||||
autoconfig.write_text(old_config, 'utf-8')
|
autoconfig.write_text(old_config, 'utf-8')
|
||||||
@ -96,13 +99,13 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
|||||||
print(lines)
|
print(lines)
|
||||||
|
|
||||||
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
|
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
|
||||||
if 'magenta' in (old_config or ''): # pylint: disable=superfluous-parens
|
# pylint: disable=superfluous-parens
|
||||||
|
if 'magenta' in (old_config or ''):
|
||||||
assert ' colors.hints.fg: magenta' in lines
|
assert ' colors.hints.fg: magenta' in lines
|
||||||
if insert:
|
if insert:
|
||||||
assert ' tabs.show: never' in lines
|
assert ' tabs.show: never' in lines
|
||||||
assert ' hello:' not in lines
|
assert ' hello:' not in lines
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('old_config', [
|
@pytest.mark.parametrize('old_config', [
|
||||||
None,
|
None,
|
||||||
'global:\n colors.hints.fg: magenta',
|
'global:\n colors.hints.fg: magenta',
|
||||||
@ -113,7 +116,7 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
|||||||
('confirm_quit', True),
|
('confirm_quit', True),
|
||||||
('confirm_quit', False),
|
('confirm_quit', False),
|
||||||
])
|
])
|
||||||
def test_yaml_config_changed(fake_save_manager, config_tmpdir, old_config,
|
def test_changed(self, fake_save_manager, config_tmpdir, old_config,
|
||||||
key, value):
|
key, value):
|
||||||
autoconfig = config_tmpdir / 'autoconfig.yml'
|
autoconfig = config_tmpdir / 'autoconfig.yml'
|
||||||
if old_config is not None:
|
if old_config is not None:
|
||||||
@ -134,12 +137,11 @@ def test_yaml_config_changed(fake_save_manager, config_tmpdir, old_config,
|
|||||||
assert key in yaml
|
assert key in yaml
|
||||||
assert yaml[key] == value
|
assert yaml[key] == value
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('old_config', [
|
@pytest.mark.parametrize('old_config', [
|
||||||
None,
|
None,
|
||||||
'global:\n colors.hints.fg: magenta',
|
'global:\n colors.hints.fg: magenta',
|
||||||
])
|
])
|
||||||
def test_yaml_config_unchanged(fake_save_manager, config_tmpdir, old_config):
|
def test_unchanged(self, fake_save_manager, config_tmpdir, old_config):
|
||||||
autoconfig = config_tmpdir / 'autoconfig.yml'
|
autoconfig = config_tmpdir / 'autoconfig.yml'
|
||||||
mtime = None
|
mtime = None
|
||||||
if old_config is not None:
|
if old_config is not None:
|
||||||
@ -155,7 +157,6 @@ def test_yaml_config_unchanged(fake_save_manager, config_tmpdir, old_config):
|
|||||||
else:
|
else:
|
||||||
assert autoconfig.stat().mtime == mtime
|
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"),
|
||||||
@ -163,7 +164,7 @@ def test_yaml_config_unchanged(fake_save_manager, config_tmpdir, old_config):
|
|||||||
"Toplevel object does not contain 'global' key"),
|
"Toplevel object does not contain 'global' key"),
|
||||||
('42', 'While loading data', "Toplevel object is not a dict"),
|
('42', 'While loading data', "Toplevel object is not a dict"),
|
||||||
])
|
])
|
||||||
def test_yaml_config_invalid(fake_save_manager, config_tmpdir,
|
def test_invalid(self, fake_save_manager, config_tmpdir,
|
||||||
line, text, exception):
|
line, text, exception):
|
||||||
autoconfig = config_tmpdir / 'autoconfig.yml'
|
autoconfig = config_tmpdir / 'autoconfig.yml'
|
||||||
autoconfig.write_text(line, 'utf-8', ensure=True)
|
autoconfig.write_text(line, 'utf-8', ensure=True)
|
||||||
@ -179,8 +180,7 @@ def test_yaml_config_invalid(fake_save_manager, config_tmpdir,
|
|||||||
assert str(error.exception).splitlines()[0] == exception
|
assert str(error.exception).splitlines()[0] == exception
|
||||||
assert error.traceback is None
|
assert error.traceback is None
|
||||||
|
|
||||||
|
def test_oserror(self, fake_save_manager, config_tmpdir):
|
||||||
def test_yaml_oserror(fake_save_manager, config_tmpdir):
|
|
||||||
autoconfig = config_tmpdir / 'autoconfig.yml'
|
autoconfig = config_tmpdir / 'autoconfig.yml'
|
||||||
autoconfig.ensure()
|
autoconfig.ensure()
|
||||||
autoconfig.chmod(0)
|
autoconfig.chmod(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user