Skip to content
GitLab
Explore
Sign in
Commits on Source (2)
Use pytest and update coverage configs
· 9dec33df
Dom Sekotill
authored
Aug 13, 2024
9dec33df
Tidy CI config and use templates for some jobs
· 18ede1e5
Dom Sekotill
authored
Aug 13, 2024
18ede1e5
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
18ede1e5
...
...
@@ -12,7 +12,5 @@ build/
dist/
# unit-testing, coverage, etc.
/*.xml
/*.json
.coverage*
.noseids
/*_cache/
/results/
.gitlab-ci.yml
View file @
18ede1e5
stages
:
-
test
-
acceptance
-
build
-
publish
include
:
-
project
:
dom/project-templates
file
:
/pipeline-templates/pre-commit.yml
-
project
:
dom/project-templates
ref
:
tmp
file
:
/pipeline-templates/python-package.yml
image
:
python:3.8
variables
:
PIP_CACHE_DIR
:
$CI_PROJECT_DIR/.cache/pip
cache
:
key
:
all
paths
:
-
.cache/
-
.eggs/
.python
:
image
:
python:3.12
variables
:
PIP_CACHE_DIR
:
$CI_PROJECT_DIR/cache/pkg
PIP_NO_COMPILE
:
"
true"
PIP_NO_CLEAN
:
"
true"
cache
:
key
:
$CI_JOB_IMAGE
paths
:
[
cache
]
# Unit Tests
.unittest
:
stage
:
test
image
:
python:$PY_VERSION
before_script
:
-
pip install -e .[test] nose2
-
pip install -e .[test] coverage pytest
-
mkdir results
script
:
-
nose2 -v -c setup.cfg
-
coverage run -m pytest -v --junit-xml=results/junit.xml
after_script
:
-
mv .coverage .coverage.$PY_VERSION
-
mv .unittest.xml .unittest.$PY_VERSION.xml
coverage
:
'
/^TOTAL.*
([0-9.]+\%)$/'
-
mv results results.$PY_VERSION
artifacts
:
when
:
always
paths
:
-
.noseids
-
.coverage.*
-
.unittest.$PY_VERSION.xml
-
results.$PY_VERSION
reports
:
junit
:
.unittest
.$PY_VERSION.xml
junit
:
results
.$PY_VERSION
/junit
.xml
u
nit
t
est
:3.8
:
extends
:
.unittest
U
nit
T
est
s (Py 3.10)
:
extends
:
[
.python
,
.unittest
]
variables
:
PY_VERSION
:
'
3.
8
'
PY_VERSION
:
'
3.
10
'
u
nit
t
est
:3.9
:
extends
:
.unittest
U
nit
T
est
s (Py 3.11)
:
extends
:
[
.python
,
.unittest
]
variables
:
PY_VERSION
:
'
3.
9
'
PY_VERSION
:
'
3.
11
'
u
nit
t
est
:
3.1
0
:
extends
:
.unittest
U
nit
T
est
s (Py
3.1
2)
:
extends
:
[
.python
,
.unittest
]
variables
:
PY_VERSION
:
'
3.1
0-rc
'
PY_VERSION
:
'
3.1
2
'
publish:unittests
:
stage
:
publish
Publish Unit Tests
:
stage
:
deploy
extends
:
[
.python
]
when
:
always
dependencies
:
&unittests
-
u
nit
t
est
:3.8
-
u
nit
t
est
:3.9
-
u
nit
t
est
:
3.1
0
-
U
nit
T
est
s (Py 3.10)
-
U
nit
T
est
s (Py 3.11)
-
U
nit
T
est
s (Py
3.1
2)
needs
:
*unittests
script
:
-
pip install --upgrade junit2html
-
mkdir -p unittest
-
python util/junit_merge.py
.unittest.*
.xml >
.
unit
test
.xml
-
junit2html
.
unit
test
.xml unittest/index.html
-
pip install --upgrade junit2html
-
mkdir -p unittest
-
python util/junit_merge.py
results.*/junit
.xml >
j
unit.xml
-
junit2html
j
unit.xml unittest/index.html
artifacts
:
when
:
always
paths
:
-
.unittest.xml
-
unittest
-
junit.xml
-
unittest
reports
:
junit
:
junit.xml
# Aggregate Coverage
coverage
:
stage
:
acceptance
Aggregate Coverage
:
stage
:
test
extends
:
[
.python
]
when
:
always
dependencies
:
*unittests
needs
:
*unittests
...
...
@@ -88,90 +87,20 @@ coverage:
artifacts
:
when
:
always
paths
:
-
.coverage
-
results
publish:coverage
:
stage
:
publish
Publish Coverage
:
stage
:
deploy
extends
:
[
.python
]
when
:
always
dependencies
:
[
coverage
]
needs
:
[
coverage
]
script
:
-
pip install --upgrade coverage
-
coverage html --fail-under=0 -d coverage
-
coverage xml --fail-under=0 -o
coverage
/coverage.xml
-
coverage html --fail-under=0 -d
results/
coverage
.db
-
coverage xml --fail-under=0 -o
results
/coverage.xml
artifacts
:
when
:
always
paths
:
-
coverage
# Quality Assurance
Code Analysis
:
stage
:
test
variables
:
FROM_REF
:
$CI_DEFAULT_BRANCH
rules
:
-
if
:
$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables
:
FROM_REF
:
$CI_COMMIT_BEFORE_SHA
-
when
:
always
before_script
:
-
pip install pre-commit
script
:
-
git fetch $CI_REPOSITORY_URL $FROM_REF:FROM_REF -f
-
pre-commit run
--hook-stage=commit
--from-ref=FROM_REF
--to-ref=${CI_COMMIT_SHA}
Commit Graph Analysis
:
stage
:
test
variables
:
FROM_REF
:
$CI_DEFAULT_BRANCH
rules
:
-
if
:
$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables
:
FROM_REF
:
$CI_COMMIT_BEFORE_SHA
-
if
:
$CI_PIPELINE_TRIGGERED == "merge_request_event"
before_script
:
-
pip install pre-commit
script
:
-
pre-commit run
--hook-stage=push
--from-ref=FROM_REF
--to-ref=${CI_COMMIT_SHA}
# Package publishing
Check Tag
:
stage
:
test
rules
:
-
if
:
$CI_COMMIT_TAG =~ /^v[0-9]/
script
:
-
test `./setup.py --version` == ${CI_COMMIT_TAG#v}
Build Packages
:
stage
:
build
script
:
-
./setup.py bdist_wheel sdist
artifacts
:
paths
:
-
dist
Upload Packages
:
stage
:
publish
rules
:
-
if
:
$CI_COMMIT_TAG =~ /^v[0-9]/
dependencies
:
-
Build Packages
script
:
-
pip install twine
-
TWINE_PASSWORD=$CI_JOB_TOKEN
TWINE_USERNAME=gitlab-ci-token
twine upload
--verbose
--non-interactive
--repository-url $CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/pypi
dist/*
-
results
pyproject.toml
View file @
18ede1e5
...
...
@@ -16,3 +16,37 @@ implicit_reexport = true
strict
=
true
warn_unreachable
=
true
warn_unused_configs
=
true
[tool.coverage.run]
data_file
=
"results/coverage.db"
branch
=
true
source
=
[
"wpa_supplicant"
]
[tool.coverage.report]
precision
=
2
skip_empty
=
true
exclude_lines
=
[
"pragma: no-cover"
,
"if .*
\\
b__name__
\\
b"
,
"if .*
\\
bTYPE_CHECKING
\\
b"
,
"class .*(.*
\\
bProtocol
\\
b.*):"
,
"def __repr__"
,
"@overload"
,
"@(abc
\\
.)abstractmethod"
,
]
partial_branches
=
[
"pragma: no-branch"
,
"if .*
\\
b__debug__
\\
b"
,
]
[tool.coverage.json]
output
=
"results/coverage.json"
show_contexts
=
true
[tool.coverage.xml]
output
=
"results/coverage.xml"
[tool.coverage.html]
directory
=
"results/coverage"
show_contexts
=
true
setup.cfg
View file @
18ede1e5
...
...
@@ -45,50 +45,6 @@ test =
nose2
[coverage_plugin]
trio
[unittest]
start-dir
=
tests/unit
verbose
=
True
plugins
=
nose2.plugins.junitxml
nose2.plugins.testid
[coverage]
always-on
=
True
coverage
=
wpa_supplicant
coverage-report
=
term
[coverage:run]
branch
=
True
[coverage:report]
fail_under
=
80
precision
=
2
show_missing
=
True
omit
=
**/__main__.py
exclude_lines
=
pragma:
no
cover
if
__name__
=
= .__main__.:
def
__repr__
__version__
=
@(.*\.)?abstract((static|class)?method|property)
except
ImportError:\s*(...|pass)
[coverage:xml]
output
=
.coverage.xml
[coverage:html]
directory
=
.coverage.html.d
[junit-xml]
always-on
=
True
path
=
.unittest.xml
[testid]
always-on
=
True
[log-capture]
always-on
=
True
[isort]
force_single_line
=
true
...
...