From f9315a8cc7f069a0513e6c23d0768065d6aae2d3 Mon Sep 17 00:00:00 2001 From: niphlod Date: Mon, 15 Apr 2013 21:50:36 +0200 Subject: [PATCH] coverage integration, default .coveragerc and .travis.yml ready for coveralls.io --- .travis.yml | 13 ++++++++++--- gluon/widget.py | 40 ++++++++++++++++++++++++++++++---------- web2py.py | 6 ++++++ 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index c733016f..859a9a27 100644 --- a/.travis.yml +++ b/.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 diff --git a/gluon/widget.py b/gluon/widget.py index 63f6621c..6e356abb 100644 --- a/gluon/widget.py +++ b/gluon/widget.py @@ -62,22 +62,34 @@ if not sys.version[:3] in ['2.4', '2.5', '2.6', '2.7']: 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() diff --git a/web2py.py b/web2py.py index 1c6ac8ae..59c02f9d 100755 --- a/web2py.py +++ b/web2py.py @@ -24,4 +24,10 @@ if __name__ == '__main__': 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)