test_startup.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # skip if python is 3.11 and if path is examples/sqlite_database
  33. if test $(python3 --version | cut -d' ' -f2 | cut -d'.' -f1,2) = "3.11" && test $path = "examples/sqlite_database"; then
  34. continue # until https://github.com/omnilib/aiosqlite/issues/241 is fixed
  35. fi
  36. # skip if python is 3.12 and if path is examples/sqlite_database
  37. if test $(python3 --version | cut -d' ' -f2 | cut -d'.' -f1,2) = "3.12" && test $path = "examples/sqlite_database"; then
  38. continue # until https://github.com/omnilib/aiosqlite/issues/241 is fixed
  39. fi
  40. # skip if path is examples/pyserial
  41. if test $path = "examples/pyserial"; then
  42. continue # because there is no serial port in github actions
  43. fi
  44. # install all requirements except nicegui
  45. if test -f $path/requirements.txt; then
  46. sed '/^nicegui/d' $path/requirements.txt > $path/requirements.tmp.txt || error=1 # remove nicegui from requirements.txt
  47. python3 -m pip install -r $path/requirements.tmp.txt || error=1
  48. rm $path/requirements.tmp.txt || error=1
  49. fi
  50. # run start.sh or main.py
  51. if test -f $path/start.sh; then
  52. check $path/start.sh dev || error=1
  53. elif test -f $path/main.py; then
  54. check $path/main.py || error=1
  55. fi
  56. if pytest -q --collect-only $path >/dev/null 2>&1; then
  57. echo "running tests for $path"
  58. pytest $path || error=1
  59. fi
  60. done
  61. test $error -eq 0