Merge "Allow running unit tests on a single charm" into main

This commit is contained in:
Zuul 2024-01-30 09:26:50 +00:00 committed by Gerrit Code Review
commit b3b850bd88
2 changed files with 109 additions and 74 deletions

View File

@ -4,6 +4,36 @@ set -o xtrace
source common.sh
# print checks to test based on the first arg
get_charms_to_test() {
local charm=$1
if [[ -z "$charm" ]]; then
ls charms
elif [[ "$charm" = "ops-sunbeam" ]]; then
# ops-sunbeam is treated differently, so don't process it here
false
else
local charms=($(ls charms))
if [[ ! ${charms[@]} =~ $charm ]];
then
echo "Argument should be one of ${charms[@]}" >&2
exit 1
fi
echo "$charm"
fi
}
should_test_ops_sunbeam() {
# ops-sunbeam should be tested
# if no arguments (test everything)
# or ops-sunbeam is specified.
if [[ -z "$1" || "$1" = "ops-sunbeam" ]]; then
true
else
false
fi
}
if [[ $1 == "fmt" ]];
then
src_path_array=$(ls -d -1 "charms/"**/src)
@ -30,34 +60,38 @@ then
black --config pyproject.toml --check --diff ${src_path} ${tst_path}
elif [[ $1 =~ ^(py3|py310|py311)$ ]];
then
# Run py3 on ops-sunbeam
if should_test_ops_sunbeam $2; then
pushd ops-sunbeam
stestr run --slowest || exit 1
popd
fi
# Run py3 on all sunbeam charms
charms=($(ls charms))
for charm in ${charms[@]}; do
# Run py3 on sunbeam charms
for charm in $(get_charms_to_test $2); do
push_common_files $charm || exit 1
pushd charms/$charm
PYTHONPATH=./src:./lib stestr run --slowest || exit 1
popd
pop_common_files $charm || exit 1
done
elif [[ $1 == "cover" ]];
then
coverage erase
# Run coverage on ops-sunbeam
if should_test_ops_sunbeam $2; then
pushd ops-sunbeam
coverage erase
PYTHON="coverage run --parallel-mode --omit .tox/*" stestr run --slowest || exit 1
coverage combine
popd
fi
# Run coverage on all sunbeam charms
charms=($(ls charms))
for charm in ${charms[@]}; do
# Run coverage on sunbeam charms
for charm in $(get_charms_to_test $2); do
push_common_files $charm || exit 1
pushd charms/$charm
coverage erase
@ -73,9 +107,10 @@ then
coverage report
# Common files should be deleted after coverage combine
for charm in ${charms[@]}; do
for charm in $(get_charms_to_test $2); do
pop_common_files $charm || exit 1
done
elif [[ $1 == "build" ]];
then
if [[ $# != 2 ]];

View File

@ -49,22 +49,22 @@ commands =
deps =
-r{toxinidir}/test-requirements.txt
commands =
{toxinidir}/run_tox.sh py3
{toxinidir}/run_tox.sh py3 {posargs}
[testenv:py310]
deps = {[testenv:py3]deps}
commands =
{toxinidir}/run_tox.sh py310
{toxinidir}/run_tox.sh py310 {posargs}
[testenv:py311]
deps = {[testenv:py3]deps}
commands =
{toxinidir}/run_tox.sh py311
{toxinidir}/run_tox.sh py311 {posargs}
[testenv:cover]
deps = {[testenv:py3]deps}
commands =
{toxinidir}/run_tox.sh cover
{toxinidir}/run_tox.sh cover {posargs}
[testenv:build]
basepython = python3