Add tests for :config-write-py

This commit is contained in:
Florian Bruhin 2017-10-05 10:34:25 +02:00
parent ade0e1bd0b
commit 3cb93b22ae

View File

@ -345,6 +345,55 @@ class TestEdit:
assert msg.text == expected
class TestWritePy:
"""Tests for :config-write-py."""
def test_custom(self, commands, config_stub, keyconf, tmpdir):
confpy = tmpdir / 'config.py'
config_stub.val.content.javascript.enabled = True
keyconf.bind(',x', 'message-info foo', mode='normal')
commands.config_write_py(str(confpy))
lines = confpy.read_text('utf-8').splitlines()
assert "c.content.javascript.enabled = True" in lines
assert "config.bind(',x', 'message-info foo')" in lines
def test_defaults(self, commands, tmpdir):
confpy = tmpdir / 'config.py'
commands.config_write_py(str(confpy), defaults=True)
lines = confpy.read_text('utf-8').splitlines()
assert "# c.content.javascript.enabled = True" in lines
assert "# config.bind('H', 'back')" in lines
def test_default_location(self, commands, config_tmpdir):
confpy = config_tmpdir / 'config.py'
commands.config_write_py()
lines = confpy.read_text('utf-8').splitlines()
assert '# Autogenerated config.py' in lines
def test_existing_file(self, commands, tmpdir):
confpy = tmpdir / 'config.py'
confpy.ensure()
with pytest.raises(cmdexc.CommandError) as excinfo:
commands.config_write_py(str(confpy))
expected = " already exists - use --force to overwrite!"
assert str(excinfo.value).endswith(expected)
def test_existing_file_force(self, commands, tmpdir):
confpy = tmpdir / 'config.py'
confpy.ensure()
commands.config_write_py(str(confpy), force=True)
lines = confpy.read_text('utf-8').splitlines()
assert '# Autogenerated config.py' in lines
class TestBind:
"""Tests for :bind and :unbind."""