diff options
author | Ned Batchelder <nedbat@gmail.com> | 2017-05-04 01:37:56 +0000 |
---|---|---|
committer | Ned Batchelder <nedbat@gmail.com> | 2017-05-04 01:37:56 +0000 |
commit | f1539ee72a2e920f3379a9d30e30ca5828bb8bec (patch) | |
tree | 5a6d60393b6a778543de592e39fad29b223301f2 /coverage/files.py | |
parent | b2f19c1ed21629d5383532cfb2a77be9a7389ea4 (diff) | |
parent | 20dc040e7a10632c90015f6211cafab5d66fd6a2 (diff) | |
download | python-coveragepy-f1539ee72a2e920f3379a9d30e30ca5828bb8bec.tar.gz |
Merged in dirk-thomas/coverage.py/fix_init_name (pull request #91)
fix name for module in __init__.py file
Diffstat (limited to 'coverage/files.py')
-rw-r--r-- | coverage/files.py | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/coverage/files.py b/coverage/files.py index 9de4849..d2c2b89 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -63,7 +63,11 @@ def canonical_filename(filename): if path is None: continue f = os.path.join(path, filename) - if os.path.exists(f): + try: + exists = os.path.exists(f) + except UnicodeError: + exists = False + if exists: filename = f break cf = abs_file(filename) @@ -147,7 +151,11 @@ else: def abs_file(filename): """Return the absolute normalized form of `filename`.""" path = os.path.expandvars(os.path.expanduser(filename)) - path = os.path.abspath(os.path.realpath(path)) + try: + path = os.path.realpath(path) + except UnicodeError: + pass + path = os.path.abspath(path) path = actual_path(path) path = unicode_filename(path) return path @@ -183,25 +191,31 @@ def prep_patterns(patterns): class TreeMatcher(object): - """A matcher for files in a tree.""" - def __init__(self, directories): - self.dirs = list(directories) + """A matcher for files in a tree. + + Construct with a list of paths, either files or directories. Paths match + with the `match` method if they are one of the files, or if they are + somewhere in a subtree rooted at one of the directories. + + """ + def __init__(self, paths): + self.paths = list(paths) def __repr__(self): - return "<TreeMatcher %r>" % self.dirs + return "<TreeMatcher %r>" % self.paths def info(self): """A list of strings for displaying when dumping state.""" - return self.dirs + return self.paths def match(self, fpath): """Does `fpath` indicate a file in one of our trees?""" - for d in self.dirs: - if fpath.startswith(d): - if fpath == d: + for p in self.paths: + if fpath.startswith(p): + if fpath == p: # This is the same file! return True - if fpath[len(d)] == os.sep: + if fpath[len(p)] == os.sep: # This is a file in the directory return True return False |