summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2020-06-29 11:47:03 -0400
committerNed Batchelder <ned@nedbatchelder.com>2020-06-29 11:47:03 -0400
commit13159a9bae170be630d501af3a2f446bc57a6837 (patch)
treeaa1ed99cd1ee3868a7a16c402d8fba92ff31a6a9 /coverage
parent44bb5857681d07c0a80f96b9c287dc4c9d23a795 (diff)
downloadpython-coveragepy-git-13159a9bae170be630d501af3a2f446bc57a6837.tar.gz
More details on --source filtering
Diffstat (limited to 'coverage')
-rw-r--r--coverage/control.py6
-rw-r--r--coverage/inorout.py42
2 files changed, 37 insertions, 11 deletions
diff --git a/coverage/control.py b/coverage/control.py
index c2f40e70..14c22eb1 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -212,7 +212,6 @@ class Coverage(object):
self._data = self._collector = None
self._plugins = None
self._inorout = None
- self._inorout_class = InOrOut
self._data_suffix = self._run_suffix = None
self._exclude_re = None
self._debug = None
@@ -483,7 +482,10 @@ class Coverage(object):
plugin._coverage_enabled = False
# Create the file classifying substructure.
- self._inorout = self._inorout_class(warn=self._warn)
+ self._inorout = InOrOut(
+ warn=self._warn,
+ debug=(self._debug if self._debug.should('trace') else None),
+ )
self._inorout.configure(self.config)
self._inorout.plugins = self._plugins
self._inorout.disp_class = self._collector.file_disposition_class
diff --git a/coverage/inorout.py b/coverage/inorout.py
index d5e8b226..ec5f2c1a 100644
--- a/coverage/inorout.py
+++ b/coverage/inorout.py
@@ -111,8 +111,9 @@ def module_has_file(mod):
class InOrOut(object):
"""Machinery for determining what files to measure."""
- def __init__(self, warn):
+ def __init__(self, warn, debug):
self.warn = warn
+ self.debug = debug
# The matchers for should_trace.
self.source_match = None
@@ -177,19 +178,33 @@ class InOrOut(object):
for mod in [contracts, six]:
self.cover_paths.append(canonical_path(mod))
+ def debug(msg):
+ if self.debug:
+ self.debug.write(msg)
+
# Create the matchers we need for should_trace
if self.source or self.source_pkgs:
- self.source_match = TreeMatcher(self.source)
- self.source_pkgs_match = ModuleMatcher(self.source_pkgs)
+ against = []
+ if self.source:
+ self.source_match = TreeMatcher(self.source)
+ against.append("trees {!r}".format(self.source_match))
+ if self.source_pkgs:
+ self.source_pkgs_match = ModuleMatcher(self.source_pkgs)
+ against.append("modules {!r}".format(self.source_pkgs_match))
+ debug("Source matching against " + " and ".join(against))
else:
if self.cover_paths:
self.cover_match = TreeMatcher(self.cover_paths)
+ debug("Coverage code matching: {!r}".format(self.cover_match))
if self.pylib_paths:
self.pylib_match = TreeMatcher(self.pylib_paths)
+ debug("Python stdlib matching: {!r}".format(self.pylib_match))
if self.include:
self.include_match = FnmatchMatcher(self.include)
+ debug("Include matching: {!r}".format(self.include_match))
if self.omit:
self.omit_match = FnmatchMatcher(self.omit)
+ debug("Omit matching: {!r}".format(self.omit_match))
def should_trace(self, filename, frame=None):
"""Decide whether to trace execution in `filename`, with a reason.
@@ -309,12 +324,21 @@ class InOrOut(object):
# about the outer bound of what to measure and we don't have to apply
# any canned exclusions. If they didn't, then we have to exclude the
# stdlib and coverage.py directories.
- if self.source_match:
- if self.source_pkgs_match.match(modulename):
- if modulename in self.source_pkgs_unmatched:
- self.source_pkgs_unmatched.remove(modulename)
- elif not self.source_match.match(filename):
- return "falls outside the --source trees"
+ if self.source_match or self.source_pkgs_match:
+ extra = ""
+ ok = False
+ if self.source_pkgs_match:
+ if self.source_pkgs_match.match(modulename):
+ ok = True
+ if modulename in self.source_pkgs_unmatched:
+ self.source_pkgs_unmatched.remove(modulename)
+ else:
+ extra = "module {!r} ".format(modulename)
+ if not ok and self.source_match:
+ if self.source_match.match(filename):
+ ok = True
+ if not ok:
+ return extra + "falls outside the --source spec"
elif self.include_match:
if not self.include_match.match(filename):
return "falls outside the --include trees"