Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/coverage/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/coverage/__pycache__/data.cpython-37.pyc

B

N^�W�k�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZddlmZddlmZddlmZmZmZee�ZGdd	�d	e�ZGd
d�de�Zdd
�Zdd�Zdd�Zedkr�ddlZeejdd��dS)zCoverage data for coverage.py.�N)�env)�iitems�string_class)�_TEST_NAME_FILE)�PathAliases)�CoverageException�file_be_gone�isolate_modulec@seZdZdZd?dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zd@dd�Zdd�Z
e
Zdd�Zdd�ZdZedd��Zedd ��Zed!d"��Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�ZdAd3d4�Zd5d6�Zd7d8�Z d9d:�Z!d;d<�Z"d=d>�Z#dS)B�CoverageDataa�
Manages collected coverage data, including file storage.

    This class is the public supported API to the data coverage.py collects
    during program execution.  It includes information about what code was
    executed. It does not include information from the analysis phase, to
    determine what lines could have been executed, or what lines were not
    executed.

    .. note::

        The file format is not documented or guaranteed.  It will change in
        the future, in possibly complicated ways.  Do not read coverage.py
        data files directly.  Use this API to avoid disruption.

    There are a number of kinds of data that can be collected:

    * **lines**: the line numbers of source lines that were executed.
      These are always available.

    * **arcs**: pairs of source and destination line numbers for transitions
      between source lines.  These are only available if branch coverage was
      used.

    * **file tracer names**: the module names of the file tracer plugins that
      handled each file in the data.

    * **run information**: information about the program execution.  This is
      written during "coverage run", and then accumulated during "coverage
      combine".

    Lines, arcs, and file tracer names are stored for each source file. File
    names in this API are case-sensitive, even on platforms with
    case-insensitive file systems.

    To read a coverage.py data file, use :meth:`read_file`, or
    :meth:`read_fileobj` if you have an already-opened file.  You can then
    access the line, arc, or file tracer data with :meth:`lines`, :meth:`arcs`,
    or :meth:`file_tracer`.  Run information is available with
    :meth:`run_infos`.

    The :meth:`has_arcs` method indicates whether arc data is available.  You
    can get a list of the files in the data with :meth:`measured_files`.
    A summary of the line data is available from :meth:`line_counts`.  As with
    most Python containers, you can determine if there is any data at all by
    using this object as a boolean value.


    Most data files will be created by coverage.py itself, but you can use
    methods here to create data files if you like.  The :meth:`add_lines`,
    :meth:`add_arcs`, and :meth:`add_file_tracers` methods add data, in ways
    that are convenient for coverage.py.  The :meth:`add_run_info` method adds
    key-value pairs to the run information.

    To add a file without any measured data, use :meth:`touch_file`.

    You write to a named file with :meth:`write_file`, or to an already opened
    file with :meth:`write_fileobj`.

    You can clear the data in memory with :meth:`erase`.  Two data collections
    can be combined by using :meth:`update` on one :class:`CoverageData`,
    passing it the other.

    NcCs"||_d|_d|_i|_g|_dS)zhCreate a CoverageData.

        `debug` is a `DebugControl` object for writing debug messages.

        N)�_debug�_lines�_arcs�
_file_tracers�_runs)�self�debug�r�@/opt/alt/python37/lib64/python3.7/site-packages/coverage/data.py�__init__ss
zCoverageData.__init__c	Csddj|jj|jdkrdnd�t|j��|jdkr4dnd�t|j��d�t|j��d�t|j��d�S)NzA<{klass} lines={lines} arcs={arcs} tracers={tracers} runs={runs}>�Nonez{{{0}}}z[{0}])�klass�lines�arcsZtracers�runs)�format�	__class__�__name__r�lenr
rr)rrrr�__repr__�szCoverageData.__repr__cCs|��S)z�Does this data have arcs?

        Arc data is only available if branch coverage was used during
        collection.

        Returns a boolean.

        )�	_has_arcs)rrrr�has_arcs�s	zCoverageData.has_arcscCs\|jdk	rB|j�|�}|dk	rXtj�|�}ttdd�|D���Sn|jdk	rX|j�|�SdS)acGet the list of lines executed for a file.

        If the file was not measured, returns None.  A file might be measured,
        and have no lines executed, in which case an empty list is returned.

        If the file was executed, returns a list of integers, the line numbers
        executed in the file. The list is in no particular order.

        Ncss|]}|dkr|VqdS)rNr)�.0�lrrr�	<genexpr>�sz%CoverageData.lines.<locals>.<genexpr>)r
�get�	itertools�chain�
from_iterable�list�setr)r�filenamerZ	all_linesrrrr�s


zCoverageData.linescCs"|jdk	r||jkr|j|SdS)a�Get the list of arcs executed for a file.

        If the file was not measured, returns None.  A file might be measured,
        and have no arcs executed, in which case an empty list is returned.

        If the file was executed, returns a list of 2-tuples of integers. Each
        pair is a starting line number and an ending line number for a
        transition from one line to another. The list is in no particular
        order.

        Negative numbers have special meaning.  If the starting line number is
        -N, it represents an entry to the code object that starts at line N.
        If the ending ling number is -N, it's an exit from the code object that
        starts at line N.

        N)r
)rr*rrrr�s


zCoverageData.arcscCs&||jp|jpikr"|j�|d�SdS)aGet the plugin name of the file tracer for a file.

        Returns the name of the plugin that handles this file.  If the file was
        measured, but didn't use a plugin, then "" is returned.  If the file
        was not measured, then None is returned.

        �N)r
rrr$)rr*rrr�file_tracer�szCoverageData.file_tracercCs|jS)z�Return the list of dicts of run information.

        For data collected during a single run, this will be a one-element
        list.  If data has been combined, there will be one element for each
        original data file.

        )r)rrrr�	run_infos�szCoverageData.run_infoscCst|jp|jpi�S)z+A list of all files that had been measured.)r(r
r)rrrr�measured_files�szCoverageData.measured_filesFcCsFi}|rdd�}ntjj}x&|��D]}t|�|��|||�<q$W|S)a\Return a dict summarizing the line coverage data.

        Keys are based on the file names, and values are the number of executed
        lines.  If `fullpath` is true, then the keys are the full pathnames of
        the files, otherwise they are the basenames of the files.

        Returns a dict mapping file names to counts of lines.

        cSs|S)Nr)�frrr�<lambda>��z*CoverageData.line_counts.<locals>.<lambda>)�os�path�basenamer.rr)r�fullpathZsummZfilename_fnr*rrr�line_counts�s

zCoverageData.line_countscCst|jp|j�S)N)�boolrr
)rrrr�__nonzero__szCoverageData.__nonzero__cCst|�|�}d|_|_d|kr(|d|_d|krLtdd�t|d�D��|_|�di�|_|�dg�|_|��dS)zzRead the coverage data from the given file object.

        Should only be used on an empty CoverageData object.

        Nrrcss$|]\}}|dd�|D�fVqdS)cSsg|]}t|��qSr)�tuple)r!�pairrrr�
<listcomp>sz7CoverageData.read_fileobj.<locals>.<genexpr>.<listcomp>Nr)r!�fnamerrrrr#sz,CoverageData.read_fileobj.<locals>.<genexpr>�file_tracersr)	�_read_raw_datarr
�dictrr$rr�	_validate)r�file_obj�datarrr�read_fileobj	s

zCoverageData.read_fileobjc
Cs�|jr$|j�d�r$|j�d|f�y$|�|��}|�|�WdQRXWn8tk
r�}ztd||jj|f��Wdd}~XYnXdS)z8Read the coverage data from `filename` into this object.�dataiozReading data from %rNz$Couldn't read data from '%s': %s: %s)	r�should�write�_open_for_readingrC�	Exceptionrrr)rr*r/�excrrr�	read_fileszCoverageData.read_filez?!coverage.py: This is a private format, don't read it directly!cCs
t|d�S)z+Open a file appropriately for reading data.�r)�open)�clsr*rrrrG/szCoverageData._open_for_readingcCs,|�t|j��}||jkr"td��t�|�S)z%Read the raw data from a file object.z*Doesn't seem to be a coverage.py data file)�readr�_GO_AWAYr�json�load)rMrAZgo_awayrrrr>4s
zCoverageData._read_raw_datac	Cs |�|��}|�|�SQRXdS)z-Read the raw data from a file, for debugging.N)rGr>)rMr*r/rrr�_read_raw_data_file<sz CoverageData._read_raw_data_filecCs�|jr<|j�d�r<|j�dt|�tdd�|��D��f�|��rLtd��|jdkr\i|_xHt	|�D]<\}}||jkr�t
|j|�}|�|�|}t|�|j|<qfW|�
�dS)z�Add measured line data.

        `line_data` is a dictionary mapping file names to dictionaries::

            { filename: { lineno: None, ... }, ...}

        �dataopz&Adding lines: %d files, %d lines totalcss|]}t|�VqdS)N)r)r!rrrrr#Psz)CoverageData.add_lines.<locals>.<genexpr>z$Can't add lines to existing arc dataN)rrErFr�sum�valuesrrrrr)�updater(r@)rZ	line_datar*ZlinenosZnew_linenosrrr�	add_linesFs"


zCoverageData.add_linescCs�|jr<|j�d�r<|j�dt|�tdd�|��D��f�|��rLtd��|jdkr\i|_xHt	|�D]<\}}||jkr�t
|j|�}|�|�|}t|�|j|<qfW|�
�dS)z�Add measured arc data.

        `arc_data` is a dictionary mapping file names to dictionaries::

            { filename: { (l1,l2): None, ... }, ...}

        rSz$Adding arcs: %d files, %d arcs totalcss|]}t|�VqdS)N)r)r!rrrrr#jsz(CoverageData.add_arcs.<locals>.<genexpr>z$Can't add arcs to existing line dataN)rrErFrrTrU�
_has_linesrr
rr)rVr(r@)rZarc_datar*rZnew_arcsrrr�add_arcs`s"


zCoverageData.add_arcscCs�|jr(|j�d�r(|j�dt|�f�|jp6|jp6i}xbt|�D]V\}}||kr`td|f��|j�	|�}|dk	r�||kr�td|||f��||j|<qBW|�
�dS)zdAdd per-file plugin information.

        `file_tracers` is { filename: plugin_name, ... }

        rSzAdding file tracers: %d filesz3Can't add file tracer data for unmeasured file '%s'Nz/Conflicting file tracer name for '%s': %r vs %r)rrErFrr
rrrrr$r@)rr=Zexisting_filesr*Zplugin_nameZexisting_pluginrrr�add_file_tracerszszCoverageData.add_file_tracerscKsN|jr$|j�d�r$|j�d|f�|js2ig|_|jd�|�|��dS)z�Add information about the run.

        Keywords are arbitrary, and are stored in the run dictionary. Values
        must be JSON serializable.  You may use this function more than once,
        but repeated keywords overwrite each other.

        rSzAdding run info: %rrN)rrErFrrVr@)r�kwargsrrr�add_run_info�szCoverageData.add_run_infocCsj|jr$|j�d�r$|j�d|f�|��s<|��s<td��|��rL|j}n|j}|�|g�|�	�dS)z<Ensure that `filename` appears in the data, empty if needed.rSzTouching %rz*Can't touch files in an empty CoverageDataN)
rrErFrrXrr
r�
setdefaultr@)rr*�whererrr�
touch_file�szCoverageData.touch_filecCsdi}|��r|j|d<|��r(|j|d<|jr8|j|d<|jrH|j|d<|�|j�t�	||�dS)z&Write the coverage data to `file_obj`.rrr=rN)
rr
rXrrrrFrOrP�dump)rrAZ	file_datarrr�
write_fileobj�s



zCoverageData.write_fileobjc	CsH|jr$|j�d�r$|j�d|f�t|d��}|�|�WdQRXdS)z&Write the coverage data to `filename`.rDzWriting data to %r�wN)rrErFrLra)rr*Zfdatarrr�
write_file�szCoverageData.write_filecCs$d|_d|_i|_g|_|��dS)zErase the data in this object.N)rr
rrr@)rrrr�erase�s
zCoverageData.erasec
Cs�|��r|��rtd��|��r0|��r0td��|p8t�}x`|��D]T}|�|�}|�|�}|�|�}|dkr~|r�||j|<qD||krDtd|||f��qDW|j�	|j�|���r|j
dkr�i|_
xVt|j
�D]H\}}|�|�}||j
k�rt|j
|�}|�
|�t|�}||j
|<q�W|���r�|jdk�r8i|_xXt|j�D]J\}}|�|�}||jk�r�t|j|�}	|	�
|�t|	�}||j|<�qDW|��dS)z�Update this data with data from another `CoverageData`.

        If `aliases` is provided, it's a `PathAliases` object that is used to
        re-map paths to match the local machine's.

        z%Can't combine arc data with line dataz%Can't combine line data with arc dataNz/Conflicting file tracer name for '%s': %r vs %r)rXrrrr.r,�maprr�extendrrr)rVr(r
r@)
rZ
other_data�aliasesr*Zother_pluginZthis_pluginZ
file_linesrZ	file_arcsrrrrrV�sL










zCoverageData.updatecCstjr|��dS)z>If we are in paranoid mode, validate that everything is right.N)rZTESTING�_validate_invariants)rrrrr@szCoverageData._validatecCsl|��r|��rtd��|��rrxPt|j�D]B\}}t|t�sLtd|f��tdd�|D��s,td||f��q,W|��r�xPt|j�D]B\}}t|t�s�td|f��tdd�|D��s�td||f��q�WxNt|j	�D]@\}}t|t�s�td	|f��|�rt|t�s�td
||f��q�WxJ|j
D]@}t|t��s8t�x(|D] }t|t��s>td|f���q>W�q$WdS)
zValidate internal invariants.z$Shouldn't have both _lines and _arcszKey in _lines shouldn't be %rcss|]}t|t�VqdS)N)�
isinstance�int)r!�xrrrr#'sz4CoverageData._validate_invariants.<locals>.<genexpr>z_lines[%r] shouldn't be %rzKey in _arcs shouldn't be %rcss&|]\}}t|t�ot|t�VqdS)N)rirj)r!rk�yrrrr#/sz_arcs[%r] shouldn't be %rz$Key in _file_tracers shouldn't be %rz _file_tracers[%r] shoudn't be %rzKey in _runs shouldn't be %rN)rXr�AssertionErrorrrrir�allr
rrr?)rr<rrZplugin�val�keyrrrrhs*
z!CoverageData._validate_invariantscCsN|��r"|�t|�|�pg��n|�t|�|�p4g��|�|�|��dS)z�Contribute `filename`'s data to the `hasher`.

        `hasher` is a `coverage.misc.Hasher` instance to be updated with
        the file's data.  It should only get the results data, not the run
        data.

        N)rrV�sortedrrr,)rr*Zhasherrrr�add_to_hashBszCoverageData.add_to_hashcCs
|jdk	S)zDo we have data in self._lines?N)r)rrrrrXTszCoverageData._has_linescCs
|jdk	S)zDo we have data in self._arcs?N)r
)rrrrrXszCoverageData._has_arcs)N)F)N)$r�
__module__�__qualname__�__doc__rrr rrr,r-r.r6r8�__bool__rCrJrO�classmethodrGr>rRrWrYrZr\r_rarcrdrVr@rhrrrXrrrrrr
s@?
 




@&r
c@s@eZdZdZddd�Zddd�Zdd	�Zdd
d�Zddd
�ZdS)�CoverageDataFilesz&Manage the use of coverage data files.NcCs||_tj�|pd�|_dS)z�Create a CoverageDataFiles to manage data files.

        `warn` is the warning function to use.

        `basename` is the name of the file to use for storing data.

        z	.coverageN)�warnr2r3�abspathr*)rr4ryrrrr`szCoverageDataFiles.__init__FcCs^t|j�|rZtj�|j�\}}|d}tj�tj�|�|�}xt�|�D]}t|�qJWdS)z�Erase the data from the file storage.

        If `parallel` is true, then also deletes data files created from the
        basename by parallel-mode.

        z.*N)rr*r2r3�split�joinrz�glob)r�parallel�data_dir�local�localdot�patternr*rrrrdls
zCoverageDataFiles.erasecCstj�|j�r|�|j�dS)zRead the coverage data.N)r2r3�existsr*rJ)rrBrrrrN{szCoverageDataFiles.readc	Csx|j}|dkrZd}tr:tt��}|��}WdQRXd|}dt��|t��t�	dd�f}|rj|d|7}|�
|�dS)a7Write the collected coverage data to a file.

        `suffix` is a suffix to append to the base file name. This can be used
        for multiple or parallel execution, so that many coverage data files
        can exist simultaneously.  A dot will be used to join the base name and
        the suffix.

        Tr+N�.z%s%s.%s.%06dri?B)r*rrLrN�socket�gethostnamer2�getpid�random�randintrc)rrB�suffixr*�extrar/Z	test_namerrrrF�s	
zCoverageDataFiles.writec
Cstj�|j�\}}|d}|p"|g}g}xn|D]f}tj�|�rR|�tj�|��q.tj�|�r�tj�tj�|�|�}	|�	t
�
|	��q.td|f��q.Wxn|D]f}
t�}y|�
|
�Wn6tk
r�}z|jr�|�t|��Wdd}~XYq�X|j||d�t|
�q�WdS)abCombine a number of data files together.

        Treat `self.filename` as a file prefix, and combine the data from all
        of the data files starting with that prefix plus a dot.

        If `aliases` is provided, it's a `PathAliases` object that is used to
        re-map paths to match the local machine's.

        If `data_paths` is provided, it is a list of directories or files to
        combine.  Directories are searched for files that start with
        `self.filename` plus dot as a prefix, and those files are combined.

        If `data_paths` is not provided, then the directory portion of
        `self.filename` is used as the directory to search for data files.

        Every data file found and combined is then deleted from disk. If a file
        cannot be read, a warning will be issued, and the file will not be
        deleted.

        z.*z,Couldn't combine from non-existent path '%s'N)rg)r2r3r{r*�isfile�appendrz�isdirr|rfr}rr
rJry�strrVr)
rrBrgZ
data_pathsrr�r�Zfiles_to_combine�pr�r/Znew_datarIrrr�combine_parallel_data�s(


 z'CoverageDataFiles.combine_parallel_data)NN)F)N)NN)	rrsrtrurrdrNrFr�rrrrrx]s


rxcCs`x,t|�di��D]\}}t|�|d|<qWx,t|�di��D]\}}t|�|d|<q@WdS)z1Canonicalize our JSON data so it can be compared.rrN)rr$rq)rBr<rrrrr�canonicalize_json_data�sr�cCs0tj|ddd�}t�dd|�}t�dd|�}|S)zLFormat data as JSON, but as nicely as possible.

    Returns a string.

    �T)�indent�	sort_keysz\[\s+(-?\d+),\s+(-?\d+)\s+]z[\1, \2]z(?m)\s+$r+)rP�dumps�re�sub)rB�outrrr�pretty_data�sr�cCsrt��}|jddddd�|�|�\}}xD|p2dgD]6}td�|��t�|�}|jr^t	|�tt
|��q4WdS)	zeDump the raw data from data files.

    Run this as::

        $ python -m coverage.data [FILE]

    z-cz--canonical�
store_truez Sort data into a canonical order)�action�helpz	.coveragez&--- {0} ------------------------------N)�optparse�OptionParser�
add_option�
parse_args�printrr
rR�	canonicalr�r�)�args�parser�optionsr*rBrrr�
debug_main�s
r��__main__�) rur}r%rPr�r2�os.pathr�r�r��coveragerZcoverage.backwardrrZcoverage.debugrZcoverage.filesrZ
coverage.miscrrr	�objectr
rxr�r�r�r�sys�argvrrrr�<module>s6Hs