Your IP : 216.73.216.213
E�W�6 � @ sr d Z d d l m Z d d l m Z m Z Gd d � d e � Z Gd d � d e � Z Gd d � d e � Z d
S)z!Plugin interfaces for coverage.py� )�files)�contract�_needs_to_implementc @ s: e Z d Z d Z d d � Z d d � Z d d � Z d S) �CoveragePluginan Base class for coverage.py plugins.
To write a coverage.py plugin, create a module with a subclass of
:class:`CoveragePlugin`. You will override methods in your class to
participate in various aspects of coverage.py's processing.
Currently the only plugin type is a file tracer, for implementing
measurement support for non-Python files. File tracer plugins implement
the :meth:`file_tracer` method to claim files and the :meth:`file_reporter`
method to report on those files.
Any plugin can optionally implement :meth:`sys_info` to provide debugging
information about their operation.
Coverage.py will store its own information on your plugin object, using
attributes whose names start with ``_coverage_``. Don't be startled.
To register your plugin, define a function called `coverage_init` in your
module::
def coverage_init(reg, options):
reg.add_file_tracer(MyPlugin())
You use the `reg` parameter passed to your `coverage_init` function to
register your plugin object. It has one method, `add_file_tracer`, which
takes a newly created instance of your plugin.
If your plugin takes options, the `options` parameter is a dictionary of
your plugin's options from the coverage.py configuration file. Use them
however you want to configure your object before registering it.
c C s d S)ai Get a :class:`FileTracer` object for a file.
Every Python source file is offered to the plugin to give it a chance
to take responsibility for tracing the file. If your plugin can handle
the file, then return a :class:`FileTracer` object. Otherwise return
None.
There is no way to register your plugin for particular files. Instead,
this method is invoked for all files, and the plugin decides whether it
can trace the file or not. Be prepared for `filename` to refer to all
kinds of files that have nothing to do with your plugin.
The file name will be a Python file being executed. There are two
broad categories of behavior for a plugin, depending on the kind of
files your plugin supports:
* Static file names: each of your original source files has been
converted into a distinct Python file. Your plugin is invoked with
the Python file name, and it maps it back to its original source
file.
* Dynamic file names: all of your source files are executed by the same
Python file. In this case, your plugin implements
:meth:`FileTracer.dynamic_source_filename` to provide the actual
source file for each execution frame.
`filename` is a string, the path to the file being considered. This is
the absolute real path to the file. If you are comparing to other
paths, be sure to take this into account.
Returns a :class:`FileTracer` object to use to trace `filename`, or
None if this plugin cannot trace this file.
N� )�self�filenamer r �B/opt/alt/python35/lib64/python3.5/site-packages/coverage/plugin.py�file_tracer, s #zCoveragePlugin.file_tracerc C s t | d � d S)a$ Get the :class:`FileReporter` class to use for a file.
This will only be invoked if `filename` returns non-None from
:meth:`file_tracer`. It's an error to return None from this method.
Returns a :class:`FileReporter` object to use to report on `filename`.
�
file_reporterN)r )r r r r r r Q s zCoveragePlugin.file_reporterc C s g S)z�Get a list of information useful for debugging.
This method will be invoked for ``--debug=sys``. Your
plugin can return any information it wants to be displayed.
Returns a list of pairs: `[(name, value), ...]`.
r )r r r r �sys_info\ s zCoveragePlugin.sys_infoN)�__name__�
__module__�__qualname__�__doc__r
r r r r r r r
s %r c @ sF e Z d Z d Z d d � Z d d � Z d d � Z d d � Z d
S)�
FileTracera� Support needed for files during the execution phase.
You may construct this object from :meth:`CoveragePlugin.file_tracer` any
way you like. A natural choice would be to pass the file name given to
`file_tracer`.
`FileTracer` objects should only be created in the
:meth:`CoveragePlugin.file_tracer` method.
See :ref:`howitworks` for details of the different coverage.py phases.
c C s t | d � d S)a� The source file name for this file.
This may be any file name you like. A key responsibility of a plugin
is to own the mapping from Python execution back to whatever source
file name was originally the source of the code.
See :meth:`CoveragePlugin.file_tracer` for details about static and
dynamic file names.
Returns the file name to credit with this execution.
�source_filenameN)r )r r r r r v s
zFileTracer.source_filenamec C s d S)am Does this FileTracer have dynamic source file names?
FileTracers can provide dynamically determined file names by
implementing :meth:`dynamic_source_filename`. Invoking that function
is expensive. To determine whether to invoke it, coverage.py uses the
result of this function to know if it needs to bother invoking
:meth:`dynamic_source_filename`.
See :meth:`CoveragePlugin.file_tracer` for details about static and
dynamic file names.
Returns True if :meth:`dynamic_source_filename` should be called to get
dynamic source file names.
Fr )r r r r �has_dynamic_source_filename� s z&FileTracer.has_dynamic_source_filenamec C s d S)ai Get a dynamically computed source file name.
Some plugins need to compute the source file name dynamically for each
frame.
This function will not be invoked if
:meth:`has_dynamic_source_filename` returns False.
Returns the source file name for this frame, or None if this frame
shouldn't be measured.
Nr )r r �framer r r �dynamic_source_filename� s
z"FileTracer.dynamic_source_filenamec C s | j } | | f S)aw Get the range of source line numbers for a given a call frame.
The call frame is examined, and the source line number in the original
file is returned. The return value is a pair of numbers, the starting
line number and the ending line number, both inclusive. For example,
returning (5, 7) means that lines 5, 6, and 7 should be considered
executed.
This function might decide that the frame doesn't indicate any lines
from the source file were executed. Return (-1, -1) in this case to
tell coverage.py that no lines should be recorded for this frame.
)�f_lineno)r r �linenor r r �line_number_range� s zFileTracer.line_number_rangeN)r
r r r r r r r r r r r r h s
r c @ s e Z d Z d Z d d � Z d d � Z d d � Z e d d � d
d � � Z d d
� Z d d � Z
d d � Z d d � Z d d � Z
d d � Z d d � Z d d d � Z d d � Z d d � Z d! d"