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:
parent
b830bb7480
commit
082b840d94
4 changed files with 44 additions and 11 deletions
6
.github/workflows/tests.yml
vendored
6
.github/workflows/tests.yml
vendored
|
|
@ -4,7 +4,7 @@ on: [pull_request, push]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pylint:
|
pylint:
|
||||||
name: "pylint"
|
name: "Source Tests"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: docker.io/library/python:3.7
|
container: docker.io/library/python:3.7
|
||||||
steps:
|
steps:
|
||||||
|
|
@ -12,8 +12,8 @@ jobs:
|
||||||
run: pip install pylint==2.4.1 jsonschema
|
run: pip install pylint==2.4.1 jsonschema
|
||||||
- name: Clone repository
|
- name: Clone repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Run pylint
|
- name: Run Source Tests
|
||||||
run: make test-pylint
|
run: make test-src
|
||||||
|
|
||||||
module:
|
module:
|
||||||
name: "Module Unittests"
|
name: "Module Unittests"
|
||||||
|
|
|
||||||
19
Makefile
19
Makefile
|
|
@ -17,7 +17,6 @@
|
||||||
BUILDDIR ?= .
|
BUILDDIR ?= .
|
||||||
SRCDIR ?= .
|
SRCDIR ?= .
|
||||||
|
|
||||||
PYLINT ?= pylint
|
|
||||||
PYTHON3 ?= python3
|
PYTHON3 ?= python3
|
||||||
RST2MAN ?= rst2man
|
RST2MAN ?= rst2man
|
||||||
|
|
||||||
|
|
@ -80,9 +79,9 @@ help:
|
||||||
@echo " man: Generate all man-pages"
|
@echo " man: Generate all man-pages"
|
||||||
@echo
|
@echo
|
||||||
@echo " test-all: Run all tests"
|
@echo " test-all: Run all tests"
|
||||||
@echo " test-pylint: Run pylint on all sources"
|
|
||||||
@echo " test-module: Run all module unit-tests"
|
@echo " test-module: Run all module unit-tests"
|
||||||
@echo " test-runtime: Run all osbuild pipeline tests"
|
@echo " test-runtime: Run all osbuild pipeline tests"
|
||||||
|
@echo " test-src: Run all osbuild source tests"
|
||||||
|
|
||||||
$(BUILDDIR)/:
|
$(BUILDDIR)/:
|
||||||
mkdir -p "$@"
|
mkdir -p "$@"
|
||||||
|
|
@ -113,7 +112,8 @@ man: $(MANPAGES_TROFF)
|
||||||
#
|
#
|
||||||
# We use the python `unittest` module for all tests. All the test-sources are
|
# 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
|
# 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
|
.PHONY: test-units
|
||||||
|
|
@ -133,13 +133,16 @@ test-runtime:
|
||||||
--top-level-directory=$(SRCDIR) \
|
--top-level-directory=$(SRCDIR) \
|
||||||
-v
|
-v
|
||||||
|
|
||||||
.PHONY: test-pylint
|
.PHONY: test-src
|
||||||
test-pylint:
|
test-src:
|
||||||
@find . -type f -name "*.py" | xargs $(PYLINT)
|
@$(PYTHON3) -m unittest \
|
||||||
@$(PYLINT) runners/* assemblers/* stages/* sources/*
|
discover \
|
||||||
|
--start=$(SRCDIR)/test/src \
|
||||||
|
--top-level-directory=$(SRCDIR) \
|
||||||
|
-v
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test-all: test-pylint
|
test-all:
|
||||||
@$(PYTHON3) -m unittest \
|
@$(PYTHON3) -m unittest \
|
||||||
discover \
|
discover \
|
||||||
--start=$(SRCDIR)/test \
|
--start=$(SRCDIR)/test \
|
||||||
|
|
|
||||||
0
test/src/__init__.py
Normal file
0
test/src/__init__.py
Normal file
30
test/src/test_pylint.py
Normal file
30
test/src/test_pylint.py
Normal 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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue