|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | + |
| 4 | +# |
| 5 | +# NAVIGATE TO CORRECT DIRECTORY |
| 6 | +# |
| 7 | + |
| 8 | +# start by going to script dir so all movements |
| 9 | +# from here are relative |
| 10 | +SCRIPT_DIR=`dirname $(realpath "$0")` |
| 11 | +cd $SCRIPT_DIR |
| 12 | + |
| 13 | + |
| 14 | +# |
| 15 | +# RUN TESTS |
| 16 | +# |
| 17 | + |
| 18 | +function unit { |
| 19 | + cd .. |
| 20 | + # enable app virtual environment |
| 21 | + eval "$(direnv export bash)" |
| 22 | + if [ !$PYTHONPATH ]; then |
| 23 | + export PYTHONPATH=$PWD |
| 24 | + fi |
| 25 | + echo "" |
| 26 | + |
| 27 | + echo "" |
| 28 | + echo "Starting unit tests..." |
| 29 | + echo "" |
| 30 | + |
| 31 | + # run unit tests & save exit code |
| 32 | + cd tests |
| 33 | + python -m unittest -b $@ |
| 34 | + # save exit code from tests |
| 35 | + unit_result=$? |
| 36 | + |
| 37 | + # return to scripts directory |
| 38 | + cd $SCRIPT_DIR |
| 39 | + echo "" |
| 40 | +} |
| 41 | + |
| 42 | +function e2e { |
| 43 | + echo "" |
| 44 | + echo "Integration tests not implemented." |
| 45 | + echo "" |
| 46 | + e2e_result=0 |
| 47 | + |
| 48 | + # echo "" |
| 49 | + # echo "Starting integration tests..." |
| 50 | + # echo "" |
| 51 | + # # go to test app dir |
| 52 | + # cd ../integration_tests |
| 53 | + |
| 54 | + # # enable app virtual environment |
| 55 | + # eval "$(direnv export bash)" |
| 56 | + # if [ !$PYTHONPATH ]; then |
| 57 | + # export PYTHONPATH=$PWD |
| 58 | + # fi |
| 59 | + # echo "" |
| 60 | + |
| 61 | + # # run integration tests & save exit code |
| 62 | + # cd tests |
| 63 | + # python -m unittest -b $@ |
| 64 | + # # save exit code from tests |
| 65 | + # e2e_result=$? |
| 66 | + |
| 67 | + # # return to scripts directory |
| 68 | + # cd $SCRIPT_DIR |
| 69 | + # echo "" |
| 70 | +} |
| 71 | + |
| 72 | +# Run unit tests or integration tests if one is specified |
| 73 | +# by passing unit, e2e, or integration as first argument to |
| 74 | +# this script, otherwise run both unit tests & integration |
| 75 | +# tests. |
| 76 | +# Additionally, arguments can be passed to pytest command |
| 77 | +# after specifying unit or integration, but no arguments can |
| 78 | +# be passed if unit or integration isn't specified. |
| 79 | +if [ $# -eq 0 ]; then |
| 80 | + unit |
| 81 | + e2e |
| 82 | + |
| 83 | + if [[ $unit_result != 0 && $e2e_result != 0 ]]; then |
| 84 | + echo "Errors found in both unit & integration tests. See output above." |
| 85 | + exit $unit_result |
| 86 | + elif [[ $unit_result != 0 && $e2e_result == 0 ]]; then |
| 87 | + echo "Errors found in unit. See output above." |
| 88 | + exit $unit_result |
| 89 | + elif [[ $unit_result == 0 && $e2e_result != 0 ]]; then |
| 90 | + echo "Errors found in integration tests. See output above." |
| 91 | + exit $e2e_result |
| 92 | + else |
| 93 | + exit 0 |
| 94 | + fi |
| 95 | + |
| 96 | +elif [ $1 == 'unit' ]; then |
| 97 | + unit ${@:2} |
| 98 | + exit $unit_result |
| 99 | +elif [[ $1 == 'e2e' || $1 == 'integration' ]]; then |
| 100 | + e2e ${@:2} |
| 101 | + exit $e2e_result |
| 102 | +else |
| 103 | + echo "Bad argument given, either specify \`unit\` or \`integration\` tests by giving either word as your first argument to this script, or run both by giving no arguments." |
| 104 | + exit 1 |
| 105 | +fi |
0 commit comments