From c3ee4d9f82904b7229f406126082a3461b6d6400 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sun, 13 Aug 2023 17:23:59 +0000 Subject: [PATCH] add noxfile to run tests and mockbuilds --- .builds/main.yml | 6 ++-- .yamllint.yaml | 5 +++ noxfile.py | 83 +++++++++++++++++++++++++++++++++++++++++++ ruff.toml | 39 ++++++++++++++++++++ tests/test_forge.py | 2 -- tests/test_vectors.py | 2 +- tests/vectors.yaml | 2 +- 7 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 .yamllint.yaml create mode 100644 noxfile.py create mode 100644 ruff.toml diff --git a/.builds/main.yml b/.builds/main.yml index 35d2e76..0e527b4 100644 --- a/.builds/main.yml +++ b/.builds/main.yml @@ -5,7 +5,7 @@ image: fedora/rawhide packages: - - pipx + - nox - python3-pytest - python3-pyyaml - redhat-rpm-config @@ -16,6 +16,6 @@ tasks: - pytest: | cd forge-srpm-macros pytest -vv - - reuse: | + - lint: | cd forge-srpm-macros - pipx run reuse lint + nox -e lint diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..8958e8e --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,5 @@ +# Copyright (C) 2023 Maxwell G +# SPDX-License-Identifier: GPL-1.0-or-later +line-length: + max: 90 + level: warning diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..51a0445 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,83 @@ +# Copyright (C) 2023 Maxwell G +# SPDX-License-Identifier: GPL-1.0-or-later + +from __future__ import annotations + +from collections.abc import Sequence +from pathlib import Path + +import nox + +LINT_SESSIONS = ("static", "formatters", "typing") +PY_FILES = ("tests", "noxfile.py") +YAML_FILES = (".builds", "tests/vectors.yaml") + +nox.options.sessions = (*LINT_SESSIONS, "test") + + +@nox.session(venv_backend="none") +def lint(session: nox.Session): + """ + Run python linters + """ + for notify in LINT_SESSIONS: + session.notify(notify) + + +@nox.session +def static(session: nox.Session): + session.install("ruff", "reuse", "yamllint") + session.run("ruff", *session.posargs, *PY_FILES) + session.run("yamllint", *YAML_FILES) + session.run("reuse", "lint") + + +@nox.session +def formatters(session: nox.Session, posargs: Sequence[str] | None = None): + if posargs is None: + posargs = session.posargs + session.install("black", "isort") + session.run("black", *posargs, *PY_FILES) + session.run("isort", *posargs, *PY_FILES) + + +@nox.session +def formatters_check(session: nox.Session): + formatters(session, ["--check"]) + + +@nox.session +def typing(session: nox.Session): + session.install("mypy", "nox", "pytest", "pyyaml", "types-pyyaml") + session.run("mypy", *session.posargs, *PY_FILES) + + +@nox.session +def test(session: nox.Session): + session.install("pytest", "pyyaml") + session.run("pytest", *session.posargs) + + +@nox.session +def srpm(session: nox.Session, posargs: Sequence[str] | None = None): + session.install("fclogr") + posargs = posargs or session.posargs + session.run("fclogr", "--debug", "dev-srpm", *posargs) + + +@nox.session +def mockbuild(session: nox.Session): + tmp = Path(session.create_tmp()) + srpm(session, ("-o", str(tmp), "--keep")) + spec_path = tmp / "fedrq.spec" + margs = [ + # fmt: off + "mock", + "--spec", str(spec_path), + "--source", str(tmp), + *session.posargs, + # fmt: on + ] + if not session.interactive: + margs.append("--verbose") + session.run(*margs, external=True) diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..7fc82d0 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,39 @@ +# Copyright (C) 2023 Maxwell G +# SPDX-License-Identifier: GPL-1.0-or-later +select = [ + # flake8-builtins + "A", + # flake8-bugbear + "B", + # pycodestyle + "E", + "W", + # pyflakes + "F", + # unused-arguments + "ARG", + # flake8-simplify + "SIM", + # pylint + "PL", +] +ignore = [ + # function-call-in-default-argument + # There's nothing wrong with calling a function that returns an immutable + # object + "B008", + # `zip()` without an explicit `strict=` parameter. + # `zip()` only has that parameter in py310+ + "B905", + # Allow overwriting loop variable + "PLW2901", + # Magic value used in comparison + # This is a good rule, but the checker is a bit overzealous. + "PLR2004", + # Too many arguments to function call + "PLR0913", +] + +[extend-per-file-ignores] +"tests/*" = ["ARG"] + diff --git a/tests/test_forge.py b/tests/test_forge.py index c1478ee..520e3ba 100644 --- a/tests/test_forge.py +++ b/tests/test_forge.py @@ -2,8 +2,6 @@ # # SPDX-License-Identifier: GPL-1.0-or-later -import os - import pytest diff --git a/tests/test_vectors.py b/tests/test_vectors.py index 1525d0a..23023ce 100644 --- a/tests/test_vectors.py +++ b/tests/test_vectors.py @@ -19,7 +19,7 @@ SENTINEL = "*-*" * 20 @dataclasses.dataclass() class _TestVector: # Test id - id: str + id: str # noqa: A003 # Longer description description: str | None = None # Macros to %define diff --git a/tests/vectors.yaml b/tests/vectors.yaml index e70c45e..c1c74eb 100644 --- a/tests/vectors.yaml +++ b/tests/vectors.yaml @@ -4,7 +4,7 @@ # This file contains a large set of test vectors for the forge macros. # Please use real projects and real versions so the resulting URLs can be # checked for accuracy. - +--- _anchors: zeroidx: &zeroidx - version