From 2cb277afd71a3597190726a797d4a9585ebfad13 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 4 Dec 2018 16:29:44 +0100 Subject: [PATCH] Fix exception messages in Command The messages weren't updated in ac78039171d6742e2b55aca146a5bab33cd565a1. --- qutebrowser/commands/command.py | 6 +++--- tests/unit/api/test_cmdutils.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 9883447a8..46f92772f 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -157,18 +157,18 @@ class Command: if 'self' in signature.parameters: if self._instance is None: raise TypeError("{} is a class method, but instance was not " - "given!".format(self.name[0])) + "given!".format(self.name)) arg_info = self.get_arg_info(signature.parameters['self']) if arg_info.value is not None: raise TypeError("{}: Can't fill 'self' with value!" .format(self.name)) elif 'self' not in signature.parameters and self._instance is not None: raise TypeError("{} is not a class method, but instance was " - "given!".format(self.name[0])) + "given!".format(self.name)) elif any(param.kind == inspect.Parameter.VAR_KEYWORD for param in signature.parameters.values()): raise TypeError("{}: functions with varkw arguments are not " - "supported!".format(self.name[0])) + "supported!".format(self.name)) def get_arg_info(self, param): """Get an ArgInfo tuple for the given inspect.Parameter.""" diff --git a/tests/unit/api/test_cmdutils.py b/tests/unit/api/test_cmdutils.py index 9f01ea7bb..4116045ae 100644 --- a/tests/unit/api/test_cmdutils.py +++ b/tests/unit/api/test_cmdutils.py @@ -190,6 +190,27 @@ class TestRegister: args, kwargs = cmd._get_call_args(win_id=0) fun(*args, **kwargs) + def test_self_without_instance(self): + with pytest.raises(TypeError, match="fun is a class method, but " + "instance was not given!"): + @cmdutils.register() + def fun(self): + """Blah.""" + + def test_instance_without_self(self): + with pytest.raises(TypeError, match="fun is not a class method, but " + "instance was given!"): + @cmdutils.register(instance='inst') + def fun(): + """Blah.""" + + def test_var_kw(self): + with pytest.raises(TypeError, match="fun: functions with varkw " + "arguments are not supported!"): + @cmdutils.register() + def fun(**kwargs): + """Blah.""" + def test_partial_arg(self): """Test with only some arguments decorated with @cmdutils.argument.""" @cmdutils.register()