Exemplo n.º 1
0
def lint(session: Session):
    """Run all lint tasks"""
    session.notify("black")
    session.notify("flake8")
    session.notify("isort")
    session.notify("mypy")
    session.notify("pylint")
Exemplo n.º 2
0
def dev_test_sim(
    session: nox.Session,
    sim: Optional[str],
    toplevel_lang: Optional[str],
    gpi_interface: Optional[str],
) -> None:
    """Test a development version of cocotb against a simulator."""

    session.env["CFLAGS"] = "-Werror -Wno-deprecated-declarations -g --coverage"
    session.env["COCOTB_LIBRARY_COVERAGE"] = "1"
    session.env["CXXFLAGS"] = "-Werror"
    session.env["LDFLAGS"] = "--coverage"

    session.install(*test_deps, *coverage_deps)
    session.install("-e", ".")

    env = env_vars_for_test(sim, toplevel_lang, gpi_interface)
    config_str = stringify_dict(env)

    # Remove a potentially existing coverage file from a previous run for the
    # same test configuration.
    coverage_file = Path(f".coverage.test.sim-{sim}-{toplevel_lang}-{gpi_interface}")
    with suppress(FileNotFoundError):
        coverage_file.unlink()

    session.log(f"Running 'make test' against a simulator {config_str}")
    session.run("make", "test", external=True, env=env)

    session.log(f"Running simulator-specific tests against a simulator {config_str}")
    session.run(
        "pytest",
        "-v",
        "--cov=cocotb",
        "--cov-branch",
        # Don't display coverage report here
        "--cov-report=",
        "-k",
        "simulator_required",
    )
    Path(".coverage").rename(".coverage.pytest")

    session.log(f"All tests passed with configuration {config_str}!")

    # Combine coverage produced during the test runs, and place it in a file
    # with a name specific to this invocation of dev_test_sim().
    coverage_files = glob.glob("**/.coverage.cocotb", recursive=True)
    if not coverage_files:
        session.error(
            "No coverage files found. Something went wrong during the test execution."
        )
    coverage_files.append(".coverage.pytest")
    session.run("coverage", "combine", "--append", *coverage_files)
    Path(".coverage").rename(coverage_file)

    session.log(f"Stored Python coverage for this test run in {coverage_file}.")

    # Combine coverage from all nox sessions as last step after all sessions
    # have completed.
    session.notify("dev_coverage_combine")
Exemplo n.º 3
0
def docker_qa_compiler(session: nox.Session, version: str) -> None:
    """Build and run the docker container for a specific GCC version."""
    session_id = "docker_qa_build_compiler({})".format(version)
    session.log(f"Notify session {session_id}")
    session.notify(session_id)
    session_id = f"docker_qa_run_compiler({version})"
    session.log(f"Notify session {session_id}")
    session.notify(session_id)
Exemplo n.º 4
0
def build_wheel(session: nox.Session) -> None:
    """Build a wheel."""
    session.install("wheel")
    session.run("python", "setup.py", "sdist", "bdist_wheel")
    dist_cache = f"{session.cache_dir}/dist"
    if os.path.isdir(dist_cache):
        shutil.rmtree(dist_cache)
    shutil.copytree("dist", dist_cache)
    session.notify("check_wheel")
Exemplo n.º 5
0
def dev_test_nosim(session: nox.Session) -> None:
    """Run the simulator-agnostic tests against a cocotb development version."""
    session.install(*test_deps, *coverage_deps)
    session.install("-e", ".")

    # Remove a potentially existing coverage file from a previous run for the
    # same test configuration.
    coverage_file = Path(".coverage.test.pytest")
    with suppress(FileNotFoundError):
        coverage_file.unlink()

    # Run pytest with the default configuration in setup.cfg.
    session.log("Running simulator-agnostic tests with pytest")
    session.run(
        "pytest",
        "-v",
        "--cov=cocotb",
        "--cov-branch",
        # Don't display coverage report here
        "--cov-report=",
        "-k",
        "not simulator_required",
    )

    # Run pytest for files which can only be tested in the source tree, not in
    # the installed binary (otherwise we get an "import file mismatch" error
    # from pytest).
    session.log("Running simulator-agnostic tests in the source tree with pytest")
    pytest_sourcetree = [
        "cocotb/utils.py",
        "cocotb/binary.py",
        "cocotb/types/",
        "cocotb/_sim_versions.py",
    ]
    session.run(
        "pytest",
        "-v",
        "--doctest-modules",
        "--cov=cocotb",
        "--cov-branch",
        # Don't display coverage report here
        "--cov-report=",
        # Append to the .coverage file created in the previous pytest
        # invocation in this session.
        "--cov-append",
        "-k",
        "not simulator_required",
        *pytest_sourcetree,
    )

    session.log("All tests passed!")

    # Rename the .coverage file to make it unique for the
    Path(".coverage").rename(coverage_file)

    session.notify("dev_coverage_combine")
Exemplo n.º 6
0
def dev_coverage_combine(session: nox.Session) -> None:
    """Combine coverage from previous dev_* runs into a .coverage file."""
    session.install(*coverage_report_deps)

    coverage_files = glob.glob("**/.coverage.test.*", recursive=True)
    session.run("coverage", "combine", *coverage_files)

    session.log("Wrote combined coverage database for all tests to '.coverage'.")

    session.notify("dev_coverage_report")
Exemplo n.º 7
0
def test_dist(session: nox.Session) -> None:
    """
    Builds SDist & Wheels then run unit tests on those.
    """
    tmp_dir = Path(session.create_tmp())
    dist = tmp_dir / "dist"
    _build(session, dist)
    python_versions = session.posargs or PYTHON_ALL_VERSIONS
    for version in python_versions:
        session.notify(f"_test_sdist-{version}", [str(dist)])
        session.notify(f"_test_wheel-{version}", [str(dist)])
Exemplo n.º 8
0
def test(session: nox.Session) -> None:
    """
    Runs the test suite against all supported python versions.
    """

    update_seeds(session)
    # Tests require the package to be installed
    session.install(".[test]")

    session.run("pytest", f"--cov={PROJECT_SRC}", f"{PROJECT_TESTS}")
    session.notify("coverage")
Exemplo n.º 9
0
def tests(session: nox.Session) -> None:
    """Run test suite with pytest."""
    session.create_tmp()  # Fixes permission errors on Windows
    session.install("-r", "requirements-test.txt")
    session.install("-e", ".[tox_to_nox]")
    session.run(
        "pytest",
        "--cov=nox",
        "--cov-config",
        "pyproject.toml",
        "--cov-report=",
        *session.posargs,
        env={"COVERAGE_FILE": f".coverage.{session.python}"},
    )
    session.notify("cover")
Exemplo n.º 10
0
def test(session: nox.Session) -> None:
    """
    Runs the test suite against all supported python versions.
    """
    session.install("--upgrade", "pip", "setuptools", "wheel")
    # Tests require the package to be installed
    session.install(".")
    session.install(
        "pytest",
        "pytest-cov",
        "pytest-mock",
        "pytest-httpx",
        "pytest-randomly",
        "freezegun",
    )

    session.run("pytest", f"--cov={PROJECT_SRC}", f"{PROJECT_TESTS}")
    session.notify("coverage")
Exemplo n.º 11
0
def qa(session: nox.Session) -> None:
    """Run the quality tests."""
    session_id = "lint"
    session.log(f"Notify session {session_id}")
    session.notify(session_id, [])
    session_id = "doc"
    session.log(f"Notify session {session_id}")
    session.notify(session_id, [])
    session_id = f"tests_compiler({GCC_VERSION2USE})"
    session.log(f"Notify session {session_id}")
    session.notify(session_id)
Exemplo n.º 12
0
def qa_compiler(session: nox.Session, version: str) -> None:
    """Run the quality tests for a specific GCC version."""
    session_id = "lint"
    session.log(f"Notify session {session_id}")
    session.notify(session_id, [])
    session_id = "doc"
    session.log(f"Notify session {session_id}")
    session.notify(session_id, [])
    session_id = f"tests_compiler({version})"
    session.log(f"Notify session {session_id}")
    session.notify(session_id)
Exemplo n.º 13
0
def docker_qa_compiler_all(session: nox.Session) -> None:
    """Build and run the docker container for the all GCC versions."""
    for version in GCC_VERSIONS:
        session_id = f"docker_qa_compiler({version})"
        session.log(f"Notify session {session_id}")
        session.notify(session_id)
Exemplo n.º 14
0
def checks(session: Session):
    """Run all checks"""
    session.notify("lint")
    session.notify("tests")
Exemplo n.º 15
0
def tests(session: nox.Session) -> None:
    """Run the tests with the default GCC version."""
    session_id = f"tests_compiler({GCC_VERSION2USE})"
    session.log(f"Notify session {session_id}")
    session.notify(session_id)
Exemplo n.º 16
0
def tests_compiler_all(session: nox.Session) -> None:
    """Run the tests with all GCC versions."""
    for version in GCC_VERSIONS:
        session_id = f"tests_compiler({version})"
        session.log(f"Notify session {session_id}")
        session.notify(session_id)
Exemplo n.º 17
0
def docker_qa(session: nox.Session) -> None:
    """Build and run the docker container for the default GCC version."""
    session_id = f"docker_qa_compiler({GCC_VERSION2USE})"
    session.log(f"Notify session {session_id}")
    session.notify(session_id)
Exemplo n.º 18
0
def qa(session: nox.Session) -> None:
    """Run the quality tests for the default GCC version."""
    session_id = f"qa_compiler({GCC_VERSION2USE})"
    session.log(f"Notify session {session_id}")
    session.notify(session_id)