Example #1
0
def cmd(command: Union[str, List[str]],
        logger: Logger,
        stderr: Optional[int] = None) -> Tuple[int, str]:
    if isinstance(command, str):
        command = shlex.split(command)

    logger.debug("|-> " + " ".join(map(shlex.quote, command)))

    p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=stderr)

    try:
        out = []
        while True:
            line = p.stdout.readline().decode()
            if line == "" and p.poll() is not None:
                break
            if line != "":
                logger.debug("    " + line.rstrip("\n"))
                out.append(line)
    except Exception:
        p.kill()
        raise
    finally:
        p.communicate()
    return p.returncode, "".join(out)
Example #2
0
def cmd(
    command: Union[str, List[str]],
    logger: Logger,
    stderr: Optional[int] = None,
    cwd: Optional[str] = None,
    input: Optional[str] = None,
) -> Tuple[int, str]:
    if isinstance(command, str):
        command = shlex.split(command)

    logger.debug("|-> " + " ".join(map(shlex.quote, command)))

    p = subprocess.Popen(
        command,
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=stderr,
        cwd=cwd,
        universal_newlines=True,
    )
    try:
        out, _ = p.communicate(input)
    except Exception:
        p.kill()
        p.communicate()
        raise
    logger.debug(out)
    return p.returncode, out
Example #3
0
def test_that_logger_with_high_verbosity_level_does_emit_debug_logs(
        logger: Logger, level: Verbosity):
    logger.set_verbosity(level)
    logger.debug("test")

    output = get_logger_output(logger)
    assert "DEBUG" in output
Example #4
0
def test_every_debug_line_is_prefixed(logger: Logger):
    logger.debug("line1\nline2")

    output = get_logger_output(logger)
    assert "DEBUG: line1" in output
    assert "DEBUG: line2" in output
Example #5
0
def test_can_log_debug(logger: Logger):
    logger.debug("test")

    assert "DEBUG: test" in get_logger_output(logger)