test_startup.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. run() {
  4. pwd
  5. output=$({ timeout 10 ./"$1" "${@:2}"; } 2>&1)
  6. exitcode=$?
  7. [[ $exitcode -eq 124 ]] && exitcode=0 # exitcode 124 is coming from "timeout command above"
  8. echo "$output" | grep -qE "NiceGUI ready to go|Uvicorn running on http://127.0.0.1:8000" || exitcode=1
  9. echo "$output" | grep -qE "Traceback|Error" && exitcode=1
  10. if [[ $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. max_attempts=3
  20. for attempt in $(seq 1 $max_attempts); do
  21. if run "$(basename "$1")" "${@:2}"; then
  22. echo "OK --------"
  23. popd > /dev/null
  24. return 0
  25. elif [ $attempt -eq $max_attempts ]; then
  26. echo "FAILED after $max_attempts attempts -------"
  27. popd > /dev/null
  28. return 1
  29. else
  30. echo "Attempt $attempt failed. Retrying..."
  31. fi
  32. done
  33. }
  34. check main.py || exit 1
  35. for path in examples/*
  36. do
  37. # Skip examples/sqlite_database for Python 3.11 and 3.12
  38. if [[ $(python3 --version | cut -d' ' -f2 | cut -d'.' -f1,2) =~ ^3.1[12]$ ]] && [[ $path == "examples/sqlite_database" ]]; then
  39. continue # until https://github.com/omnilib/aiosqlite/issues/241 is fixed
  40. fi
  41. # skip if path is examples/pyserial
  42. if test $path = "examples/pyserial"; then
  43. continue # because there is no serial port in github actions
  44. fi
  45. # install all requirements except nicegui
  46. if test -f $path/requirements.txt; then
  47. sed '/^nicegui/d' $path/requirements.txt > $path/requirements.tmp.txt || exit 1 # remove nicegui from requirements.txt
  48. python3 -m pip install -r $path/requirements.tmp.txt || exit 1
  49. rm $path/requirements.tmp.txt || exit 1
  50. fi
  51. # run start.sh or main.py
  52. if test -f $path/start.sh; then
  53. check $path/start.sh dev || exit 1
  54. elif test -f $path/main.py; then
  55. check $path/main.py || exit 1
  56. fi
  57. if pytest -q --collect-only $path >/dev/null 2>&1; then
  58. echo "running tests for $path"
  59. pytest $path || exit 1
  60. fi
  61. done
  62. exit 0