Merge "Allow running unit tests on a single charm" into main
This commit is contained in:
commit
b3b850bd88
173
run_tox.sh
173
run_tox.sh
@ -4,9 +4,39 @@ set -o xtrace
|
|||||||
|
|
||||||
source common.sh
|
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" ]];
|
if [[ $1 == "fmt" ]];
|
||||||
then
|
then
|
||||||
src_path_array=$(ls -d -1 "charms/"**/src)
|
src_path_array=$(ls -d -1 "charms/"**/src)
|
||||||
tst_path_array=$(ls -d -1 "charms/"**/tests)
|
tst_path_array=$(ls -d -1 "charms/"**/tests)
|
||||||
lib_path_array=$(ls -d -1 "charms/"**/lib)
|
lib_path_array=$(ls -d -1 "charms/"**/lib)
|
||||||
|
|
||||||
@ -14,99 +44,104 @@ then
|
|||||||
tst_path="${tst_path_array[*]}"
|
tst_path="${tst_path_array[*]}"
|
||||||
lib_path="${lib_path_array[*]}"
|
lib_path="${lib_path_array[*]}"
|
||||||
|
|
||||||
isort ${src_path} ${tst_path}
|
isort ${src_path} ${tst_path}
|
||||||
black --config pyproject.toml ${src_path} ${tst_path}
|
black --config pyproject.toml ${src_path} ${tst_path}
|
||||||
elif [[ $1 == "pep8" ]];
|
elif [[ $1 == "pep8" ]];
|
||||||
then
|
then
|
||||||
src_path_array=$(ls -d -1 "charms/"**/src)
|
src_path_array=$(ls -d -1 "charms/"**/src)
|
||||||
tst_path_array=$(ls -d -1 "charms/"**/tests)
|
tst_path_array=$(ls -d -1 "charms/"**/tests)
|
||||||
|
|
||||||
src_path="${src_path_array[*]}"
|
src_path="${src_path_array[*]}"
|
||||||
tst_path="${tst_path_array[*]}"
|
tst_path="${tst_path_array[*]}"
|
||||||
|
|
||||||
codespell ${src_path} ${tst_path}
|
codespell ${src_path} ${tst_path}
|
||||||
pflake8 --config pyproject.toml ${src_path} ${tst_path}
|
pflake8 --config pyproject.toml ${src_path} ${tst_path}
|
||||||
isort --check-only --diff ${src_path} ${tst_path}
|
isort --check-only --diff ${src_path} ${tst_path}
|
||||||
black --config pyproject.toml --check --diff ${src_path} ${tst_path}
|
black --config pyproject.toml --check --diff ${src_path} ${tst_path}
|
||||||
elif [[ $1 =~ ^(py3|py310|py311)$ ]];
|
elif [[ $1 =~ ^(py3|py310|py311)$ ]];
|
||||||
then
|
then
|
||||||
# Run py3 on ops-sunbeam
|
|
||||||
pushd ops-sunbeam
|
# Run py3 on ops-sunbeam
|
||||||
|
if should_test_ops_sunbeam $2; then
|
||||||
|
pushd ops-sunbeam
|
||||||
stestr run --slowest || exit 1
|
stestr run --slowest || exit 1
|
||||||
popd
|
popd
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
# Run py3 on all sunbeam charms
|
|
||||||
charms=($(ls charms))
|
|
||||||
for charm in ${charms[@]}; 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" ]];
|
elif [[ $1 == "cover" ]];
|
||||||
then
|
then
|
||||||
coverage erase
|
coverage erase
|
||||||
|
|
||||||
# Run coverage on ops-sunbeam
|
# Run coverage on ops-sunbeam
|
||||||
pushd ops-sunbeam
|
if should_test_ops_sunbeam $2; then
|
||||||
coverage erase
|
pushd ops-sunbeam
|
||||||
|
coverage erase
|
||||||
PYTHON="coverage run --parallel-mode --omit .tox/*" stestr run --slowest || exit 1
|
PYTHON="coverage run --parallel-mode --omit .tox/*" stestr run --slowest || exit 1
|
||||||
coverage combine
|
coverage combine
|
||||||
popd
|
popd
|
||||||
|
fi
|
||||||
|
|
||||||
# Run coverage on all sunbeam charms
|
# Run coverage on sunbeam charms
|
||||||
charms=($(ls charms))
|
for charm in $(get_charms_to_test $2); do
|
||||||
for charm in ${charms[@]}; do
|
push_common_files $charm || exit 1
|
||||||
push_common_files $charm || exit 1
|
pushd charms/$charm
|
||||||
pushd charms/$charm
|
coverage erase
|
||||||
coverage erase
|
PYTHONPATH=./src:./lib:../../ops-sunbeam PYTHON="coverage run --parallel-mode --omit .tox/*,src/templates/*" stestr run --slowest || exit 1
|
||||||
PYTHONPATH=./src:./lib:../../ops-sunbeam PYTHON="coverage run --parallel-mode --omit .tox/*,src/templates/*" stestr run --slowest || exit 1
|
coverage combine
|
||||||
coverage combine
|
popd
|
||||||
popd
|
done
|
||||||
done
|
|
||||||
|
|
||||||
# Prepare coverage report
|
# Prepare coverage report
|
||||||
coverage combine charms/*/.coverage ops-sunbeam/.coverage
|
coverage combine charms/*/.coverage ops-sunbeam/.coverage
|
||||||
coverage html -d cover
|
coverage html -d cover
|
||||||
coverage xml -o cover/coverage.xml
|
coverage xml -o cover/coverage.xml
|
||||||
coverage report
|
coverage report
|
||||||
|
|
||||||
|
# Common files should be deleted after coverage combine
|
||||||
|
for charm in $(get_charms_to_test $2); do
|
||||||
|
pop_common_files $charm || exit 1
|
||||||
|
done
|
||||||
|
|
||||||
# Common files should be deleted after coverage combine
|
|
||||||
for charm in ${charms[@]}; do
|
|
||||||
pop_common_files $charm || exit 1
|
|
||||||
done
|
|
||||||
elif [[ $1 == "build" ]];
|
elif [[ $1 == "build" ]];
|
||||||
then
|
then
|
||||||
if [[ $# != 2 ]];
|
if [[ $# != 2 ]];
|
||||||
then
|
then
|
||||||
echo "Command format: tox -e build <charm>"
|
echo "Command format: tox -e build <charm>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
charm=$2
|
charm=$2
|
||||||
charms=($(ls charms))
|
charms=($(ls charms))
|
||||||
if [[ ! ${charms[@]} =~ $charm ]];
|
if [[ ! ${charms[@]} =~ $charm ]];
|
||||||
then
|
then
|
||||||
echo "Argument should be one of ${charms[@]}";
|
echo "Argument should be one of ${charms[@]}";
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
push_common_files $charm || exit 1
|
push_common_files $charm || exit 1
|
||||||
pushd charms/$charm || exit 1
|
pushd charms/$charm || exit 1
|
||||||
charmcraft -v pack || exit 1
|
charmcraft -v pack || exit 1
|
||||||
if [[ -e "${charm}.charm" ]];
|
if [[ -e "${charm}.charm" ]];
|
||||||
then
|
then
|
||||||
echo "Removing bad downloaded charm maybe?"
|
echo "Removing bad downloaded charm maybe?"
|
||||||
rm "${charm}.charm"
|
rm "${charm}.charm"
|
||||||
fi
|
fi
|
||||||
echo "Renaming charm ${charm}_*.charm to ${charm}.charm"
|
echo "Renaming charm ${charm}_*.charm to ${charm}.charm"
|
||||||
|
|
||||||
mv ${charm}_*.charm ${charm}.charm
|
mv ${charm}_*.charm ${charm}.charm
|
||||||
|
|
||||||
popd || exit 1
|
popd || exit 1
|
||||||
pop_common_files $charm || exit 1
|
pop_common_files $charm || exit 1
|
||||||
else
|
else
|
||||||
echo "tox argument should be one of pep8, py3, py310, py311, cover";
|
echo "tox argument should be one of pep8, py3, py310, py311, cover";
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
8
tox.ini
8
tox.ini
@ -49,22 +49,22 @@ commands =
|
|||||||
deps =
|
deps =
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
commands =
|
commands =
|
||||||
{toxinidir}/run_tox.sh py3
|
{toxinidir}/run_tox.sh py3 {posargs}
|
||||||
|
|
||||||
[testenv:py310]
|
[testenv:py310]
|
||||||
deps = {[testenv:py3]deps}
|
deps = {[testenv:py3]deps}
|
||||||
commands =
|
commands =
|
||||||
{toxinidir}/run_tox.sh py310
|
{toxinidir}/run_tox.sh py310 {posargs}
|
||||||
|
|
||||||
[testenv:py311]
|
[testenv:py311]
|
||||||
deps = {[testenv:py3]deps}
|
deps = {[testenv:py3]deps}
|
||||||
commands =
|
commands =
|
||||||
{toxinidir}/run_tox.sh py311
|
{toxinidir}/run_tox.sh py311 {posargs}
|
||||||
|
|
||||||
[testenv:cover]
|
[testenv:cover]
|
||||||
deps = {[testenv:py3]deps}
|
deps = {[testenv:py3]deps}
|
||||||
commands =
|
commands =
|
||||||
{toxinidir}/run_tox.sh cover
|
{toxinidir}/run_tox.sh cover {posargs}
|
||||||
|
|
||||||
[testenv:build]
|
[testenv:build]
|
||||||
basepython = python3
|
basepython = python3
|
||||||
|
Loading…
Reference in New Issue
Block a user