
:WT	                 @   su   d  d l  m Z d  d l Z d  d l j j Z d  d l Z d  d l	 Z	 e j
 j Z Gd d   d  Z d d   Z d S)    )
generatorsNc               @   sd   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z	 d S)TestSafeReprc          
   C   s  d } t  |  } d } | | k } | s t j d | f d | | f  d t j |  d d t j   k s{ t j t   r t j t   n d d t j |  d	 t j |  i } d d | i } t t j |    d  } } } } d  } t  |  } d } | | k } | st j d | f d | | f  d t j |  d d t j   k sdt j t   rst j t   n d d t j |  d	 t j |  i } d d | i } t t j |    d  } } } } d  S)N   1==0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py7)spy4py0safereprpy2py7 assert %(py9)spy9None)r   )r   r   )r   )r   r   )	r
   
@pytest_ar_call_reprcompare	_saferepr@py_builtinslocals_should_repr_global_nameAssertionError_format_explanation)self@py_assert1@py_assert3@py_assert6@py_assert5@py_format8@py_format10 r    ?/home/ronny/Projects/pytest-dev/py/testing/io_/test_saferepr.pytest_simple_repr
   s$                    zTestSafeRepr.test_simple_reprc          
   C   s  t  d d d d } t |  } d } | | k } | st j d | f d | | f  d d t j   k s| t j |  r t j |  n d d	 t j |  d
 d t j   k s t j t  r t j t  n d d t j |  i } d d | i } t t j	 |    d  } } } t
 d d  } | | k } | st j d | f d | | f  d
 d t j   k st j |  rt j |  n d d d t j   k st j |  rt j |  n d i }	 d d |	 i }
 t t j	 |
    d  } d  S) Nx2   maxsize   r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)spy1spy6r	   lenpy3r   assert %(py8)spy8
   z...%(py0)s == %(py2)sr   expectedassert %(py4)sr   )r   )r'   r-   
xxxxxxxxxxzxxxxxxxxxx...r3   )r   )r0   r2   )r
   r+   r   r   r   r   r   r   r   r   repr)r   r)   @py_assert2r   @py_assert4@py_format7@py_format9r1   r   @py_format3@py_format5r    r    r!   test_maxsize   s                 zTestSafeRepr.test_maxsizec          
   C   s  Gd d   d  } t  d d |   f d d } t |  } d } | | k } | s*t j d | f d  | | f  d	 d
 t j   k s t j |  r t j |  n d
 d t j |  d d t j   k s t j t  r t j t  n d d t j |  i } d! d | i } t t j	 |    d  } } } g  } | d } d } | | k } | }	 | r| d" }
 d } |
 | k } | }	 |	 st j d# | f d$ | | f  d t j |  d t j |  i } d d | i } | j
 |  | rTt j d% | f d& |
 | f  d t j |  d t j |
  i } d d | i } | j
 |  t j | d  i  } d' d | i } t t j	 |    d  }	 } } } } }
 } } d  S)(Nc               @   s   e  Z d  Z d d   Z d S)z6TestSafeRepr.test_maxsize_error_on_instance.<locals>.Ac             S   s   t  d   d  S)Nz...)
ValueError)r   r    r    r!   __repr__   s    z?TestSafeRepr.test_maxsize_error_on_instance.<locals>.A.__repr__N)__name__
__module____qualname__r=   r    r    r    r!   A   s   rA   *r$   r%   r&   r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sr(   r)   r*   r	   r+   r,   r   assert %(py8)sr.   r   (r   )%(py3)s == %(py6)sz%(py8)s%(py11)s == %(py14)spy14py11z%(py16)spy16assert %(py19)spy19)r   )rC   rD   )r   )rG   )r   )rH   rL   )r
   r+   r   r   r   r   r   r   r   r   append_format_boolop)r   rA   r)   r5   r   r6   r7   r8   r   @py_assert0@py_assert10@py_assert13@py_assert12@py_format15@py_format17@py_format18@py_format20r    r    r!   test_maxsize_error_on_instance   s@            
     
     C    C      z+TestSafeRepr.test_maxsize_error_on_instancec             C   s  Gd d   d  } Gd d   d t   } d } d } t  |  } | |  } t |  } | | k } | rt j d f | f d f | | f  d	 d t j   k p t j t   r t j t   n d d
 t j |  d t j |  d d t j   k pt j |  rt j |  n d d t j |  d t j |  d d t j   k pYt j t  rkt j t  n d d t j |  i }	 d d d |	 i }
 t t j	 |
    d  } } } } } } t | d   } d } | | k } | rt j d f | f d f | | f  d t j |  d d t j   k pFt j |  rXt j |  n d i } d d d	 | i } t t j	 |    d  } } t
 j j j d d f k  rd } d } | |  } t |  } | | k } | rt j d f | f d f | | f  d t j |  d  t j |  d d t j   k pJt j |  r\t j |  n d d t j |  d! t j |  d d t j   k pt j t  rt j t  n d i } d d" d# | i } t t j	 |    d  } } } } } nId } d } | |  } t |  } | | k } | r/t j d f | f d f | | f  d t j |  d  t j |  d d t j   k pt j |  rt j |  n d d t j |  d! t j |  d d t j   k pt j t  rt j t  n d i } d d" d# | i } t t j	 |    d  } } } } } t | | d$    } d% } | | k } | rt j d& f | f d' f | | f  d t j |  d d( t j   k pt j |  rt j |  n d( i } d d d	 | i } t t j	 |    d  } } d } | | k } | rt j d f | f d f | | f  d t j |  d d( t j   k pt j |  rt j |  n d( i } d d d	 | i } t t j	 |    d  } } d  S))Nc               @   s(   e  Z d  Z d d   Z d d   Z d S)z0TestSafeRepr.test_exceptions.<locals>.BrokenReprc             S   s   | |  _  d } d  S)Nr   )ex)r   rZ   foor    r    r!   __init__   s    	z9TestSafeRepr.test_exceptions.<locals>.BrokenRepr.__init__c             S   s   |  j   d  S)N)rZ   )r   r    r    r!   r=   "   s    z9TestSafeRepr.test_exceptions.<locals>.BrokenRepr.__repr__N)r>   r?   r@   r\   r=   r    r    r    r!   
BrokenRepr   s   r]   c               @   s   e  Z d  Z d Z d Z d S)z9TestSafeRepr.test_exceptions.<locals>.BrokenReprExceptionN)r>   r?   r@   __str__r=   r    r    r    r!   BrokenReprException$   s   r_   	Exceptionbrokeninzp%(py1)s in %(py13)s
{%(py13)s = %(py3)s(%(py11)s
{%(py11)s = %(py4)s(%(py9)s
{%(py9)s = %(py5)s(%(py7)s)
})
})
}py5r   py13r   r(   rJ   r,   r
   r   r   zassert %(py15)spy15zreally broken	TypeErrorz%(py1)s in %(py3)sr)   zassert %(py5)s      unknownstringzP%(py1)s in %(py10)s
{%(py10)s = %(py3)s(%(py8)s
{%(py8)s = %(py4)s(%(py6)s)
})
}r.   py10r*   zassert %(py12)spy12zomg even worse	NameErrornot inz%(py1)s not in %(py3)ss2)r`   r
   r   r   r   r   r   r   r   r   pystdsysversion_info)r   r]   r_   rQ   r   @py_assert8rR   rT   r5   @py_format14@py_format16r)   @py_format4@py_format6r   @py_assert7@py_assert9@py_format11@py_format13ro   r    r    r!   test_exceptions   st                  p   
                     p   
   p   zTestSafeRepr.test_exceptionsc              C   s  d d l  m } d } t |  } t |  } t |  } d } |   } | j } d }	 | |	 }
 | |
 } d } | | } t |  } | | k } | rt j d f | f d f | | f  d	 d
 t j	   k p t j
 t  r t j t  n d
 d t j |  d t j |  d t j |  d t j |  d t j |  d t j |  d t j |	  d d
 t j	   k pt j
 t  rt j t  n d
 d t j |  d d t j	   k pt j
 t  rt j t  n d d t j |  d t j |  d d t j	   k pt j
 |  r*t j |  n d d d t j	   k pNt j
 t  r`t j t  n d i } d d d | i } t t j |    d  } } } } } } } } }	 }
 } } } } d  S)Nr   )SafeRepri  [Z1000]<=z%(py10)s
{%(py10)s = %(py0)s(%(py8)s
{%(py8)s = %(py1)s(%(py6)s
{%(py6)s = %(py2)s(%(py4)s)
})
})
} <= %(py28)s
{%(py28)s = %(py12)s(((%(py14)s + (%(py19)s
{%(py19)s = %(py17)s
{%(py17)s = %(py15)s()
}.maxlist
} * %(py21)s)) + %(py25)s))
}rl   r+   r.   rk   r   rI   r*   Zpy25Zpy21r	   Zpy28r(   r
   rM   py17re   r~   r   ranger   zassert %(py30)sZpy30)Zpy._io.safereprr~   r   r
   r+   maxlistr   r   r   r   r   r   r   r   )r   r~   r   r   ry   rz   rS   @py_assert16Z@py_assert18Z@py_assert20Z@py_assert22Z@py_assert23Z@py_assert24Z@py_assert26Z@py_assert27@py_assert11Z@py_format29Z@py_format31r    r    r!   test_big_repr3   s*         	 	  
 
  
        zTestSafeRepr.test_big_reprc             C   sR   Gd d   d t   } y t |    } Wn" t k
 rM t j j d  Yn Xd  S)Nc               @   s   e  Z d  Z d d   Z d S)z4TestSafeRepr.test_repr_on_newstyle.<locals>.Functionc             S   s   d |  j  S)Nz<%s>)name)r   r    r    r!   r=   :   s    z=TestSafeRepr.test_repr_on_newstyle.<locals>.Function.__repr__N)r>   r?   r@   r=   r    r    r    r!   Function9   s   r   z"saferepr failed for newstyle class)objectr
   r`   rp   testfail)r   r   r)   r    r    r!   test_repr_on_newstyle8   s
    z"TestSafeRepr.test_repr_on_newstylec          
   C   sQ  t  j j d d  } t  j j d d  } t |  } | | k } | sCt j d | f d | | f  d d t j   k s t j |  r t j	 |  n d d d	 t j   k s t j |  r t j	 |  n d	 d
 d t j   k s t j t  rt j	 t  n d d t j	 |  i } d d | i } t
 t j |    d  } } d  S)Nu   £€zutf-8u   '£€'r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py5)src   reprvalr(   valr	   r
   r,   r   assert %(py7)sr   )r   )r   r   )rp   builtin_totextr
   r   r   r   r   r   r   r   r   )r   r   r   r5   r6   rx   r   r    r    r!   test_unicodeA   s          zTestSafeRepr.test_unicodeN)
r>   r?   r@   r"   r;   rY   r}   r   r   r   r    r    r    r!   r   	   s   		r   c                 st   t  j j d d  j d      f d d   }  t  j j t |   } t |  } t j	 d d k  rp t
 |  } d  S)Nu	   ÄÄ
zutf-8utf8c                  s   t      d  S)N)r`   r    )valuer    r!   fH   s    z test_unicode_handling.<locals>.fr      )rp   r   r   encoder   raisesr`   strrr   rs   unicode)r   excinfor)   ur    )r   r!   test_unicode_handlingF   s    r   )
__future__r   builtinsr   _pytest.assertion.rewrite	assertionrewriter   rp   rr   ior
   r   r   r    r    r    r!   <module>   s     =