Skip to content

Commit

Permalink
fix: give a default value to the name argument for Matchers. #1273
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Nov 6, 2021
1 parent 5ade5cd commit e3e637c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ Unreleased
- Fix: Removed another vestige of jQuery from the source tarball
(`issue 840`_).

- Fix: Added a default value for a new-to-6.x argument of an internal class.
This unsupported class is being used by coveralls (`issue 1273`_). Although
I'd rather not "fix" unsupported interfaces, it's actually nicer with a
default value.

.. _issue 1271: https://github.com/nedbat/coveragepy/issues/1271
.. _issue 1273: https://github.com/nedbat/coveragepy/issues/1273


.. _changes_611:
Expand Down
6 changes: 3 additions & 3 deletions coverage/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class TreeMatcher:
somewhere in a subtree rooted at one of the directories.
"""
def __init__(self, paths, name):
def __init__(self, paths, name="unknown"):
self.original_paths = human_sorted(paths)
self.paths = list(map(os.path.normcase, paths))
self.name = name
Expand Down Expand Up @@ -226,7 +226,7 @@ def match(self, fpath):

class ModuleMatcher:
"""A matcher for modules in a tree."""
def __init__(self, module_names, name):
def __init__(self, module_names, name="unknown"):
self.modules = list(module_names)
self.name = name

Expand Down Expand Up @@ -255,7 +255,7 @@ def match(self, module_name):

class FnmatchMatcher:
"""A matcher for files by file name pattern."""
def __init__(self, pats, name):
def __init__(self, pats, name="unknown"):
self.pats = list(pats)
self.re = fnmatches_to_regex(self.pats, case_insensitive=env.WINDOWS)
self.name = name
Expand Down
12 changes: 6 additions & 6 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_tree_matcher(self):
files.canonical_filename("sub4/file5.py"),
files.canonical_filename("SUB5/file6.py"),
]
tm = TreeMatcher(trees, "test")
tm = TreeMatcher(trees)
assert tm.info() == sorted(trees)
for filepath, matches in matches_to_try:
self.assertMatches(tm, filepath, matches)
Expand All @@ -194,7 +194,7 @@ def test_module_matcher(self):
('yourmain', False),
]
modules = ['test', 'py.test', 'mymain']
mm = ModuleMatcher(modules, "test")
mm = ModuleMatcher(modules)
assert mm.info() == modules
for modulename, matches in matches_to_try:
assert mm.match(modulename) == matches, modulename
Expand All @@ -207,23 +207,23 @@ def test_fnmatch_matcher(self):
(self.make_file("sub3/file4.py"), True),
(self.make_file("sub3/file5.c"), False),
]
fnm = FnmatchMatcher(["*.py", "*/sub2/*"], "test")
fnm = FnmatchMatcher(["*.py", "*/sub2/*"])
assert fnm.info() == ["*.py", "*/sub2/*"]
for filepath, matches in matches_to_try:
self.assertMatches(fnm, filepath, matches)

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

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


Expand Down

0 comments on commit e3e637c

Please sign in to comment.