Add tests for Command.run

This commit is contained in:
Florian Bruhin 2016-07-08 19:30:40 +02:00
parent b07cca023b
commit 7859df74c4

View File

@ -33,6 +33,19 @@ def clear_globals(monkeypatch):
monkeypatch.setattr(cmdutils, 'aliases', [])
def _get_cmd(*args, **kwargs):
"""Get a command object created via @cmdutils.register.
Args:
Passed to @cmdutils.register decorator
"""
@cmdutils.register(*args, **kwargs)
def fun():
"""Blah."""
pass
return cmdutils.cmd_dict['fun']
class TestCheckOverflow:
def test_good(self):
@ -351,3 +364,32 @@ class TestArgument:
pass
assert str(excinfo.value) == "Argument marked as both count/win_id!"
class TestRun:
@pytest.fixture(autouse=True)
def patching(self, mode_manager, fake_args):
fake_args.backend = 'webkit'
@pytest.mark.parametrize('backend, used, ok', [
(tabmod.Backend.QtWebEngine, 'webengine', True),
(tabmod.Backend.QtWebEngine, 'webkit', False),
(tabmod.Backend.QtWebKit, 'webengine', False),
(tabmod.Backend.QtWebKit, 'webkit', True),
(None, 'webengine', True),
(None, 'webkit', True),
])
def test_backend(self, fake_args, backend, used, ok):
fake_args.backend = used
cmd = _get_cmd(backend=backend)
if ok:
cmd.run(win_id=0)
else:
with pytest.raises(cmdexc.PrerequisitesError) as excinfo:
cmd.run(win_id=0)
assert str(excinfo.value).endswith(' backend.')
def test_no_args(self):
cmd = _get_cmd()
cmd.run(win_id=0)