Ejemplo n.º 1
0
def test_context_aware_command_valid(_):
    """Check command succeeds when context exists."""
    def test_callback():
        return 10

    command = ContextAwareCommand(name='test-command', callback=test_callback)
    context = Context(command)

    assert command.invoke(context) == 10
Ejemplo n.º 2
0
Archivo: help.py Proyecto: utf/emmet
def recursive_help(cmd, parent=None):
    ctx = Context(cmd, info_name=cmd.name, parent=parent)
    print("```")
    print(cmd.get_help(ctx))
    print("```")
    commands = getattr(cmd, "commands", {})
    for sub in commands.values():
        if isinstance(sub, Group):
            print("## " + sub.name)
        elif isinstance(sub, Command):
            print("### " + sub.name)
        recursive_help(sub, ctx)
Ejemplo n.º 3
0
def invoke_brick_command(monkeypatch,
                         command: str,
                         folder: str,
                         recursive=False) -> Result:
    # pylint: disable import-outside-toplevel

    if recursive:
        assert folder == EXAMPLES_FOLDER

    monkeypatch.chdir(folder)

    # The funky import order and module reloading is due to the monkey patching
    # and the nature of the code running when the modules are imported.

    from brick import lib

    importlib.reload(lib)

    from brick import __main__

    importlib.reload(__main__)

    commands = {
        "build": __main__.build,
        "deploy": __main__.deploy,
        "prepare": __main__.prepare,
        "test": __main__.test,
    }
    command_fn = commands[command]

    parent = Context(command=command_fn)

    if recursive:
        parent.params = {"recursive": True}

    runner = CliRunner()
    result = runner.invoke(command_fn, args=None, parent=parent)

    if result.exception:
        raise result.exception

    assert result.exit_code == 0

    return result