From 7859df74c4d6eab4f45ab7d2957e7aecd04ee2be Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 8 Jul 2016 19:30:40 +0200 Subject: [PATCH] Add tests for Command.run --- tests/unit/commands/test_cmdutils.py | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/unit/commands/test_cmdutils.py b/tests/unit/commands/test_cmdutils.py index c10a2cac3..56be49b61 100644 --- a/tests/unit/commands/test_cmdutils.py +++ b/tests/unit/commands/test_cmdutils.py @@ -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)