def test_typecheck(self): with taddons.context(loadcore=False) as tctx: cm = command.CommandManager(tctx.master) a = TypeErrAddon() command.Command(cm, "noret", a.noret) with pytest.raises(exceptions.CommandError): command.Command(cm, "invalidret", a.invalidret) with pytest.raises(exceptions.CommandError): assert command.Command(cm, "invalidarg", a.invalidarg)
def test_call(self): o = options.Options() m = master.Master(o, proxy.DummyServer(o)) cm = command.CommandManager(m) a = TAddon() c = command.Command(cm, "cmd.path", a.cmd1) assert c.call(["foo"]) == "ret foo" assert c.signature_help() == "cmd.path str -> str" c = command.Command(cm, "cmd.two", a.cmd2) with pytest.raises(exceptions.CommandError): c.call(["foo"])
def test_call(self): with taddons.context() as tctx: cm = command.CommandManager(tctx.master) a = TAddon() c = command.Command(cm, "cmd.path", a.cmd1) assert c.call(["foo"]) == "ret foo" assert c.signature_help() == "cmd.path str -> str" c = command.Command(cm, "cmd.two", a.cmd2) with pytest.raises(exceptions.CommandError): c.call(["foo"]) c = command.Command(cm, "cmd.three", a.cmd3) assert c.call(["1"]) == 1
def test_varargs(self): with taddons.context() as tctx: cm = command.CommandManager(tctx.master) a = TAddon() c = command.Command(cm, "varargs", a.varargs) assert c.signature_help() == "varargs one *var -> str[]" assert c.call(["one", "two", "three"]) == ["two", "three"]
def test_varargs(self): with taddons.context() as tctx: cm = command.CommandManager(tctx.master) a = TAddon() c = command.Command(cm, "varargs", a.varargs) assert c.signature_help() == "varargs str *str -> [str]" assert c.call(["one", "two", "three"]) == ["two", "three"] with pytest.raises(exceptions.CommandError): c.call(["one", "two", 3])
def command(self, func, *args): """ Invoke a command function with a list of string arguments within a command context, mimicing the actual command environment. """ cmd = command.Command(self.master.commands, "test.command", func) return cmd.call(args)