Commit 5de0ff3a authored by Julien Muchembled's avatar Julien Muchembled

New neotestrunner option for code coverage testing

parent 4ef05b9e
[run]
source = neo
omit =
neo/debug.py
neo/scripts/runner.py
neo/tests/*
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
*.pyo *.pyo
*.swp *.swp
*~ *~
/.coverage
/build/ /build/
/dist/ /dist/
/htmlcov/
/mock.py /mock.py
/neoppod.egg-info/ /neoppod.egg-info/
In order to check the test-coverage of Neo, we used the figleaf tool. The usage
(for a complete neo test suite) is :
Download and install figleaf : http://darcs.idyll.org/~t/projects/figleaf/doc/
$ figleaf neotestrunner -u (it will generate a .figleaf file)
$figleaf2html .figleaf (to convert .figleaf file in html pages)
$firefox html/ (to read the results)
Each one of the page contains Neo code, which the following colours :
Green : Executed code during test suite
Red : Unexecuted code
Black : Comments and "unused" lines
In order to check only needed neo file, you should specify the following options:
figleaf -i : ignore python libraries
figleaf2html -f : allows to specify a list of check-needed files
For stats, you can also check the index.html page, which indicated which
percentage of test-coverage.
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
General General
- Review XXX/TODO code tags (CODE) - Review XXX/TODO code tags (CODE)
- Coverage for functional tests (i.e. collect results from subprocesses)
- When all cells are OUT_OF_DATE in backup mode, the one with most data - When all cells are OUT_OF_DATE in backup mode, the one with most data
could become UP_TO_DATE with appropriate backup_tid, so that the cluster could become UP_TO_DATE with appropriate backup_tid, so that the cluster
stays operational. (FEATURE) stays operational. (FEATURE)
......
...@@ -20,11 +20,19 @@ import unittest ...@@ -20,11 +20,19 @@ import unittest
import logging import logging
import time import time
import sys import sys
import neo
import os import os
import re
from collections import Counter, defaultdict from collections import Counter, defaultdict
from cStringIO import StringIO from cStringIO import StringIO
from unittest.runner import _WritelnDecorator from unittest.runner import _WritelnDecorator
if filter(re.compile(r'--coverage$|-\w*c').match, sys.argv[1:]):
# Start coverage as soon as possible.
import coverage
coverage = coverage.Coverage()
coverage.start()
import neo
from neo.tests import getTempDirectory, __dict__ as neo_tests__dict__ from neo.tests import getTempDirectory, __dict__ as neo_tests__dict__
from neo.tests.benchmark import BenchmarkRunner from neo.tests.benchmark import BenchmarkRunner
...@@ -201,6 +209,8 @@ class NeoTestRunner(unittest.TextTestResult): ...@@ -201,6 +209,8 @@ class NeoTestRunner(unittest.TextTestResult):
class TestRunner(BenchmarkRunner): class TestRunner(BenchmarkRunner):
def add_options(self, parser): def add_options(self, parser):
parser.add_option('-c', '--coverage', action='store_true',
help='Enable coverage (not working yet for functional tests)')
parser.add_option('-f', '--functional', action='store_true', parser.add_option('-f', '--functional', action='store_true',
help='Functional tests') help='Functional tests')
parser.add_option('-u', '--unit', action='store_true', parser.add_option('-u', '--unit', action='store_true',
...@@ -238,6 +248,7 @@ Environment Variables: ...@@ -238,6 +248,7 @@ Environment Variables:
functional = options.functional, functional = options.functional,
zodb = options.zodb, zodb = options.zodb,
verbosity = 2 if options.verbose else 1, verbosity = 2 if options.verbose else 1,
coverage = options.coverage,
) )
def start(self): def start(self):
...@@ -254,6 +265,9 @@ Environment Variables: ...@@ -254,6 +265,9 @@ Environment Variables:
except KeyboardInterrupt: except KeyboardInterrupt:
config['mail_to'] = None config['mail_to'] = None
traceback.print_exc() traceback.print_exc()
if config.coverage:
coverage.stop()
coverage.save()
# build report # build report
self._successful = runner.wasSuccessful() self._successful = runner.wasSuccessful()
return runner.buildReport(self.add_status) return runner.buildReport(self.add_status)
......
...@@ -38,7 +38,7 @@ extras_require = { ...@@ -38,7 +38,7 @@ extras_require = {
'storage-mysqldb': ['mysqlclient'], 'storage-mysqldb': ['mysqlclient'],
'storage-importer': zodb_require, 'storage-importer': zodb_require,
} }
extras_require['tests'] = ['zope.testing', 'psutil>=2', extras_require['tests'] = ['coverage', 'zope.testing', 'psutil>=2',
'neoppod[%s]' % ', '.join(extras_require)] 'neoppod[%s]' % ', '.join(extras_require)]
try: try:
......
#!/bin/sh -e
for COV in coverage python-coverage
do type $COV && break
done >/dev/null 2>&1 || exit
$COV html "$@"
# https://bitbucket.org/ned/coveragepy/issues/474/javascript-in-html-captures-all-keys
sed -i "
/assign_shortkeys *=/s/$/return;/
/^ *\.bind('keydown',/s,^,//,
" htmlcov/coverage_html.js
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment