Пример #1
0
 def test_storage(self):
     @cmdutils.argument('foo', flag='x')
     @cmdutils.argument('bar', flag='y')
     def fun(foo, bar):
         """Blah."""
     expected = {
         'foo': command.ArgInfo(flag='x'),
         'bar': command.ArgInfo(flag='y')
     }
     assert fun.qute_args == expected
Пример #2
0
    def test_pos_arg_info(self):
        @cmdutils.register()
        @cmdutils.argument('foo', choices=('a', 'b'))
        @cmdutils.argument('bar', choices=('x', 'y'))
        @cmdutils.argument('opt')
        def fun(foo, bar, opt=False):
            """Blah."""

        cmd = objects.commands['fun']
        assert cmd.get_pos_arg_info(0) == command.ArgInfo(choices=('a', 'b'))
        assert cmd.get_pos_arg_info(1) == command.ArgInfo(choices=('x', 'y'))
        with pytest.raises(IndexError):
            cmd.get_pos_arg_info(2)
Пример #3
0
    def __call__(self, func):
        funcname = func.__name__

        if self._argname not in inspect.signature(func).parameters:
            raise ValueError("{} has no argument {}!".format(
                funcname, self._argname))
        if not hasattr(func, 'qute_args'):
            func.qute_args = {}
        elif func.qute_args is None:
            raise ValueError("@cmdutils.argument got called above (after) "
                             "@cmdutils.register for {}!".format(funcname))

        func.qute_args[self._argname] = command.ArgInfo(**self._kwargs)
        return func
Пример #4
0
    def __call__(self, func: typing.Callable) -> typing.Callable:
        funcname = func.__name__

        if self._argname not in inspect.signature(func).parameters:
            raise ValueError("{} has no argument {}!".format(
                funcname, self._argname))
        if not hasattr(func, 'qute_args'):
            func.qute_args = {}  # type: ignore[attr-defined]
        elif func.qute_args is None:  # type: ignore[attr-defined]
            raise ValueError("@cmdutils.argument got called above (after) "
                             "@cmdutils.register for {}!".format(funcname))

        arginfo = command.ArgInfo(**self._kwargs)
        func.qute_args[self._argname] = arginfo  # type: ignore[attr-defined]

        return func