
|WLx                 @   s  d  d l  Z d  d l j j Z d  d l Z d  d l m Z m	 Z	 e j
 j d d  Z e j j j d  Z d  d l m Z y d  d l Z Wn e k
 r d Z Yn Xe e d d  Z d  d l Z e e e e j j d  d d	    Z Gd
 d   d  Z d d   Z d d   Z  d d   Z! d d   Z" d d   Z# Gd 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'   Z, d( d)   Z- d* d+   Z. Gd, d-   d-  Z/ d S).    N)FormattedExcinfoReprExceptionInfoqueueQueuezsys.platform.startswith('java'))astonlyinvalidate_caches.   c               @   sI   e  Z d  Z d d   Z d d d  Z d d   Z d d	   Z d
 Z d S)TWMockc             C   s   g  |  _  d  S)N)lines)self r   ?/home/ronny/Projects/pytest-dev/py/testing/code/test_excinfo.py__init__   s    zTWMock.__init__Nc             C   s   |  j  j | | f  d  S)N)r   append)r   sepliner   r   r   r      s    z
TWMock.sepc             K   s   |  j  j |  d  S)N)r   r   )r   r   kwr   r   r   r      s    zTWMock.linec             K   s   | S)Nr   )r   textr   r   r   r   markup   s    zTWMock.markupP   )__name__
__module____qualname__r   r   r   r   	fullwidthr   r   r   r   r
      s
   r
   c              C   s  y
 t   Wn! t  k
 r- t j j   }  Yn X|  j } | t  k } | st j d | f d | t  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 i } d d
 | i } t t j |    d  } } d  S)N==,%(py2)s
{%(py2)s = %(py0)s.type
} == %(py4)spy0infopy2py4
ValueError assert %(py6)spy6)r   )r   r#   )r!   pycodeExceptionInfotype
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation)r   @py_assert1@py_assert3@py_format5@py_format7r   r   r   test_excinfo_simple    s    
	      r5   c                 s  d d       f d d   }  y |    Wn! t  k
 rL t j j   } Yn Xt j j |   j d d t j j |   j d d t j j    j d d g } t | j  } d 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 sMt j |  r\t j |  n d i } d d | i } t t j |    d  } d  S)Nc               S   s
   t   d  S)N)r!   r   r   r   r   g(   s    z$test_excinfo_getstatement.<locals>.gc                  s       d  S)Nr   r   )r6   r   r   f*   s    z$test_excinfo_getstatement.<locals>.f   r	   c             S   s   g  |  ] } | j   q Sr   )lineno).0xr   r   r   
<listcomp>4   s   	 z-test_excinfo_getstatement.<locals>.<listcomp>r   %(py0)s == %(py2)sr   foundlinenumbersr   linenumbersr"   assert %(py4)sr    )r   )r=   r@   )r!   r%   r&   r'   
getrawcodeco_firstlinenolist	tracebackr)   r*   r+   r,   r-   r.   r/   r0   )r7   excinfor?   lr>   r1   @py_format3r3   r   )r6   r   test_excinfo_getstatement'   s"          rH   c               C   s
   t   d  S)N)r!   r   r   r   r   r7   ;   s    r7   c              C   s   d }  t    d  S)NT)r7   )__tracebackhide__r   r   r   r6   ?   s    r6   c               C   s   t    d  S)N)r6   r   r   r   r   hD   s    rJ   c               @   s   e  Z d  Z d d   Z d d   Z d d   Z e e 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   Z d d   Z d S)TestTraceback_f_g_hc             C   s6   y t    Wn$ t k
 r1 t j j   |  _ Yn Xd  S)N)rJ   r!   r%   r&   r'   rE   )r   methodr   r   r   setup_methodJ   s    z TestTraceback_f_g_h.setup_methodc             C   s  |  j  j } t |  } 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 } | | 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  } } } d d d g } x= | D]5 }	 y | j |	 j j j  Wq:t k
 rnYq:Xq:W| }
 |
 sd d d t j   k st j |  rt j	 |  n d i } t
 t j |    d  }
 d  S)N   r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)spy1tbr$   r   lenpy3r"   assert %(py8)spy8entriesr7   r6   rJ   assert not %(py0)snames)r   )rO   rT   )r   )rO   rT   rW   )rE   rD   rC   rR   r)   r*   r+   r,   r-   r.   r/   r0   removeframer&   namer!   )r   rQ   rV   @py_assert2@py_assert5@py_assert4r4   @py_format9rX   entryr1   @py_format2r   r   r   test_traceback_entriesP   s:                  	  @  z*TestTraceback_f_g_h.test_traceback_entriesc          
   C   s  |  j  j } t | d j    } | j } d } | |  } | s d d d t j |  d d t j   k s} t j	 |  r t j |  n d d t j |  d	 t j |  i } t
 t j |    d  } } } | j } d
 } | |  } | s~d d d t j |  d d t j   k s2t j	 |  rAt j |  n d d t j |  d	 t j |  i } t
 t j |    d  } } } d  S)Nr8   zdef f():r"   zLassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}r$   r   sr   r    zraise ValueErrorzJassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.endswith
}(%(py4)s)
})rE   rD   str	getsource
startswithr)   r.   r+   r,   r-   r/   r0   endswith)r   rQ   rc   r1   r2   r]   r4   r   r   r   test_traceback_entry_getsource]   s     	    q  	    q  z2TestTraceback_f_g_h.test_traceback_entry_getsourcec             C   s  t  j j d  } y t | j    Wnt k
 rt  j j   j } t | d j	    t
 | d j	    } | j } d } | |  } | sd d d t j |  d d t j   k s t j |  r t j |  n d d	 t j |  d
 t j |  i } t t j |    d  } } } | j } |   } | j } d } | |  }	 |	 sd d d t j |  d d t j   k st j |  rt j |  n d d	 t j |  d
 t j |  d t j |	  d t j |  i }
 t t j |
    d  } } } } }	 Yn Xd  S)Nz            def xyz():
                try:
                    raise ValueError
                except somenoname:
                    pass
            xyz()
        r8   zdef xyz():
    try:r"   zLassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}r$   r   rc   r   r    zexcept somenoname:z~assert %(py10)s
{%(py10)s = %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.strip
}()
}.endswith
}(%(py8)s)
}py10rU   rd   rd   )r%   r&   Sourceexeccompile	NameErrorr'   rD   printrf   re   rg   r)   r.   r+   r,   r-   r/   r0   striprh   )r   sourcerQ   rc   r1   r2   r]   r4   @py_assert7@py_assert9@py_format11r   r   r   +test_traceback_entry_getsource_in_constructc   s0    			    q  	 	 	      z?TestTraceback_f_g_h.test_traceback_entry_getsource_in_constructc          
   C   su  t  j j t  } | j | j } } |  j j } | j d | d |  } t	 |  } d } | | k } | sA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  } } } | j d | d | d  } t	 |  } d } | | k } | sc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  } } } d  S)Npathfirstlinenor8   r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)srP   newtracebackr$   r   rR   rS   r"   assert %(py8)srU   r9      )r   )rx   rz   )r   )rx   rz   )r%   r&   Coder7   rv   rw   rE   rD   cutrR   r)   r*   r+   r,   r-   r.   r/   r0   )r   corv   rw   rD   ry   r\   r]   r^   r4   r_   r   r   r   test_traceback_cutw   s*                  z&TestTraceback_f_g_h.test_traceback_cutc             C   s  | j  d  } t j j t d  } t j j t j j  j   } | j	 j
 d |  } x| D]} t | d  rt j } | j } | j }	 | |	  }
 |
 j } | |  } | } | rd d d t j |	  d t j |  d	 d
 t j   k pt j t  rt j t  n d
 d d t j   k p9t j |  rKt j |  n d d t j |  d t j |  d t j |  d d t j   k pt j |  rt j |  n d d t j |
  i	 } t t j |    d  } } }	 }
 } } } q^ W| d } | j } | j } | j }	 |	 | k }
 |
 rt j d f |
 f d f |	 | f  d t j |	  d t j |  d t j |  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)Nzdef f(): raise ValueErrorzp.pyimport().f()excludepathrv   r"   zassert not %(py14)s
{%(py14)s = %(py11)s
{%(py11)s = %(py9)s
{%(py9)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.path
}.local
}(%(py7)s
{%(py7)s = %(py5)s.path
})
}.relto
}(%(py12)s)
}py7py11r   r%   py5r;   r   r    py14py12basedirpy9r8   r   za%(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py3)s
{%(py3)s = %(py1)s.frame
}.code
}.path
} == %(py9)srP   rS   pzassert %(py11)s)
makepyfiler%   testraisesr!   rv   local__file__dirpathrD   r}   hasattrreltor)   r.   r+   r,   r-   r/   r0   rZ   r&   r*   )r   testdirr   rE   r   ry   r;   r1   r2   @py_assert6@py_assert8@py_assert10@py_assert13Z@py_assert15@py_format16@py_assert0r\   r^   @py_format10@py_format12r   r   r   test_traceback_cut_excludepath   s8    	 	 	  	       " 	 	 	      z2TestTraceback_f_g_h.test_traceback_cut_excludepathc       
      C   s  |  j  j } | j   } t |  } t |  } d } | | } | | k } | rt j d f | f d f | | f  d d t j   k p t j |  r t j	 |  n d d d t j   k p t j |  r t j	 |  n d d d	 t j   k pt j t  rt j	 t  n d	 d
 d	 t j   k p:t j t  rLt j	 t  n d	 d t j	 |  d t j	 |  d t j	 |  i } d d d | i }	 t
 t j |	    d  } } } } } d  S)Nr8   r   z[%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == (%(py8)s
{%(py8)s = %(py5)s(%(py6)s)
} - %(py10)s)r$   rD   rP   
ntracebackr   rR   r   rS   rj   rU   r"   zassert %(py13)spy13)rE   rD   filterrR   r)   r*   r+   r,   r-   r.   r/   r0   )
r   rD   r   r\   rr   rs   @py_assert11r^   r   @py_format14r   r   r   test_traceback_filter   s       
    1   z)TestTraceback_f_g_h.test_traceback_filterc                s     f d d     t  j j t   d  } | j } | j   } 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 |  i } d d | i } t t j |    d  } } d  S)Nc                s$   |  d k  r |  d 7}    |   d  S)N
   r8   r   )n)r7   r   r   r7      s    
z=TestTraceback_f_g_h.test_traceback_recursion_index.<locals>.f   r	   r   %(py0)s == %(py3)sr   recindexrS   r"   assert %(py5)sr   )r   )r   r   )r%   r   r   RuntimeErrorrD   recursionindexr)   r*   r+   r,   r-   r.   r/   r0   )r   rE   rD   r   r\   r1   @py_format4@py_format6r   )r7   r   test_traceback_recursion_index   s    	   j   z2TestTraceback_f_g_h.test_traceback_recursion_indexc       
         so    f d d     t  j t   d  } | j | j j d  | j   } d } | j } t |  } | | k } | sYt	 j
 d | f d | | f  d t	 j |  d	 t	 j |  d
 d t j   k s t	 j t  r t	 j t  n d d t	 j |  d d t j   k st	 j |  r*t	 j |  n d i } d d | i }	 t t	 j |	    d  } } } } d  S)Nc                s*   |  d k r t  d     |  d  d  S)Nr   hellor8   )r   )r   )r7   r   r   r7      s    zLTestTraceback_f_g_h.test_traceback_only_specific_recursion_errors.<locals>.fd   r   zRuntimeError: helloinO%(py1)s in %(py8)s
{%(py8)s = %(py3)s(%(py6)s
{%(py6)s = %(py4)s.reprcrash
})
}r$   rP   rS   re   rU   r    reprr"   assert %(py10)srj   )r   )r   r   )pytestr   r   delattrrD   	__class__getrepr	reprcrashre   r)   r*   r.   r+   r,   r-   r/   r0   )
r   monkeypatchrE   r   r   r]   rr   r\   r_   rt   r   )r7   r   -test_traceback_only_specific_recursion_errors   s     	       zATestTraceback_f_g_h.test_traceback_only_specific_recursion_errorsc       	         s  d d     d d       f d d   } t  j j t | d  } | j } | j   } 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 |  i } d d | i } t t j |    d  } } d  S)Nc               S   s
   t   d  S)N)r   r   r   r   r   do_stuff   s    zGTestTraceback_f_g_h.test_traceback_no_recursion_index.<locals>.do_stuffc              S   s;   d d  l  }  |  j   \ } } } t j j | | |  d  S)Nr   )sysexc_infor%   builtin_reraise)r   excvalrQ   r   r   r   
reraise_me   s    zITestTraceback_f_g_h.test_traceback_no_recursion_index.<locals>.reraise_mec          	      s!   y     Wn    Yn Xd  S)Nr   )r   )r   r   r   r   r7      s    z@TestTraceback_f_g_h.test_traceback_no_recursion_index.<locals>.fr   is%(py0)s is %(py3)sr   r   rS   r"   assert %(py5)sr   )r   )r   r   )r%   r   r   r   rD   r   r)   r*   r+   r,   r-   r.   r/   r0   )	r   r7   rE   rD   r   r\   r1   r   r   r   )r   r   r   !test_traceback_no_recursion_index   s    	   j   z5TestTraceback_f_g_h.test_traceback_no_recursion_indexc             C   si  t  j j d  j } d d   } | |  } d d   } | | |   } t  j j t |  } | j } | j } |   } d  } | | k }	 |	 sOt j	 d |	 f d | | f  d t j
 |  d	 t j
 |  d
 d t j   k s t j |  rt j
 |  n d d t j
 |  d t j
 |  i }
 d d |
 i } t t j |    d  } } } }	 } d  S)N	decoratorc             _   s%   t  d | | f  |  | |   d  S)Nz%s %s)ro   )r7   kr   r   r   r   log   s    z?TestTraceback_f_g_h.test_traceback_messy_recursion.<locals>.logc               S   s   t  d   d  S)Nr"   )r!   r   r   r   r   fail   s    z@TestTraceback_f_g_h.test_traceback_messy_recursion.<locals>.failr   l%(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.traceback
}.recursionindex
}()
} is %(py9)sr   r$   r   rE   r   r    r"   assert %(py11)sr   )r   )r   r   )r%   r   importorskipr   r   r!   rD   r   r)   r*   r.   r+   r,   r-   r/   r0   )r   r   r   r   rE   r1   r2   r]   r   rr   r   r   r   r   r   test_traceback_messy_recursion   s     	 	 	       z2TestTraceback_f_g_h.test_traceback_messy_recursionc                s  d d     f d d     f d d       f d d   } t  j j t |  } | j } | j   } t  j j   } | j } | j } | j	 } | j	 }	 | |	 k }
 |
 st
 j d |
 f d | |	 f  d t
 j |  d d t j   k st
 j |  rt
 j |  n d d t
 j |  d t
 j |  d t
 j |	  d d t j   k sht
 j |  rwt
 j |  n d i } d d | i } t t
 j |    d  } } } }
 }	 | j } | j } d }
 | |
 }	 | |	 k } | st
 j d  | f d! | |	 f  d t
 j |
  d t
 j |  d d t j   k sPt
 j |  r_t
 j |  n d d t
 j |  d d t j   k st
 j |  rt
 j |  n d i } d" d | i } t t
 j |    d  } } } }
 }	 | j } | j } | j } d } | | k }
 |
 st
 j d# |
 f d$ | | f  d t
 j |  d t
 j |  d d t j   k s|t
 j |  rt
 j |  n d d t
 j |  d t
 j |  i } d% d | i } t t
 j |    d  } } } }
 } d  S)&Nc              S   s   d }  t   d  S)NT)r!   )rI   r   r   r   i   s    z;TestTraceback_f_g_h.test_traceback_getcrashentry.<locals>.ic                  s       d  S)Nr   r   )r   r   r   rJ      s    z;TestTraceback_f_g_h.test_traceback_getcrashentry.<locals>.hc                 s   d }      d  S)NTr   )rI   )rJ   r   r   r6      s    z;TestTraceback_f_g_h.test_traceback_getcrashentry.<locals>.gc                  s       d  S)Nr   r   )r6   r   r   r7      s    z;TestTraceback_f_g_h.test_traceback_getcrashentry.<locals>.fr   }%(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.frame
}.code
}.path
} == %(py10)s
{%(py10)s = %(py8)s.path
}r$   r   r`   r   r    rj   rU   r~   r"   assert %(py12)sr   r8   [%(py2)s
{%(py2)s = %(py0)s.lineno
} == (%(py6)s
{%(py6)s = %(py4)s.firstlineno
} + %(py8)s)assert %(py11)sr   rJ   a%(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.frame
}.code
}.name
} == %(py9)sr   )r   )r   r   )r   )r   r   )r   )r   r   )r%   r   r   r!   rD   getcrashentryr&   r|   rZ   rv   r)   r*   r.   r+   r,   r-   r/   r0   r9   rw   r[   )r   r7   rE   rQ   r`   r~   r1   r2   r]   rs   rr   rt   @py_format13r   r   r   r   )r6   rJ   r   r   test_traceback_getcrashentry   sL    		 	 	 	      	 	  
      	 	 	       z0TestTraceback_f_g_h.test_traceback_getcrashentryc                s  d d       f d d   } t  j j t |  } | j } | j   } t  j j    } | j } | j } | j	 } | j	 }	 | |	 k }
 |
 st
 j d |
 f d | |	 f  d t
 j |  d d	 t j   k s t
 j |  r t
 j |  n d	 d
 t
 j |  d t
 j |  d t
 j |	  d d t j   k sDt
 j |  rSt
 j |  n d i } d d | i } t t
 j |    d  } } } }
 }	 | j } | j } d }
 | |
 }	 | |	 k } | st
 j d | f d | |	 f  d t
 j |
  d t
 j |  d d	 t j   k s,t
 j |  r;t
 j |  n d	 d
 t
 j |  d d t j   k sqt
 j |  rt
 j |  n d i } d d | i } t t
 j |    d  } } } }
 }	 | j } | j } | j } d } | | k }
 |
 st
 j d |
 f d  | | f  d t
 j |  d t
 j |  d d	 t j   k sXt
 j |  rgt
 j |  n d	 d
 t
 j |  d t
 j |  i } d! d | i } t t
 j |    d  } } } }
 } d  S)"Nc              S   s   d }  t   d  S)NT)r!   )rI   r   r   r   r6      s    zATestTraceback_f_g_h.test_traceback_getcrashentry_empty.<locals>.gc                 s   d }      d  S)NTr   )rI   )r6   r   r   r7      s    zATestTraceback_f_g_h.test_traceback_getcrashentry_empty.<locals>.fr   }%(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.frame
}.code
}.path
} == %(py10)s
{%(py10)s = %(py8)s.path
}r$   r   r`   r   r    rj   rU   r~   r"   assert %(py12)sr   r{   [%(py2)s
{%(py2)s = %(py0)s.lineno
} == (%(py6)s
{%(py6)s = %(py4)s.firstlineno
} + %(py8)s)assert %(py11)sr   r6   a%(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.frame
}.code
}.name
} == %(py9)sr   )r   )r   r   )r   )r   r   )r   )r   r   )r%   r   r   r!   rD   r   r&   r|   rZ   rv   r)   r*   r.   r+   r,   r-   r/   r0   r9   rw   r[   )r   r7   rE   rQ   r`   r~   r1   r2   r]   rs   rr   rt   r   r   r   r   r   )r6   r   "test_traceback_getcrashentry_empty   sH    		 	 	 	      	 	  
      	 	 	       z6TestTraceback_f_g_h.test_traceback_getcrashentry_emptyN)r   r   r   rM   rb   ri   r   failsonjythonru   r   r   r   r   r   r   r   r   r   r   r   r   r   rK   I   s   	

rK   c             C   s   |  d d  S)N   r   )r;   r   r   r   r      s    r   c              C   s  y t  d  Wn! t k
 r1 t j j   }  Yn X|  j d } | j   } | j } d } | |  } | s d d d t j	 |  d d t
 j   k s t j |  r t j	 |  n d d	 t j	 |  d
 t j	 |  i } t t j |    d  } } } d  S)Nr   r8   zTypeError: ('hello' + 5)r"   zLassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}r$   r   msgr   r    rd   )r   	TypeErrorr%   r&   r'   rD   reinterpretrg   r)   r.   r+   r,   r-   r/   r0   )rE   Ztbentryr   r1   r2   r]   r4   r   r   r   test_tbentry_reinterpret   s    	    q  r   c        	      C   s  t  j j t t  }  |  j } |   } | j } d } | |  } | s d d d t j |  d d t	 j
   k s t j |   r t j |   n d d t j |  d t j |  d	 t j |  d
 t j |  i } t t j |    d  } } } } } t  j j t d  }  |  j d d  } | j } d } | |  } | sd d d t j |  d d t	 j
   k st j |  rt j |  n d d t j |  d t j |  i } t t j |    d  } } } | j } d } | |  } | sd d d t j |  d d t	 j
   k s9t j |  rHt j |  n d d t j |  d t j |  i } t t j |    d  } } } d  S)Nr!   r"   zassert %(py10)s
{%(py10)s = %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exconly
}()
}.startswith
}(%(py8)s)
}r$   r   rE   r   r    rj   rU   z raise ValueError('hello\nworld')tryshortTzLassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}r   ZworldzJassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.endswith
}(%(py4)s)
})r%   r   r   r!   rJ   exconlyrg   r)   r.   r+   r,   r-   r/   r0   rh   )	rE   r1   r2   r]   rr   rs   rt   r   r4   r   r   r   test_excinfo_exconly   s6    	 	 	      		    q  	    q  r   c              C   s   t  j j t t  }  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 |  i } d d	 | i } t t j |    d  } } d  S)Nz"<ExceptionInfo ValueError tblen=4>r   %(py0)s == %(py3)sr   rc   rS   r"   assert %(py5)sr   )r   )r   r   )r%   r   r   r!   rJ   r   r)   r*   r+   r,   r-   r.   r/   r0   )rE   rc   r\   r1   r   r   r   r   r   test_excinfo_repr  s       j   r   c              C   s  t  j j t t  }  t |   } | j } t d  d  } | |  } | s d d d t j	 |  d d t
 j   k s t j |  r t j	 |  n d d t j	 |  d t j	 |  i } t t j |    d  } } } | j } d	 } | |  } | sd d
 d t j	 |  d d t
 j   k s;t j |  rJt j	 |  n d d t j	 |  d t j	 |  i } t t j |    d  } } } | j } d } | |  } t |  }	 d }
 |	 |
 k } | st j d | f d |	 |
 f  d t j	 |  d d t
 j   k s%t j |  r4t j	 |  n d d t j	 |  d t j	 |	  d d t
 j   k syt j t  rt j	 t  n d d t j	 |
  d t j	 |  i } d d | i } t t j |    d  } } } }	 } }
 d  S)N	   r"   zLassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}r$   r   rc   r   r    r!   zJassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.endswith
}(%(py4)s)
}:r	   >=j%(py9)s
{%(py9)s = %(py0)s(%(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.split
}(%(py5)s)
})
} >= %(py12)sr   rP   r   r   rR   r   rS   assert %(py14)sr   i)r   )r   r   )r%   r   r   r!   rJ   re   rg   r   r)   r.   r+   r,   r-   r/   r0   rh   splitrR   r*   )rE   rc   r1   r2   r]   r4   r\   r^   r   r   r   r   r   @py_format15r   r   r   test_excinfo_str  s6    	    q  	    q  	          r   c           
   C   s   t  j j t t  }  |  j } | t  } | s d d d t j |  d d t j	   k sj t j
 |   ry t j |   n d d d t j	   k s t j
 t  r t j t  n d d t j |  i } t t j |    d  } } d  S)	Nr"   zOassert %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.errisinstance
}(%(py3)s)
}r   r   rE   rS   r!   r   )r%   r   r   r!   rJ   errisinstancer)   r.   r+   r,   r-   r/   r0   )rE   r1   r^   r   r   r   r   test_excinfo_errisinstance  s    	     r   c              C   s  y t  d  Wn! t k
 r1 t j j   }  Yn Xt |  j d  } t j j j	 d k  r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 |  i } d d | i } t t
 j |    d  } } n d } | | k } | st
 j d | f d | | f  d d	 t j   k sht
 j |  rwt
 j |  n d	 d
 t
 j |  i } d d | i } t t
 j |    d  } } d  S)Nzraise ValueError()r8   r{   r   z  File '<string>':1 in ?
  ???
r   %(py0)s == %(py3)sr   rc   rS   r"   assert %(py5)sr   z&  File '<string>':1 in <module>
  ???
rd   )r{   r   )r   )r   r   )r   )r   r   )rl   r!   r%   r&   r'   re   rD   stdr   version_infor)   r*   r+   r,   r-   r.   r/   r0   )rE   rc   r\   r1   r   r   r   r   r   test_excinfo_no_sourcecode  s(       j      j   r   c             C   s  |  j  d  j d  t j j d  } | j t |    } | j d |  } | j d  } t j j	 t
 | j d t } xV| j D]K} t |  | j | j j d k r | j } t |  } 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 sTt j t  rct j t  n d d t j |  d t j |  d t j |	  i } d d | i } t t j |    d  } } }
 }	 q Wd  S)Nztest.txtz	{{ h()}}:jinja2loaderrJ   r   L%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.source
})
} == %(py8)srP   itemr   re   rS   r   rU   r"   assert %(py10)srj   )r   )r   r   )joinwriter%   r   r   ZFileSystemLoaderre   EnvironmentZget_templater   r!   ZrenderrJ   rD   ro   rq   rv   basenamer)   r*   r+   r,   r-   r.   r/   r0   )tmpdirr   r   envtemplaterE   r   r\   r^   rr   r   r_   rt   r   r   r   !test_excinfo_no_python_sourcecode  s(    
	        r  c              C   s  y t  j   j d d  Wn$ t  j k
 r@ t j j   }  Yn X|  j d } | j   } 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 |  i } d d | i } t t	 j |    d  } } t |  j   } | j } d } | |  }	 |	 sd	 d d t	 j |	  d d t j   k sxt	 j |  rt	 j |  n d d t	 j |  d t	 j |  i }
 t t	 j |
    d  } } }	 d  S)NtimeoutgMbP?r8   is not%(py0)s is not %(py3)sr   rq   rS   r"   assert %(py5)sr   zdef getzLassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}r$   rc   r   r    rd   )r  )r  r  )r   r   getEmptyr%   r&   r'   rD   rf   r)   r*   r+   r,   r-   r.   r/   r0   re   rp   rg   )rE   r`   rq   r\   r1   r   r   rc   r2   r]   r4   r   r   r   test_entrysource_Queue_example-  s*       j   
	    q  r
  c              C   s   y t  j   j d d  Wn$ t  j k
 r@ t j j   }  Yn X|  j d } | j } t j } | j	 } t
 | |  } | spd d d t j |  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 |  d d t j   k s3t j t
  rBt j t
  n d d t j |  i } t t j |    d  } } } | j } | j } |   } d } | | k } | smt j d | f d | | f  d t j |  d t j |  d d t j   k st j |  r t j |  n d d	 t j |  d t j |  i }	 d d |	 i }
 t t j |
    d  } } } } } | j } |   } | sd d d d t j   k st j |  rt j |  n d d	 t j |  d t j |  i } t t j |    d  } } d  S)Nr  gMbP?r8   r"   zjassert %(py8)s
{%(py8)s = %(py0)s(%(py1)s, %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s.path
}.local
})
}r$   rP   rv   r   r%   r    r   
isinstancerU   zqueue.pyr   b%(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.basename
}.lower
}()
} == %(py9)sr   assert %(py11)sr   z@assert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.check
}()
}rd   )r   )r  r  )r   r   r  r	  r%   r&   r'   rD   rv   r   r  r)   r.   r+   r,   r-   r/   r0   r   lowerr*   check)rE   r`   rv   r2   r]   rr   r_   r1   r   r   r   r3   r   r   r   test_codepath_Queue_example8  s:    		 	     	 	 	       	 	  b  r  c               @   s  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 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   Z d  d!   Z d" d#   Z d$ d%   Z d& d'   Z d( d)   Z d* d+   Z d, d-   Z d. d/   Z d0 d1   Z d2 d3   Z d4 d5   Z e j j j  d6 d7 d8   dC D  d< d=    Z! d> d?   Z" d@ dA   Z# dB S)DTestFormattedExcinfoc                s     f d d   } | S)Nc                sg   t  j j |   }    j d  } | j d  } | j d  | j |   t d  k	 r] t   | j   S)Nr   zmod.pyz__init__.py)	r%   r&   rk   getfuncargvaluer   ensurer   invalidate_import_cachespyimport)rq   r   modpath)requestr   r   importasmodE  s    zETestFormattedExcinfo.pytest_funcarg__importasmod.<locals>.importasmodr   )r   r  r  r   )r  r   pytest_funcarg__importasmodD  s    	z0TestFormattedExcinfo.pytest_funcarg__importasmodc             C   s   t  j j |  j   } y t | j    Wn) t k
 rC   Yn t  j j   SYn Xd } | s t j	 d  d d t j
 |  i } t t j |    d  } d  S)Nr   zdid not raisez
>assert %(py1)srP   )r%   r&   rk   rp   rl   rm   KeyboardInterruptr'   r)   _format_assertmsgr.   r/   r0   )r   rq   r   ra   r   r   r   excinfo_from_execP  s      &  z&TestFormattedExcinfo.excinfo_from_execc          
   C   sv  t    } t j j d  j   } d | _ | j | d  } t |  } d } | | k } | s4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  } } } | d }	 d }
 |	 |
 k } | st j	 d | f d |	 |
 f  d t j |	  d t j |
  i } d d	 | i } t t j |    d  }	 } }
 | d }	 d }
 |	 |
 k } | sdt j	 d | f d |	 |
 f  d t j |	  d t j |
  i } d d	 | i } t t j |    d  }	 } }
 d  S)Nz4
            def f(x):
                pass
        |r   r{   r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)srP   r   r$   r   rR   rS   r"   assert %(py8)srU   z|   def f(x):%(py1)s == %(py4)sr    assert %(py6)sr8   z        pass)r   )r  r  )r   )r   r!  )r   )r   r!  )r   r%   r&   rk   rp   flow_marker
get_sourcerR   r)   r*   r+   r,   r-   r.   r/   r0   )r   prrq   r   r\   r]   r^   r4   r_   r   r2   r3   r   r   r   test_repr_sourceZ  s:    			       
    C   
    C   z%TestFormattedExcinfo.test_repr_sourcec       	      C   s
  t    } |  j d  } t    } | j | j d  } | j | d |  } d d d g } | | k } | s t j d | f d | | f  d d	 t j   k s t j	 |  r t j
 |  n d	 d
 t j
 |  i } d d | i } t t j |    d } } d S)z check if indentation is right zS
                def f():
                    assert 0
                f()
        r8   z    def f():z>       assert 0zE       assert 0r   %(py0)s == %(py3)sr   r   rS   r"   assert %(py5)sr   Nrd   )r   )r&  r'  )r   r  _getentrysourcerD   r#  r)   r*   r+   r,   r-   r.   r/   r0   )	r   r$  rE   rq   r   r\   r1   r   r   r   r   r   test_repr_source_excinfof  s    			   j   z-TestFormattedExcinfo.test_repr_source_excinfoc       
      C   s  t    } t d d d  } y t |  Wn! t k
 rL t j j   } Yn X| j |  } | j j	 d j
 d } d } | | k } | s t j d | f d | | f  d	 t j |  d
 t j |  i } d d | i }	 t t j |	    d  } } } d  S)Nzraise ValueError()r"   rl   r8   r   z>   ???r   %(py1)s == %(py4)srP   r    assert %(py6)sr$   )r   )r*  r+  )r   rm   rl   r!   r%   r&   r'   repr_excinforeprtracebackreprentriesr   r)   r*   r.   r/   r0   )
r   r$  r~   rE   r   r   r2   r\   r3   r4   r   r   r   test_repr_source_not_existingx  s    	    C   z2TestFormattedExcinfo.test_repr_source_not_existingc       
      C   s  t    } t d d d  } y t |  Wn! t k
 rL t j j   } Yn X| j |  } | j j	 d j
 d } d } | | k } | s t j d | f d | | f  d	 t j |  d
 t j |  i } d d | i }	 t t j |	    d  } } } d  S)Nz
a = 1
raise ValueError()
r"   rl   r8   r   z>   ???r   %(py1)s == %(py4)srP   r    assert %(py6)sr$   )r   )r0  r1  )r   rm   rl   r!   r%   r&   r'   r,  r-  r.  r   r)   r*   r.   r/   r0   )
r   r$  r~   rE   r   r   r2   r\   r3   r4   r   r   r   'test_repr_many_line_source_not_existing  s     	    C   z<TestFormattedExcinfo.test_repr_many_line_source_not_existingc                sV  t    } Gd d   d t    G  f d d   d t   G f d d   d t j j j   G f d d   d t j j  } Gd	 d
   d
 t j j  } |   } Gd d   d t  } |   } | |  | _ t   } | j	 |  } | j
 j d j d }	 d }
 |	 |
 k } | st j d | f d |	 |
 f  d t j |	  d t j |
  i } d d | i } t t j |    d  }	 } }
 t j j } | j	 |  } | j
 j d j d }	 d }
 |	 |
 k } | sDt j d | f d |	 |
 f  d t j |	  d t j |
  i } d d | i } t t j |    d  }	 } }
 d  S)Nc               @   sG   e  Z d  Z Gd d   d  Z d Z d Z d d   Z e e  Z d S)zJTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeCodec               @   s   e  Z d  Z d Z d S)zNTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeCode.raw?N)r   r   r   co_filenamer   r   r   r   raw  s   r5  r3  r   c             S   s   d  S)Nr   )r   r   r   r   
fullsource  s    zUTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeCode.fullsourceN)r   r   r   r5  rv   rw   r6  propertyr   r   r   r   FakeCode  s
   r8  c                   s%   e  Z d  Z     Z i  Z i  Z d S)zKTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeFrameN)r   r   r   r&   f_locals	f_globalsr   )r8  r   r   	FakeFrame  s   	r;  c                   s4   e  Z d  Z d d   Z e   f d d    Z d S)zTTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeTracebackEntryc             S   s   d |  _  d  S)Nr   r	   r   )r9   )r   rQ   r   r   r   r     s    z]TestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeTracebackEntry.__init__c                s       S)Nr   )r   )r;  r   r   rZ     s    zZTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeTracebackEntry.frameN)r   r   r   r   r7  rZ   r   )r;  r   r   FakeTracebackEntry  s   r<  c                   s   e  Z d  Z   Z d S)zKTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.TracebackN)r   r   r   Entryr   )r<  r   r   	Traceback  s   r>  c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	zMTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeExcinfoFooc             S   s   d  S)Nr   )r   r   r   r   r     s    zVTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeExcinfo.__init__c             S   s   d S)NZEXCr   )r   r   r   r   r   r     s    zUTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeExcinfo.exconlyc             S   s   d S)NFr   )r   clsr   r   r   r     s    z[TestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeExcinfo.errisinstanceN)r   r   r   typenamer   r   r   r   r   r   r   FakeExcinfo  s   rB  c               @   s   e  Z d  Z d Z d S)zKTestFormattedExcinfo.test_repr_source_failing_fullsource.<locals>.FakeRawTBN)r   r   r   tb_nextr   r   r   r   	FakeRawTB  s   rD  r   z>   ???r   %(py1)s == %(py4)srP   r    r"   assert %(py6)sr$   )r   )rE  rF  )r   )rE  rF  )r   objectr%   r&   r>  r=  r'   rD   IOErrorr,  r-  r.  r   r)   r*   r.   r/   r0   errorENOENT)r   r$  r>  rB  rE   rD  rQ   r   r   r   r2   r\   r3   r4   r   )r8  r;  r<  r   #test_repr_source_failing_fullsource  s<    	
%"
			    C       C   z8TestFormattedExcinfo.test_repr_source_failing_fullsourcec          
   C   s/  t  d d  } d d d d d d d	 d
 d i  i } | j |  } | j } | s d d d d t j   k s| t j |  r t j |  n d d t j |  i } t t j	 |    d  } | j d } d } | | k } | sLt j
 d | f d | | f  d t j |  d t j |  i }	 d d |	 i }
 t t j	 |
    d  } } } | j d } d } | | k } | st j
 d  | f d! | | f  d t j |  d t j |  i }	 d" d |	 i }
 t t j	 |
    d  } } } | j d
 } d } | | k } | st j
 d# | f d$ | | f  d t j |  d t j |  i }	 d% d |	 i }
 t t j	 |
    d  } } } | j d } d } | | k } | st j
 d& | f d' | | f  d t j |  d t j |  i }	 d( d |	 i }
 t t j	 |
    d  } } } d  S))N
showlocalsTyr   z   r;   r	   z@xr{   __builtins__r"   z)assert %(py2)s
{%(py2)s = %(py0)s.lines
}r   
reprlocalsr   r   z__builtins__ = <builtins>r   %(py1)s == %(py4)srP   r    assert %(py6)sr$   r8   zx          = 3zy          = 5zz          = 7)r   )rR  rS  )r   )rR  rS  )r   )rR  rS  )r   )rR  rS  )r   repr_localsr   r+   r,   r)   r-   r.   r/   r0   r*   )r   r   locrQ  r1   rG   r   r2   r\   r3   r4   r   r   r   test_repr_local  sP    $	  S      C       C       C       C   z$TestFormattedExcinfo.test_repr_localc          
   C   sc  | d  } t  j j t | j  } | j j   | _ t   } | j | j d   } | j	 } | d } d } | | k }	 |	 s t
 j d! |	 f d" | | f  d t
 j |  d t
 j |  i }
 d# d |
 i } t t
 j |    d  } }	 } | d } d } | | k }	 |	 st
 j d$ |	 f d% | | f  d t
 j |  d t
 j |  i }
 d& d |
 i } t t
 j |    d  } }	 } t d d  } | j | j d' |  } | j	 } | d } d } | | k }	 |	 sIt
 j d( |	 f d) | | f  d t
 j |  d t
 j |  i }
 d* d |
 i } t t
 j |    d  } }	 } | d } d } | | k }	 |	 st
 j d+ |	 f d, | | f  d t
 j |  d t
 j |  i }
 d- d |
 i } t t
 j |    d  } }	 } | d } d } | | k }	 |	 syt
 j d. |	 f d/ | | f  d t
 j |  d t
 j |  i }
 d0 d |
 i } t t
 j |    d  } }	 } | d } d } | | k }	 |	 st
 j d1 |	 f d2 | | f  d t
 j |  d t
 j |  i }
 d3 d |
 i } t t
 j |    d  } }	 } | d d   } | }	 |	 sjd4 d t
 j |  i } t t
 j |    d  } }	 | j d  k	 } | j } | j } | j } | | k } | st
 j d5 | f d6 | | f  d t
 j |  d d t j   k st
 j |  rt
 j |  n d d t
 j |  d d t j   k sFt
 j |  rUt
 j |  n d i } d7 d | i } t t
 j |    d  } } } | j } d } | | k } | sQt
 j d8 | f d9 | | f  d d t j   k st
 j |  rt
 j |  n d d t
 j |  d t
 j |  i } d: d | i } t t
 j |    d  } } } d  S);NzS
            def func1():
                raise ValueError("hello\nworld")
        r8   r   z    def func1():r   %(py1)s == %(py4)srP   r    r"   assert %(py6)sr$   z(>       raise ValueError("hello\nworld")rL  Tr{   zE       ValueError: hellor	   zE       worldrN   assert not %(py1)sJ%(py2)s
{%(py2)s = %(py0)s.path
} == %(py6)s
{%(py6)s = %(py4)s.__file__
}r   rU  r   modassert %(py8)srU   .%(py2)s
{%(py2)s = %(py0)s.lineno
} == %(py5)sr   assert %(py7)sr   rd   )r   )rW  rX  )r   )rW  rX  rd   )r   )rW  rX  )r   )rW  rX  )r   )rW  rX  )r   )rW  rX  rY  )r   )rZ  r\  )r   )r]  r^  )r%   r   r   r!   func1rD   r   r   repr_traceback_entryr   r)   r*   r.   r/   r0   rQ  reprfilelocrv   r   r+   r,   r-   r9   )r   r  r[  rE   r   reprtbr   r   r2   r\   r3   r4   
repr_entryrG   rU  r1   r]   r_   r^   r   @py_format8r   r   r   test_repr_tracebackentry_lines  s    			
    C   
    C   	
    C   
    C   
    C   
    C        
		 	      	    y   z3TestFormattedExcinfo.test_repr_tracebackentry_linesc             C   sr  | d  } t  j j t | j d d d d d d  } | j j   | _ | j d, } t d	 d
  } | j |  } | j	 d } d t
 d d  f } | | k }	 |	 st j d- |	 f d. | | f  d t j |  d t j |  i }
 d/ d |
 i } t t j |    d  } }	 } | j	 d } d0 } | | k }	 |	 st j d1 |	 f d2 | | f  d t j |  d t j |  i }
 d3 d |
 i } t t j |    d  } }	 } | j	 d } d4 } | | k }	 |	 sHt j d5 |	 f d6 | | f  d t j |  d t j |  i }
 d7 d |
 i } t t j |    d  } }	 } | j	 d } d t
 d d  f } | | k }	 |	 st j d8 |	 f d9 | | f  d t j |  d t j |  i }
 d: d |
 i } t t j |    d  } }	 } t d	 d
  } | j |  } | j } | j	 } | j	 } | | k } | s/t j d; | f d< | | f  d t j |  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 t j |  d t j |  i } d= d  | i } t t j |    d  } } } } t   } | j |  | j d } d! } d } d } | | } t
 |  } | | } | | k }	 |	 sst j d> |	 f d? | | f  d# t j |  d t j |  d$ d% t j   k st j t
  rt j t
  n d% d& t j |  d' t j |  d t j |  i } d@ d) | i } t t j |    d  } }	 } } } } } } | j d } d* } | | k }	 |	 s"t j dA |	 f dB | | f  d t j |  d t j |  i }
 dC d |
 i } t t j |    d  } }	 } | j d } d+ } d } d } | | } t
 |  } | | } | | k }	 |	 sLt j dD |	 f dE | | f  d# t j |  d t j |  d$ d% t j   k st j t
  rt j t
  n d% d& t j |  d' t j |  d t j |  i } dF d) | i } t t j |    d  } }	 } } } } } } d  S)GNz]
            def func1(m, x, y, z):
                raise ValueError("hello\nworld")
        mZ   r      rN  x   r8   funcargsTr   r   %(py1)s == %(py4)srP   r    r"   assert %(py6)sr$   r;   5r{   rM  13r	   h%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.reprfuncargs
}.args
} == %(py8)s
{%(py8)s = %(py6)s.args
}rU   reprfuncargsr   rc  r   assert %(py10)srj   zm = J%(py1)s == (%(py4)s + %(py12)s
{%(py12)s = %(py5)s((%(py7)s * %(py9)s))
})r   r   r   r   r   assert %(py15)spy15zx = 5, y = 13zz = rd   )r   )rk  rl  )r;   rm  )r   )rk  rl  )rM  rn  )r   )rk  rl  )r   )rk  rl  )r   )ro  rq  )r   )rr  rs  )r   )rk  rl  )r   )rr  rs  )r%   r   r   r!   r_  rD   r   r   	repr_argsargsr   r)   r*   r.   r/   r0   r`  rp  r+   r,   r-   r
   
toterminalr   )r   r  r[  rE   r`   r   rp  r   r2   r\   r3   r4   rc  r1   rr   r]   r_   rt   twr   r   r   r   r   r   r   r   r   r   re    s    	,    C       C       C       C   	 	 	      	    
  
      "    C       
  
      c             C   s]  | d  } t  j j t | j d d d d } | j j   | _ | j d } t d d  } | j |  } | j	 d	 } d
 t
 d  f } | | k }	 |	 st j d |	 f d  | | f  d t j |  d t j |  i }
 d! d |
 i } t t j |    d  } }	 } | j	 d } d t
 d"  f } | | k }	 |	 st j d# |	 f d$ | | f  d t j |  d t j |  i }
 d% d |
 i } t t j |    d  } }	 } | j	 d } d t
 d d i  f } | | k }	 |	 sZt j d& |	 f d' | | f  d t j |  d t j |  i }
 d( d |
 i } t t j |    d  } }	 } t d d  } | j |  } | j } | j	 } | j	 } | | k } | st j d) | f d* | | f  d t j |  d d t j   k st j |  rt j |  n d d d t j   k s:t j |  rIt j |  n d d t j |  d t j |  i } d+ d | i } t t j |    d  } } } } t   } | j |  | j d	 } d } | | k }	 |	 sKt j d, |	 f d- | | f  d t j |  d t j |  i }
 d. d |
 i } t t j |    d  } }	 } d  S)/Nz]
            def func1(x, *y, **z):
                raise ValueError("hello\nworld")
        abcdr8   rj  Tr   r;   r   %(py1)s == %(py4)srP   r    r"   assert %(py6)sr$   rM  r{   rN  h%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.reprfuncargs
}.args
} == %(py8)s
{%(py8)s = %(py6)s.args
}rU   rp  r   rc  r   assert %(py10)srj   z#x = 'a', y = ('b',), z = {'c': 'd'}rd   )r   )r}  r~  )rz  )r   )r}  r~  )r   )r}  r~  )r   )r  r  )r   )r}  r~  )r%   r   r   r!   r_  rD   r   r   ru  rv  r   r)   r*   r.   r/   r0   r`  rp  r+   r,   r-   r
   rw  r   )r   r  r[  rE   r`   r   rp  r   r2   r\   r3   r4   rc  r1   rr   r]   r_   rt   rx  r   r   r   *test_repr_tracebackentry_lines_var_kw_args  sh    	$    C       C       C   	 	 	      	    C   z?TestFormattedExcinfo.test_repr_tracebackentry_lines_var_kw_argsc             C   s  | d  } t  j j t | j  } t d d  } | j | j d"  } | j } t  j	 j
 | j  j } | d } d }	 | |	 k }
 |
 s t j d# |
 f d$ | |	 f  d	 t j |  d
 t j |	  i } d% d | i } t t j |    d  } }
 }	 | j } | j	 } t |  } | | k } | sKt j d& | f d' | | f  d t j |  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 |  d d t j   k st j |  rt j |  n d i } d( d | i } t t j |    d  } } } } | j } | j }	 d } |	 | k } | s4t j d) | f d* |	 | f  d t j |  d d t j   k st j |  rt j |  n d d t j |  d
 t j |	  i } d+ d | i } t t j |    d  } }	 } } t d d  } | j | j d, |  } | j } | d } d }	 | |	 k }
 |
 st j d- |
 f d. | |	 f  d	 t j |  d
 t j |	  i } d/ d | i } t t j |    d  } }
 }	 | d } d  }	 | |	 k }
 |
 st j d0 |
 f d1 | |	 f  d	 t j |  d
 t j |	  i } d2 d | i } t t j |    d  } }
 }	 | j } | j	 } t |  } | | k } | st j d3 | f d4 | | f  d t j |  d d t j   k s(t j |  r7t j |  n d d t j |  d d t j   k smt j t  r|t j t  n d d t j |  d d t j   k st j |  rt j |  n d i } d5 d | i } t t j |    d  } } } } | j } | j }	 d! } |	 | k } | st j d6 | f d7 |	 | f  d t j |  d d t j   k s}t j |  rt j |  n d d t j |  d
 t j |	  i } d8 d | i } t t j |    d  } }	 } } d  S)9Nz}
            def func1():
                raise ValueError("hello")
            def entry():
                func1()
        styleshortr{   r   z    func1()r   %(py1)s == %(py4)srP   r    r"   assert %(py6)sr$   r   k%(py0)s in %(py9)s
{%(py9)s = %(py2)s(%(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py3)s.reprfileloc
}.path
})
}r   r   r   r   r   re   r   rS   rb  assert %(py11)sr   r   O%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.reprfileloc
}.lineno
} == %(py7)sassert %(py9)sr8   z    raise ValueError("hello")zE   ValueError: hellor	   )r   )r  r  )r   )r  r  )r   )r  r  rd   )r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r%   r   r   r!   r`   r   r`  rD   r   rv   r   r   r   r)   r*   r.   r/   r0   ra  re   r+   r,   r-   r9   )r   r  r[  rE   r   rb  r   r   r   r2   r\   r3   r4   r^   r   r   r1   r   r   r]   rd  r   r   r   test_repr_tracebackentry_short  s    		
    C   	 	       	 	       	
    C   
    C   	 	       	 	       z3TestFormattedExcinfo.test_repr_tracebackentry_shortc             C   si  | d  } t  j j t | j  } t d d  } | j | j d  t d d  } | j | j d |  } | j } | d } d } | | k }	 |	 st	 j
 d |	 f d | | f  d
 t	 j |  d t	 j |  i }
 d d |
 i } t t	 j |    d  } }	 } | d d   } | }	 |	 s[d d
 t	 j |  i } t t	 j |    d  } }	 d  S)Nz}
            def func1():
                raise ValueError("hello")
            def entry():
                func1()
        r  nor{   r8   r   zE   ValueError: hellor   %(py1)s == %(py4)srP   r    r"   assert %(py6)sr$   assert not %(py1)sr  rd   )r   )r  r  r  )r%   r   r   r!   r`   r   r`  rD   r   r)   r*   r.   r/   r0   )r   r  r[  rE   r   	reprentryr   r   r2   r\   r3   r4   rG   r   r   r   test_repr_tracebackentry_no4  s,    		
    C        z0TestFormattedExcinfo.test_repr_tracebackentry_noc             C   s  | d  } t  j j t | j  } t d d  } | j |  } | j } t |  } d } | | k }	 |	 sR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 t  r t	 j t  n d
 d t	 j |  d t	 j |  d t	 j |  i }
 d d |
 i } t t	 j |    d  } } }	 } t d d  } | j |  } | j } t |  } 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 t  r6t	 j t  n d
 d t	 j |  d t	 j |  d t	 j |  i }
 d d |
 i } t t	 j |    d  } } }	 } d  S)Nzq
            def f(x):
                raise ValueError(x)
            def entry():
                f(0)
        tbfilterTr{   r   Q%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.reprentries
})
} == %(py8)srP   rb  r   rR   rS   r   rU   r"   assert %(py10)srj   Fr	   )r   )r  r  )r   )r  r  )r%   r   r   r!   r`   r   repr_tracebackr.  rR   r)   r*   r+   r,   r-   r.   r/   r0   )r   r  r[  rE   r   rb  r\   r^   rr   r   r_   rt   r   r   r   test_repr_traceback_tbfilterE  s2    		        	        z1TestFormattedExcinfo.test_repr_traceback_tbfilterc             C   s  | d  } y | j    Wn! t k
 r= t j j   } Yn Xd d l m } | j | d d  d | j d j	 j _
 t d d  } | j | j d  } | j } t d d  }	 |	 j | j d |  }
 |
 j } | j   t j
 j | j  j } | d } d
 } | | k } | st j d | f d | | f  d t j |  d t j |  i } d d | i } t t j |    d  } } } | d } d } | | k } | st j d | f d | | f  d t j |  d t j |  i } d d | i } t t j |    d  } } } | d	 } d } | | k } | st j d | f d | | f  d t j |  d t j |  i } d d | i } t t j |    d  } } } d  S)Nz}
            def func1():
                raise ValueError("hello")
            def entry():
                func1()
        r   )r|   rv   Zbogusr  r  r{   r8   z    func1()r   %(py1)s == %(py4)srP   r    r"   assert %(py6)sr$   z    raise ValueError("hello")zE   ValueError: hellor  rd   )r   )r  r  )r   )r  r  )r   )r  r  )r`   r!   r%   r&   r'   py._code.coder|   setattrrD   rZ   rv   r   r`  r   undor   r   r   r)   r*   r.   r/   r0   )r   r  r   r[  rE   r|   r   rb  r   Zlast_pZlast_reprtbZ
last_linesr   r   r2   r\   r3   r4   r   r   r   test_traceback_short_no_sourceT  sR    			

    C   
    C   
    C   z3TestFormattedExcinfo.test_traceback_short_no_sourcec             C   sN  | d  } t  j j t | j  } x#d d f D]} t d |  } | j |  } | j } t |  } d }	 | |	 k }
 |
 rpt	 j
 d f |
 f d f | |	 f  d d	 t j   k p t	 j |  r t	 j |  n d	 d
 d t j   k p t	 j t  rt	 j t  n d d t	 j |  d t	 j |  d t	 j |	  i } d d d | i } t t	 j |    d  } } }
 }	 | j } | | k } | rmt	 j
 d f | f d f | | f  d
 d	 t j   k pt	 j |  rt	 j |  n d	 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  } } | j } | } | rd d d
 d	 t j   k pt	 j |  rt	 j |  n d	 d t	 j |  i } t t	 j |    d  } } | j |  } | j } | rd d d
 d t j   k pGt	 j |  rYt	 j |  n d d t	 j |  i } t t	 j |    d  } | j } | j } t |  }
 | j } t |  } |
 | k } | rJt	 j
 d f | f d f |
 | f  d t	 j |
  d t	 j |  d d t j   k p6t	 j |  rHt	 j |  n d d t	 j |  d d t j   k p{t	 j t  rt	 j t  n d 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	 i	 } d d d  | i } t t	 j |    d  } } }
 } } } | j } | j } | j } d! }	 | |	  } | r<d d" d t	 j |  d
 d t j   k pt	 j |  rt	 j |  n d d t	 j |  d t	 j |  d t	 j |  d t	 j |	  i } t t	 j |    d  } } } }	 } | j } | j } d# }
 | |
 k } | r4t	 j
 d f | f d$ f | |
 f  d t	 j |
  d
 d t j   k pt	 j |  rt	 j |  n d d t	 j |  d t	 j |  i } d d% d | i } t t	 j |    d  } } } }
 q1 Wd  S)&Nzq
            def f(x):
                raise ValueError(x)
            def entry():
                f(0)
        longr  r  r{   r   zQ%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.reprentries
})
} == %(py8)srP   rb  r   rR   rS   r   rU   r"   zassert %(py10)srj   z-%(py2)s
{%(py2)s = %(py0)s.style
} == %(py4)sr   r    zassert %(py6)sr$   z1assert not %(py2)s
{%(py2)s = %(py0)s.extraline
}z1assert %(py2)s
{%(py2)s = %(py0)s.reprtraceback
}r   z%(py7)s
{%(py7)s = %(py0)s(%(py5)s
{%(py5)s = %(py3)s
{%(py3)s = %(py1)s.reprtraceback
}.reprentries
})
} == %(py14)s
{%(py14)s = %(py9)s(%(py12)s
{%(py12)s = %(py10)s.reprentries
})
}r   r   r   r   zassert %(py16)spy16zmod.pyzassert %(py10)s
{%(py10)s = %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.reprcrash
}.path
}.endswith
}(%(py8)s)
}zValueError: 0zN%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.reprcrash
}.message
} == %(py7)szassert %(py9)s)r%   r   r   r!   r`   r   r  r.  rR   r)   r*   r+   r,   r-   r.   r/   r0   r  	extraliner,  r-  r   rv   rh   message)r   r  r[  rE   r  r   rb  r\   r^   rr   r   r_   rt   r1   r2   r3   r4   r   r   rG   r   r   r   r   @py_format17r]   rs   rd  r   r   r   r   test_repr_traceback_and_excinfoo  s    		        	      
	   S  
	  S  	 	  	     O   	 	 	      	 	       z4TestFormattedExcinfo.test_repr_traceback_and_excinfoc             C   s  | d  } t  j j t | j  } t   } d d   } | j t  j j d |  | j	 } | t
  } | t
 k }	 |	 st j d |	 f d | t
 f  d d t j   k s t j t
  r t j t
  n d d	 t j |  d
 d t j   k s t j |  rt j |  n d d d t j   k s6t j t
  rEt j t
  n d d t j |  i }
 d d |
 i } t t j |    d  } } }	 | j |  } d  S)Nzq
            def f(x):
                raise ValueError(x)
            def entry():
                f(0)
        c               S   s   t  d   d  S)Nr{   )OSErrorr   r   r   r   raiseos  s    zJTestFormattedExcinfo.test_repr_traceback_with_invalid_cwd.<locals>.raiseosgetcwdr   O%(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s._makepath
}(%(py3)s)
} == %(py7)sr   r   r   r   r   rS   r   r"   assert %(py9)sr   )r   )r  r  )r%   r   r   r!   r`   r   r  r   os	_makepathr   r)   r*   r+   r,   r-   r.   r/   r0   r  )r   r  r   r[  rE   r   r  r1   r^   r   rd  r   rb  r   r   r   $test_repr_traceback_with_invalid_cwd  s    			       z9TestFormattedExcinfo.test_repr_traceback_with_invalid_cwdc             C   s  | d  } t  j j t | j  } | j   } | j d d  t   } | j |  | j	 d } d } | | k } | s t
 j d | f d | | f  d t
 j |  d t
 j |  i }	 d d |	 i }
 t t
 j |
    d  } } } | j	 d } d } | | k } | s~t
 j d | f d | | f  d t
 j |  d t
 j |  i }	 d d |	 i }
 t t
 j |
    d  } } } d  S)NzE
            def entry():
                raise ValueError()
        titlecontentr8   r   %(py1)s == %(py4)srP   r    r"   assert %(py6)sr$   r{   -rd   )r   )r  r  r  )r  ztitle)r   )r  r  )r%   r   r   r!   r`   r   
addsectionr
   rw  r   r)   r*   r.   r/   r0   )r   r  r[  rE   r   Ztwmockr   r2   r\   r3   r4   r   r   r   test_repr_excinfo_addouterr  s.    		    C       C   z0TestFormattedExcinfo.test_repr_excinfo_addouterrc             C   s  | d  } t  j j t | j  } | j   } | j } | j } | j } d } | |  }	 |	 sd d d t	 j
 |  d d t j   k s t	 j |  r t	 j
 |  n d d t	 j
 |  d	 t	 j
 |  d
 t	 j
 |	  d t	 j
 |  i }
 t t	 j |
    d  } } } } }	 | j } | j } d } | | k } | st	 j d | f d | | f  d t	 j
 |  d d t j   k st	 j |  rt	 j
 |  n d d t	 j
 |  d	 t	 j
 |  i } d d | i } t t	 j |    d  } } } } | j } | j } d } | | k } | st	 j d | f d | | f  d t	 j
 |  d d t j   k st	 j |  rt	 j
 |  n d d t	 j
 |  d	 t	 j
 |  i } d  d | i } t t	 j |    d  } } } } | j } t |  } | j } d } | |  } | sd d d t	 j
 |  d t	 j
 |  d d t j   k snt	 j |  r}t	 j
 |  n d d t	 j
 |  d t	 j
 |  d d t j   k st	 j t  rt	 j
 t  n d d t	 j
 |  i } t t	 j |    d  } } } } } d  S)!NzE
            def entry():
                raise ValueError()
        zmod.pyr"   zassert %(py10)s
{%(py10)s = %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.reprcrash
}.path
}.endswith
}(%(py8)s)
}r$   r   r   r   r    rj   rU   r	   r   M%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.reprcrash
}.lineno
} == %(py7)sr   assert %(py9)sr   r!   N%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.reprcrash
}.message
} == %(py7)szmod.py:3: ValueErrorzassert %(py11)s
{%(py11)s = %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.reprcrash
})
}.endswith
}(%(py9)s)
}r   rP   r   re   rS   )r   )r  r  )r   )r  r  )r%   r   r   r!   r`   r   r   rv   rh   r)   r.   r+   r,   r-   r/   r0   r9   r*   r  re   )r   r  r[  rE   r   r1   r2   r]   rr   rs   rt   r   rd  r   r\   r^   r   r   r   r   r   r   test_repr_excinfo_reprcrash  sP    		 	 	      	 	       	 	       	  	      z0TestFormattedExcinfo.test_repr_excinfo_reprcrashc          	   C   s  | d  } t  j j t | j  } xd D]} t d d  } | j |  } | j } 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 t j |  i }
 d d |
 i } t t j |    d  } }	 } t |  } | sd d d d
 t
 j   k sYt j |  rht j |  n d
 d	 d t
 j   k st j t  rt j t  n d d t j |  i } t t j |    d  } q+ Wd  S)Nz
            def rec2(x):
                return rec1(x+1)
            def rec1(x):
                return rec2(x-1)
            def entry():
                rec1(42)
        r  r  r  r  z/!!! Recursion detected (same locals & position)r   1%(py2)s
{%(py2)s = %(py0)s.extraline
} == %(py5)sr   rb  r   r   r"   assert %(py7)sr   z,assert %(py3)s
{%(py3)s = %(py0)s(%(py1)s)
}rP   re   rS   )zshortzlongzno)r   )r  r  )r%   r   r   r   r`   r   r  r  r)   r*   r+   r,   r-   r.   r/   r0   re   )r   r  r[  rE   r  r   rb  r1   r^   r2   r   rd  r\   r   r   r   r   test_repr_traceback_recursion  s&    		    y       z2TestFormattedExcinfo.test_repr_traceback_recursionc             C   s   | d  } t  j j t | j  } t   } | j | j d |  } | j } | d } d } | | k }	 |	 s t	 j
 d |	 f d | | f  d t	 j |  d t	 j |  i }
 d d
 |
 i } t t	 j |    d  } }	 } d  S)NzY
            def somefunc():
                x = 1
                assert x == 2
        r8   zE       assert 1 == 2r   %(py1)s == %(py4)srP   r    r"   assert %(py6)sr$   rd   rd   )r   )r  r  )r%   r   r   r/   Zsomefuncr   r`  rD   r   r)   r*   r.   r0   )r   r  r[  rE   r   r  r   r   r2   r\   r3   r4   r   r   r   test_tb_entry_AssertionError  s    			
    C   z1TestFormattedExcinfo.test_tb_entry_AssertionErrorc             C   sq  | d  } y | j    Wn! t k
 r= t j j   } Yn Xx,d D]$} xd D]} | j d | d |  } t | t  } | sYd	 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 d t j	   k st
 j t  r+t
 j t  n d d t
 j |  i } t t
 j |    d  } | j }	 |	 j } | | k }
 |
 sW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 t
 j |	  d t
 j |  i } d d | i } t t
 j |    d  }	 } }
 qR WqE Wd  S)Nzq
            def f(x):
                raise ValueError(x)
            def entry():
                f(0)
        r  r  r  TFr  rL  r"   z5assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}rP   r   r   r  r   r   r    r   P%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.reprtraceback
}.style
} == %(py6)sr$   assert %(py8)srU   )zshortzlongzno)TF)r   )r  r  )r`   r!   r%   r&   r'   r   r  r   r+   r,   r)   r-   r.   r/   r0   r-  r  r*   )r   r  r[  rE   r  rL  r   r2   r3   r1   r]   r4   r_   r   r   r   test_reprexcinfo_getrepr  s,    	    	 	      z-TestFormattedExcinfo.test_reprexcinfo_getreprc             C   s  d d l  m } Gd d   d |  } t j j |    } t j } | j } d } d } | | |  } | | k }	 |	 s{t j d |	 f d | | f  d	 t j |  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 |  d t j |  d t j |  d t j |  i }
 d d |
 i } t t j |    d  }	 } } } } } d  S)Nr   )TerminalReprc               @   s   e  Z d  Z d d   Z d S)z=TestFormattedExcinfo.test_reprexcinfo_unicode.<locals>.MyReprc             S   s    | j  t j j d d   d  S)Nu   яzutf-8)r   r%   r   _totext)r   rx  r   r   r   rw    s    zHTestFormattedExcinfo.test_reprexcinfo_unicode.<locals>.MyRepr.toterminalN)r   r   r   rw  r   r   r   r   MyRepr  s   r  u   яzutf-8r   v%(py0)s == %(py12)s
{%(py12)s = %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s.builtin
}._totext
}(%(py8)s, %(py10)s)
}r$   r   r;   r   r%   r    r   rj   rU   r"   assert %(py14)sr   )r   )r  r  )r  r  r%   r   r  r)   r*   r.   r+   r,   r-   r/   r0   )r   r  r  r;   r2   r]   rr   rs   r   r1   r   r   r   r   r   test_reprexcinfo_unicode  s    	 	         z-TestFormattedExcinfo.test_reprexcinfo_unicodec          
   C   s  | d  } t  j j t | j  } | j j   | _ | j   } t   } | j	 |  | j
 d } d } | | k } | s t j d  | f d! | | f  d t j |  d t j |  i }	 d" d	 |	 i }
 t t j |
    d  } } } | j
 j d  | j
 d } d
 } | | k } | st j d# | f d$ | | f  d t j |  d t j |  i }	 d% d	 |	 i }
 t t j |
    d  } } } | j
 d } d } | | k } | s+t j d& | f d' | | f  d t j |  d t j |  i }	 d( d	 |	 i }
 t t j |
    d  } } } | j
 d } d } | | k } | st j d) | f d* | | f  d t j |  d t j |  i }	 d+ d	 |	 i }
 t t j |
    d  } } } | j
 d } | j } d } | |  } | sad d d t j |  d t j |  d t j |  d t j |  i } t t j |    d  } } } } | j
 d } d, } | | k } | s t j d- | f d. | | f  d t j |  d t j |  i }	 d/ d	 |	 i }
 t t j |
    d  } } } | j
 d } d } | | k } | st j d0 | f d1 | | f  d t j |  d t j |  i }	 d2 d	 |	 i }
 t t j |
    d  } } } | j
 d } d } | | k } | s6t j d3 | f d4 | | f  d t j |  d t j |  i }	 d5 d	 |	 i }
 t t j |
    d  } } } | j
 d } d } | | k } | st j d6 | f d7 | | f  d t j |  d t j |  i }	 d8 d	 |	 i }
 t t j |
    d  } } } | j
 d } d } | | k } | slt j d9 | f d: | | f  d t j |  d t j |  i }	 d; d	 |	 i }
 t t j |
    d  } } } | j
 d } d } | | k } | st j d< | f d= | | f  d t j |  d t j |  i }	 d> d	 |	 i }
 t t j |
    d  } } } | j
 d } | j } d } | |  } | sd d d t j |  d t j |  d t j |  d t j |  i } t t j |    d  } } } } d  S)?Nzm
            def g(x):
                raise ValueError(x)
            def f():
                g(3)
        r   r"   r   %(py1)s == %(py4)srP   r    assert %(py6)sr$   z    def f():r8   z>       g(3)r{   r	   z
mod.py:5: zJassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.endswith
}(%(py5)s)
}r   r   rS   rN   _ r      z    def g(x):rO  z>       raise ValueError(x)r   zE       ValueError: 3r   r   zmod.py:3: ValueError)r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r  N)r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r%   r   r   r!   r7   rD   r   r   r
   rw  r   r)   r*   r.   r/   r0   poprh   )r   r  r[  rE   r   rx  r   r2   r\   r3   r4   r^   r   rd  r   r   r   test_toterminal_long  s    		    C       C       C       C    	    J      C       C       C       C       C       C    	    J  z)TestFormattedExcinfo.test_toterminal_longc          
   C   s  | d  } t  j j t | j  } | j d  j   | j j   | _ | j	   } t
   } | j |  | j d } d } | | k }	 |	 s t j d |	 f d | | f  d t j |  d t j |  i }
 d d
 |
 i } t t j |    d  } }	 } | j j d  | j d } d } | | k }	 |	 st j d |	 f d  | | f  d t j |  d t j |  i }
 d! d
 |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 s>t j d" |	 f d# | | f  d t j |  d t j |  i }
 d$ d
 |
 i } t t j |    d  } }	 } | j d } | j }	 d } |	 |  } | sd d d t j |  d t j |  d t j |  d t j |	  i } t t j |    d  } }	 } } | j d } d% } | | k }	 |	 sxt j d& |	 f d' | | f  d t j |  d t j |  i }
 d( d
 |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 st j d) |	 f d* | | f  d t j |  d t j |  i }
 d+ d
 |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 st j d, |	 f d- | | f  d t j |  d t j |  i }
 d. d
 |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 sIt j d/ |	 f d0 | | f  d t j |  d t j |  i }
 d1 d
 |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 st j d2 |	 f d3 | | f  d t j |  d t j |  i }
 d4 d
 |
 i } t t j |    d  } }	 } | j d } | j }	 d } |	 |  } | sd d d t j |  d t j |  d t j |  d t j |	  i } t t j |    d  } }	 } } d  S)5Nzm
            def g(x):
                raise ValueError(x)
            def f():
                g(3)
        zmod.pyr   r"   r   %(py1)s == %(py4)srP   r    assert %(py6)sr$   z>   ???r8   r{   z
mod.py:5: zJassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.endswith
}(%(py5)s)
}r   r   rS   r	   _ rN   r   r  zE   ValueError: 3rO  r   zmod.py:3: ValueError)r   )r  r  )r   )r  r  )r   )r  r  )r  N)r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r%   r   r   r!   r7   r   rY   rD   r   r   r
   rw  r   r)   r*   r.   r/   r0   r  rh   )r   r  r   r[  rE   r   rx  r   r2   r\   r3   r4   r^   r   rd  r   r   r   #test_toterminal_long_missing_source  s    		    C       C       C    	    J      C       C       C       C       C    	    J  z8TestFormattedExcinfo.test_toterminal_long_missing_sourcec          
   C   s  | d  } t  j j t | j  } | j d  j d  | j j   | _ | j	   } t
   } | j |  | j d } d } | | k }	 |	 s t j d |	 f d | | f  d t j |  d	 t j |  i }
 d d |
 i } t t j |    d  } }	 } | j j d  | j d } d } | | k }	 |	 st j d  |	 f d! | | f  d t j |  d	 t j |  i }
 d" d |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 sAt j d# |	 f d$ | | f  d t j |  d	 t j |  i }
 d% d |
 i } t t j |    d  } }	 } | j d } | j }	 d } |	 |  } | sd d d t j |  d t j |  d t j |  d t j |	  i } t t j |    d  } }	 } } | j d } d& } | | k }	 |	 s{t j d' |	 f d( | | f  d t j |  d	 t j |  i }
 d) d |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 st j d* |	 f d+ | | f  d t j |  d	 t j |  i }
 d, d |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 st j d- |	 f d. | | f  d t j |  d	 t j |  i }
 d/ d |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 sLt j d0 |	 f d1 | | f  d t j |  d	 t j |  i }
 d2 d |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 st j d3 |	 f d4 | | f  d t j |  d	 t j |  i }
 d5 d |
 i } t t j |    d  } }	 } | j d } | j }	 d } |	 |  } | sd d d t j |  d t j |  d t j |  d t j |	  i } t t j |    d  } }	 } } d  S)6Nzm
            def g(x):
                raise ValueError(x)
            def f():
                g(3)
        zmod.pyZasdfr   r"   r   %(py1)s == %(py4)srP   r    assert %(py6)sr$   z>   ???r8   r{   z
mod.py:5: zJassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.endswith
}(%(py5)s)
}r   r   rS   r	   _ rN   r   r  zE   ValueError: 3rO  r   zmod.py:3: ValueError)r   )r  r  )r   )r  r  )r   )r  r  )r  N)r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r%   r   r   r!   r7   r   r   rD   r   r   r
   rw  r   r)   r*   r.   r/   r0   r  rh   )r   r  r   r[  rE   r   rx  r   r2   r\   r3   r4   r^   r   rd  r   r   r   &test_toterminal_long_incomplete_source  s    		    C       C       C    	    J      C       C       C       C       C    	    J  z;TestFormattedExcinfo.test_toterminal_long_incomplete_sourcec             C   s  | d  } t  j j t | j  } t   } t  j j | j  } | j	   j
   } z| j d d  } | j |  | j d } t  j j   j |  }	 t |	  t t |   k  rj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 |
  i } d d | i } t t j |    d  } }
 | j d d  } | j |  | j d } d }
 | f } |
 | } | | k } | s_t j d | f d | | f  d t j |  d d	 t j   k st j |  r!t j |  n d	 d
 t j |
  i } d d | i } t t j |    d  } }
 } } Wd  | j
   Xd  S)NzA
            def f():
                raise ValueError()
        abspathFr8   zmod.py:3: ValueErrorr   %(py0)s == %(py3)sr   r   rS   r"   assert %(py5)sr   Tz%s:3: ValueError%(py0)s == (%(py3)s %% %(py5)s)assert %(py8)srU   rd   )r   )r  r  rd   )r   )r  r  )r%   r   r   r!   r7   r
   rv   r   r   r   chdirr   rw  r   bestrelpathrR   re   r)   r*   r+   r,   r-   r.   r/   r0   )r   r  r[  rE   rx  rv   oldr   r   r;   r\   r1   r   r   r^   r   r4   r_   r   r   r   test_toterminal_long_filenames5  s@    		   j   
 	 
   y   z3TestFormattedExcinfo.test_toterminal_long_filenamesreproptionsc             C   sU   g  |  ]K } d D]> } d D]1 } d D]$ } d | d | d | d | i  q$ q q q S)	TFr  rL  rj  r  )TF)TF)TFr   )r:   r  rL  r  rj  r   r   r   r<   N  s   	

zTestFormattedExcinfo.<listcomp>r  r  r  c          
   C   s  | d  } t  j j t | j  } t  j j d d  } | j |   } | j |  | j	 } | j
 } |   }	 |	 s d d d t j |	  d d t j   k s t j |  r t j |  n d d	 t j |  d
 t j |  i }
 t t j |
    d  } } }	 d  S)Nzm
            def g(x):
                raise ValueError(x)
            def f():
                g(3)
        stringioTr"   zaassert %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.stringio
}.getvalue
}()
}r$   r   rx  r   r    )r%   r   r   r!   r7   ioTerminalWriterr   rw  r  getvaluer)   r.   r+   r,   r-   r/   r0   )r   r  r  r[  rE   rx  r   r1   r2   r]   r4   r   r   r   test_format_excinfoM  s    		 	 	  q  z(TestFormattedExcinfo.test_format_excinfoc             C   s  |  j  d  } | j d d  } d } | j } t |  } | | k } | s1t j d# | f d$ | | f  d t j |  d t j |  d	 d
 t j   k s t j	 t  r t j t  n d
 d t j |  d d t j   k s t j	 |  rt j |  n d i } d% d | i } t
 t j |    d  } } } } t |  }	 |	 j }
 d } |
 |  } | sd d d t j |  d d t j   k st j	 |	  rt j |	  n d d t j |
  d t j |  i } t
 t j |    d  }
 } } |	 j }
 d } |
 |  } | sd d d t j |  d d t j   k s_t j	 |	  rnt j |	  n d d t j |
  d t j |  i } t
 t j |    d  }
 } } d } | |	 k } | s`t j d& | f d' | |	 f  d t j |  d	 d t j   k s"t j	 |	  r1t j |	  n d i } d( d | i } t
 t j |    d  } } t j j j d) k r|	 j }
 d } |
 |  } d } | | k } | snt j d* | f d+ | | f  d  t j |  d t j |  d d t j   k st j	 |	  r!t j |	  n d d t j |
  d t j |  i } d, d" | i } t
 t j |    d  }
 } } } } d  S)-Nz
            assert 0
        r  nativezassert 0r   O%(py1)s in %(py8)s
{%(py8)s = %(py3)s(%(py6)s
{%(py6)s = %(py4)s.reprcrash
})
}r$   rP   rS   re   rU   r    r   r"   assert %(py10)srj   z)Traceback (most recent call last):
  FilezLassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}r   rc   r   z
AssertionError: assert 0zJassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.endswith
}(%(py4)s)
}zexec (source.compile())%(py1)s in %(py3)sassert %(py5)sr   r{   r   r   K%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.count
}(%(py4)s)
} == %(py9)sr   assert %(py11)sr   )r   )r  r  )r   )r  r  )r{   r   )r   )r  r  )r  r   r   re   r)   r*   r.   r+   r,   r-   r/   r0   rg   rh   r%   r   r   r   count)r   rE   r   r   r]   rr   r\   r_   rt   rc   r1   r2   r4   r   r   r   r   r   r   r   r   test_native_styleb  sZ    	 	       	    q  	    q     j   
	         z&TestFormattedExcinfo.test_native_stylec          
   C   s  | d  } t  j j t | j  } | j j   | _ | j d j d  | j d j d  | j d d  } t	   } | j
 |  x | j D] } t |  q W| j d } d } | | k }	 |	 s1t j d- |	 f d. | | f  d t j |  d t j |  i }
 d/ d |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 st j d0 |	 f d1 | | f  d t j |  d t j |  i }
 d2 d |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 sgt j d3 |	 f d4 | | f  d t j |  d t j |  i }
 d5 d |
 i } t t j |    d  } }	 } | j d } d } | | k }	 |	 st j d6 |	 f d7 | | f  d t j |  d t j |  i }
 d8 d |
 i } t t j |    d  } }	 } | j d } | j }	 d } |	 |  } | sd d d t j |  d t j |  d t j |  d t j |	  i } t t j |    d  } }	 } } | j d } d9 } | | k }	 |	 s<t j d: |	 f d; | | f  d t j |  d t j |  i }
 d< d |
 i } t t j |    d  } }	 } | j d } | j }	 d } |	 |  } | sd d d t j |  d t j |  d t j |  d t j |	  i } t t j |    d  } }	 } } | j d } d } | | k }	 |	 svt j d= |	 f d> | | f  d t j |  d t j |  i }
 d? d |
 i } t t j |    d  } }	 } | j d } | j }	 d } |	 |  } | sd d d t j |  d t j |  d t j |  d t j |	  i } t t j |    d  } }	 } } | j d  } d! } | | k }	 |	 st j d@ |	 f dA | | f  d t j |  d t j |  i }
 dB d |
 i } t t j |    d  } }	 } | j d" } dC } | | k }	 |	 sKt j dD |	 f dE | | f  d t j |  d t j |  i }
 dF d |
 i } t t j |    d  } }	 } | j d# } d } | | k }	 |	 st j dG |	 f dH | | f  d t j |  d t j |  i }
 dI d |
 i } t t j |    d  } }	 } | j d$ } d% } | | k }	 |	 st j dJ |	 f dK | | f  d t j |  d t j |  i }
 dL d |
 i } t t j |    d  } }	 } | j d& } d' } | | k }	 |	 s	t j dM |	 f dN | | f  d t j |  d t j |  i }
 dO d |
 i } t t j |    d  } }	 } | j d( } d) } | | k }	 |	 s	t j dP |	 f dQ | | f  d t j |  d t j |  i }
 dR d |
 i } t t j |    d  } }	 } | j d* } d } | | k }	 |	 sR
t j dS |	 f dT | | f  d t j |  d t j |  i }
 dU d |
 i } t t j |    d  } }	 } | j d+ } | j }	 d, } |	 |  } | s
d d d t j |  d t j |  d t j |  d t j |	  i } t t j |    d  } }	 } } d  S)VNz
            def f():
                g()
            def g():
                h()
            def h():
                i()
            def i():
                raise ValueError()
        r8   r  r{   r  r  r   r"   r   %(py1)s == %(py4)srP   r    assert %(py6)sr$   z    def f():z>       g()r	   rN   z
mod.py:3: zJassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.endswith
}(%(py5)s)
}r   r   rS   r   _ r  zin grO  z    h()r   zin hr   z    i()r         z    def i():rh  z>       raise ValueError()   zE       ValueError      zmod.py:9: ValueError)r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r  N)r   )r  r  )r   )r  r  )r   )r  r  )r  N)r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r   )r  r  )r%   r   r   r!   r7   rD   r   set_repr_styler   r
   rw  r   ro   r)   r*   r.   r/   r0   rh   )r   r  r[  rE   rrx  r   r   r2   r\   r3   r4   r^   r   rd  r   r   r   test_traceback_repr_stylep  s&   			     C       C       C       C    	    J      C    	    J      C    	    J      C       C       C       C       C       C       C    	    J  z.TestFormattedExcinfo.test_traceback_repr_styleN)zlongzshortzno)$r   r   r   r  r  r%  r)  r/  r2  rK  rV  re  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%   r   markmultir  r  r  r   r   r   r   r  C  s@   

6
	r  )0builtinsr+   _pytest.assertion.rewrite	assertionrewriter)   r%   r  r   r   r   
_tryimportr   r   r  xfailr   Ztest_sourcer   	importlibImportErrorr  getattrr   tuplemapint__version__r   Zpytest_version_infor
   r5   rH   r7   r6   rJ   rK   r   r   r   r   r   r   r   r  r
  r  r  r   r   r   r   <module>   s>     +		