Mercurial > bitten > bitten-test
changeset 172:d7c8d4375374
More improvements to the `<python:trace>` code coverage report:
* For files missing coverage, only take files into account that have a Python file name extension.
* Previously, a `.pyc` file would have overwritten the coverage of a `.py` file, so it looked like the module had a coverage of 0 percent.
* The line number of the `bitten.util.loc` module now starts at 0 to be consistent with the line numbering of files with coverage information.
author | cmlenz |
---|---|
date | Tue, 30 Aug 2005 10:28:24 +0000 |
parents | 51e23a05e3fa |
children | f0c8d52a9447 |
files | bitten/build/pythontools.py bitten/util/loc.py |
diffstat | 2 files changed, 21 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/bitten/build/pythontools.py +++ b/bitten/build/pythontools.py @@ -10,6 +10,10 @@ import logging import os import re +try: + set +except NameError: + from sets import Set as set from bitten.build import CommandLine, FileSet from bitten.util import loc, xmlio @@ -102,7 +106,10 @@ fileset = FileSet(ctxt.basedir, include, exclude) missing_files = [] for filename in fileset: + if os.path.splitext(filename)[1] != '.py': + continue missing_files.append(filename) + covered_modules = set() try: summary_file = open(ctxt.resolve(summary), 'r') @@ -119,6 +126,7 @@ if not filename in fileset: continue missing_files.remove(filename) + covered_modules.add(modname) module = xmlio.Element('coverage', file=filename, module=modname, percentage=cov) coverage_path = ctxt.resolve(coverdir, @@ -142,8 +150,11 @@ coverage.append(module) for filename in missing_files: - modulename = os.path.splitext(filename.replace(os.sep, '.'))[0] - module = xmlio.Element('coverage', module=modulename, + modname = os.path.splitext(filename.replace(os.sep, '.'))[0] + if modname in covered_modules: + continue + covered_modules.add(modname) + module = xmlio.Element('coverage', module=modname, file=filename, percentage=0) filepath = ctxt.resolve(filename) fileobj = file(filepath, 'r')
--- a/bitten/util/loc.py +++ b/bitten/util/loc.py @@ -62,8 +62,8 @@ """Parse the given file-like object. For every line, returns a `(lineno, type, line)` tuple, where `lineno` - is the line number starting at 1, `type` is one of `BLANK`, `CODE, `COMMENT` - or `DOC`, and `line` is the actual content of the line.""" + is the line number (starting at 0), `type` is one of `BLANK`, `CODE, + `COMMENT` or `DOC`, and `line` is the actual content of the line.""" quote3_finder = {'"': _dquote3_finder, "'": _squote3_finder} quote1_finder = {'"': _dquote1_finder, "'": _squote1_finder } @@ -76,9 +76,9 @@ if in_triple_quote: if in_doc: - yield lineno + 1, DOC, line + yield lineno, DOC, line else: - yield lineno + 1, CODE, line + yield lineno, CODE, line classified = True m = in_triple_quote.match(line) if m == None: @@ -90,12 +90,12 @@ if _is_blank(line): if not classified: - yield lineno + 1, BLANK, line + yield lineno, BLANK, line continue if _is_comment(line): if not classified: - yield lineno + 1, COMMENT, line + yield lineno, COMMENT, line continue # Now we have a code line, a doc start line, or crap left @@ -103,10 +103,10 @@ # (& only in) the last case, classified==1. if not classified: if _is_doc_candidate.match(line): - yield lineno + 1, DOC, line + yield lineno, DOC, line in_doc = True else: - yield lineno + 1, CODE, line + yield lineno, CODE, line # The only reason to continue parsing is to make sure the # start of a multi-line triple quote isn't missed.