run.sh 974 B

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