From 34e39bed4e1f3b6c1300a0e23caff93ee321aa1d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 8 Jul 2016 20:31:09 +0200 Subject: [PATCH] Add a test for cmd instance with wrong backend --- qutebrowser/commands/command.py | 1 - tests/unit/commands/test_cmdutils.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index d288118af..c6db96e1c 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -518,7 +518,6 @@ class Command: e.status, e)) return self._count = count - # FIXME add tests for the _check_prerequisites move! self._check_prerequisites(win_id) posargs, kwargs = self._get_call_args(win_id) log.commands.debug('Calling {}'.format( diff --git a/tests/unit/commands/test_cmdutils.py b/tests/unit/commands/test_cmdutils.py index 56be49b61..31735a101 100644 --- a/tests/unit/commands/test_cmdutils.py +++ b/tests/unit/commands/test_cmdutils.py @@ -393,3 +393,22 @@ class TestRun: def test_no_args(self): cmd = _get_cmd() cmd.run(win_id=0) + + def test_instance_unavailable_with_backend(self, fake_args): + """Test what happens when a backend doesn't have an objreg object. + + For example, QtWebEngine doesn't have 'hintmanager' registered. We make + sure the backend checking happens before resolving the instance, so we + display an error instead of crashing. + """ + @cmdutils.register(instance='doesnotexist', + backend=tabmod.Backend.QtWebEngine) + def fun(self): + """Blah.""" + pass + + fake_args.backend = 'webkit' + cmd = cmdutils.cmd_dict['fun'] + with pytest.raises(cmdexc.PrerequisitesError) as excinfo: + cmd.run(win_id=0) + assert str(excinfo.value).endswith(' backend.')