test_startup.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. run() {
  3. pwd
  4. output=$({ timeout 10 ./$1 $2; } 2>&1)
  5. exitcode=$?
  6. test $exitcode -eq 124 && exitcode=0 # exitcode 124 is comming from "timeout command above"
  7. echo $output | grep -e "NiceGUI ready to go" -e "Uvicorn running on http://127.0.0.1:8000" > /dev/null || exitcode=1
  8. echo $output | grep "Traceback" > /dev/null && exitcode=1
  9. echo $output | grep "Error" > /dev/null && exitcode=1
  10. if test $exitcode -ne 0; then
  11. echo "wrong exit code $exitcode. Output was:"
  12. echo $output
  13. return 1
  14. fi
  15. }
  16. check() {
  17. echo checking $1 ----------
  18. pushd $(dirname "$1") >/dev/null
  19. if run $(basename "$1") $2; then
  20. echo "ok --------"
  21. popd > /dev/null
  22. else
  23. echo "failed -------"
  24. popd > /dev/null
  25. return 1
  26. fi
  27. }
  28. error=0
  29. check main.py || error=1
  30. for path in examples/*
  31. do
  32. if [[ $path == *"chat_with_ai"* ]] && [[ $(python3 --version) == *"3.7"* ]]; then
  33. # NOTE: chat_with_ai example is not working with python 3.7
  34. continue
  35. fi
  36. if test -f $path/start.sh; then
  37. check $path/start.sh dev || error=1
  38. elif test -f $path/main.py; then
  39. check $path/main.py || error=1
  40. fi
  41. done
  42. test $error -eq 0