예제 #1
0
    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")
예제 #2
0
def get_coverage(datafile, config):
    # basepath = config.topdir
    basepath = py.path.local()
    data = figleaf.read_coverage(str(datafile))
    d = {}
    coverage = figleaf.combine_coverage(d, data)
    for path in coverage.keys():
        if not py.path.local(path).relto(basepath):
            del coverage[path]
    return coverage
예제 #3
0
def main():
    import sys
    import logging
    from optparse import OptionParser
    ###

    usage = "usage: %prog [options] [coverage files ... ]"
    option_parser = OptionParser(usage=usage)

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

    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='Suppress all but error messages')
    
    option_parser.add_option('-D', '--debug', action='store_true',
                             dest='debug',
                             help='Show all debugging messages')

    (options, args) = option_parser.parse_args()

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

    exclude_patterns = []
    if options.exclude_patterns_file:
        exclude_patterns = read_exclude_patterns(exclude_patterns_file)

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

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

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

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

    create_report(coverage, exclude_patterns, files_list)
예제 #4
0
def main():
    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(
        '-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')

    (options, args) = option_parser.parse_args()

    if options.quiet:
        logging.disable(logging.DEBUG)

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

    ### load

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

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

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

    exclude = read_exclude_patterns(options.exclude_patterns_file)
    report_as_cover(coverage, exclude)
예제 #5
0
def main():
	###

	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('-d', '--output-directory', action='store',
				 dest="output_dir",
				 default = "html",
				 help="directory for HTML output")
        option_parser.add_option('-r', '--root', action="store",
                                 dest="root",
                                 default=None,
                                 help="only pay attention to modules under this directory")

	option_parser.add_option('-q', '--quiet', action='store_true', dest='quiet', help='Suppress all but error messages')

	(options, args) = option_parser.parse_args()

	if options.quiet:
		logging.disable(logging.DEBUG)

        if options.root:
                options.root = os.path.abspath(options.root)
                if options.root[-1] != "/":
                        options.root = options.root + "/"

	### load

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

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

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

	### make directory
	prepare_reportdir(options.output_dir)
	report_as_html(coverage, options.output_dir,
                       read_exclude_patterns(options.exclude_patterns_file),
                       options.root)
예제 #6
0
def main():
    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('-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')

    (options, args) = option_parser.parse_args()

    if options.quiet:
        logging.disable(logging.DEBUG)

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

    ### load

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

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

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

    exclude = read_exclude_patterns(options.exclude_patterns_file)
    report_as_cover(coverage, exclude)
예제 #7
0
def main():
    """
    Command-line function to do HTML annotation (red/green).

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

    ###

    usage = "usage: %prog [options] [coverage files ... ]"
    option_parser = OptionParser(usage=usage)

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

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

    option_parser.add_option('-d', '--output-directory', action='store',
                             dest="output_dir",
                             default = "html",
                             help="directory for HTML output")

    option_parser.add_option('-q', '--quiet', action='store_true',
                             dest='quiet',
                             help='Suppress all but error messages')
    
    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:
        logging.disable(logging.WARNING)
        
    if options.debug:
        logger.setLevel(logging.DEBUG)

    ### load/combine

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

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

    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)

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

    ### make directory
    prepare_reportdir(options.output_dir)
    report_as_html(coverage, options.output_dir, exclude, files_list,
                   include_zero=not options.no_zero)

    print 'figleaf: HTML output written to %s' % (options.output_dir,)
예제 #8
0
def main():
    import sys
    import logging
    from optparse import OptionParser
    ###

    usage = "usage: %prog [options] [coverage files ... ]"
    option_parser = OptionParser(usage=usage)

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

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

    option_parser.add_option('-d', '--output-directory', action='store',
                             dest="output_dir",
                             default = "html",
                             help="directory for HTML output")

    option_parser.add_option('-q', '--quiet', action='store_true',
                             dest='quiet',
                             help='Suppress all but error messages')
    
    option_parser.add_option('-D', '--debug', action='store_true',
                             dest='debug',
                             help='Show all debugging messages')

    (options, args) = option_parser.parse_args()

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

    ### load/combine

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

    coverage = {}
    for filename in args:
        logger.debug("loading coverage info from '%s'\n" % (filename,))
        try:
            d = figleaf.read_coverage(filename)
            coverage = figleaf.combine_coverage(coverage, d)
        except IOError:
            logger.error("cannot open filename '%s'\n" % (filename,))

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

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

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

    ### make directory
    prepare_reportdir(options.output_dir)
    report_as_html(coverage, options.output_dir, exclude, files_list)

    print 'figleaf: HTML output written to %s' % (options.output_dir,)
예제 #9
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)