summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2012-03-24 15:12:20 -0400
committerNed Batchelder <ned@nedbatchelder.com>2012-03-24 15:12:20 -0400
commit7f9d40fe5474a6f59e9a1cf2c52179f77f9a1714 (patch)
tree5921bf309f131635256e63c062ee8d400f46bfdb
parentf143f15d06ca120034c6178036243aa90a4ef8e6 (diff)
downloadpython-coveragepy-git-7f9d40fe5474a6f59e9a1cf2c52179f77f9a1714.tar.gz
When looking for python files, don't take suspicious ones. Fixes #168.
-rw-r--r--CHANGES.txt4
-rw-r--r--coverage/files.py5
-rw-r--r--test/test_files.py1
3 files changed, 9 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index ccc41abe..78d81758 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -9,6 +9,9 @@ Version 3.5.2b1
properly handled during reporting on Python 2. Python 3 always handled them
properly. This fixes `issue 157`_.
+- Backup files left behind by editors are no longer collected by the source=
+ option, fixing `issue 168`_.
+
- When running a module with ``coverage run -m <modulename>``, certain details
of the execution environment weren't the same as for
``python -m <modulename>``. This had the unfortunate side-effect of making
@@ -24,6 +27,7 @@ Version 3.5.2b1
.. _issue 155: https://bitbucket.org/ned/coveragepy/issue/155/cant-use-coverage-run-m-unittest-discover
.. _issue 157: https://bitbucket.org/ned/coveragepy/issue/157/chokes-on-source-files-with-non-utf-8
.. _issue 166: https://bitbucket.org/ned/coveragepy/issue/166/dont-try-to-compile-c-extension-on-pypy
+.. _issue 168: https://bitbucket.org/ned/coveragepy/issue/168/dont-be-alarmed-by-emacs-droppings
Version 3.5.1 --- 23 September 2011
diff --git a/coverage/files.py b/coverage/files.py
index 81ec196f..e6dc4aa1 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -215,5 +215,8 @@ def find_python_files(dirname):
del dirnames[:]
continue
for filename in filenames:
- if fnmatch.fnmatch(filename, "*.py"):
+ # We're only interested in files that look like reasonable Python
+ # files: Must end with .py, and must not have certain funny
+ # characters that probably mean they are editor junk.
+ if re.match(r"^[^.#~!$@%^&*()+=,]+\.py$", filename):
yield os.path.join(dirpath, filename)
diff --git a/test/test_files.py b/test/test_files.py
index 565bbaa4..a00a9680 100644
--- a/test/test_files.py
+++ b/test/test_files.py
@@ -151,6 +151,7 @@ class FindPythonFilesTest(CoverageTest):
self.make_file("sub/x.c") # nope: not .py
self.make_file("sub/ssub/__init__.py")
self.make_file("sub/ssub/s.py")
+ self.make_file("sub/ssub/~s.py") # nope: editor effluvia
self.make_file("sub/lab/exp.py") # nope: no __init__.py
py_files = set(find_python_files("sub"))
self.assert_same_files(py_files, [