Add tests for CommandRunner/KeyConfigParser.
This commit is contained in:
parent
fa2340b61e
commit
3433a1ec7a
44
tests/commands/test_runners.py
Normal file
44
tests/commands/test_runners.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
|
|
||||||
|
# Copyright 2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""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))
|
@ -157,6 +157,27 @@ class TestConfigParser:
|
|||||||
self.cfg.get('general', 'bar') # pylint: disable=bad-config-call
|
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:
|
class TestDefaultConfig:
|
||||||
|
|
||||||
"""Test validating of the default config."""
|
"""Test validating of the default config."""
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
"""The qutebrowser test suite contest file."""
|
"""The qutebrowser test suite contest file."""
|
||||||
|
|
||||||
|
import collections
|
||||||
|
import itertools
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@ -98,3 +101,41 @@ def pytest_collection_modifyitems(items):
|
|||||||
for item in items:
|
for item in items:
|
||||||
if 'qtbot' in item.fixturenames:
|
if 'qtbot' in item.fixturenames:
|
||||||
item.add_marker('gui')
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user