run.sh 1005 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. # basedir is the root of the test directory in the package
  3. basedir="$(realpath -e "$0" | xargs dirname)"
  4. # rootdir is the root of the package
  5. rootdir="$basedir/.."
  6. die()
  7. {
  8. [ -n "$*" ] && echo "$*" >&2
  9. exit 1
  10. }
  11. # $1=interpreter
  12. # $2=test_dir
  13. run_pyunit()
  14. {
  15. local interpreter="$1"
  16. local test_dir="$2"
  17. (
  18. echo
  19. echo "==="
  20. echo "= Running $interpreter..."
  21. echo "==="
  22. export PYTHONPATH="$rootdir/tests:$PYTHONPATH"
  23. cd "$rootdir" || die "Failed to cd to rootdir."
  24. "$interpreter" -m unittest --failfast --buffer --catch "$test_dir" ||\
  25. die "Test failed"
  26. ) || die
  27. }
  28. # $1=test_dir
  29. run_testdir()
  30. {
  31. local test_dir="$1"
  32. unset PYTHONPATH
  33. unset PYTHONSTARTUP
  34. unset PYTHONY2K
  35. unset PYTHONOPTIMIZE
  36. unset PYTHONDEBUG
  37. export PYTHONDONTWRITEBYTECODE=1
  38. unset PYTHONINSPECT
  39. unset PYTHONIOENCODING
  40. unset PYTHONNOUSERSITE
  41. unset PYTHONUNBUFFERED
  42. unset PYTHONVERBOSE
  43. export PYTHONWARNINGS=once
  44. export PYTHONHASHSEED=random
  45. run_pyunit python3 "$test_dir"
  46. }
  47. run_testdir tests