test: integrate pylint into the test infrastructure

Introduce a third test-group called `src` alongside `mod` and `run.
This will contain tests that run against the source code of osbuild.

This initial commit introduces `test/src/test_pylint.py` which will run
the python linter against all our sources.
This commit is contained in:
David Rheinsberg 2020-05-06 11:52:54 +02:00
parent b830bb7480
commit 082b840d94
4 changed files with 44 additions and 11 deletions

View file

@ -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"

View file

@ -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 \

0
test/src/__init__.py Normal file
View file

30
test/src/test_pylint.py Normal file
View file

@ -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)