ó
çiõ\c           @` s~  d  Z  d d l m Z d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l	 m
 Z
 d d l m Z d d	 l m Z d Z d
 „  Z d „  Z d „  Z d „  Z y
 e Z Wn e k
 r× e Z n Xd „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z  d d „ Z! d d „ Z" d d „ Z# d d „ Z$ d „  Z% d d „ Z& d S(   s!   Utilities for assertion debuggingi    (   t   absolute_import(   t   division(   t   print_functionNi   (   t   Sequence(   t   outcomes(   t   safereprc         C` s'   t  |  t ƒ r |  j d d ƒ S|  Sd  S(   Ns   UTF-8t   replace(   t
   isinstancet   bytest   decode(   t   s(    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt   ecu   s    c         C` s1   t  |  ƒ }  t |  ƒ } t | ƒ } d j | ƒ S(   sŒ  This formats an explanation

    Normally all embedded newlines are escaped, however there are
    three exceptions: 
{, 
} and 
~.  The first two are intended
    cover nested explanations, see function and attribute explanations
    for examples (.visit_Call(), visit_Attribute()).  The last one is
    for when one explanation needs to span multiple lines, e.g. when
    displaying diffs.
    u   
(   R   t   _split_explanationt   _format_linest   join(   t   explanationt   linest   result(    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt   format_explanation    s    
c         C` su   |  p	 d j  d ƒ } | d g } xL | d D]@ } | rY | d d k rY | j | ƒ q- | d	 c d
 | 7<q- W| S(   sÞ   Return a list of individual lines in the explanation

    This will return a list of lines split on '
{', '
}' and '
~'.
    Any other newlines will be escaped and appear in the line as the
    literal '
' characters.
    u    s   
i    i   t   {t   }t   ~t   >iÿÿÿÿs   \n(   R   R   R   R   (   t   splitt   append(   R   t	   raw_linesR   t   values(    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyR   0   s    c         C` s{  |  d  } d g } d g } x@|  d D]4} | j  d ƒ r³ | d rO d } n d } | j t | ƒ ƒ | d c d 7<| j d ƒ | j d d t | ƒ d | | d ƒ q' | j  d	 ƒ rñ | j ƒ  | j ƒ  | | d c | d 7<q' | d d k st ‚ | d c d 7<| j  d
 ƒ r2t | ƒ n t | ƒ d } | j d | | d ƒ q' Wt | ƒ d k swt ‚ | S(   s
  Format the individual lines

    This will replace the '{', '}' and '~' characters of our mini
    formatting language with the proper 'where ...', 'and ...' and ' +
    ...' text, taking care of indentation along the way.

    Return a list of formatted lines.
    i   i    R   iÿÿÿÿu   and   u   where u    +u     R   R   R   (   R   R   (   t
   startswithR   t   lent   popt   AssertionError(   R   R   t   stackt   stackcntt   lineR
   t   indent(    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyR   A   s,    	
		
	.

+c         C` s   t  |  t ƒ o t  |  t ƒ S(   N(   R   R   t
   basestring(   t   x(    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt
   issequencek   s    c         C` s   t  |  t ƒ S(   N(   R   R#   (   R$   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt   istexto   s    c         C` s   t  |  t ƒ S(   N(   R   t   dict(   R$   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt   isdicts   s    c         C` s   t  |  t t f ƒ S(   N(   R   t   sett	   frozenset(   R$   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt   issetw   s    c         C` s   t  |  d d  ƒ d  k	 S(   Nt   __dataclass_fields__(   t   getattrt   None(   t   obj(    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt	   isdatacls{   s    c         C` s   t  |  d d  ƒ d  k	 S(   Nt   __attrs_attrs__(   R-   R.   (   R/   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt   isattrs   s    c         C` s2   y t  |  ƒ t |  ƒ SWn t k
 r- t SXd  S(   N(   t   iterR&   t	   TypeErrort   False(   R/   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt
   isiterableƒ   s
    
c         C` s¤  d t  | ƒ d } t | d t | d ƒ ƒ} t | d | t  | ƒ ƒ} d t | ƒ | t | ƒ f } |  j d ƒ } d }	 yÄ| d k rt | ƒ r¼ t | ƒ r¼ t | | | ƒ }	 qCt | ƒ ré t | ƒ ré t	 | | | ƒ }	 nÌ t
 | ƒ rt
 | ƒ rt | | | ƒ }	 nŸ t | ƒ rCt | ƒ rCt | | | ƒ }	 nr t | ƒ t | ƒ k r—t | ƒ sst | ƒ r—t t f }
 t | | | |
 ƒ }	 n | d k rµt | | ƒ }	 n  t | ƒ rCt | ƒ rCt | | | ƒ } |	 d k	 rû|	 j | ƒ q| }	 qCn< | d	 k rCt | ƒ rCt | ƒ rCt | | | ƒ }	 qCn  WnH t j k
 r]‚  n2 t k
 rŽd
 t j t j j j ƒ  ƒ g }	 n X|	 s™d S| g |	 S(   s;   Return specialised explanations for some operators/operandsiP   i   i   t   maxsizeu   %s %s %st   verboses   ==i    s   not inug   (pytest_assertion plugin: representation of details failed.  Probably an object has a faulty __repr__.)iA   N(    R   R   t   intR   t	   getoptionR.   R&   t
   _diff_textR%   t   _compare_eq_sequenceR+   t   _compare_eq_setR(   t   _compare_eq_dictt   typeR0   R2   t   _compare_eq_clst   _compare_eq_verboseR6   t   _compare_eq_iterablet   extendt   _notin_textR   t   Exitt	   Exceptiont   sixt	   text_typet   _pytestt   _codet   ExceptionInfot   from_current(   t   configt   opt   leftt   rightt   widtht	   left_reprt
   right_reprt   summaryR8   R   t   type_fnt   expl(    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt   assertrepr_compare‹   sJ    0"c   	      C` s  d d l  m } g  } d „  } t |  t ƒ r= | |  ƒ }  n  t | t ƒ r[ | | ƒ } n  | d k  r…d } xA t t t |  ƒ t | ƒ ƒ ƒ D] } |  | | | k r Pq q W| d k rë | d 8} d | g } |  | }  | | } n  t |  ƒ t | ƒ k r…x4 t t |  ƒ ƒ D]  } |  | | | k rPqqW| d k r‚| d 8} | d j | ƒ g 7} |  |  }  | |  } q‚q…n  t } |  j	 ƒ  s£| j	 ƒ  r×t
 t |  ƒ ƒ }  t
 t | ƒ ƒ } | d	 g 7} n  | g  | |  j | ƒ | j | ƒ ƒ D] } | j d
 ƒ ^ qü7} | S(   s  Return the explanation for the diff between text or bytes.

    Unless --verbose is used this will skip leading and trailing
    characters which are identical to keep the diff minimal.

    If the input are bytes they will be safely converted to text.
    i    (   t   ndiffc         S` sD   t  j t |  ƒ d d !ƒ } | j d d ƒ } | j d d ƒ } | S(   s  
        Ensures that the internal string is always valid unicode, converting any bytes safely to valid unicode.
        This is done using repr() which then needs post-processing to fix the encompassing quotes and un-escape
        newlines and carriage returns (#429).
        i   iÿÿÿÿs   \ns   
s   \rs   (   RG   RH   t   reprR   (   t   binary_textt   r(    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt   escape_for_readable_diffÉ   s    i   i*   i
   u@   Skipping %s identical leading characters in diff, use -v to showuA   Skipping {} identical trailing characters in diff, use -v to showu;   Strings contain only whitespace, escaping them using repr()s   
(   t   difflibRX   R   R   t   ranget   minR   t   formatt   Truet   isspaceRY   t   strt
   splitlinest   strip(	   RO   RP   R8   RX   R   R\   t   it   keependsR!   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyR;   ½   sJ    	(


;c         C` s|   t  } t |  ƒ j | ƒ } t | ƒ j | ƒ } g  } | g  | D] } d | ^ q@ 7} | g  | D] } d | ^ qa 7} | S(   Nu   -u   +(   Ra   RY   Rd   (   RO   RP   Rg   t
   left_linest   right_linesR   R!   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyRA   ü   s    !!c         C` sÀ   | s d g Sd d  l  } y7 t j |  ƒ j ƒ  } t j | ƒ j ƒ  } d g } WnF t k
 r˜ t d „  |  Dƒ ƒ } t d „  | Dƒ ƒ } d g } n X| j d „  | j | | ƒ Dƒ ƒ | S(   Nu   Use -v to get the full diffi    u
   Full diff:c         s` s   |  ] } t  | ƒ Vq d  S(   N(   RY   (   t   .0R$   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pys	   <genexpr>  s    c         s` s   |  ] } t  | ƒ Vq d  S(   N(   RY   (   Rj   R$   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pys	   <genexpr>  s    u2   Full diff (fallback to calling repr on each item):c         s` s   |  ] } | j  ƒ  Vq d  S(   N(   Re   (   Rj   R!   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pys	   <genexpr>  s    (   R]   t   pprintt   pformatRd   RF   t   sortedRC   RX   (   RO   RP   R8   R]   t   left_formattingt   right_formattingR   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyRB     s    c   
      C` s  g  } t  |  ƒ } t  | ƒ } xW t t | | ƒ ƒ D]@ } |  | | | k r4 | d | |  | | | f g 7} Pq4 q4 W| | } | r| d k r­ d } t |  | ƒ }	 n  d | } d } t | | ƒ }	 | d k ró | d | |	 f g 7} q| d | | |	 f g 7} n  | S(   Nu   At index %s diff: %r != %ri    t   Leftt   Righti   u   %s contains one more item: %su/   %s contains %d more items, first extra item: %s(   R   R^   R_   R   (
   RO   RP   R8   R   t   len_leftt	   len_rightRf   t   len_difft   dir_with_moret   extra(    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyR<     s*    "

c         C` s’   g  } |  | } | |  } | rT | j  d ƒ x$ | D] } | j  t | ƒ ƒ q4 Wn  | rŽ | j  d ƒ x$ | D] } | j  t | ƒ ƒ qn Wn  | S(   Nu   Extra items in the left set:u   Extra items in the right set:(   R   R   (   RO   RP   R8   R   t	   diff_leftt
   diff_rightt   item(    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyR=   <  s    

c         ` s  g  } t  ˆ  ƒ } t  ˆ ƒ } | j | ƒ } ‡  ‡ f d †  | Dƒ } | rr | d k  rr | d t | ƒ g 7} n/ | r¡ | d g 7} | t j | ƒ j ƒ  7} n  ‡  ‡ f d †  | Dƒ } | r| d g 7} xH | D]= }	 | t i ˆ  |	 |	 6ƒ d t i ˆ |	 |	 6ƒ g 7} qÔ Wn  | | }
 t |
 ƒ } | rŒ| j d | | d	 k rRd
 n d f ƒ | j t j ‡  f d †  |
 Dƒ ƒ j ƒ  ƒ n  | | } t | ƒ } | r | j d | | d	 k rÆd
 n d f ƒ | j t j ‡ f d †  | Dƒ ƒ j ƒ  ƒ n  | S(   Nc         ` s1   i  |  ]' } ˆ  | ˆ | k r ˆ  | | “ q S(    (    (   Rj   t   k(   RO   RP   (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pys
   <dictcomp>P  s   	 i   u,   Omitting %s identical items, use -vv to showu   Common items:c         ` s*   h  |  ]  } ˆ  | ˆ | k r | ’ q S(    (    (   Rj   Rz   (   RO   RP   (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pys	   <setcomp>V  s   	 u   Differing items:s    != u   Left contains %d more item%s:i   t    R
   c         ` s   i  |  ] } ˆ  | | “ q S(    (    (   Rj   Rz   (   RO   (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pys
   <dictcomp>c  s   	 u   Right contains %d more item%s:c         ` s   i  |  ] } ˆ  | | “ q S(    (    (   Rj   Rz   (   RP   (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pys
   <dictcomp>m  s   	 (	   R)   t   intersectionR   Rk   Rl   Rd   R   R   RC   (   RO   RP   R8   R   t   set_leftt	   set_rightt   commont   samet   diffRz   t
   extra_leftt   len_extra_leftt   extra_rightt   len_extra_right(    (   RO   RP   s5   lib/python2.7/site-packages/_pytest/assertion/util.pyR>   K  s@    >
 )
 )c         C` sŸ  | \ } } | |  ƒ rR |  j  } g  | j ƒ  D] \ } } | j r. | ^ q. }	 n= | |  ƒ r |  j } g  | D] } | j rn | j ^ qn }	 n  g  }
 g  } xI |	 D]A } t |  | ƒ t | | ƒ k rÖ |
 j | ƒ q¢ | j | ƒ q¢ Wg  } |
 r| d k  r| j d t |
 ƒ ƒ n/ |
 rH| d g 7} | t	 j
 |
 ƒ j ƒ  7} n  | r›| d g 7} x= | D]2 } | d | t |  | ƒ t | | ƒ f g 7} qbWn  | S(   Ni   u,   Omitting %s identical items, use -vv to showu   Matching attributes:u   Differing attributes:u   %s: %r != %r(   R,   t   itemst   compareR1   t   cmpt   nameR-   R   R   Rk   Rl   Rd   (   RO   RP   R8   t   type_fnsR0   R2   t
   all_fieldst   fieldt   infot   fields_to_checkR€   R   R   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyR@   r  s2    	1	(0c   
      C` sÕ   | j  |  ƒ } | |  } | | t |  ƒ } | | } t | | | ƒ } d t |  d d ƒg } xl | D]d }	 |	 j d ƒ r„ qi n  |	 j d ƒ r™ qi n  |	 j d ƒ rÀ | j d |	 d ƒ qi | j |	 ƒ qi W| S(	   Nu   %s is contained here:R7   i*   u   Skippingu   - u   + u     i   (   t   findR   R;   R   R   R   (
   t   termt   textR8   t   indext   headt   tailt   correct_textR   t   newdiffR!   (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyRD   ’  s    

('   t   __doc__t
   __future__R    R   R   Rk   RG   t   _pytest._codeRI   t   compatR   R   t   _pytest._io.safereprR   R.   t   _reprcompareR   R   R   R   R#   t	   NameErrorRc   R%   R&   R(   R+   R0   R2   R6   RW   R;   RA   RB   R<   R=   R>   R@   RD   (    (    (    s5   lib/python2.7/site-packages/_pytest/assertion/util.pyt   <module>   sD   				$

								2?	'	 