From: Brian Warner Date: Thu, 4 Jan 2007 05:23:25 +0000 (-0700) Subject: modify figleaf2html to show module names instead of .py filenames, also add a --root... X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~409 X-Git-Url: https://git.rkrishnan.org/pf/reliability?a=commitdiff_plain;h=8a78065f1694a985c30f68b9e91355c38ef0410a;p=tahoe-lafs%2Ftahoe-lafs.git modify figleaf2html to show module names instead of .py filenames, also add a --root argument to restrict coverage to a specific parent directory --- diff --git a/Makefile b/Makefile index 5f0d4927..fe42dd10 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ test-figleaf: $(PP) trial --reporter=bwverbose-figleaf $(TEST) figleaf-output: - $(PP) python misc/figleaf2html -d coverage-html -x src/allmydata/test/figleaf.excludes + $(PP) python misc/figleaf2html -d coverage-html -r `python ./builddir.py` @echo "now point your browser at coverage-html/index.html" # after doing test-figleaf and figleaf-output, point your browser at # coverage-html/index.html diff --git a/src/allmydata/util/figleaf_htmlizer.py b/src/allmydata/util/figleaf_htmlizer.py index 63a7960d..0aac077e 100644 --- a/src/allmydata/util/figleaf_htmlizer.py +++ b/src/allmydata/util/figleaf_htmlizer.py @@ -26,7 +26,7 @@ def read_exclude_patterns(f): return exclude_patterns -def report_as_html(coverage, directory, exclude_patterns=[], ): +def report_as_html(coverage, directory, exclude_patterns=[], root=None): ### now, output. keys = coverage.keys() @@ -45,6 +45,16 @@ def report_as_html(coverage, directory, exclude_patterns=[], ): if k.endswith('figleaf.py'): continue + display_filename = k + if root: + if not k.startswith(root): + continue + display_filename = k[len(root):] + assert not display_filename.startswith("/") + assert display_filename.endswith(".py") + display_filename = display_filename[:-3] # trim .py + display_filename = display_filename.replace("/", ".") + if not k.startswith("/"): continue @@ -100,9 +110,9 @@ def report_as_html(coverage, directory, exclude_patterns=[], ): pcnt = n_covered * 100. / n_lines except ZeroDivisionError: pcnt = 100 - info_dict[k] = (n_lines, n_covered, pcnt) + info_dict[k] = (n_lines, n_covered, pcnt, display_filename) - html_outfile = make_html_filename(os.path.basename(k)) + html_outfile = make_html_filename(display_filename) html_outfp = open(os.path.join(directory, html_outfile), 'w') html_outfp.write('source file: %s
\n' % (k,)) html_outfp.write('file stats: %d lines, %d executed: %.1f%% covered\n' % (n_lines, n_covered, pcnt)) @@ -141,10 +151,10 @@ def report_as_html(coverage, directory, exclude_patterns=[], ): index_fp.write('\n') index_fp.write('\n' % (summary_lines, summary_cover, summary_pcnt,)) - for filename, (n_lines, n_covered, percent_covered,) in info_dict_items: - html_outfile = make_html_filename(os.path.basename(filename)) + for filename, (n_lines, n_covered, percent_covered, display_filename) in info_dict_items: + html_outfile = make_html_filename(display_filename) - index_fp.write('\n' % (html_outfile, filename, n_lines, n_covered, percent_covered,)) + index_fp.write('\n' % (html_outfile, display_filename, n_lines, n_covered, percent_covered,)) index_fp.write('
Filename# lines# covered% covered
totals:%d%d%.1f%%
%s%d%d%.1f
%s%d%d%.1f
\n') index_fp.close() @@ -159,8 +169,7 @@ def prepare_reportdir(dirname='html'): pass def make_html_filename(orig): - orig = os.path.splitdrive(orig)[1].replace('_', '__') - return orig.replace(os.path.sep, '_') + '.html' + return orig + ".html" def escape_html(s): s = s.replace("&", "&") @@ -175,13 +184,17 @@ 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") + 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') @@ -190,6 +203,11 @@ def main(): 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: @@ -207,5 +225,7 @@ def main(): ### make directory prepare_reportdir(options.output_dir) - report_as_html(coverage, options.output_dir, read_exclude_patterns(options.exclude_patterns_file)) + report_as_html(coverage, options.output_dir, + read_exclude_patterns(options.exclude_patterns_file), + options.root)