OpenStack Database As A Service (Trove)
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.

run_tests.sh 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/bin/bash
  2. set -eu
  3. function usage {
  4. echo "Usage: $0 [OPTION]..."
  5. echo "Run Trove's test suite(s)"
  6. echo ""
  7. echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
  8. echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
  9. echo " -r, --recreate-db Recreate the test database (deprecated, as this is now the default)."
  10. echo " -n, --no-recreate-db Don't recreate the test database."
  11. echo " -x, --stop Stop running tests after the first error or failure."
  12. echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
  13. echo " -p, --pep8 Just run pep8"
  14. echo " -P, --no-pep8 Don't run pep8"
  15. echo " -c, --coverage Generate coverage report"
  16. echo " -h, --help Print this usage message"
  17. echo " --hide-elapsed Don't print the elapsed time for each test along with slow test list"
  18. echo ""
  19. echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
  20. echo " If no virtualenv is found, the script will ask if you would like to create one. If you "
  21. echo " prefer to run tests NOT in a virtual environment, simply pass the -N option."
  22. exit
  23. }
  24. function process_option {
  25. case "$1" in
  26. -h|--help) usage;;
  27. -V|--virtual-env) always_venv=1; never_venv=0;;
  28. -N|--no-virtual-env) always_venv=0; never_venv=1;;
  29. -r|--recreate-db) recreate_db=1;;
  30. -n|--no-recreate-db) recreate_db=0;;
  31. -f|--force) force=1;;
  32. -p|--pep8) just_pep8=1;;
  33. -P|--no-pep8) no_pep8=1;;
  34. -c|--coverage) coverage=1;;
  35. -*) noseopts="$noseopts $1";;
  36. *) noseargs="$noseargs $1"
  37. esac
  38. }
  39. venv=.venv
  40. with_venv=tools/with_venv.sh
  41. always_venv=0
  42. never_venv=0
  43. force=0
  44. noseargs=
  45. noseopts=
  46. wrapper=""
  47. just_pep8=0
  48. no_pep8=0
  49. coverage=0
  50. recreate_db=1
  51. for arg in "$@"; do
  52. process_option $arg
  53. done
  54. # If enabled, tell nose to collect coverage data
  55. if [ $coverage -eq 1 ]; then
  56. noseopts="$noseopts --with-coverage --cover-package=trove"
  57. fi
  58. function run_tests {
  59. # Just run the test suites in current environment
  60. ${wrapper} $NOSETESTS 2> run_tests.log
  61. # If we get some short import error right away, print the error log directly
  62. RESULT=$?
  63. if [ "$RESULT" -ne "0" ];
  64. then
  65. ERRSIZE=`wc -l run_tests.log | awk '{print \$1}'`
  66. if [ "$ERRSIZE" -lt "40" ];
  67. then
  68. cat run_tests.log
  69. fi
  70. fi
  71. return $RESULT
  72. }
  73. function run_pep8 {
  74. echo "Running pep8 ..."
  75. # Just run PEP8 in current environment
  76. #
  77. # NOTE(sirp): W602 (deprecated 3-arg raise) is being ignored for the
  78. # following reasons:
  79. #
  80. # 1. It's needed to preserve traceback information when re-raising
  81. # exceptions; this is needed b/c Eventlet will clear exceptions when
  82. # switching contexts.
  83. #
  84. # 2. There doesn't appear to be an alternative, "pep8-tool" compatible way of doing this
  85. # in Python 2 (in Python 3 `with_traceback` could be used).
  86. #
  87. # 3. Can find no corroborating evidence that this is deprecated in Python 2
  88. # other than what the PEP8 tool claims. It is deprecated in Python 3, so,
  89. # perhaps the mistake was thinking that the deprecation applied to Python 2
  90. # as well.
  91. ${wrapper} flake8
  92. }
  93. NOSETESTS="python run_tests.py $noseopts $noseargs"
  94. if [ $never_venv -eq 0 ]
  95. then
  96. # Remove the virtual environment if --force used
  97. if [ $force -eq 1 ]; then
  98. echo "Cleaning virtualenv..."
  99. rm -rf ${venv}
  100. fi
  101. if [ -e ${venv} ]; then
  102. wrapper="${with_venv}"
  103. else
  104. if [ $always_venv -eq 1 ]; then
  105. # Automatically install the virtualenv
  106. python tools/install_venv.py
  107. wrapper="${with_venv}"
  108. else
  109. echo -e "No virtual environment found...create one? (Y/n) \c"
  110. read use_ve
  111. if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
  112. # Install the virtualenv and run the test suite in it
  113. python tools/install_venv.py
  114. wrapper=${with_venv}
  115. fi
  116. fi
  117. fi
  118. fi
  119. # Delete old coverage data from previous runs
  120. if [ $coverage -eq 1 ]; then
  121. ${wrapper} coverage erase
  122. fi
  123. if [ $just_pep8 -eq 1 ]; then
  124. run_pep8
  125. exit
  126. fi
  127. if [ $recreate_db -eq 1 ]; then
  128. rm -f tests.sqlite
  129. fi
  130. run_tests
  131. # NOTE(sirp): we only want to run pep8 when we're running the full-test suite,
  132. # not when we're running tests individually. To handle this, we need to
  133. # distinguish between options (noseopts), which begin with a '-', and
  134. # arguments (noseargs).
  135. if [ -z "$noseargs" ]; then
  136. if [ $no_pep8 -eq 0 ]; then
  137. run_pep8
  138. fi
  139. fi
  140. if [ $coverage -eq 1 ]; then
  141. echo "Generating coverage report in covhtml/"
  142. ${wrapper} coverage html -d covhtml -i
  143. fi