summaryrefslogtreecommitdiff
path: root/coverage/codeunit.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/codeunit.py')
-rw-r--r--coverage/codeunit.py62
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.