Beispiel #1
0
def _run_nosetests():
    click.echo("Running unit tests ... ", nl=False)
    nose_bin = os.path.join(aeriscloud_path, "venv/bin/nosetests")

    errors = 0
    try:
        python(nose_bin, "-v", "--with-id", module_path(), _err_to_out=True, _ok_code=[0])
        click.echo("[%s]" % click.style("OK", fg="green"))
    except ErrorReturnCode as e:
        click.echo("[%s]\n" % click.style("FAIL", fg="red"))

        for line in e.stdout.split("\n")[:-2]:
            if line.startswith("#"):
                print(line)
                (id, name, test_file, ellipsis, res) = line.rstrip().split(" ")

                if res == "ok":
                    res = click.style(res, fg="green", bold=True)
                elif res == "FAIL":
                    res = click.style(res, fg="red", bold=True)

                line = " ".join(
                    [click.style(id, bold=True, fg="yellow"), click.style(name, fg="blue"), test_file, ellipsis, res]
                )
            elif line.startswith("FAIL:"):
                (_, name, test_file) = line.split(" ")

                line = " ".join(
                    [click.style("FAIL", bold=True, fg="red") + ":", click.style(name, fg="blue"), test_file]
                )

            click.echo("  " + line)
            errors += 1
    return errors
Beispiel #2
0
def _run_flake8():
    click.echo("Running flake8 on codebase ... ", nl=False)
    flake8_bin = os.path.join(aeriscloud_path, "venv/bin/flake8")

    keys = ["file", "row", "col", "message"]
    reports = [
        dict(zip(keys, line.strip().split(":")))
        for line in python(flake8_bin, "--max-complexity", 11, module_path(), _ok_code=[0, 1])
    ]

    errors = 0
    last_file = None
    if reports:
        click.echo("[%s]\n" % click.style("FAIL", fg="red"))

        for report in reports:
            report_file = report["file"][len(module_path()) + 1 :]
            if report_file != last_file:
                click.secho("  Errors in file: %s" % report_file, fg="blue", bold=True)
                last_file = report_file

            click.echo(
                "    line %s char %s: %s"
                % (
                    click.style(report["row"], fg="green"),
                    click.style(report["col"], fg="green"),
                    click.style(report["message"], fg="red"),
                )
            )
            errors += 1

        click.echo("")
    else:
        click.echo("[%s]" % click.style("OK", fg="green"))

    return errors