diff options
author | Buck Golemon <buck@yelp.com> | 2014-11-14 14:00:27 -0800 |
---|---|---|
committer | Buck Golemon <buck@yelp.com> | 2014-11-14 14:00:27 -0800 |
commit | d05360a060187452f49302467f87ead09d27c9ba (patch) | |
tree | 9e82e20acb7358109ffd77de863088faf7a7c0eb | |
parent | a3cb81edd6053a273447ba3821655320ed234a41 (diff) | |
download | python-coveragepy-git-d05360a060187452f49302467f87ead09d27c9ba.tar.gz |
ModuleFinder no longer takes a main-module argument.
--HG--
branch : __main__-support
extra : rebase_source : 3f4c29876960153907b65b6e8e818b8228ca4ec0
extra : histedit_source : 6567adaf9c89483b71501fd91e9d3c83ed3daec7%2C2c5c8a7af95b8b26af384b9a65815d077e4313ec
-rw-r--r-- | coverage/cmdline.py | 3 | ||||
-rw-r--r-- | coverage/control.py | 5 | ||||
-rw-r--r-- | coverage/files.py | 20 | ||||
-rw-r--r-- | tests/test_cmdline.py | 9 | ||||
-rw-r--r-- | tests/test_files.py | 39 |
5 files changed, 17 insertions, 59 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index a80d1168..e7efe5c4 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -519,10 +519,9 @@ class CoverageScript(object): # Set the first path element properly. old_path0 = sys.path[0] - main_module = args[0] if options.module else None # Run the script. - self.coverage.start(main_module=main_module) + self.coverage.start() code_ran = True try: if options.module: diff --git a/coverage/control.py b/coverage/control.py index 5e154537..47e5b508 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -141,7 +141,7 @@ class Coverage(object): # Other instance attributes, set later. self.omit = self.include = self.source = None - self.not_imported = self.source_pkgs = self.file_locator = None + self.source_pkgs = self.file_locator = None self.data = self.collector = None self.plugins = self.file_tracers = None self.pylib_dirs = self.cover_dir = None @@ -426,8 +426,7 @@ class Coverage(object): # any canned exclusions. If they didn't, then we have to exclude the # stdlib and coverage.py directories. if self.source_match: - match = self.source_pkgs_match.match(modulename) - if match: + if self.source_pkgs_match.match(modulename): if modulename in self.not_imported: self.not_imported.remove(modulename) return None # There's no reason to skip this file. diff --git a/coverage/files.py b/coverage/files.py index 5e7c35aa..97888b62 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -175,21 +175,16 @@ class TreeMatcher(object): class ModuleMatcher(object): """A matcher for files in a tree.""" - def __init__(self, module_names, main_module=None): + def __init__(self, module_names): self.modules = list(module_names) - self.main_module = main_module self.not_imported = list(module_names) def __repr__(self): - if self.main_module: - main_module = ', main_module=%r' % self.main_module - else: - main_module = '' - return "<ModuleMatcher %r%s>" % (self.modules, main_module) + return "<ModuleMatcher %r>" % (self.modules) def info(self): """A list of strings for displaying when dumping state.""" - return ['main_module=%r' % self.main_module] + self.modules + return self.modules def add(self, module): """Add another directory to the list we match for.""" @@ -197,22 +192,17 @@ class ModuleMatcher(object): def match(self, module_name): """Does `module_name` indicate a module in one of our packages? - - On success, returns the matched module name, which can be different in - the case of __main__. """ if not module_name: return False - elif module_name == '__main__': - module_name = self.main_module or module_name for m in self.modules: if module_name.startswith(m): if module_name == m: - return module_name + return True if module_name[len(m)] == '.': # This is a module in the package - return module_name + return True return False diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 3032a2f1..695c3bec 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -33,9 +33,6 @@ class BaseCmdLineTest(CoverageTest): ignore_errors=None, include=None, omit=None, morfs=[], show_missing=None, ) - defaults.start( - main_module=None, - ) defaults.xml_report( ignore_errors=None, include=None, omit=None, morfs=[], outfile=None, ) @@ -475,7 +472,7 @@ class CmdLineTest(BaseCmdLineTest): self.cmd_executes("run -m mymodule", """\ .coverage() .erase() - .start(main_module='mymodule') + .start() .run_python_module('mymodule', ['mymodule']) .stop() .save() @@ -483,7 +480,7 @@ class CmdLineTest(BaseCmdLineTest): self.cmd_executes("run -m mymodule -qq arg1 arg2", """\ .coverage() .erase() - .start(main_module='mymodule') + .start() .run_python_module('mymodule', ['mymodule', '-qq', 'arg1', 'arg2']) .stop() .save() @@ -491,7 +488,7 @@ class CmdLineTest(BaseCmdLineTest): self.cmd_executes("run --branch -m mymodule", """\ .coverage(branch=True) .erase() - .start(main_module='mymodule') + .start() .run_python_module('mymodule', ['mymodule']) .stop() .save() diff --git a/tests/test_files.py b/tests/test_files.py index d72788c4..f6976a81 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -101,42 +101,15 @@ class MatcherTest(CoverageTest): ('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) + mm = ModuleMatcher(modules) + self.assertEqual( + mm.info(), + 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, + matches, modulename, ) |