Fix exception messages in Command
The messages weren't updated in ac78039171
.
This commit is contained in:
parent
268ad40982
commit
2cb277afd7
@ -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."""
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user