~ubuntu-branches/ubuntu/saucy/keystone/saucy-proposed

« back to all changes in this revision

Viewing changes to run_tests.sh

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-08-23 10:18:22 UTC
  • Revision ID: james.westby@ubuntu.com-20110823101822-enve6zceb3lqhuvj
Tags: upstream-1.0~d4~20110823.1078
ImportĀ upstreamĀ versionĀ 1.0~d4~20110823.1078

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 Keystone'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 "  -f, --force              Force a clean re-build of the virtual environment. Useful when dependencies have been added."
 
10
  echo "  --unittests-only         Run unit tests only, exclude functional tests."
 
11
  echo "  -p, --pep8               Just run pep8"
 
12
  echo "  -l, --pylint             Just run pylint"
 
13
  echo "  -h, --help               Print this usage message"
 
14
  echo ""
 
15
  echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
 
16
  echo "      If no virtualenv is found, the script will ask if you would like to create one.  If you "
 
17
  echo "      prefer to run tests NOT in a virtual environment, simply pass the -N option."
 
18
  exit
 
19
}
 
20
 
 
21
function process_option {
 
22
  case "$1" in
 
23
    -h|--help) usage;;
 
24
    -V|--virtual-env) let always_venv=1; let never_venv=0;;
 
25
    -N|--no-virtual-env) let always_venv=0; let never_venv=1;;
 
26
    -p|--pep8) let just_pep8=1; let never_venv=1;;
 
27
    -l|--pylint) let just_pylint=1; let never_venv=0;;
 
28
    -f|--force) let force=1;;
 
29
    --unittests-only) noseargs="$noseargs --exclude-dir=keystone/tests/functional --exclude-dir=keystone/tests/system";;
 
30
    *) noseargs="$noseargs $1"
 
31
  esac
 
32
}
 
33
 
 
34
venv=.keystone-venv
 
35
with_venv=tools/with_venv.sh
 
36
always_venv=0
 
37
never_venv=0
 
38
force=0
 
39
noseargs=
 
40
wrapper=""
 
41
just_pep8=0
 
42
just_pylint=0
 
43
 
 
44
for arg in "$@"; do
 
45
  process_option $arg
 
46
done
 
47
 
 
48
function run_tests {
 
49
  # Just run the test suites in current environment
 
50
  ${wrapper} $NOSETESTS
 
51
}
 
52
 
 
53
function run_pep8 {
 
54
  echo "Running pep8 ..."
 
55
  PEP8_EXCLUDE="vcsversion.py"
 
56
  PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-pep8 --show-source"
 
57
  PEP8_INCLUDE="bin/k* keystone examples tools setup.py run_tests.py"
 
58
  pep8 $PEP8_OPTIONS $PEP8_INCLUDE
 
59
}
 
60
 
 
61
function run_pylint {
 
62
  echo "Running pylint ..."
 
63
  PYLINT_OPTIONS="--rcfile=.pylintrc --output-format=parseable"
 
64
  PYLINT_INCLUDE="keystone"
 
65
  echo "Pylint messages count: "
 
66
  pylint $PYLINT_OPTIONS $PYLINT_INCLUDE | grep 'keystone/' | wc -l
 
67
  echo "Run 'pylint $PYLINT_OPTIONS $PYLINT_INCLUDE' for a full report."
 
68
}
 
69
 
 
70
 
 
71
NOSETESTS="python run_tests.py $noseargs"
 
72
 
 
73
if [ $never_venv -eq 0 ]
 
74
then
 
75
  # Remove the virtual environment if --force used
 
76
  if [ $force -eq 1 ]; then
 
77
    echo "Cleaning virtualenv..."
 
78
    rm -rf ${venv}
 
79
  fi
 
80
  if [ -e ${venv} ]; then
 
81
    wrapper="${with_venv}"
 
82
  else
 
83
    if [ $always_venv -eq 1 ]; then
 
84
      # Automatically install the virtualenv
 
85
      python tools/install_venv.py
 
86
      wrapper="${with_venv}"
 
87
    else
 
88
      echo -e "No virtual environment found...create one? (Y/n) \c"
 
89
      read use_ve
 
90
      if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
 
91
        # Install the virtualenv and run the test suite in it
 
92
        python tools/install_venv.py
 
93
                    wrapper=${with_venv}
 
94
      fi
 
95
    fi
 
96
  fi
 
97
fi
 
98
 
 
99
if [ $just_pep8 -eq 1 ]; then
 
100
    run_pep8
 
101
    exit
 
102
fi
 
103
 
 
104
if [ $just_pylint -eq 1 ]; then
 
105
    run_pylint
 
106
    exit
 
107
fi
 
108
 
 
109
run_tests || exit
 
110
 
 
111
#if [ -z "$noseargs" ]; then
 
112
#  run_pep8
 
113
#fi