You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

101 lines
2.5 KiB

  1. #!/bin/bash
  2. VERSION=$(grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' kosmorrolib/version.py)
  3. PYTHON_BIN=$(command -v python)
  4. PIP_BIN=$(command -v pip)
  5. if python3 --version > /dev/null; then
  6. PYTHON_BIN=$(command -v python3)
  7. PIP_BIN=$(command -v pip3)
  8. fi
  9. failures=''
  10. function fail() {
  11. failures="$failures\n\n - $1\n\n$2"
  12. }
  13. function run() {
  14. eval "$1" &> /tmp/output.txt
  15. return $?
  16. }
  17. function canRun() {
  18. if [[ "$1" != "" && "$1" != "$ENVIRONMENT" ]]; then
  19. return 1
  20. fi
  21. return 0
  22. }
  23. # Asserts that command $1 has finished with sucess
  24. # $1: the command to run
  25. function assertSuccess() {
  26. if ! canRun "$2"; then
  27. echo -n 'I'
  28. return
  29. fi
  30. run "$1"
  31. returned=$?
  32. if [ $returned -ne 0 ]; then
  33. fail "Failed asserting that command '$1' finishes with success, returned status $returned." "$(cat /tmp/output.txt)"
  34. echo -n 'F'
  35. return
  36. fi
  37. echo -n '.'
  38. }
  39. # Asserts that command $1 has finished with sucess
  40. # $1: the command to run
  41. function assertFailure() {
  42. if ! canRun "$2"; then
  43. echo -n 'I'
  44. return
  45. fi
  46. run "$1"
  47. returned=$?
  48. if [ $returned -eq 0 ]; then
  49. fail "Failed asserting that command '$1' finishes with failure." "$(cat /tmp/output.txt)"
  50. echo -n 'F'
  51. return
  52. fi
  53. echo -n '.'
  54. }
  55. echo
  56. echo "==== RUNNING E2E TESTS ===="
  57. echo
  58. # Create the package and install it
  59. assertSuccess "$PYTHON_BIN setup.py sdist"
  60. assertSuccess "$PIP_BIN install dist/kosmorro-$VERSION.tar.gz" "CI"
  61. assertSuccess kosmorro
  62. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624"
  63. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 27 -m 1 -y 2020"
  64. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 27 -m 1 -y 2020 --timezone=1"
  65. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 27 -m 1 -y 2020 --timezone=-1"
  66. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 27 -m 1 -y 2020 --format=json"
  67. assertFailure "kosmorro --latitude=50.5876 --longitude=3.0624 -d 27 -m 1 -y 2020 --format=pdf"
  68. # Missing dependencies, should fail
  69. assertFailure "kosmorro --latitude=50.5876 --longitude=3.0624 -d 27 -m 1 -y 2020 --format=pdf -o /tmp/document.pdf"
  70. assertSuccess "sudo apt-get install -y texlive" "CI"
  71. assertSuccess "$PIP_BIN install latex" "CI"
  72. # Dependencies installed, should not fail
  73. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 27 -m 1 -y 2020 --format=pdf -o /tmp/document.pdf"
  74. if [ "$failures" != "" ]; then
  75. echo -e "\n$failures"
  76. exit 2
  77. fi
  78. echo -e "\n\n==== TESTS RAN SUCCESSFULLY 👍 ===="