Exemple #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))
Exemple #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))
Exemple #3
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))
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))