Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

coverage integration, default .coveragerc and .travis.yml ready for …

…coveralls.io
  • Loading branch information...
commit f9315a8cc7f069a0513e6c23d0768065d6aae2d3 1 parent 40918f4
@niphlod niphlod authored
Showing with 46 additions and 13 deletions.
  1. +10 −3 .travis.yml
  2. +30 −10 gluon/widget.py
  3. +6 −0 web2py.py
View
13 .travis.yml
@@ -5,12 +5,16 @@ python:
- '2.6'
- '2.7'
- 'pypy'
+install:
+ - pip install -e . --use-mirrors
env:
- DB=sqlite:memory
- DB=mysql://root:@localhost/test_w2p
- DB=postgres://postgres:@localhost/test_w2p
before_script:
- - pip install unittest2
+ - if [[ $TRAVIS_PYTHON_VERSION != '2.7' ]]; then pip install --use-mirrors unittest2; fi
+ - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install --use-mirrors coverage; fi;
+ - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install --use-mirrors python-coveralls; fi
- if [[ $DB == postgres* ]]; then pip install --use-mirrors psycopg2; fi;
- if [[ $TRAVIS_PYTHON_VERSION == '2.5' ]]; then pip install --use-mirrors pysqlite; fi
- if [[ $DB == mysql* ]]; then mysql -e 'create database test_w2p;'; fi
@@ -25,7 +29,10 @@ matrix:
- python: 'pypy'
env: DB=mysql://root:@localhost/test_w2p
-script: PYTHONPATH=. unit2 -v gluon.tests
-
+script: export COVERAGE_PROCESS_START=gluon/tests/.coveragerc; ./web2py.py --run_system_tests --with_coverage
+after_success:
+ - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then coverage combine; fi
+ - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then coveralls --config_file=gluon/tests/.coveragerc; fi
+
notifications:
email: true
View
40 gluon/widget.py
@@ -62,22 +62,34 @@
logger = logging.getLogger("web2py")
-def run_system_tests():
+def run_system_tests(options):
+ """
+ Runs unittests for gluon.tests
+ """
+ import subprocess
major_version = sys.version_info[0]
minor_version = sys.version_info[1]
- print "minor_version = %r" % minor_version
if major_version == 2:
if minor_version in (5, 6):
- print "Python 2.5 or 2.6"
- ret = os.system("PYTHONPATH=. unit2 -v gluon.tests")
+ sys.stderr.write("Python 2.5 or 2.6\n")
+ ret = subprocess.call(['unit2', '-v', 'gluon.tests'])
elif minor_version in (7,):
- print "Python 2.7"
- ret = os.system("PYTHONPATH=. python -m unittest -v gluon.tests")
+ call_args = [sys.executable, '-m', 'unittest', '-v', 'gluon.tests']
+ if options.with_coverage:
+ try:
+ import coverage
+ coverage_config = os.path.join('gluon', 'tests', '.coveragerc')
+ call_args = ['coverage', 'run', '--rcfile=%s' % coverage_config,
+ '-m', 'unittest', '-v', 'gluon.tests']
+ except:
+ sys.stderr.write('Coverage was not installed, skipping\n')
+ sys.stderr.write("Python 2.7\n")
+ ret = subprocess.call(call_args)
else:
- print "unknown python 2.x version"
+ sys.stderr.write("unknown python 2.x version\n")
ret = 256
else:
- print "Only Python 2.x supported."
+ sys.stderr.write("Only Python 2.x supported.\n")
ret = 256
sys.exit(ret and 1)
@@ -902,7 +914,15 @@ def console():
dest='run_system_tests',
default=False,
help=msg)
-
+
+ msg = ('adds coverage reporting (needs --run_system_tests), '
+ 'python 2.7 and the coverage module installed')
+ parser.add_option('--with_coverage',
+ action='store_true',
+ dest='with_coverage',
+ default=False,
+ help=msg)
+
if '-A' in sys.argv:
k = sys.argv.index('-A')
elif '--args' in sys.argv:
@@ -923,7 +943,7 @@ def console():
options.ips = []
if options.run_system_tests:
- run_system_tests()
+ run_system_tests(options)
if options.quiet:
capture = cStringIO.StringIO()
View
6 web2py.py
@@ -24,4 +24,10 @@
freeze_support()
except:
sys.stderr.write('Sorry, -K only supported for python 2.6-2.7\n')
+ if os.environ.has_key("COVERAGE_PROCESS_START"):
+ try:
+ import coverage
+ coverage.process_startup()
+ except:
+ pass
gluon.widget.start(cron=True)
Please sign in to comment.
Something went wrong with that request. Please try again.