diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-01-01 12:16:30 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-01-01 12:16:30 -0500 |
commit | ea231af0bbb3aa1eed780ece6c567857845d7c96 (patch) | |
tree | 5eacdef7a96b5a3063b75009346a4de8cc99ec52 /coverage/codeunit.py | |
parent | b88a6b2d44ef513503547fe2908fb41d298e87ec (diff) | |
download | python-coveragepy-git-ea231af0bbb3aa1eed780ece6c567857845d7c96.tar.gz |
Move code_unit_factory into Coverage
Diffstat (limited to 'coverage/codeunit.py')
-rw-r--r-- | coverage/codeunit.py | 62 |
1 files changed, 1 insertions, 61 deletions
diff --git a/coverage/codeunit.py b/coverage/codeunit.py index a607ae1a..e9efa396 100644 --- a/coverage/codeunit.py +++ b/coverage/codeunit.py @@ -3,72 +3,12 @@ import os import sys -from coverage.backward import string_class, unicode_class +from coverage.backward import unicode_class from coverage.files import get_python_source, FileLocator -from coverage.misc import CoverageException from coverage.parser import PythonParser from coverage.phystokens import source_token_lines, source_encoding -def code_units_factory(morfs, file_locator=None, get_plugin=None): - """Construct a list of CodeUnits from modules or filenames. - - `morfs` is a module or filename, or a list of the same. - - `file_locator` is a FileLocator that can help resolve filenames. - - `get_plugin` is a function taking a filename, and returning a plugin - responsible for the file. It can also return None if there is no plugin - claiming the file. - - Returns a list of CodeUnit objects. - - """ - # Be sure we have a list. - if not isinstance(morfs, (list, tuple)): - morfs = [morfs] - - code_units = [] - for morf in morfs: - file_reporter = code_unit_factory(morf, file_locator, get_plugin) - code_units.append(file_reporter) - - return code_units - - -def code_unit_factory(morf, file_locator=None, get_plugin=None): - """Construct a CodeUnit from a module or filename. - - `morfs` is a module or a filename. - - `file_locator` is a FileLocator that can help resolve filenames. - - `get_plugin` is a function taking a filename, and returning a plugin - responsible for the file. It can also return None if there is no plugin - claiming the file. - - Returns a CodeUnit object. - - """ - plugin = None - - if isinstance(morf, string_class) and get_plugin: - plugin = get_plugin(morf) - - if plugin: - file_reporter = plugin.file_reporter(morf) - if file_reporter is None: - raise CoverageException( - "Plugin %r did not provide a file reporter for %r." % ( - plugin.plugin_name, morf - ) - ) - else: - file_reporter = PythonCodeUnit(morf, file_locator) - - return file_reporter - - class CodeUnit(object): """Code unit: a filename or module. |