示例#1
0
def precommit(session: Session) -> None:
    """Lint using pre-commit.

    Parameters
    ----------
    session: Session
        The Session object.
    """
    args = session.posargs or ["run", "--all-files", "--show-diff-on-failure"]
    session.install(
        "black",
        "darglint",
        "flake8",
        "flake8-bandit",
        "flake8-bugbear",
        "flake8-docstrings",
        "flake8-rst-docstrings",
        "pep8-naming",
        "pre-commit",
        "pre-commit-hooks",
        "reorder-python-imports",
    )
    session.run("pre-commit", *args)
    if args and args[0] == "install":
        activate_virtualenv_in_precommit_hooks(session)
示例#2
0
def contract_tests(session: Session) -> None:
    """Run the contract test suite."""
    args = session.posargs
    session.install(".")
    session.install(
        "pytest",
        "pytest-docker",
        "pytest_mock",
        "pytest-asyncio",
        "requests",
    )
    session.run(
        "pytest",
        "-m contract",
        "-rA",
        *args,
        env={
            "ADMIN_USERNAME": "******",
            "ADMIN_PASSWORD": "******",
            "JWT_EXP_DELTA_SECONDS": "60",
            "DB_USER": "******",
            "DB_PASSWORD": "******",
            "LOGGING_LEVEL": "DEBUG",
        },
    )
示例#3
0
def mypy(session: Session) -> None:
    """Type-check using mypy."""
    args = session.posargs or ["cookietemple", "tests", "docs/conf.py"]
    session.install(".")
    session.install("mypy", "pytest", "types-pkg-resources", "types-requests",
                    "types-attrs")
    session.run("mypy", *args)
示例#4
0
def test(session):
    """Run tests for a specific python version"""
    test_paths = session.posargs or [UNIT_TESTS]
    session.install('.', 'pytest', 'pytest-xdist', 'requests-mock', 'timeout-decorator')

    cmd = f'pytest -rs {XDIST_ARGS}'
    session.run(*cmd.split(' '), *test_paths)
def precommit(session: Session) -> None:
    """Lint using pre-commit."""
    args = session.posargs or [
        "run",
        "--all-files",
        "--hook-stage=manual",
        "--show-diff-on-failure",
    ]
    session.install(
        "black",
        "darglint",
        "flake8",
        "flake8-bandit",
        "flake8-bugbear",
        "flake8-docstrings",
        "flake8-rst-docstrings",
        "isort",
        "pep8-naming",
        "pre-commit",
        "pre-commit-hooks",
        "pyupgrade",
    )
    session.run("pre-commit", *args)
    if args and args[0] == "install":
        activate_virtualenv_in_precommit_hooks(session)
示例#6
0
def linkcheck(session: Session) -> None:
    """Check links."""
    args = session.posargs or [
        "-b", "linkcheck", "-aWTE", "docs", "docs/public/_links"
    ]
    session.install(".", *docs_dependencies)
    session.run("sphinx-build", *args)
示例#7
0
def black(session: nox.Session) -> None:
    """Automatic format code following black codestyle:
    https://github.com/psf/black
    """
    args = session.posargs or locations
    session.install("black")
    session.run("black", *args)
示例#8
0
def safety(session: Session) -> None:
    """Scan dependencies for insecure packages."""
    requirements = session.poetry.export_requirements()
    session.install("safety")
    # Ignore CVE-2020-28476 affecting all versions of tornado
    # https://github.com/tornadoweb/tornado/issues/2981
    session.run("safety", "check", f"--file={requirements}", "--bare", "--ignore=39462")
示例#9
0
def linkcheck(session):
    session.install(".")
    # LinkCheck cn handle rate limits since Sphinx 3.4, which is needed as
    # our doc has to many links to github.
    session.run("pip", "install", "sphinx==3.5.4", silent=True)

    session.run("pip", "install", "-r", "docs/requirements.txt", silent=True)
    session.run("make", "docs-linkcheck", external=True)
示例#10
0
def run_tests(session, sphinx):
    session.install(".")
    session.install(*TEST_DEPENDENCIES)
    session.run("pip", "install", f"sphinx=={sphinx}", silent=True)
    session.run("pip", "install", "-r", "docs/requirements.txt", silent=True)
    session.run("echo", "TEST FINAL PACKAGE LIST")
    session.run("pip", "freeze")
    session.run("make", "test", external=True)
示例#11
0
def xdoctest(session: Session) -> None:
    """Run examples with xdoctest."""
    args = session.posargs or ["all"]
    session.install(".")
    session.install(
        "xdoctest[colors]",
    )
    session.run("python", "-m", "xdoctest", PACKAGE, *args)
示例#12
0
def xml(session: Session) -> None:
    """Build XML version of the docs.

    This can be useful for development, to look at the structure and node types.
    """
    args = ["-b", "xml", "-aWTE", "docs", "docs/public/xml"]
    session.install(".", *docs_dependencies)
    session.run("sphinx-build", *args)
示例#13
0
def mypy(session: Session) -> None:
    """Type-check using mypy."""
    args = session.posargs or ["src", "tests", "docs/conf.py"]
    session.install(".")
    session.install("mypy", "pytest")
    session.run("mypy", *args)
    if not session.posargs:
        session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
示例#14
0
def mypy(session: Session) -> None:
    """Type-check using mypy."""
    args = session.posargs or ["svante"]
    session.install(".")
    session.install("mypy", "pandas-stubs", "types-toml", "pytest")
    session.run("mypy", *args)
    if not session.posargs:
        session.run("mypy", f"--python-executable={sys.executable}",
                    "noxfile.py")
示例#15
0
def tests(session):
    """Run the test suite."""
    session.install(".[data]")
    session.install("coverage[toml]", "pytest", "nox", "nox-poetry")
    try:
        session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
    finally:
        if session.interactive:
            session.notify("coverage")
示例#16
0
def mypy(session: Session) -> None:
    """Type-check using mypy."""
    args = session.posargs or [
        "{{ cookiecutter.project_slug_no_hyphen }}", "tests", "docs/conf.py"
    ]
    session.install(".")
    session.install("mypy", "pytest", "types-pkg-resources", "types-requests",
                    "types-attrs")
    session.run("mypy", *args)
示例#17
0
def tests(session: Session) -> None:
    """Run the test suite."""
    session.install(".")
    session.install("coverage[toml]", "pytest", "pygments")
    try:
        session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
    finally:
        if session.interactive:
            session.notify("coverage", posargs=[])
示例#18
0
def coverage(session: Session) -> None:
    """Produce the coverage report."""
    # Do not use session.posargs unless this is the only session.
    nsessions = len(session._runner.manifest)  # type: ignore[attr-defined]
    has_args = session.posargs and nsessions == 1
    args = session.posargs if has_args else ["report"]
    session.install("coverage[toml]")
    if not has_args and any(Path().glob(".coverage.*")):
        session.run("coverage", "combine")
    session.run("coverage", *args)
示例#19
0
def mypy(session: Session) -> None:
    """Type-check using mypy."""
    args = session.posargs or ["src", "tests", "docs/conf.py"]
    session.install(".")
    session.install("mypy", *TEST_REQUIREMENTS)
    session.run("mypy", *args)
    # TODO: figure out how to type annotate for nox_poetry session
    if not session.posargs:
        session.run("mypy", f"--python-executable={sys.executable}",
                    "noxfile.py")
def coverage(session: Session) -> None:
    """Produce the coverage report."""
    args = session.posargs or ["report"]

    session.install("coverage[toml]")

    if not session.posargs and any(Path().glob(".coverage.*")):
        session.run("coverage", "combine")

    session.run("coverage", *args)
示例#21
0
def lint(session: nox.Session) -> None:
    """Provide lint warnings to help enforce style guide."""
    args = session.posargs or locations
    session.install(
        "flake8",
        "flake8-aaa",
        "flake8-bandit",
        "flake8-black",
        "flake8-bugbear",
    )
    session.run("flake8", *args)
示例#22
0
def typeguard(session: Session) -> None:
    """Runtime type checking using Typeguard."""
    session.install(".")
    session.install(
        "pygments",
        "pytest",
        "pytest-benchmark",
        "pytest-mock",
        "typeguard",
    )
    session.run("pytest", f"--typeguard-packages={PACKAGE}", *session.posargs)
示例#23
0
def typeguard(session: Session) -> None:
    """Runtime type checking using Typeguard.

    Parameters
    ----------
    session: Session
        The Session object.
    """
    session.install(".")
    session.install("pytest", "typeguard", "pygments")
    session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
示例#24
0
def docs_build(session: Session) -> None:
    """Build the documentation."""
    args = session.posargs or ["docs", "docs/_build"]
    session.install(".")
    session.install("sphinx", "sphinx-click", "sphinx-rtd-theme")

    build_dir = Path("docs", "_build")
    if build_dir.exists():
        shutil.rmtree(build_dir)

    session.run("sphinx-build", *args)
示例#25
0
def typeguard(session: Session) -> None:
    """Runtime type checking using Typeguard."""
    session.install(".")
    session.install(
        "pytest",
        "typeguard",
        "pygments",
        "pytest-datadir-mgr",
        "sh",
    )
    session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
示例#26
0
def tests(session: Session) -> None:
    """Run the test suite."""
    # by default, run only the tests that are in the `tests` directory
    args = session.posargs or ["tests"]
    session.install(".")
    session.install("coverage[toml]", "pytest", "pygments")
    try:
        session.run("coverage", "run", "--parallel", "-m", "pytest", *args)
    finally:
        if session.interactive:
            session.notify("coverage")
示例#27
0
def docs(session: Session) -> None:
    """Build and serve the documentation with live reloading on file changes."""
    args = session.posargs or ["--open-browser", "docs", "docs/_build"]
    session.install(".")
    session.install("sphinx", "sphinx-autobuild", "sphinx-click", "furo")

    build_dir = Path("docs", "_build")
    if build_dir.exists():
        shutil.rmtree(build_dir)

    session.run("sphinx-autobuild", *args)
示例#28
0
def safety(session: Session) -> None:
    """Scan dependencies for insecure packages.

    Parameters
    ----------
    session: Session
        The Session object.
    """
    requirements = session.poetry.export_requirements()
    session.install("safety")
    session.run("safety", "check", f"--file={requirements}", "--bare")
示例#29
0
def safety(session: Session) -> None:
    """Scan dependencies for insecure packages."""
    requirements = session.poetry.export_requirements()
    session.install("safety")
    # Ignore some issues in some dev dependencies
    session.run(
        "safety",
        "check",
        f"--file={requirements}",
        "--bare",
    )
示例#30
0
def tests(session: Session) -> None:
    """Run the test suite."""
    session.install(".")
    session.install("coverage[toml]", "pytest", "pytest-mock", "pygments",
                    "ruamel.yaml")
    try:
        session.run("coverage", "run", "--parallel", "-m", "pytest",
                    "--ignore-glob=**/templates/*", *session.posargs)
    finally:
        if session.interactive:
            session.notify("coverage")