Esempio n. 1
0
def test_get_cli_parser_func_with_kwargs_raises():
    @cbox.stream()
    def func(**kargs):
        pass

    with pytest.raises(ValueError):
        cliparser.get_cli_parser(func)
Esempio n. 2
0
def test_cli_docstring_help():
    @cbox.stream()
    def nth_item(line, n: int = 0):
        """returns the nth item from each line.

        :param n: the number of item position starting from 0
        """
        return line.split()[n]

    parser = cliparser.get_cli_parser(nth_item, skip_first=1)
    output = parser.format_help()

    expected = 'usage: %s [-h] [-n N]\n\nreturns the nth item from each ' \
               'line.\n\noptional arguments:\n  -h, --help  ' \
               'show this help message and exit\n  -n N        ' \
               'the number of item position starting from 0\n' % parser.prog

    assert output == expected
Esempio n. 3
0
def _execute_cmd(func, argv, input_stream, output_stream, error_stream):
    parser = cliparser.get_cli_parser(func, skip_first=0)
    func_kwargs = cliparser.parse_args(parser, argv=argv)
    return func(**func_kwargs)