def generate_coverage(func, path, *args, **kwds): """ Generates code coverage for the function and places the results in the path """ import figleaf from figleaf import annotate_html if os.path.isdir(path): shutil.rmtree(path) # execute the function itself return_vals = func(*args, **kwds) logger.info('generating coverage') coverage = figleaf.get_data().gather_files() annotate_html.prepare_reportdir(path) # skip python modules and the test modules regpatt = lambda patt: re.compile(patt, re.IGNORECASE) patterns = map(regpatt, ['python', 'tests']) annotate_html.report_as_html(coverage, path, exclude_patterns=patterns, files_list='') return return_vals
def generate_coverage_report(self): """ Generates a coverage report in HTML format. Returns the absolute path to the report file. Note that it is generated in a temp directory, so be sure to either move or delete the report. """ if not has_figleaf: return figleaf.stop() tempdir = tempfile.mkdtemp() coverage_file = os.path.join(tempdir, "coverage.txt") logging.info("Writing coverage to %s" % coverage_file) logging.info("coverage info = %r" % figleaf.get_data()) figleaf.write_coverage(coverage_file) coverage = {} d = figleaf.read_coverage(coverage_file) coverage_data = figleaf.combine_coverage(coverage, d) logging.info("Preparing to write report...") report_dir = os.path.join(tempdir, "figleaf-html-report") if not os.path.exists(report_dir): os.makedirs(report_dir) html_report.report_as_html(coverage_data, report_dir, [ re.compile(".*site-packages.*"), re.compile(".*pubsub.*"), re.compile(".*pew/.*") ], {}) logging.info("Writing report to %s" % report_dir) return os.path.join(report_dir, "index.html")
def generate_coverage(func, path, *args, **kwds): """ Generates code coverage for the function and places the results in the path """ import figleaf from figleaf import annotate_html if os.path.isdir(path): shutil.rmtree(path) # execute the function itself return_vals = func(*args, **kwds) logger.info('generating coverage') coverage = figleaf.get_data().gather_files() annotate_html.prepare_reportdir(path) # skip python modules and the test modules regpatt = lambda patt: re.compile(patt, re.IGNORECASE) patterns = map(regpatt, [ 'python', 'tests' ]) annotate_html.report_as_html(coverage, path, exclude_patterns=patterns, files_list='') return return_vals
def generate_coverage(func, path, *args, **kwds): """ Generates code coverage for the function and places the results in the path """ import figleaf from figleaf import annotate_html # Fix for figleaf misbehaving. It is adding a logger at root level # and that will add a handler to all subloggers (ours as well) # needs to be fixed in figleaf import logging root = logging.getLogger() # remove all root handlers for hand in root.handlers: root.removeHandler(hand) if os.path.isdir(path): shutil.rmtree(path) info("collecting coverage information") figleaf.start() # execute the function itself return_vals = func(*args, **kwds) figleaf.stop() info('generating coverage') coverage = figleaf.get_data().gather_files() annotate_html.prepare_reportdir(path) # skip python modules and the test modules regpatt = lambda patt: re.compile(patt, re.IGNORECASE) patterns = map(regpatt, ['python', 'tests', 'django', 'path*']) annotate_html.report_as_html(coverage, path, exclude_patterns=patterns, files_list='') return return_vals
def generate_coverage( func, path, *args, **kwds): """ Generates code coverage for the function and places the results in the path """ import figleaf from figleaf import annotate_html # Fix for figleaf misbehaving. It is adding a logger at root level # and that will add a handler to all subloggers (ours as well) # needs to be fixed in figleaf import logging root = logging.getLogger() # remove all root handlers for hand in root.handlers: root.removeHandler(hand) if os.path.isdir( path ): shutil.rmtree( path ) info( "collecting coverage information" ) figleaf.start() # execute the function itself return_vals = func( *args, **kwds) figleaf.stop() info( 'generating coverage' ) coverage = figleaf.get_data().gather_files() annotate_html.prepare_reportdir( path ) # skip python modules and the test modules regpatt = lambda patt: re.compile( patt, re.IGNORECASE ) patterns = map( regpatt, [ 'python', 'tests', 'django', 'path*' ] ) annotate_html.report_as_html( coverage, path, exclude_patterns=patterns, files_list='') return return_vals
if MODE == 'coverage': # coverage with coverage module, will write to standard output import coverage coverage.erase() coverage.start() import test_all from statlib import stats, pstat suite = test_all.get_suite() unittest.TextTestRunner(verbosity=2).run(suite) coverage.report([stats, pstat]) elif MODE == 'figleaf': # coverage with figleaf, will write to the html directrory import figleaf from figleaf import annotate_html figleaf.start() import test_all from statlib import stats, pstat suite = test_all.get_suite() unittest.TextTestRunner(verbosity=2).run(suite) figleaf.stop() figleaf.write_coverage('.figleaf') data = figleaf.get_data().gather_files() annotate_html.report_as_html(data, 'html', []) else: print 'Invalid mode %s' % mode
if MODE == 'coverage': # coverage with coverage module, will write to standard output import coverage coverage.erase() coverage.start() import test_all from statlib import stats, pstat suite = test_all.get_suite() unittest.TextTestRunner(verbosity=2).run(suite) coverage.report( [ stats, pstat ] ) elif MODE == 'figleaf': # coverage with figleaf, will write to the html directrory import figleaf from figleaf import annotate_html figleaf.start() import test_all from statlib import stats, pstat suite = test_all.get_suite() unittest.TextTestRunner(verbosity=2).run(suite) figleaf.stop() figleaf.write_coverage('.figleaf') data = figleaf.get_data().gather_files() annotate_html.report_as_html( data, 'cover-reports', [] ) else: print 'Invalid mode %s' % mode