tox: add tox

`tox` is a standard testing tool for Python projects, this allows you to
test locally with all your installed Python version with the following
command:

`tox -m test -p all`

To run the tests in parallel for all supported Python versions.

To run linters or type analysis:

```
tox -m lint -p all
tox -m type -p all
```

This commit *also* disables the `import-error` warning from `pylint`,
not all Python versions have the system-installed Python libraries
available and they can't be fetched from PyPI.

Some linters have been added and the general order linters run in has
been changed. This allows for quicker test failure when running
`tox -m lint`. As a consequence the `test_pylint` test has been removed
as it's role can now be fulfilled by `tox`.

Other assorted linter fixes due to newer versions:
- use a str.join method (`consider-using-join`)
- fix various (newer) mypy and pylint issues
- comments starting with `#` and no space due to `autopep8`

This also changes our CI to use the new `tox` setup and on top of that
pins the versions of linters used. This might move into separate
requirements.txt files later on to allow for easier updating of those
dependencies.
This commit is contained in:
Simon de Vlieger 2023-03-20 11:54:35 +01:00
parent a7b75bea3b
commit d60690ce46
23 changed files with 193 additions and 184 deletions

67
tox.ini Normal file
View file

@ -0,0 +1,67 @@
[tox]
env_list =
py{36,37,38,39,310,311}
lint
type
labels =
test = py{36,37,38,39,310,311}
lint = ruff, isort, autopep8, pylint
type = mypy
[testenv]
description = "run osbuild unit tests"
deps =
pytest
jsonschema
mako
iniparse
pyyaml
setenv =
LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/* stages/*
TYPEABLES = osbuild
passenv =
TEST_CATEGORY
commands =
bash -c 'python -m pytest --pyargs --rootdir=. {env:TEST_CATEGORY}'
allowlist_externals =
bash
[testenv:ruff]
deps =
ruff==0.0.263
commands =
bash -c 'python -m ruff {env:LINTABLES}'
[testenv:isort]
deps =
isort==5.12.0
commands =
bash -c 'python -m isort --check --diff {env:LINTABLES}'
[testenv:autopep8]
deps =
autopep8==2.0.2
commands =
bash -c 'python -m autopep8 -r --diff --exit-code {env:LINTABLES}'
[testenv:pylint]
deps =
pylint==2.17.3
commands =
bash -c 'python -m pylint {env:LINTABLES}'
[testenv:mypy]
deps =
mypy==1.2.0
commands =
bash -c 'python -m mypy {env:TYPEABLES}'