Skip to content

Commit 16f54a9

Browse files
committed
debug: label each matcher with its role
1 parent 0285af9 commit 16f54a9

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

coverage/files.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,13 @@ class TreeMatcher(object):
215215
somewhere in a subtree rooted at one of the directories.
216216
217217
"""
218-
def __init__(self, paths):
218+
def __init__(self, paths, name):
219219
self.original_paths = list(paths)
220220
self.paths = list(map(os.path.normcase, paths))
221+
self.name = name
221222

222223
def __repr__(self):
223-
return "<TreeMatcher %r>" % self.paths
224+
return "<TreeMatcher {!r} {!r}>".format(self.name, self.original_paths)
224225

225226
def info(self):
226227
"""A list of strings for displaying when dumping state."""
@@ -242,11 +243,12 @@ def match(self, fpath):
242243

243244
class ModuleMatcher(object):
244245
"""A matcher for modules in a tree."""
245-
def __init__(self, module_names):
246+
def __init__(self, module_names, name):
246247
self.modules = list(module_names)
248+
self.name = name
247249

248250
def __repr__(self):
249-
return "<ModuleMatcher %r>" % (self.modules)
251+
return "<ModuleMatcher {!r} {!r}>".format(self.name, self.modules)
250252

251253
def info(self):
252254
"""A list of strings for displaying when dumping state."""
@@ -270,12 +272,13 @@ def match(self, module_name):
270272

271273
class FnmatchMatcher(object):
272274
"""A matcher for files by file name pattern."""
273-
def __init__(self, pats):
275+
def __init__(self, pats, name):
274276
self.pats = list(pats)
275277
self.re = fnmatches_to_regex(self.pats, case_insensitive=env.WINDOWS)
278+
self.name = name
276279

277280
def __repr__(self):
278-
return "<FnmatchMatcher %r>" % self.pats
281+
return "<FnmatchMatcher {!r} {!r}>".format(self.name, self.pats)
279282

280283
def info(self):
281284
"""A list of strings for displaying when dumping state."""

coverage/inorout.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -258,27 +258,27 @@ def debug(msg):
258258
if self.source or self.source_pkgs:
259259
against = []
260260
if self.source:
261-
self.source_match = TreeMatcher(self.source)
261+
self.source_match = TreeMatcher(self.source, "source")
262262
against.append("trees {!r}".format(self.source_match))
263263
if self.source_pkgs:
264-
self.source_pkgs_match = ModuleMatcher(self.source_pkgs)
264+
self.source_pkgs_match = ModuleMatcher(self.source_pkgs, "source_pkgs")
265265
against.append("modules {!r}".format(self.source_pkgs_match))
266266
debug("Source matching against " + " and ".join(against))
267267
else:
268268
if self.cover_paths:
269-
self.cover_match = TreeMatcher(self.cover_paths)
269+
self.cover_match = TreeMatcher(self.cover_paths, "coverage")
270270
debug("Coverage code matching: {!r}".format(self.cover_match))
271271
if self.pylib_paths:
272-
self.pylib_match = TreeMatcher(self.pylib_paths)
272+
self.pylib_match = TreeMatcher(self.pylib_paths, "pylib")
273273
debug("Python stdlib matching: {!r}".format(self.pylib_match))
274274
if self.include:
275-
self.include_match = FnmatchMatcher(self.include)
275+
self.include_match = FnmatchMatcher(self.include, "include")
276276
debug("Include matching: {!r}".format(self.include_match))
277277
if self.omit:
278-
self.omit_match = FnmatchMatcher(self.omit)
278+
self.omit_match = FnmatchMatcher(self.omit, "omit")
279279
debug("Omit matching: {!r}".format(self.omit_match))
280280
if self.third_paths:
281-
self.third_match = TreeMatcher(self.third_paths)
281+
self.third_match = TreeMatcher(self.third_paths, "third")
282282
debug("Third-party lib matching: {!r}".format(self.third_match))
283283

284284
# Check if the source we want to measure has been installed as a

coverage/report.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def get_analysis_to_report(coverage, morfs):
5757
config = coverage.config
5858

5959
if config.report_include:
60-
matcher = FnmatchMatcher(prep_patterns(config.report_include))
60+
matcher = FnmatchMatcher(prep_patterns(config.report_include), "report_include")
6161
file_reporters = [fr for fr in file_reporters if matcher.match(fr.filename)]
6262

6363
if config.report_omit:
64-
matcher = FnmatchMatcher(prep_patterns(config.report_omit))
64+
matcher = FnmatchMatcher(prep_patterns(config.report_omit), "report_omit")
6565
file_reporters = [fr for fr in file_reporters if not matcher.match(fr.filename)]
6666

6767
if not file_reporters:

tests/test_files.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_tree_matcher(self):
167167
files.canonical_filename("sub4/file5.py"),
168168
files.canonical_filename("SUB5/file6.py"),
169169
]
170-
tm = TreeMatcher(trees)
170+
tm = TreeMatcher(trees, "test")
171171
assert tm.info() == trees
172172
for filepath, matches in matches_to_try:
173173
self.assertMatches(tm, filepath, matches)
@@ -190,7 +190,7 @@ def test_module_matcher(self):
190190
('yourmain', False),
191191
]
192192
modules = ['test', 'py.test', 'mymain']
193-
mm = ModuleMatcher(modules)
193+
mm = ModuleMatcher(modules, "test")
194194
assert mm.info() == modules
195195
for modulename, matches in matches_to_try:
196196
assert mm.match(modulename) == matches, modulename
@@ -203,23 +203,23 @@ def test_fnmatch_matcher(self):
203203
(self.make_file("sub3/file4.py"), True),
204204
(self.make_file("sub3/file5.c"), False),
205205
]
206-
fnm = FnmatchMatcher(["*.py", "*/sub2/*"])
206+
fnm = FnmatchMatcher(["*.py", "*/sub2/*"], "test")
207207
assert fnm.info() == ["*.py", "*/sub2/*"]
208208
for filepath, matches in matches_to_try:
209209
self.assertMatches(fnm, filepath, matches)
210210

211211
def test_fnmatch_matcher_overload(self):
212-
fnm = FnmatchMatcher(["*x%03d*.txt" % i for i in range(500)])
212+
fnm = FnmatchMatcher(["*x%03d*.txt" % i for i in range(500)], "test")
213213
self.assertMatches(fnm, "x007foo.txt", True)
214214
self.assertMatches(fnm, "x123foo.txt", True)
215215
self.assertMatches(fnm, "x798bar.txt", False)
216216

217217
def test_fnmatch_windows_paths(self):
218218
# We should be able to match Windows paths even if we are running on
219219
# a non-Windows OS.
220-
fnm = FnmatchMatcher(["*/foo.py"])
220+
fnm = FnmatchMatcher(["*/foo.py"], "test")
221221
self.assertMatches(fnm, r"dir\foo.py", True)
222-
fnm = FnmatchMatcher([r"*\foo.py"])
222+
fnm = FnmatchMatcher([r"*\foo.py"], "test")
223223
self.assertMatches(fnm, r"dir\foo.py", True)
224224

225225

0 commit comments

Comments
 (0)