コード例 #1
0
def main() -> None:

    # All imports moved here to prevent to slow down the import of main
    import warnings

    from controller import TESTING, log, print_and_exit

    if TESTING:
        warnings.filterwarnings("error")
    else:  # pragma: no cover
        warnings.filterwarnings("default")

    from colorama import deinit, init  # type: ignore
    from python_on_whales.utils import DockerException

    from controller.app import Application

    try:
        init()
        Application.load_projectrc()
        controller = Application()
        controller.app()
    except DockerException as e:  # pragma: no cover
        log.critical("Uncatched exception: {}", type(e))
        print_and_exit(str(e))
    deinit()
コード例 #2
0
def exec_command(capfd: Capture, command: str, *asserts: str) -> List[str]:

    # This is needed to reload the LOG dir
    import controller

    reload(controller)

    with capfd.disabled():
        print("\n")
        print("_____________________________________________")
        print(f"rapydo {command}")

    from controller.app import Application
    from controller.project import Project

    ctrl = Application()

    # re-read everytime before invoking a command to cleanup the Configuration class
    Application.load_projectrc()
    Application.project_scaffold = Project()
    Application.gits = {}

    start = datetime.now()
    result = runner.invoke(ctrl.app, command)
    end = datetime.now()

    elapsed_time = (end - start).seconds

    with capfd.disabled():
        print(f"Exit code: {result.exit_code}")
        print(f"Execution time: {elapsed_time} second(s)")
        print(result.stdout)
        print("_____________________________________________")

    captured = capfd.readouterr()

    # Here outputs from inside the containers
    cout = [x for x in captured.out.replace("\r", "").split("\n") if x.strip()]
    # Here output from rapydo
    err = [x for x in captured.err.replace("\r", "").split("\n") if x.strip()]
    # Here output from other sources, e.g. typer errors o docker-compose output
    out = [x for x in result.stdout.replace("\r", "").split("\n") if x.strip()]
    # Here exceptions, e.g. Time is up
    if result.exception:
        exc = [
            x for x in str(result.exception).replace("\r", "").split("\n")
            if x.strip()
        ]
    else:
        exc = []

    with capfd.disabled():
        for e in err:
            print(f"{e}")
        for o in cout:
            print(f">> {o}")
        for o in out:
            print(f"_ {o}")
        if result.exception and str(result.exception) != result.exit_code:
            print("\n!! Exception:")
            print(result.exception)

    for a in asserts:
        # Check if the assert is in any line (also as substring) from out or err
        assert a in out + err or any(a in x for x in out + err + cout + exc)

    return out + err + cout + exc