Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/testfixtures/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/testfixtures/__pycache__/comparison.cpython-37.pyc

B

R�XW�@s�ddlmZddlmZddlmZddlmZmZddl	m
Z
ddlmZm
Z
mZmZmZmZddlmZddlmZd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zede�Zdd�Z dd�Z!d d!�Z"d"d#�Z#e$ee%ee&ee'ee(e"e
e"eeej)eej)ei	Z*d$d%�Z+d&d'�Z,d(d)�Z-ee$fZ.Gd*d+�d+e/�Z0d,d-�Z1Gd.d/�d/e/�Z2Gd0d1�d1�Z3Gd2d3�d3�Z4d:d5d6�Z5Gd7d8�d8�Z6d9S);�)�Iterable)�unified_diff)�pformat)�compile�	MULTILINE)�	not_there)�	ClassType�Unicode�
basestring�PY3�	mock_call�unittest_mock_call)�resolve)�
GeneratorTypecCs>|jrt|�t|�krdS|�dt|��d|�dt|��S)zT
    Returns a very simple textual difference between the two supplied objects.
    N�xz != �y)�	ignore_eq�hash�label�repr)rr�context�r�H/opt/alt/python37/lib/python3.7/site-packages/testfixtures/comparison.py�compare_simplesrc	CsLt�}i}x4dD],}||}|�|d�t|�t|���||<qWdjf|�S)zy
    Return a textual description of the difference between two objects
    including information about their types.
    )rrz{0} ({1!r})z
{x} != {y})�localsr�format�_short_repr�type)rrr�sourceZ	to_render�name�objrrr�compare_with_types
r!c	Cs�t|�}t|�}d}x8||krL||krL|�||||d|�rBP|d7}qW||krb||krbdSdt|d|��|jpzdt||d��|jp�dt||d��fS)zb
    Returns a textual description of the differences between the two
    supplied sequences.
    rz[%i]�Nz3sequence not as expected:

same:
%s

%s:
%s

%s:
%s�first�second)�len�	differentr�x_label�y_label)rrrZl_xZl_y�irrr�compare_sequence)sr*cCs.t|�}t|�}|js"||kr"dSt|||�S)z�
    Returns a textual description of the differences between the two
    supplied generators.

    This is done by first unwinding each of the generators supplied
    into tuples and then passing those tuples to
    :func:`compare_sequence`.
    N)�tuplerr*)rrrrrr�compare_generatorBs
	r,cCsbt|dd�}t|dd�}|rV|rV||krJttt||��tt||��||�St|||�St|||�S)z�
    Returns a textual difference between two tuples or
    :func:`collections.namedtuple` instances.

    The presence of a ``_fields`` attribute on a tuple is used to
    decide whether or not it is a :func:`~collections.namedtuple`.
    �_fieldsN)�getattr�_compare_mapping�dict�zipr!r*)rrrZx_fieldsZy_fieldsrrr�
compare_tupleTsr2cCst||||�S)ze
    Returns a textual description of the differences between the two
    supplied dictionaries.
    )r/)rrrrrr�compare_dictisr3cCst|dd�d�S)NcSst|�S)N)r)�orrr�<lambda>r�z sorted_by_repr.<locals>.<lambda>)�key)�sorted)�sequencerrr�sorted_by_reprqsr:cCs�t|���}t|���}||}||}g}g}	xrt|�|��D]`}
|�||
||
d|
f�r�|	�d|
|�dt||
��|�dt||
��f�q@|�|
�q@Wd|jj	g}|r�t|�}||kr�|kr�nndS|�
ddt|�f�|jp�d}
|j
�pd	}|�rN|�
dd
|
|ff�x,t|�D] }
|�d|
t||
�f��q*W|�r�|�
dd
||
ff�x,t|�D] }
|�d|
t||
�f��qtW|	�r�|�
d�|�
|	�d
�|�S)Nz[%r]z%r: %s != %srrz%s not as expected:�zsame:r#r$zin %s but not %s:z%r: %s)r;zvalues differ:�
)�set�keysr:�intersectionr&�appendrr�	__class__�__name__�extendrr'r(�join)rrrZ
obj_for_classZx_keysZy_keys�x_not_y�y_not_xZsameZdiffsr7�linesZset_samer'r(rrrr/usJ


r/cCs�||}||}d|jjdg}|jp(d}|jp2d}|rX|�d||ftt|��df�|r||�d||ftt|��df�d�|�dS)z]
    Returns a textual description of the differences between the two
    supplied sets.
    z%s not as expected:r;r#r$zin %s but not %s:r<)rArBr'r(rCrr:rD)rrrrErFrGr'r(rrr�compare_set�s 





rHz\s+$cCs8g}x(|�d�D]}|r|��s|�|�qWd�|�S)Nr<)�split�isspacer@rD)�text�result�linerrr�strip_blank_lines�s
rNcCsR|�d�}x,t|dd��D]\}}t|d�||<qWt|d�|d<d�|�S)Nr<���)rI�	enumeraterrD)rK�partsr)�partrrr�
split_repr�s

rSc	Cs�|�dd�}|�dd�}|�dd�}|s@t�d|�}t�d|�}|sTt|�}t|�}||kr`dS|�dt|��}|�d	t|��}t|�d
ks�t|�d
kr�d|ks�d|kr�|r�t|�}t|�}dt|||j	|j
�}q�d||f}n|d
|}|S)a�
    Returns an informative string describing the differences between the two
    supplied strings. The way in which this comparison is performed
    can be controlled using the following parameters:

    :param blanklines: If `False`, then when comparing multi-line
                       strings, any blank lines in either argument
                       will be ignored.

    :param trailing_whitespace: If `False`, then when comparing
                                multi-line strings, trailing
                                whilespace on lines will be ignored.

    :param show_whitespace: If `True`, then whitespace characters in
                            multi-line strings will be replaced with their
                            representations.
    �
blanklinesT�trailing_whitespace�show_whitespaceFr;Nrr�
r<z	
%s
!=
%sz != )�
get_option�trailing_whitespace_re�subrNrrr%rS�diffr'r()	rrrrTrUrVZ
labelled_xZ
labelled_y�messagerrr�compare_text�s,r]cCs(t|�}t|�dkr$|dd�d}|S)N�z...)rr%)r �repr_rrrr�srcCs|t|<dS)z�
    Register the supplied comparer for the specified type.
    This registration is global and will be in effect from the point
    this function is called until the end of the current process.
    N)�	_registry)r�comparerrrr�registersrbcCs8t|dd�}|dkr|fSt|dd�}|dkr4|fS|S)NrA�__mro__)r.)r �class_�mrorrr�_mrosrfccs0tt|��}xt|�D]}||kr|VqWdS)N)r=rf)rrZy_mrordrrr�_shared_mro%srgc@sNeZdZdZZdd�Zdd�Zddd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdS)�CompareContextNcCs�|�dd�}|r(tt�|_|j�|�nt|_|�dd�|_|�dd�|_|�dd�|_d|kshd|krtd|_d|_	|�d	|j�|_|�d
|j	�|_	||_
d|_g|_dS)N�	comparers�	recursiveT�strictFr�expected�actualr'r(r;)
�popr0r`�registry�updaterjrkrr'r(�optionsr\�breadcrumbs)�selfrqrirrr�__init__2s 
zCompareContext.__init__cCsng}|j�dt�}|tk	r$|�|�|�|�|j�dt�}|tk	rN|�|�t|�dkrjtdt|���|S)Nrlrm�z*Exactly two objects needed, you supplied: )rqrnrr@rCr%�	TypeErrorr)rs�args�possiblerlrmrrr�extract_argsHs


zCompareContext.extract_argscCs|j�||�S)N)rq�get)rsr�defaultrrrrX[szCompareContext.get_optioncCs.t|�}t||d�}|r*|d|d7}|S)NZ_labelz (�))�strr.)rsZside�value�rrrrrr^s
zCompareContext.labelcCsr|jrt|�t|�k	rtSx&t||�D]}|j�|�}|r&|Sq&Wt|t�rnt|t�rnt|t�snt|t�snt	St
S)N)rkrr!rgrorz�
isinstancer�_unsafe_iterablesr,r)rsrrrdrarrr�_lookupes

zCompareContext._lookupcCsdd�|jdd��S)Nz

While comparing %s: r;r")rDrr)rsrrr�
_separatorvszCompareContext._separatorc
Cs�t|j�}|j�|�|j}d|_d}z�|js@|js@||kr@dS|�||�}||||�}|tk	}	|jr�t|�t|�kr�||kr�|	s�dS|r�|	r�|r�|�	�}|	s�|s�||7}|j
r�||j7}|S|||_|j��XdS)Nr;F)�boolrrr@r\rkrr�rrr�rjrn)
rsrrZ
breadcrumbZrecursedZexisting_messageZcurrent_messagerarLZspecific_comparerrrrr&ys0


zCompareContext.different)N)rB�
__module__�__qualname__r'r(rtryrXrr�r�r&rrrrrh.s
rhc	Os�|�dd�}|�dd�}|�dd�}t|�}|�|�\}}|�||t�sLdS|j}|rb|d|}|rr|d|7}|r~t|��|S)a�
    Compare the two arguments passed either positionally or using
    explicit ``expected`` and ``actual`` keyword paramaters. An
    :class:`AssertionError` will be raised if they are not the same.
    The :class:`AssertionError` raised will attempt to provide
    descriptions of the differences found.

    Any other keyword parameters supplied will be passed to the functions
    that end up doing the comparison. See the API documentation below
    for details of these.

    :param prefix: If provided, in the event of an :class:`AssertionError`
                   being raised, the prefix supplied will be prepended to the
                   message in the :class:`AssertionError`.

    :param suffix: If provided, in the event of an :class:`AssertionError`
                   being raised, the suffix supplied will be appended to the
                   message in the :class:`AssertionError`.

    :param raises: If ``False``, the message that would be raised in the
                   :class:`AssertionError` will be returned instead of the
                   exception being raised.

    :param recursive: If ``True``, when a difference is found in a
                      nested data structure, attempt to highlight the location
                      of the difference.

    :param strict: If ``True``, objects will only compare equal if they are
                   of the same type as well as being equal.

    :param ignore_eq: If ``True``, object equality, which relies on ``__eq__``
                      being correctly implemented, will not be used.
                      Instead, comparers will be looked up and used
                      and, if no suitable comparer is found, objects will
                      be considered equal if their hash is equal.

    :param comparers: If supplied, should be a dictionary mapping
                      types to comparer functions for those types. These will
                      be added to the global comparer registry for the duration
                      of this call.
    �prefixN�suffix�raisesTz: r<)rnrhryr&rr\�AssertionError)	rw�kwr�r�r�rrrr\rrr�compare�s*r�c@s8eZdZdZdZd
dd�Zdd�Zdd	�Zddd�ZdS)�
Comparisona�
    These are used when you need to compare objects
    that do not natively support comparison.

    :param object_or_type: The object or class from which to create the
                           :class:`Comparison`.

    :param attribute_dict: An optional dictionary containing attibutes
                           to place on the :class:`Comparison`.

    :param strict: If true, any expected attributes not present or extra
                   attributes not expected on the object involved in the
                   comparison will cause the comparison to fail.

    :param attributes: Any other keyword parameters passed will placed
                       as attributes on the :class:`Comparison`.
    NTc	Ks�|r|dkr|}n
|�|�t|t�rLt|�\}}}}|tkr�td|��nVt|ttf�r`|}nBt|t�r�|j	}|dkr�t
|�}|j|d<n|j	}|dkr�t
|�}||_||_
||_dS)Nz%r could not be resolvedrw)rpr�r
rr�AttributeErrorrr�
BaseExceptionrA�varsrw�c�vrk)	rsZobject_or_typeZattribute_dictrkZ
attributesZ	container�methodrr�rrrrt�s,


zComparison.__init__cCs�|j|jk	rd|_dS|jdkr$dSi|_t|t�r^tt|��}|j|d<t	r�d|kr�|d=ntyt|�}Wnft
k
r�|jr�t
d|��i}x:|j��D],}yt
||�||<Wq�tk
r�Yq�Xq�WYnXt|j���}t|���}x^|�|�D]P}yt
||�||<Wn.tk
�r<dt|j|�|j|<Yq�X|�|�q�W|j�r�x*|�|�D]}dt||�|j|<�q`WxB|�|�D]4}|j|}||}||k�r�d||f|j|<�q�W|j�r�dSdS)	NTFrwZ
_not_foundz9%r does not support vars() so cannot do strict comparisonz%s not in otherz%s not in Comparisonz%r != %r)r�rA�failedr�r�r�r0r�rwrrvrkr>r.r�r=�
differencer�addr?)rs�otherr��k�e�aZev�avrrr�__eq__sV




zComparison.__eq__cCs
||kS)Nr)rsr�rrr�__ne__EszComparison.__ne__ruc
Csd}|jdkrd}n�|jdkr$d}n�d}d}|jr>|j}t}n
|j}t}xRt|���D]B\}}t|t�rx|�|d�}n||�}|d|d||f7}qVW|d|d	7}t	|j
d
d�}	|	r�|	d7}	|	t	|j
dd�7}	|	s�t|j
�}	d
|jr�dp�d|	|f}|�rdd||S|SdS)NFTzwrong type</C>r;r<ru� z%s:%s
z</C>r��.rBz
<C%s:%s>%sz(failed))r�r�r}rr8�itemsr�r��__repr__r.r�)
rs�indent�fullr�ZvdrZvk�vvZvvrrrrrr�Hs8



zComparison.__repr__)NT)ru)	rBr�r��__doc__r�rtr�r�r�rrrrr��s
2r�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�StringComparisona�
    An object that can be used in comparisons of expected and actual
    strings where the string expected matches a pattern rather than a
    specific concrete string.

    :param regex_source: A string containing the source for a regular
                         expression that will be used whenever this
                         :class:`StringComparison` is compared with
                         any :class:`basestring` instance.

    cCst|�|_dS)N)r�re)rsZregex_sourcerrrrtwszStringComparison.__init__cCs"t|t�sdS|j�|�rdSdS)NTF)r�r
r��match)rsr�rrrr�zs

zStringComparison.__eq__cCs
||kS)Nr)rsr�rrrr��szStringComparison.__ne__cCsd|jjS)Nz<S:%s>)r��pattern)rsrrrr��szStringComparison.__repr__cCs|jj|kS)N)r�r�)rsr�rrr�__lt__�szStringComparison.__lt__cCs|jj|kS)N)r�r�)rsr�rrr�__gt__�szStringComparison.__gt__N)
rBr�r�r�rtr�r�r�r�r�rrrrr�ksr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�RoundComparisona
    An object that can be used in comparisons of expected and actual
    numerics to a specified precision.

    :param value: numeric to be compared.

    :param precision: Number of decimal places to round to in order
                      to perform the comparison.
    cCst||�|_||_dS)N)�round�rounded�	precision)rsr~r�rrrrt�szRoundComparison.__init__cCs<t||j�}t|j�t|�k	r2td|t|�f��|j|kS)NzCannot compare %r with %r)r�r�rr�rv)rsr�Z
other_roundedrrrr��szRoundComparison.__eq__cCs
||kS)Nr)rsr�rrrr��szRoundComparison.__ne__cCsd|j|jfS)Nz<R:%s to %i digits>)r�r�)rsrrrr��szRoundComparison.__repr__N)rBr�r�r�rtr�r�r�rrrrr��s
	r�r;c	Cs,d�t|�d�|�d�|pd|p"ddd��S)z�
    A shorthand function that uses :mod:`difflib` to return a
    string representing the differences between the two string
    arguments.

    Most useful when comparing multi-line strings.
    r<r#r$r;)Zlineterm)rDrrI)rrr'r(rrrr[�sr[c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�RangeComparisona
    An object that can be used in comparisons of orderable types to
    check that a value specified within the given range.

    :param lower_bound: the inclusive lower bound for the acceptable range.

    :param upper_bound: the inclusive upper bound for the acceptable range.
    cCs||_||_dS)N)�lower_bound�upper_bound)rsr�r�rrrrt�szRangeComparison.__init__cCs|j|ko|jkSS)N)r�r�)rsr�rrrr��szRangeComparison.__eq__cCs
||kS)Nr)rsr�rrrr��szRangeComparison.__ne__cCsd|j|jfS)Nz<Range: [%s, %s]>)r�r�)rsrrrr��szRangeComparison.__repr__N)rBr�r�r�rtr�r�r�rrrrr��s
r�N)r;r;)7�collectionsrZdifflibr�pprintrr�rr�testfixturesrZtestfixtures.compatrr	r
rrr
Ztestfixtures.resolver�typesrrr!r*r,r2r3r:r/rHrYrNrSr]rr0r=�listr+r}rAr`rbrfrgr��objectrhr�r�r�r�r[r�rrrr�<module>sT 	/
-
	r?
#