summaryrefslogtreecommitdiff
path: root/tests/test_files.py
diff options
context:
space:
mode:
authorbuck <buck.2019@gmail.com>2014-10-15 12:04:05 -0700
committerbuck <buck.2019@gmail.com>2014-10-15 12:04:05 -0700
commita3cb81edd6053a273447ba3821655320ed234a41 (patch)
tree8a1a84f15ccace44c409d297f7350a4b3f1cb3a7 /tests/test_files.py
parentc2f80902e35e5e4f638d66d1a1996e1ba6dca642 (diff)
downloadpython-coveragepy-git-a3cb81edd6053a273447ba3821655320ed234a41.tar.gz
make --source and -m play nice together
--HG-- branch : __main__-support extra : rebase_source : c9ca9fddecafddd5ef4db9cc64ca1c0972130aab
Diffstat (limited to 'tests/test_files.py')
-rw-r--r--tests/test_files.py62
1 files changed, 61 insertions, 1 deletions
diff --git a/tests/test_files.py b/tests/test_files.py
index 648c76a9..d72788c4 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -2,7 +2,9 @@
import os, os.path
-from coverage.files import FileLocator, TreeMatcher, FnmatchMatcher
+from coverage.files import (
+ FileLocator, TreeMatcher, FnmatchMatcher, ModuleMatcher
+)
from coverage.files import PathAliases, find_python_files, abs_file
from coverage.misc import CoverageException
@@ -80,6 +82,64 @@ class MatcherTest(CoverageTest):
for filepath, matches in matches_to_try:
self.assertMatches(tm, filepath, matches)
+ def test_module_matcher(self):
+ matches_to_try = [
+ ('test', True),
+ ('test', True),
+ ('trash', False),
+ ('testing', False),
+ ('test.x', True),
+ ('test.x.y.z', True),
+ ('py', False),
+ ('py.t', False),
+ ('py.test', True),
+ ('py.testing', False),
+ ('py.test.buz', True),
+ ('py.test.buz.baz', True),
+ ('__main__', False),
+ ('mymain', True),
+ ('yourmain', False),
+ ]
+ modules = ['test', 'py.test', 'mymain']
+ for mm in (
+ ModuleMatcher(modules),
+ ModuleMatcher(modules, main_module=None),
+ ModuleMatcher(modules, main_module='yourmain'),
+ ):
+ self.assertEqual(
+ mm.info(),
+ ['main_module=%r' % mm.main_module] + modules
+ )
+ for modulename, matches in matches_to_try:
+ self.assertEqual(
+ mm.match(modulename),
+ modulename if matches else False,
+ modulename,
+ )
+
+ def test_module_matcher_dunder_main(self):
+ matches_to_try = [
+ ('__main__', True),
+ ('mymain', True),
+ ('yourmain', False),
+ ]
+ modules = ['test', 'py.test', 'mymain']
+ mm = ModuleMatcher(modules, main_module='mymain')
+ self.assertEqual(mm.info(), ["main_module='mymain'"] + modules)
+ for modulename, matches in matches_to_try:
+ if not matches:
+ expected = False
+ elif modulename == '__main__':
+ expected = mm.main_module
+ else:
+ expected = modulename
+
+ self.assertEqual(
+ mm.match(modulename),
+ expected,
+ modulename,
+ )
+
def test_fnmatch_matcher(self):
matches_to_try = [
(self.make_file("sub/file1.py"), True),