diff options
-rw-r--r-- | coverage/misc.py | 18 | ||||
-rw-r--r-- | coverage/plugin.py | 37 |
2 files changed, 29 insertions, 26 deletions
diff --git a/coverage/misc.py b/coverage/misc.py index 02fb10ef..17fb3df9 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -162,6 +162,24 @@ def overrides(obj, method_name, base_class): return klass_func is not base_func +# TODO: abc? +def _needs_to_implement(that, func_name): + """Helper to raise NotImplementedError in interface stubs.""" + if hasattr(that, "plugin_name"): + thing = "Plugin" + name = that.plugin_name + else: + thing = "Class" + klass = that.__class__ + name = "{klass.__module__}.{klass.__name__}".format(klass=klass) + + raise NotImplementedError( + "{thing} {name!r} needs to implement {func_name}()".format( + thing=thing, name=name, func_name=func_name + ) + ) + + class CoverageException(Exception): """An exception specific to Coverage.""" pass diff --git a/coverage/plugin.py b/coverage/plugin.py index 64767e5e..c80a1a24 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -1,26 +1,6 @@ -""" -Coverage.py's behavior can be extended by writing plugins. These are Python -classes installed separately, and then configured in your .coveragerc file. - -""" - - -# TODO: abc? -def _needs_to_implement(that, func_name): - """Helper to raise NotImplementedError in interface stubs.""" - if hasattr(that, "plugin_name"): - thing = "Plugin" - name = that.plugin_name - else: - thing = "Class" - klass = that.__class__ - name = "{klass.__module__}.{klass.__name__}".format(klass=klass) - - raise NotImplementedError( - "{thing} {name!r} needs to implement {func_name}()".format( - thing=thing, name=name, func_name=func_name - ) - ) +"""Plugin interfaces for coverage.py""" + +from coverage.misc import _needs_to_implement class CoveragePlugin(object): @@ -117,8 +97,8 @@ class FileTracer(object): Some plugins need to compute the source filename dynamically for each frame. - This function will not be invoked if :meth:`has_dynamic_source_filename` - returns False. + This function will not be invoked if + :meth:`has_dynamic_source_filename` returns False. Returns: The source filename for this frame, or None if this frame shouldn't @@ -227,4 +207,9 @@ class FileReporter(object): def flat_rootname(self): # TODO: a better generic implementation? - return self.filename.replace('\\', '_').replace('/', '_').replace('.', '_') + return ( + self.filename + .replace('\\', '_') + .replace('/', '_') + .replace('.', '_') + ) |