[apycotlib] Correct pyunit and pycoverage behavior by updating coverage_data
Also add pycoverage checker in recipe, run if unit tests don't explode.
--- a/_apycotlib/checkers/python.py Thu Feb 27 10:31:26 2014 +0100
+++ b/_apycotlib/checkers/python.py Fri Apr 25 14:21:23 2014 +0200
@@ -214,6 +214,7 @@
def __init__(self, writer, options=None):
BaseChecker.__init__(self, writer, options)
+ self.coverage_data = None
self._path = None
self.test = None
@@ -602,9 +603,9 @@
def do_check(self, test):
"""run the checker against <path> (usually a directory)"""
self.threshold = float(self.options.get('coverage_threshold')) / 100
- self.coverage_data = self.options.get('coverage_data')
- if not exists(self.coverage_data):
- self.writer.fatal('no coverage information', path=self.coverage_data)
+ coverage_data = self.options.get('coverage_data')
+ if coverage_data == None or not exists(coverage_data):
+ self.writer.fatal('no coverage information', path=coverage_data)
return NODATA
line_rate, branch_rate = self._get_cover_info(test)
# in case of error during coverage reporting
@@ -630,7 +631,7 @@
if coverage is None:
raise Exception('install python-coverage')
covertool = coverage.coverage()
- covertool.use_cache(self.coverage_data)
+ covertool.use_cache(self.options.get('coverage_data'))
covertool.load()
try:
report_file = join(test.project_path(), "coverage.xml")
--- a/recipes.py Thu Feb 27 10:31:26 2014 +0100
+++ b/recipes.py Fri Apr 25 14:21:23 2014 +0200
@@ -16,13 +16,18 @@
full_script = u'''
from apycotlib import registered, narvalactions as na
from checkers.apycot import python # trigger registration
+from apycotlib import ERROR
# `plan`
with na.apycot_environment(plan) as test:
na.install_environment(test)
- checker, status = test.run_checker('pyunit')
if registered('checker', 'pylint'): # pylint may not be available
checker, status = test.run_checker('pylint')
+ checker, status = test.run_checker('pyunit', pycoverage=True)
+ if status > ERROR:
+ checker, status = test.run_checker('pycoverage',
+ coverage_data=checker.coverage_data)
+
'''
def create_full_recipe(session):
return session.create_entity('Recipe', name=u'apycot.recipe.full',
--- a/test/test_functional.py Thu Feb 27 10:31:26 2014 +0100
+++ b/test/test_functional.py Fri Apr 25 14:21:23 2014 +0200
@@ -39,7 +39,7 @@
te = tc.start(self.lgce)
self.commit()
self.run_plan(te)
- exp = {u'pyunit': u'nodata'}
+ exp = {u'pycoverage': u'error', u'pyunit': u'nodata'}
try:
from pylint import checkers as pycheckers
from pylint.lint import PyLinter
@@ -49,7 +49,6 @@
exp['pylint'] = u'error'
except:
pass
-
self.assertDictEqual(exp,
dict((checker.name, checker.status) for checker in te.checkers),
)