Skip to content

Commit e3e637c

Browse files
committed
fix: give a default value to the name argument for Matchers. #1273
1 parent 5ade5cd commit e3e637c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ Unreleased
2828
- Fix: Removed another vestige of jQuery from the source tarball
2929
(`issue 840`_).
3030

31+
- Fix: Added a default value for a new-to-6.x argument of an internal class.
32+
This unsupported class is being used by coveralls (`issue 1273`_). Although
33+
I'd rather not "fix" unsupported interfaces, it's actually nicer with a
34+
default value.
35+
3136
.. _issue 1271: https://github.com/nedbat/coveragepy/issues/1271
37+
.. _issue 1273: https://github.com/nedbat/coveragepy/issues/1273
3238

3339

3440
.. _changes_611:

coverage/files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class TreeMatcher:
198198
somewhere in a subtree rooted at one of the directories.
199199
200200
"""
201-
def __init__(self, paths, name):
201+
def __init__(self, paths, name="unknown"):
202202
self.original_paths = human_sorted(paths)
203203
self.paths = list(map(os.path.normcase, paths))
204204
self.name = name
@@ -226,7 +226,7 @@ def match(self, fpath):
226226

227227
class ModuleMatcher:
228228
"""A matcher for modules in a tree."""
229-
def __init__(self, module_names, name):
229+
def __init__(self, module_names, name="unknown"):
230230
self.modules = list(module_names)
231231
self.name = name
232232

@@ -255,7 +255,7 @@ def match(self, module_name):
255255

256256
class FnmatchMatcher:
257257
"""A matcher for files by file name pattern."""
258-
def __init__(self, pats, name):
258+
def __init__(self, pats, name="unknown"):
259259
self.pats = list(pats)
260260
self.re = fnmatches_to_regex(self.pats, case_insensitive=env.WINDOWS)
261261
self.name = name

tests/test_files.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_tree_matcher(self):
171171
files.canonical_filename("sub4/file5.py"),
172172
files.canonical_filename("SUB5/file6.py"),
173173
]
174-
tm = TreeMatcher(trees, "test")
174+
tm = TreeMatcher(trees)
175175
assert tm.info() == sorted(trees)
176176
for filepath, matches in matches_to_try:
177177
self.assertMatches(tm, filepath, matches)
@@ -194,7 +194,7 @@ def test_module_matcher(self):
194194
('yourmain', False),
195195
]
196196
modules = ['test', 'py.test', 'mymain']
197-
mm = ModuleMatcher(modules, "test")
197+
mm = ModuleMatcher(modules)
198198
assert mm.info() == modules
199199
for modulename, matches in matches_to_try:
200200
assert mm.match(modulename) == matches, modulename
@@ -207,23 +207,23 @@ def test_fnmatch_matcher(self):
207207
(self.make_file("sub3/file4.py"), True),
208208
(self.make_file("sub3/file5.c"), False),
209209
]
210-
fnm = FnmatchMatcher(["*.py", "*/sub2/*"], "test")
210+
fnm = FnmatchMatcher(["*.py", "*/sub2/*"])
211211
assert fnm.info() == ["*.py", "*/sub2/*"]
212212
for filepath, matches in matches_to_try:
213213
self.assertMatches(fnm, filepath, matches)
214214

215215
def test_fnmatch_matcher_overload(self):
216-
fnm = FnmatchMatcher(["*x%03d*.txt" % i for i in range(500)], "test")
216+
fnm = FnmatchMatcher(["*x%03d*.txt" % i for i in range(500)])
217217
self.assertMatches(fnm, "x007foo.txt", True)
218218
self.assertMatches(fnm, "x123foo.txt", True)
219219
self.assertMatches(fnm, "x798bar.txt", False)
220220

221221
def test_fnmatch_windows_paths(self):
222222
# We should be able to match Windows paths even if we are running on
223223
# a non-Windows OS.
224-
fnm = FnmatchMatcher(["*/foo.py"], "test")
224+
fnm = FnmatchMatcher(["*/foo.py"])
225225
self.assertMatches(fnm, r"dir\foo.py", True)
226-
fnm = FnmatchMatcher([r"*\foo.py"], "test")
226+
fnm = FnmatchMatcher([r"*\foo.py"])
227227
self.assertMatches(fnm, r"dir\foo.py", True)
228228

229229

0 commit comments

Comments
 (0)