From e3e637c97365ceae4ee959bc4a0571c85f38355d Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 5 Nov 2021 19:58:24 -0400 Subject: [PATCH] fix: give a default value to the name argument for Matchers. #1273 --- CHANGES.rst | 6 ++++++ coverage/files.py | 6 +++--- tests/test_files.py | 12 ++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9028a0de8..209f27dbb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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: diff --git a/coverage/files.py b/coverage/files.py index 6a4f5906d..acce05077 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -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 @@ -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 @@ -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 diff --git a/tests/test_files.py b/tests/test_files.py index e5dd83bd8..a07f7704c 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -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) @@ -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 @@ -207,13 +207,13 @@ 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) @@ -221,9 +221,9 @@ def test_fnmatch_matcher_overload(self): 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)