Exemplo n.º 1
0
def test_module():
    modules = Modules('cli')
    assert modules['normalization'] is cli
    assert modules.normalization is cli
    for k, v in modules:
        assert modules[k] is v
        assert getattr(modules, k) is v

    keys = modules.keys()
    assert type(keys) is list
    assert 'normalization' in keys
Exemplo n.º 2
0
def argparser():
    name = 'benchmarkstt-tools'
    desc = 'Some additional helpful tools'
    parser = create_parser(prog=name, description=desc)

    subparsers = parser.add_subparsers(dest='subcommand')

    for module, cli in Modules('cli'):
        kwargs = dict()
        if hasattr(cli, 'Formatter'):
            kwargs['formatter_class'] = cli.Formatter
        else:
            kwargs['formatter_class'] = CustomHelpFormatter

        if cli.__doc__ is not None:
            docs = cli.__doc__
        else:
            docs = '?'
            logger.warning('Missing __doc__ for benchmarkstt.%s._cli', module)

        kwargs['description'] = textwrap.dedent(docs)
        subparser = subparsers.add_parser(module,
                                          add_help=False,
                                          allow_abbrev=False,
                                          **kwargs)

        cli.argparser(subparser)
        args_common(subparser)
        args_help(subparser)

    args_help(parser)
    return parser
Exemplo n.º 3
0
def tools_parser():
    name = 'benchmarkstt-tools'
    desc = 'Some additional helpful tools'
    parser = create_parser(prog=name, description=desc)

    subparsers = parser.add_subparsers(dest='subcommand')

    for module, cli in Modules('cli'):
        kwargs = dict()
        if hasattr(cli, 'Formatter'):
            kwargs['formatter_class'] = cli.Formatter
        else:
            kwargs['formatter_class'] = HelpFormatter

        docs = cli.__doc__ if cli.__doc__ is not None else (
            'TODO: add description to benchmarkstt.%s.cli' % (module, ))
        kwargs['description'] = textwrap.dedent(docs)
        subparser = subparsers.add_parser(module,
                                          add_help=False,
                                          allow_abbrev=False,
                                          **kwargs)

        cli.argparser(subparser)
        args_common(subparser)
        args_help(subparser)

    args_help(parser)
    return parser
Exemplo n.º 4
0
def test_hidden_module():
    modules = Modules('cli')

    with pytest.raises(IndexError) as exc:
        modules['benchmark']

    assert 'Module is hidden' in str(exc)
    assert 'benchmark' not in [m for m in modules]
Exemplo n.º 5
0
def test_unknown_module():
    modules = Modules('cli')
    assert 'doesntexist' not in modules

    with pytest.raises(IndexError) as exc:
        modules['doesntexist']

    assert 'Module not found' in str(exc)
Exemplo n.º 6
0
def run():
    determine_log_level()
    parser = argparser()
    args_complete(parser)

    args = parser.parse_args()

    if not args.subcommand:
        parser.error("expects at least 1 argument")

    Modules('cli')[args.subcommand].run(parser, args)
    exit(0)
Exemplo n.º 7
0
def get_methods() -> jsonrpcserver.methods.Methods:
    """
    Returns the available JSON-RPC api methods

    :return: jsonrpcserver.methods.Methods
    """

    methods = MagicMethods()
    methods.register('version', DefaultMethods.version)
    for name, module in Modules('api'):
        methods.load(name, module)

    methods.register('help', DefaultMethods.help(methods.methods))
    return methods.methods