From 3cb93b22ae78cd0f12de5e0f6bb1f5bf9b8ec667 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 5 Oct 2017 10:34:25 +0200 Subject: [PATCH] Add tests for :config-write-py --- tests/unit/config/test_configcommands.py | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index 9c6a9e460..359a4b23a 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -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."""