summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2012-07-04 00:13:03 -0400
committerNed Batchelder <ned@nedbatchelder.com>2012-07-04 00:13:03 -0400
commit5a8af8616b6638921d0c7bc74537eca372a5eeaf (patch)
tree2c081c758d23d7e640d4678692766c44fa6d5128
parentc7d1c79367fa22c88a932d6a5e88095b74092fcf (diff)
downloadpython-coveragepy-git-5a8af8616b6638921d0c7bc74537eca372a5eeaf.tar.gz
With --source=dir, dir/__init__.py need not exist any longer, but dir/sub/__init__.py still does.
-rw-r--r--CHANGES.txt4
-rw-r--r--coverage/files.py14
-rw-r--r--test/test_files.py3
3 files changed, 16 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 955e523f..490a81b7 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -5,6 +5,10 @@ Change history for Coverage.py
Version 3.5.3b1
---------------
+- When specifying a directory as the source= option, the directory itself no
+ longer needs to have a ``__init__.py`` file, though its subdirectories do, to
+ be considered as source files.
+
- Files encoded as UTF-8 with a BOM are now properly handled, fixing
`issue 179`_. Thanks, Pablo Carballo.
diff --git a/coverage/files.py b/coverage/files.py
index e6dc4aa1..e07c5766 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -207,9 +207,17 @@ class PathAliases(object):
def find_python_files(dirname):
- """Yield all of the importable Python files in `dirname`, recursively."""
- for dirpath, dirnames, filenames in os.walk(dirname, topdown=True):
- if '__init__.py' not in filenames:
+ """Yield all of the importable Python files in `dirname`, recursively.
+
+ To be importable, the files have to be in a directory with a __init__.py,
+ except for `dirname` itself, which isn't required to have one. The
+ assumption is that `dirname` was specified directly, so the user knows
+ best, but subdirectories are checked for a __init__.py to be sure we only
+ find the importable files.
+
+ """
+ for i, (dirpath, dirnames, filenames) in enumerate(os.walk(dirname)):
+ if i > 0 and '__init__.py' not in filenames:
# If a directory doesn't have __init__.py, then it isn't
# importable and neither are its files
del dirnames[:]
diff --git a/test/test_files.py b/test/test_files.py
index a00a9680..d45f5973 100644
--- a/test/test_files.py
+++ b/test/test_files.py
@@ -147,7 +147,6 @@ class FindPythonFilesTest(CoverageTest):
def test_find_python_files(self):
self.make_file("sub/a.py")
self.make_file("sub/b.py")
- self.make_file("sub/__init__.py")
self.make_file("sub/x.c") # nope: not .py
self.make_file("sub/ssub/__init__.py")
self.make_file("sub/ssub/s.py")
@@ -155,7 +154,7 @@ class FindPythonFilesTest(CoverageTest):
self.make_file("sub/lab/exp.py") # nope: no __init__.py
py_files = set(find_python_files("sub"))
self.assert_same_files(py_files, [
- "sub/__init__.py", "sub/a.py", "sub/b.py",
+ "sub/a.py", "sub/b.py",
"sub/ssub/__init__.py", "sub/ssub/s.py",
])