From 44e2fec038fbb9b8c171c4f6ac04ea644b48c63c Mon Sep 17 00:00:00 2001 From: Krassimir Valev Date: Wed, 8 Jan 2020 22:19:53 +0100 Subject: [PATCH] Support patterns in module names --- coverage/files.py | 5 +++++ tests/test_files.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/coverage/files.py b/coverage/files.py index 59b2bd61d..64e1fba08 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -242,6 +242,7 @@ class ModuleMatcher(object): """A matcher for modules in a tree.""" def __init__(self, module_names): self.modules = list(module_names) + self.module_patterns = [re.compile(m) for m in self.modules] def __repr__(self): return "" % (self.modules) @@ -263,6 +264,10 @@ def match(self, module_name): # This is a module in the package return True + for pattern in self.module_patterns: + if pattern.match(module_name): + return True + return False diff --git a/tests/test_files.py b/tests/test_files.py index 84e25f107..8f488effa 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -174,12 +174,15 @@ def test_tree_matcher(self): def test_module_matcher(self): matches_to_try = [ ('test', True), + ('te.*', True), ('trash', False), + ('tra.*', False), ('testing', False), ('test.x', True), ('test.x.y.z', True), ('py', False), ('py.t', False), + ('py.t.*', True), ('py.test', True), ('py.testing', False), ('py.test.buz', True),