Browse Source

updating run_tests.sh to mimic other openstack projects, pep8, pylint, coverage

tags/2011.3
Joe Heck 8 years ago
parent
commit
6d633a9ec7
5 changed files with 196 additions and 22 deletions
  1. 3
    1
      .gitignore
  2. 42
    0
      .pylintrc
  3. 6
    5
      django-openstack/buildout.cfg
  4. 1
    0
      openstack-dashboard/tools/pip-requires
  5. 144
    16
      run_tests.sh

+ 3
- 1
.gitignore View File

@@ -1,6 +1,8 @@
1 1
 *.pyc
2 2
 *.swp
3
-django-openstack/.coverage
3
+.coverage
4
+coverage.xml
5
+reports
4 6
 django-openstack/.installed.cfg
5 7
 django-openstack/bin
6 8
 django-openstack/develop-eggs/

+ 42
- 0
.pylintrc View File

@@ -0,0 +1,42 @@
1
+# The format of this file isn't really documented; just use --generate-rcfile
2
+[MASTER]
3
+# Add <file or directory> to the black list. It should be a base name, not a
4
+# path. You may set this option multiple times.
5
+ignore=test
6
+
7
+[Messages Control]
8
+# NOTE(justinsb): We might want to have a 2nd strict pylintrc in future
9
+# C0111: Don't require docstrings on every method
10
+# W0511: TODOs in code comments are fine.
11
+# W0142: *args and **kwargs are fine.
12
+# W0622: Redefining id is fine.
13
+disable=C0111,W0511,W0142,W0622
14
+
15
+[Basic]
16
+# Variable names can be 1 to 31 characters long, with lowercase and underscores
17
+variable-rgx=[a-z_][a-z0-9_]{0,30}$
18
+
19
+# Argument names can be 2 to 31 characters long, with lowercase and underscores
20
+argument-rgx=[a-z_][a-z0-9_]{1,30}$
21
+
22
+# Method names should be at least 3 characters long
23
+# and be lowecased with underscores
24
+method-rgx=([a-z_][a-z0-9_]{2,50}|setUp|tearDown)$
25
+
26
+# Module names matching keystone-* are ok (files in bin/)
27
+module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|(keystone-[a-z0-9_-]+))$
28
+
29
+# Don't require docstrings on tests.
30
+no-docstring-rgx=((__.*__)|([tT]est.*)|setUp|tearDown)$
31
+
32
+[Design]
33
+max-public-methods=100
34
+min-public-methods=0
35
+max-args=6
36
+
37
+[Variables]
38
+
39
+# List of additional names supposed to be defined in builtins. Remember that
40
+# you should avoid to define new builtins when possible.
41
+# _ is used by our localization
42
+additional-builtins=_

+ 6
- 5
django-openstack/buildout.cfg View File

@@ -1,5 +1,5 @@
1 1
 [buildout]
2
-parts = 
2
+parts =
3 3
    django
4 4
    launchpad
5 5
    openstack-compute
@@ -23,10 +23,11 @@ webob = 1.0.8
23 23
 # dependencies that are found locally ${buildout:directory}/module
24 24
 # or can be fetched from pypi
25 25
 recipe = zc.recipe.egg
26
-eggs = 
26
+eggs =
27 27
     django-mailer
28 28
     httplib2
29 29
     python-cloudfiles
30
+    coverage
30 31
 interpreter = python
31 32
 
32 33
 
@@ -93,17 +94,17 @@ as_egg = True
93 94
 ## Dependencies fetched from launchpad
94 95
 # launchpad dependencies will appear as subfolders of
95 96
 # ${buildout:directory}/launchpad/
96
-# multiple urls can be specified, format is 
97
+# multiple urls can be specified, format is
97 98
 # branch_url subfolder_name
98 99
 # don't forget to add directory to extra_paths in [django]
99 100
 [launchpad]
100 101
 recipe = bazaarrecipe
101
-urls = 
102
+urls =
102 103
    https://launchpad.net/~hudson-openstack/glance/trunk/ glance
103 104
 
104 105
 
105 106
 ## Dependencies fetch from other bzr locations
106 107
 #[bzrdeps]
107 108
 #recipe = bazaarrecipe
108
-#urls = 
109
+#urls =
109 110
 #   https://launchpad.net/~hudson-openstack/glance/trunk/ glance

+ 1
- 0
openstack-dashboard/tools/pip-requires View File

@@ -15,6 +15,7 @@ PasteDeploy
15 15
 sqlalchemy-migrate
16 16
 eventlet
17 17
 xattr
18
+coverage
18 19
 
19 20
 bzr+https://launchpad.net/glance#egg=glance
20 21
 bzr+https://launchpad.net/quantum#egg=quantum

+ 144
- 16
run_tests.sh View File

@@ -1,18 +1,146 @@
1 1
 #!/bin/bash
2 2
 
3
-cd django-openstack
4
-python bootstrap.py
5
-bin/buildout
6
-bin/test
7
-# get results of the django-openstack tests
8
-OPENSTACK_RESULT=$?
9
-
10
-cd ../openstack-dashboard
11
-python tools/install_venv.py
12
-
13
-cp local/local_settings.py.example local/local_settings.py
14
-tools/with_venv.sh dashboard/manage.py test
15
-# get results of the openstack-dashboard tests
16
-DASHBOARD_RESULT=$?
17
-
18
-exit $(($OPENSTACK_RESULT || $DASHBOARD_RESULT))
3
+function usage {
4
+  echo "Usage: $0 [OPTION]..."
5
+  echo "Run Maestro's test suite(s)"
6
+  echo ""
7
+  echo "  -V, --virtual-env        Always use virtualenv.  Install automatically"
8
+  echo "                           if not present"
9
+  echo "  -N, --no-virtual-env     Don't use virtualenv.  Run tests in local"
10
+  echo "                           environment"
11
+  echo "  -f, --force              Force a clean re-build of the virtual"
12
+  echo "                           environment. Useful when dependencies have"
13
+  echo "                           been added."
14
+  echo "  -p, --pep8               Just run pep8"
15
+  echo "  -y, --pylint             Just run pylint"
16
+  echo "  -h, --help               Print this usage message"
17
+  echo ""
18
+  echo "Note: with no options specified, the script will try to run the tests in"
19
+  echo "  a virtual environment,  If no virtualenv is found, the script will ask"
20
+  echo "  if you would like to create one.  If you prefer to run tests NOT in a"
21
+  echo "  virtual environment, simply pass the -N option."
22
+  exit
23
+}
24
+
25
+function process_option {
26
+  case "$1" in
27
+    -h|--help) usage;;
28
+    -V|--virtual-env) let always_venv=1; let never_venv=0;;
29
+    -N|--no-virtual-env) let always_venv=0; let never_venv=1;;
30
+    -p|--pep8) let just_pep8=1;;
31
+    -y|--pylint) let just_pylint=1;;
32
+    -f|--force) let force=1;;
33
+    *) testargs="$testargs $1"
34
+  esac
35
+}
36
+
37
+function run_pylint {
38
+  echo "Running pylint ..."
39
+  PYLINT_INCLUDE="openstack-dashboard/dashboard django-openstack/django_openstack"
40
+  ${wrapper} pylint --rcfile=.pylintrc -f parseable $PYLINT_INCLUDE > pylint.txt
41
+  CODE=$?
42
+  grep Global -A2 pylint.txt
43
+  if [ $CODE -lt 32 ]
44
+  then
45
+      exit 0
46
+  else
47
+      exit $CODE
48
+  fi
49
+}
50
+
51
+function run_pep8 {
52
+  echo "Running pep8 ..."
53
+  PEP8_EXCLUDE=vcsversion.py
54
+  PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-pep8 --show-source"
55
+  PEP8_INCLUDE="openstack-dashboard/dashboard django-openstack/django_openstack"
56
+  ${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE > pep8.txt
57
+  #perl string strips out the [ and ] characters
58
+  #${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE | perl -ple 's/: ([WE]\d+)/: [$1]/' > pep8.txt
59
+}
60
+
61
+
62
+# DEFAULTS FOR RUN_TESTS.SH
63
+#
64
+venv=openstack-dashboard/.dashboard-venv
65
+django_with_venv=openstack-dashboard/tools/with_venv.sh
66
+dashboard_with_venv=tools/with_venv.sh
67
+always_venv=0
68
+never_venv=0
69
+force=0
70
+testargs=""
71
+django_wrapper=""
72
+dashboard_wrapper=""
73
+just_pep8=0
74
+just_pylint=0
75
+
76
+# PROCESS ARGUMENTS, OVERRIDE DEFAULTS
77
+for arg in "$@"; do
78
+    process_option $arg
79
+done
80
+
81
+if [ $never_venv -eq 0 ]
82
+then
83
+  # Remove the virtual environment if --force used
84
+  if [ $force -eq 1 ]; then
85
+    echo "Cleaning virtualenv..."
86
+    rm -rf ${venv}
87
+  fi
88
+  if [ -e ${venv} ]; then
89
+    django_wrapper="${django_with_venv}"
90
+    dashboard_wrapper="${dashboard_with_venv}"
91
+  else
92
+    if [ $always_venv -eq 1 ]; then
93
+      # Automatically install the virtualenv
94
+      python tools/install_venv.py
95
+      django_wrapper="${django_with_venv}"
96
+      dashboard_wrapper="${dashboard_with_venv}"
97
+    else
98
+      echo -e "No virtual environment found...create one? (Y/n) \c"
99
+      read use_ve
100
+      if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
101
+        # Install the virtualenv and run the test suite in it
102
+        python tools/install_venv.py
103
+        django_wrapper="${django_with_venv}"
104
+        dashboard_wrapper="${dashboard_with_venv}"
105
+      fi
106
+    fi
107
+  fi
108
+fi
109
+
110
+function run_tests {
111
+  echo "Running django-openstack (core django) tests"
112
+  ${django_wrapper} coverage erase
113
+  cd django-openstack
114
+  python bootstrap.py
115
+  bin/buildout
116
+  cd ..
117
+  ${django_wrapper} coverage run django-openstack/bin/test
118
+  # get results of the django-openstack tests
119
+  OPENSTACK_RESULT=$?
120
+
121
+  echo "Running openstack-dashboard (django website) tests"
122
+  cd openstack-dashboard
123
+  cp local/local_settings.py.example local/local_settings.py
124
+  ${dashboard_wrapper} coverage run dashboard/manage.py test
125
+  # get results of the openstack-dashboard tests
126
+  DASHBOARD_RESULT=$?
127
+  cd ..
128
+
129
+  echo "Generating coverage reports"
130
+  ${django_wrapper} coverage combine
131
+  ${django_wrapper} coverage xml --omit='/usr*,setup.py,*egg*'
132
+  ${django_wrapper} coverage html --omit='/usr*,setup.py,*egg*' -d reports
133
+  exit $(($OPENSTACK_RESULT || $DASHBOARD_RESULT))
134
+}
135
+
136
+if [ $just_pep8 -eq 1 ]; then
137
+    run_pep8
138
+    exit $?
139
+fi
140
+
141
+if [ $just_pylint -eq 1 ]; then
142
+    run_pylint
143
+    exit $?
144
+fi
145
+
146
+run_tests || exit

Loading…
Cancel
Save