summaryrefslogtreecommitdiff
path: root/coverage/files.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2012-10-29 12:17:00 -0400
committerNed Batchelder <ned@nedbatchelder.com>2012-10-29 12:17:00 -0400
commit8804c84df66576394cd9eb81a83818abf632d3c9 (patch)
tree15fd85f9b12339179566303bf167f40282a08fcc /coverage/files.py
parent754c8b3c11ed4d6c2b2281796522cd5d812e8b5f (diff)
downloadpython-coveragepy-git-8804c84df66576394cd9eb81a83818abf632d3c9.tar.gz
Fix #163: embarassingly, the wildcards for include and omit didn't work properly for reporting functions. This is now fixed.
Diffstat (limited to 'coverage/files.py')
-rw-r--r--coverage/files.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/coverage/files.py b/coverage/files.py
index 13f43930..632d6e31 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -9,16 +9,12 @@ class FileLocator(object):
def __init__(self):
# The absolute path to our current directory.
- self.relative_dir = self.abs_file(os.curdir) + os.sep
+ self.relative_dir = abs_file(os.curdir) + os.sep
# Cache of results of calling the canonical_filename() method, to
# avoid duplicating work.
self.canonical_filename_cache = {}
- def abs_file(self, filename):
- """Return the absolute normalized form of `filename`."""
- return os.path.normcase(os.path.abspath(os.path.realpath(filename)))
-
def relative_filename(self, filename):
"""Return the relative form of `filename`.
@@ -49,7 +45,7 @@ class FileLocator(object):
if os.path.exists(g):
f = g
break
- cf = self.abs_file(f)
+ cf = abs_file(f)
self.canonical_filename_cache[filename] = cf
return self.canonical_filename_cache[filename]
@@ -78,6 +74,31 @@ class FileLocator(object):
return None
+def abs_file(filename):
+ """Return the absolute normalized form of `filename`."""
+ return os.path.normcase(os.path.abspath(os.path.realpath(filename)))
+
+
+def prep_patterns(patterns):
+ """Prepare the file patterns for use in a `FnmatchMatcher`.
+
+ If a pattern starts with a wildcard, it is used as a pattern
+ as-is. If it does not start with a wildcard, then it is made
+ absolute with the current directory.
+
+ If `patterns` is None, an empty list is returned.
+
+ """
+ patterns = patterns or []
+ prepped = []
+ for p in patterns or []:
+ if p.startswith("*") or p.startswith("?"):
+ prepped.append(p)
+ else:
+ prepped.append(abs_file(p))
+ return prepped
+
+
class TreeMatcher(object):
"""A matcher for files in a tree."""
def __init__(self, directories):