예제 #1
0
def create_report(coverage, exclude_patterns, files_list, extra_files=None):

    line_info = annotate.build_python_coverage_info(coverage, exclude_patterns,
                                                    files_list)

    if extra_files:
        for (otherfile, lines, covered) in extra_files:
            line_info[otherfile] = (lines, covered)

    info_dict = {}
    for filename, (lines, covered) in line_info.items():
        fp = open(filename, 'rU')

        # annotate
        n_covered, n_lines, percent, not_covered \
                = calc_coverage_lines(fp, lines, covered)

        # summarize
        info_dict[filename] = (n_lines, n_covered, percent, not_covered)

    ### print the report
    dirname = os.getcwd()
    write_txt_report(info_dict, remove_prefix=dirname)

    logger.info('reported on %d file(s) total\n' % len(info_dict))
예제 #2
0
def report_as_html(coverage, directory, exclude_patterns, files_list,
                   extra_files=None, include_zero=True):
    """
    Write an HTML report on all of the files, plus a summary.
    """

    ### assemble information.
    
    line_info = annotate.build_python_coverage_info(coverage, exclude_patterns,
                                                    files_list)

    if extra_files:
        for (otherfile, lines, covered) in extra_files:
            line_info[otherfile] = (lines, covered)

    ### now, output.
    info_dict = {}

    for filename, (lines, covered) in line_info.items():
        fp = open(filename, 'rU')

        #
        # ok, we want to annotate this file.  now annotate file ==> html.
        #

        # annotate
        output, n_covered, n_lines, percent = annotate_file_html(fp,
                                                                 lines,
                                                                 covered)

        if not include_zero and n_covered == 0:
            continue

        # summarize
        info_dict[filename] = (n_lines, n_covered, percent)

        # write out the file
        html_outfile = make_html_filename(filename)
        html_outfile = os.path.join(directory, html_outfile)
        html_outfp = open(html_outfile, 'w')
        
        html_outfp.write('source file: <b>%s</b><br>\n' % (filename,))
        html_outfp.write('''

file stats: <b>%d lines, %d executed: %.1f%% covered</b>
<pre>
%s
</pre>

''' % (n_lines, n_covered, percent, "\n".join(output)))
            
        html_outfp.close()

        logger.info('reported on %s' % (filename,))

    ### print a summary, too.
    write_html_summary(info_dict, directory)

    logger.info('reported on %d file(s) total\n' % len(info_dict))
예제 #3
0
def report_as_html(coverage, directory, exclude_patterns, files_list):
    """
    Write an HTML report on all of the files, plus a summary.
    """

    ### now, output.

    keys = coverage.keys()
    info_dict = {}
    for pyfile in filter_files(keys, exclude_patterns, files_list):

        try:
            fp = open(pyfile, 'rU')
            lines = figleaf.get_lines(fp)
        except KeyboardInterrupt:
            raise
        except IOError:
            logger.error('CANNOT OPEN: %s' % (pyfile,))
            continue
        except Exception, e:
            logger.error('ERROR: file %s, exception %s' % (pyfile, str(e)))
            continue

        #
        # ok, we want to annotate this file.  now annotate file ==> html.
        #

        # initialize
        covered = coverage.get(pyfile, set())

        # rewind
        fp.seek(0)

        # annotate
        output, n_covered, n_lines, percent = annotate_file(fp, lines, covered)

        # summarize
        info_dict[pyfile] = (n_lines, n_covered, percent)

        # write out the file
        html_outfile = make_html_filename(pyfile)
        html_outfile = os.path.join(directory, html_outfile)
        html_outfp = open(html_outfile, 'w')
        
        html_outfp.write('source file: <b>%s</b><br>\n' % (pyfile,))
        html_outfp.write('''

file stats: <b>%d lines, %d executed: %.1f%% covered</b>
<pre>
%s
</pre>

''' % (n_lines, n_covered, percent, "\n".join(output)))
            
        html_outfp.close()

        logger.info('reported on %s' % (pyfile,))
예제 #4
0
def report_as_cover(coverage, exclude_patterns, files_list,
                    extra_files=None, include_zero=True):
    """
    Annotate Python & other files with basic coverage information.
    """

    ### assemble information

    # python files
    line_info = annotate.build_python_coverage_info(coverage,
                                                    exclude_patterns,
                                                    files_list)

    # any other files that were passed in
    if extra_files:
        for (otherfile, lines, covered) in extra_files:
            line_info[otherfile] = (lines, covered)

    ### annotate each files & gather summary statistics.

    info_dict = {}
    for filename, (lines, covered) in line_info.items():
        fp = open(filename, 'rU')

        (n_covered, n_lines, output) = annotate_file_cov(fp, lines, covered)

        if not include_zero and n_covered == 0: # include in summary stats?
            continue
        
        try:
            pcnt = n_covered * 100. / n_lines
        except ZeroDivisionError:
            pcnt = 100
        info_dict[filename] = (n_lines, n_covered, pcnt)

        outfile = filename + '.cover'
        try:
            outfp = open(outfile, 'w')
            outfp.write("\n".join(output))
            outfp.write("\n")
            outfp.close()
        except IOError:
            logger.warning('cannot open filename %s' % (outfile,))
            continue

        logger.info('reported on %s' % (outfile,))

    logger.info('reported on %d file(s) total\n' % len(info_dict))
예제 #5
0
def report_as_html(coverage, directory, exclude_patterns, files_list,
                   extra_files=None, include_zero=True):
    """
    Write an HTML report on all of the files, plus a summary.
    """

    ### assemble information.
    
    line_info = annotate.build_python_coverage_info(coverage, exclude_patterns,
                                                    files_list)

    if extra_files:
        for (otherfile, lines, covered) in extra_files:
            line_info[otherfile] = (lines, covered)

    ### now, output.
    info_dict = {}

    for filename, (lines, covered) in line_info.items():
        fp = open(filename, 'rU')

        #
        # ok, we want to annotate this file.  now annotate file ==> html.
        #

        # annotate
        output, n_covered, n_lines, percent = annotate_file_html(fp,
                                                                 lines,
                                                                 covered)

        if not include_zero and n_covered == 0:
            continue

        # summarize
        info_dict[filename] = (n_lines, n_covered, percent)

        # write out the file
        html_outfile = make_html_filename(filename)
        html_outfile = os.path.join(directory, html_outfile)
        html_outfp = open(html_outfile, 'w')
        html_outfp.write('''
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Figleaf code coverage report</title>
    <style type="text/css" media="screen">
        body { padding: 20px; font-family: helvetica, arial, sans-serif; color: #333; }
        table { width: 100%%; border-collapse: collapse; border: none; font-size: 13px; }
        h2 { margin: 0 0 5px 0; font-size: 18px; }
        p { margin: 0; font-size: 14px; }
        a { text-decoration: none; color: #175e99; }
        a:hover { text-decoration: underline; }
        a:visited { color: #8baecc; }
        #summary { margin-bottom: 10px; padding: 10px; background: #eee; border-bottom: 1px solid #ddd; }
        pre { font-size: 11px; line-height: 17px; font-family: 'Monaco', 'Courier New', monospace; }
        pre span strong { padding: 1px 5px; background: #eee; border-right: 1px solid #ddd; font-weight: normal; color: #999; }
        pre span { padding: 1px 0; }
        pre span.covered { background: #e8f6e5; color: #509e42; }
        pre span.uncovered { background: #f8e1d9; color: #d13600; }
    </style>
</head>
<body>
<div id="summary">
    <h2>Source file: <strong>%s</strong></h2>
    <p>File stats: <strong>%d lines, %d executed: %.1f%% covered</strong></p>
</div>
<pre>
%s
</pre>
</body>
</html>
''' % (html_outfile, n_lines, n_covered, percent, "\n".join(output)))
            
        html_outfp.close()

        logger.info('reported on %s' % (filename,))

    ### print a summary, too.
    write_html_summary(info_dict, directory)

    logger.info('reported on %d file(s) total\n' % len(info_dict))
예제 #6
0
file stats: <b>%d lines, %d executed: %.1f%% covered</b>
<pre>
%s
</pre>

''' % (n_lines, n_covered, percent, "\n".join(output)))
            
        html_outfp.close()

        logger.info('reported on %s' % (pyfile,))

    ### print a summary, too.
    write_html_summary(info_dict, directory)

    logger.info('reported on %d file(s) total\n' % len(info_dict))

def prepare_reportdir(dirname):
    "Create output directory."
    try:
        os.mkdir(dirname)
    except OSError:                         # already exists
        pass

def make_html_filename(orig):
    "'escape' original paths into a single filename"

    orig = os.path.abspath(orig)
#    orig = os.path.basename(orig)
    orig = os.path.splitdrive(orig)[1]
    orig = orig.replace('_', '__')
예제 #7
0
def main():
    """
    Command-line function to do a basic 'coverage'-style annotation.

    Setuptools entry-point for figleaf2cov; see setup.py
    """
    
    import sys
    import logging
    from optparse import OptionParser
    
    ###

    option_parser = OptionParser()

    option_parser.add_option('-x', '--exclude-patterns', action="store",
                             dest="exclude_patterns_file",
                             help="file containing regexp patterns to exclude")

    option_parser.add_option('-f', '--files-list', action="store",
                             dest="files_list",
                             help="file containing filenames to report on")

    option_parser.add_option('-q', '--quiet', action='store_true',
                             dest='quiet',
         help="file containig regexp patterns of files to exclude from report")
    
    option_parser.add_option('-D', '--debug', action='store_true',
                             dest='debug',
                             help='Show all debugging messages')

    option_parser.add_option('-z', '--no-zero', action='store_true',
                             dest='no_zero',
                             help='Omit files with zero lines covered.')

    (options, args) = option_parser.parse_args()

    logger.setLevel(logging.INFO)

    if options.quiet:
        logger.setLevel(logging.ERROR)

    if options.debug:
        logger.setLevel(logging.DEBUG)

    ### load

    if not args:
        args = ['.figleaf']

    coverage = {}
    for filename in args:
        logger.info("loading coverage info from '%s'\n" % (filename,))
        d = figleaf.read_coverage(filename)
        coverage = figleaf.combine_coverage(coverage, d)

    files_list = {}
    if options.files_list:
        files_list = annotate.read_files_list(options.files_list)

    if not coverage:
        logger.warning('EXITING -- no coverage info!\n')
        sys.exit(-1)

    exclude = []
    if options.exclude_patterns_file:
        exclude = annotate.read_exclude_patterns(options.exclude_patterns_file)

    report_as_cover(coverage, exclude, files_list,
                    include_zero=not options.no_zero)