|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +declare -A summary |
| 4 | +failures=false |
| 5 | +# get a list of all Python component directories |
| 6 | +# exclude submodules (external component repositories) |
| 7 | +components=$(comm -3 <(ls | grep -P "[qQ]anary-component.*Python-[a-zA-Z]+$") <(git config --file .gitmodules --get-regexp path | awk '{ print $2 }')) |
| 8 | + |
| 9 | +# create a super directory to hold virtual environments (for caching) |
| 10 | + |
| 11 | +if [ -d environments ]; then |
| 12 | + echo "External evironment directory exists" |
| 13 | +else |
| 14 | + if mkdir environments; then |
| 15 | + echo "External environment directory created" |
| 16 | + else |
| 17 | + echo "External environment directory could not be created" |
| 18 | + exit 4 |
| 19 | + fi |
| 20 | +fi |
| 21 | + |
| 22 | +printf "Found Python components:\n\n${components}\n\n" |
| 23 | + |
| 24 | + |
| 25 | +# iterate over components |
| 26 | +for dir in $components |
| 27 | +do |
| 28 | + # iterate over Python components |
| 29 | + name=$(echo ${dir} | tr "[:upper:]" "[:lower:]") |
| 30 | + printf "\n\n===== ${name} =====\n\n" |
| 31 | + |
| 32 | + cd $dir |
| 33 | + # setup virtual environment in external super directory |
| 34 | + envname=../environments/${name} |
| 35 | + python -m venv ${envname} |
| 36 | + if source ${envname}/bin/activate; then |
| 37 | + pip install -r requirements.txt |
| 38 | + else |
| 39 | + echo "Something went wrong trying to install requirements! Exiting ..." |
| 40 | + exit 4 |
| 41 | + fi |
| 42 | + |
| 43 | + # install pytest manually if not included in requirements |
| 44 | + if ! pip show pytest; then |
| 45 | + echo "Installing pytest manually..." |
| 46 | + pip install pytest |
| 47 | + fi |
| 48 | + if ! pip show pytest-env; then |
| 49 | + echo "Installing pytest-env manually..." |
| 50 | + pip install pytest-env |
| 51 | + fi |
| 52 | + |
| 53 | + # run tests |
| 54 | + pytest |
| 55 | + test_status=$? |
| 56 | + # check exit codes |
| 57 | + if [ $test_status -eq 0 ]; then # all tests successful |
| 58 | + summary[${name}]="passed" |
| 59 | + elif [ $test_status -eq 5 ]; then # no tests found |
| 60 | + summary[${name}]="no tests" |
| 61 | + else # tests failed or something else went wrong |
| 62 | + summary[${name}]="failed" |
| 63 | + failures=true |
| 64 | + fi |
| 65 | + |
| 66 | + #pip freeze | xargs pip uninstall -y TODO: disabled because that would mess with caching |
| 67 | + deactivate |
| 68 | + rm -r ${envname} |
| 69 | + |
| 70 | + cd .. |
| 71 | + |
| 72 | +done |
| 73 | + |
| 74 | + |
| 75 | +# print a summary |
| 76 | +printf "\n\n===== SUMMARY =====\n\n" |
| 77 | +for x in "${!summary[@]}"; do printf "%s\t:\t[%s]\n" "$x" "${summary[$x]}"; done | column -s$'\t' -t |
| 78 | +if $failures; then |
| 79 | + printf "\nSome tests failed!\n" |
| 80 | + exit 4 |
| 81 | +else |
| 82 | + printf "\nTests succeeded\n" |
| 83 | +fi |
0 commit comments