~glance-coresec/glance/trunk

« back to all changes in this revision

Viewing changes to run_tests.sh

  • Committer: jaypipes at gmail
  • Date: 2010-10-08 20:42:13 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: jaypipes@gmail.com-20101008204213-oy424tgk853jaq6r
First round of cleaning up the unittests. Adds test suite runner, support for virtualenv setup and library dependencies, resolves issues with ImportErrors on cloudfiles, adds pymox/stubout support and splits the backend testing into distinct unittest cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
function usage {
 
4
  echo "Usage: $0 [OPTION]..."
 
5
  echo "Run Glance'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 "  -h, --help               Print this usage message"
 
10
  echo ""
 
11
  echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
 
12
  echo "      If no virtualenv is found, the script will ask if you would like to create one.  If you "
 
13
  echo "      prefer to run tests NOT in a virtual environment, simply pass the -N option."
 
14
  exit
 
15
}
 
16
 
 
17
function process_options {
 
18
  array=$1
 
19
  elements=${#array[@]}
 
20
  for (( x=0;x<$elements;x++)); do
 
21
    process_option ${array[${x}]}
 
22
  done
 
23
}
 
24
 
 
25
function process_option {
 
26
  option=$1
 
27
  case $option in
 
28
    -h|--help) usage;;
 
29
    -V|--virtual-env) let always_venv=1; let never_venv=0;;
 
30
    -N|--no-virtual-env) let always_venv=0; let never_venv=1;;
 
31
  esac
 
32
}
 
33
 
 
34
venv=.glance-venv
 
35
with_venv=tools/with_venv.sh
 
36
always_venv=0
 
37
never_venv=0
 
38
options=("$@")
 
39
 
 
40
process_options $options
 
41
 
 
42
if [ $never_venv -eq 1 ]; then
 
43
  # Just run the test suites in current environment
 
44
  python run_tests.py
 
45
  exit
 
46
fi
 
47
 
 
48
if [ -e ${venv} ]; then
 
49
  ${with_venv} nosetests
 
50
else  
 
51
  if [ $always_venv -eq 1 ]; then
 
52
    # Automatically install the virtualenv
 
53
    python tools/install_venv.py
 
54
  else
 
55
    echo -e "No virtual environment found...create one? (Y/n) \c"
 
56
    read use_ve
 
57
    if [ "x$use_ve" = "xY" ]; then
 
58
      # Install the virtualenv and run the test suite in it
 
59
      python tools/install_venv.py
 
60
    else
 
61
      nosetests
 
62
      exit
 
63
    fi
 
64
  fi
 
65
  ${with_venv} nosetests
 
66
fi