summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-11-05 19:58:24 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-11-05 20:01:28 -0400
commite3e637c97365ceae4ee959bc4a0571c85f38355d (patch)
treefd370fa7fbb04d184d646868cbef7a560bdbbb00
parent5ade5cdb5fe1b583d874838c6be80b08d30249fc (diff)
downloadpython-coveragepy-git-e3e637c97365ceae4ee959bc4a0571c85f38355d.tar.gz
fix: give a default value to the name argument for Matchers. #1273
-rw-r--r--CHANGES.rst6
-rw-r--r--coverage/files.py6
-rw-r--r--tests/test_files.py12
3 files changed, 15 insertions, 9 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 9028a0de..209f27db 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 6a4f5906..acce0507 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 @@ class TreeMatcher:
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 @@ class ModuleMatcher:
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 e5dd83bd..a07f7704 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -171,7 +171,7 @@ class MatcherTest(CoverageTest):
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 @@ class MatcherTest(CoverageTest):
('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 @@ class MatcherTest(CoverageTest):
(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 @@ class MatcherTest(CoverageTest):
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)