diff --git a/tests/commands/test_runners.py b/tests/commands/test_runners.py new file mode 100644 index 000000000..a03eab9d8 --- /dev/null +++ b/tests/commands/test_runners.py @@ -0,0 +1,44 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2015 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""Tests for qutebrowser.commands.runners.""" + +import pytest + +from qutebrowser.commands import runners, cmdexc + + +class TestCommandRunner: + + """Tests for CommandRunner.""" + + def test_parse_all(self, cmdline_test): + """Test parsing of commands. + + See https://github.com/The-Compiler/qutebrowser/issues/615 + + Args: + cmdline_test: A pytest fixture which provides testcases. + """ + cr = runners.CommandRunner(0) + if cmdline_test.valid: + list(cr.parse_all(cmdline_test.cmd, aliases=False)) + else: + with pytest.raises(cmdexc.NoSuchCommandError): + list(cr.parse_all(cmdline_test.cmd, aliases=False)) diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 37ab94c26..c8937671f 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -157,6 +157,27 @@ class TestConfigParser: self.cfg.get('general', 'bar') # pylint: disable=bad-config-call +class TestKeyConfigParser: + + """Test config.parsers.keyconf.KeyConfigParser.""" + + def test_cmd_binding(self, cmdline_test): + """Test various command bindings. + + See https://github.com/The-Compiler/qutebrowser/issues/615 + + Args: + cmdline_test: A pytest fixture which provides testcases. + """ + kcp = keyconf.KeyConfigParser(None, None) + kcp._cur_section = 'normal' + if cmdline_test.valid: + kcp._read_command(cmdline_test.cmd) + else: + with pytest.raises(keyconf.KeyConfigError): + kcp._read_command(cmdline_test.cmd) + + class TestDefaultConfig: """Test validating of the default config.""" diff --git a/tests/conftest.py b/tests/conftest.py index 865cb22f9..3f3fc7ba0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,6 +19,9 @@ """The qutebrowser test suite contest file.""" +import collections +import itertools + import pytest @@ -98,3 +101,41 @@ def pytest_collection_modifyitems(items): for item in items: if 'qtbot' in item.fixturenames: item.add_marker('gui') + + +def _generate_cmdline_tests(): + """Generate testcases for test_split_binding.""" + # pylint: disable=invalid-name + TestCase = collections.namedtuple('TestCase', 'cmd, valid') + separators = [';;', ' ;; ', ';; ', ' ;;'] + invalid = ['foo', ''] + valid = ['leave-mode', 'hint all'] + # Valid command only -> valid + for item in valid: + yield TestCase(''.join(item), True) + # Invalid command only -> invalid + for item in valid: + yield TestCase(''.join(item), True) + # Invalid command combined with invalid command -> invalid + for item in itertools.product(invalid, separators, invalid): + yield TestCase(''.join(item), False) + # Valid command combined with valid command -> valid + for item in itertools.product(valid, separators, valid): + yield TestCase(''.join(item), True) + # Valid command combined with invalid command -> invalid + for item in itertools.product(valid, separators, invalid): + yield TestCase(''.join(item), False) + # Invalid command combined with valid command -> invalid + for item in itertools.product(invalid, separators, valid): + yield TestCase(''.join(item), False) + # Command with no_cmd_split combined with an "invalid" command -> valid + for item in itertools.product(['bind x open'], separators, invalid): + yield TestCase(''.join(item), True) + + +@pytest.fixture(params=_generate_cmdline_tests()) +def cmdline_test(request): + """Fixture which generates tests for things validating commandlines.""" + # Import qutebrowser.app so all cmdutils.register decorators get run. + import qutebrowser.app # pylint: disable=unused-variable + return request.param