diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b450d58a..0dfe7e3f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,7 @@ on: [pull_request, push] jobs: pylint: - name: "pylint" + name: "Source Tests" runs-on: ubuntu-latest container: docker.io/library/python:3.7 steps: @@ -12,8 +12,8 @@ jobs: run: pip install pylint==2.4.1 jsonschema - name: Clone repository uses: actions/checkout@v2 - - name: Run pylint - run: make test-pylint + - name: Run Source Tests + run: make test-src module: name: "Module Unittests" diff --git a/Makefile b/Makefile index 924896f4..792d7f00 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,6 @@ BUILDDIR ?= . SRCDIR ?= . -PYLINT ?= pylint PYTHON3 ?= python3 RST2MAN ?= rst2man @@ -80,9 +79,9 @@ help: @echo " man: Generate all man-pages" @echo @echo " test-all: Run all tests" - @echo " test-pylint: Run pylint on all sources" @echo " test-module: Run all module unit-tests" @echo " test-runtime: Run all osbuild pipeline tests" + @echo " test-src: Run all osbuild source tests" $(BUILDDIR)/: mkdir -p "$@" @@ -113,7 +112,8 @@ man: $(MANPAGES_TROFF) # # We use the python `unittest` module for all tests. All the test-sources are # located in the `./test/` top-level directory, with `./test/mod/` for module -# unittests and `./test/run/` for osbuild pipeline runtime tests. +# unittests, `./test/run/` for osbuild pipeline runtime tests, and `./test/src/` +# for linters and other tests on the source code. # .PHONY: test-units @@ -133,13 +133,16 @@ test-runtime: --top-level-directory=$(SRCDIR) \ -v -.PHONY: test-pylint -test-pylint: - @find . -type f -name "*.py" | xargs $(PYLINT) - @$(PYLINT) runners/* assemblers/* stages/* sources/* +.PHONY: test-src +test-src: + @$(PYTHON3) -m unittest \ + discover \ + --start=$(SRCDIR)/test/src \ + --top-level-directory=$(SRCDIR) \ + -v .PHONY: test -test-all: test-pylint +test-all: @$(PYTHON3) -m unittest \ discover \ --start=$(SRCDIR)/test \ diff --git a/test/src/__init__.py b/test/src/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/src/test_pylint.py b/test/src/test_pylint.py new file mode 100644 index 00000000..45cbabf0 --- /dev/null +++ b/test/src/test_pylint.py @@ -0,0 +1,30 @@ +# +# Run `pylint` on all python sources. +# + +import subprocess +import unittest + +from .. import test + + +@unittest.skipUnless(test.TestBase.have_test_checkout(), "no test-checkout access") +class TestPylint(test.TestBase, unittest.TestCase): + def test_pylint(self): + # + # Run `pylint` on all python sources. We simply use `find` to locate + # all `*.py` files, and then manually select the reverse-domain named + # modules we have. + # + + path = self.locate_test_checkout() + options = "--errors-only" + + subprocess.run(f"find {path} -type f -name '*.py' | xargs pylint {options}", + shell=True, check=True) + subprocess.run(f"pylint {options}" + + f" {path}/assemblers/*" + + f" {path}/runners/*" + + f" {path}/sources/*" + + f" {path}/stages/*", + shell=True, check=True)