
:Wt                 @   s   d  d l  Z d  d l j j Z d  d l Z d  d l 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 Gd d   d  Z Gd d   d  Z d S)     Nc              C   s  t  j j t d d d   }  |  |  k } | s t j d | f d |  |  f  d d t j   k sr 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  } t  j j t d d d   } | |  k } | st j d | f d | |  f  d d t j   k s^t j |  rm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)Nzfoo = "bar" exec==%(py0)s == %(py2)spy0code1py2assert %(py4)spy4zfoo = "baz"!=%(py0)s != %(py2)scode2)r   )r   r	   )r   )r   r	   )pycodeCodecompile
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation)r   @py_assert1@py_format3@py_format5r    r   </home/ronny/Projects/pytest-dev/py/testing/code/test_code.pytest_ne   s              r   c              C   s$  d }  t  d |  d  } | j } | |  k } | s t j d | f d | |  f  d d t j   k su t j |   r t j |   n d 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 |  } | j } t |  } | |  k }	 |	 sE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 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  } | | 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  } } } d  S)#Nzabc-123zpass
r   r   3%(py2)s
{%(py2)s = %(py0)s.co_filename
} == %(py4)sr
   namer   co_coder   r   assert %(py6)spy6J%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.path
})
} == %(py7)spy5py1r   py7strpy3assert %(py9)spy9is2%(py2)s
{%(py2)s = %(py0)s.fullsource
} is %(py5)sassert %(py7)s)r   )r    r#   )r   )r%   r+   )r-   )r.   r/   )r   co_filenamer   r   r   r   r   r   r   r   r   r   r   pathr)   
fullsource)r!   r"   r   @py_assert3r   @py_format7r   @py_assert2@py_assert4@py_assert6@py_format8@py_format10@py_format6r   r   r   /test_code_gives_back_name_for_not_existing_file
   s4    	      
	       	    y   r;   c              C   s*   Gd d   d  }  t  j j t d  d  S)Nc               @   s   e  Z d  Z d S)ztest_code_with_class.<locals>.AN)__name__
__module____qualname__r   r   r   r   A   s   r?   zpy.code.Code(A))r   testraises	TypeError)r?   r   r   r   test_code_with_class   s    rC   c               C   s   d  S)Nr   r   r   r   r   x   s    rD   c           
   C   s%  t  j j t  }  |  j } d } t |  } | | 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 |  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)Nztest_code_fullsource()in0%(py1)s in %(py6)s
{%(py6)s = %(py3)s(%(py4)s)
}r
   fullr'   r$   r*   r)   r   assert %(py8)spy8)rE   )rF   rH   )r   r   r   rD   r2   r)   r   r   r   r   r   r   r   r   )r   rG   @py_assert0@py_assert5r5   r4   @py_format9r   r   r   test_code_fullsource   s    	       rM   c           
   C   sK  t  j j t  }  |  j   } d } t |  } | | 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 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)Nzdef x():
    passr   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py5)sr&   expectedr'   srcr   r)   r*   r   assert %(py7)sr(   )r   )rN   rQ   )r   r   r   rD   sourcer)   r   r   r   r   r   r   r   r   )r   rP   rO   r5   r6   r:   r8   r   r   r   test_code_source    s          rS   c        	   
   C   s   d d   }  |    } t  j j |  } | j j | j } } | | } | j } d } | |  } | s d d d t j |  d t j |  d t j |  d	 t j |  i } t t j	 |    d  } } } } d  S)
Nc               S   s   t  j d  S)Nr   )sys	_getframer   r   r   r   func(   s    z/test_frame_getsourcelineno_myself.<locals>.funcz        return sys._getframe(0)r   zLassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.startswith
}(%(py5)s)
}r'   r(   r*   r&   )
r   r   Framer2   lineno
startswithr   r   r   r   )	rV   frR   rX   rJ   r5   r6   r7   r8   r   r   r   !test_frame_getsourcelineno_myself'   s    	
 	    J  r[   c              C   s  d d   }  |    } t  j j |  } | j j j } zmd  | j j _ | j } t  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
 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  } } } } } } Wd  | | j j _ Xd  S)Nc               S   s   t  j d  S)Nr   )rT   rU   r   r   r   r   rV   0   s    z0test_getstatement_empty_fullsource.<locals>.funcr   r   %(py2)s
{%(py2)s = %(py0)s.statement
} == %(py12)s
{%(py12)s = %(py8)s
{%(py8)s = %(py6)s
{%(py6)s = %(py4)s.code
}.Source
}(%(py10)s)
}py12rI   r   rZ   r
   r   r$   py10r   assert %(py14)spy14)r   )r\   r_   )r   r   rW   	__class__r2   	statementSourcer   r   r   r   r   r   r   r   )rV   rZ   propr   rK   @py_assert7@py_assert9@py_assert11r3   @py_format13@py_format15r   r   r   "test_getstatement_empty_fullsource/   s$    		 	 	        rj   c              C   s  t  j j t  }  |  j } | s d d d d t j   k sL t j |   r[ t j	 |   n d d t j	 |  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	 |  i } t
 t j |    d  } d  S)Nr   z/assert %(py2)s
{%(py2)s = %(py0)s.firstlineno
}r   cor   z(assert %(py2)s
{%(py2)s = %(py0)s.path
})r   r   r   r[   firstlinenor   r   r   r   r   r   r   r1   )rk   r   r   r   r   r   test_code_from_func;   s    	  S  	  S  rm   c                s)  t  j j } | j     f d d   } Gd d   d t  } |  j | d |  |  j | d |  t  j j   | j } | | k } | sP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 |  i } d d | i } t t j |    d  } } | j } | | 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 d t j |  i } d d | i } t t j |    d  } } t  j j   | j } | | k } | s1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 |  i } d d | i } t t j |    d  } } | j } | | 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 d t j |  i } d! d | i } t t j |    d  } } d  S)"Nc                 s     |  |   S)Nr   )argskwargs)compr   r   	mycompileE   s    z-test_builtin_patch_unpatch.<locals>.mycompilec               @   s   e  Z d  Z d S)z'test_builtin_patch_unpatch.<locals>.SubN)r<   r=   r>   r   r   r   r   SubG   s   rr   r   r   r   6%(py2)s
{%(py2)s = %(py0)s.AssertionError
} != %(py4)sr
   r   cpy_builtinr   r   assert %(py6)sr$   /%(py2)s
{%(py2)s = %(py0)s.compile
} != %(py4)srq   r-   6%(py2)s
{%(py2)s = %(py0)s.AssertionError
} is %(py4)sr   /%(py2)s
{%(py2)s = %(py0)s.compile
} == %(py4)s)r   )rs   ru   )r   )rv   ru   )r-   )rw   ru   )r   )rx   ru   )r   builtinbuiltinsr   r   setattrr   patch_builtinsr   r   r   r   r   r   r   unpatch_builtins)monkeypatchrt   rq   rr   r   r3   r   r4   r   )rp   r   test_builtin_patch_unpatchB   sH    		      
	      
	      
	      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)	Exceptionr   )valuer   r   rZ   U   s    z test_unicode_handling.<locals>.fr      )r   ry   _totextencoder@   rA   r   r)   rT   version_infounicode)rZ   excinfosur   )r   r   test_unicode_handlingS   s    r   c              C   s  d d   }  t  j j |   } | j } d } | d |  } d } | | k } | st j d | f d | | f  d t j |  d	 t j |  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  } } } } } d d   }	 t  j j |	  }
 |
 j } d } | d |  } d  } | | k } | s6t j d! | f d" | | f  d t j |  d	 t j |  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  } } } } } d d   } t  j j |  } | j } d } | d |  } d$ } | | k } | s\t j d% | f d& | | f  d t j |  d	 t j |  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  } } } } } d d   } t  j j |  } | j } d } | d |  } d( } | | k } | st j d) | f d* | | f  d t j |  d	 t j |  d
 t j |  d d t j   k s5t j	 |  rDt j |  n d d t j |  i } d+ d | i } t
 t j |    d  } } } } } d  S),Nc             S   s   d  S)Nr   )rD   r   r   r   f1]   s    ztest_code_getargs.<locals>.f1TvarrD   r   Q%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.getargs
}(var=%(py4)s)
} == %(py9)sr
   r,   r$   r   c1r   r   assert %(py11)spy11c             W   s   d  S)Nr   )rD   yr   r   r   f2b   s    ztest_code_getargs.<locals>.f2r   c2c             [   s   d  S)Nr   )rD   zr   r   r   f3g   s    ztest_code_getargs.<locals>.f3r   c3c             _   s   d  S)Nr   )rD   r   r   r   r   r   f4l   s    ztest_code_getargs.<locals>.f4c4)rD   )r   )r   r   )rD   r   )r   )r   r   )rD   r   )r   )r   r   )rD   r   r   )r   )r   r   )r   r   r   getargsr   r   r   r   r   r   r   r   )r   r   r   r3   rK   @py_assert8re   r9   @py_format12r   r   r   r   r   r   r   r   r   test_code_getargs\   s`    	         	         	         	         r   c              C   s  d d   }  t  j j |  d   } | j } d } | d |  } d  g } | | k } | st j d! | f d" | | f  d	 t j |  d
 t j |  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  } } } } } d d   }	 t  j j |	 d d d   }
 |
 j } d } | d |  } d$ d& g } | | k } | sQt j d' | f d( | | f  d	 t j |  d
 t j |  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  } } } } } d d   } t  j j | d d d  } | j } d } | d |  } d* d d d i f g } | | k } | st j d+ | f d, | | f  d	 t j |  d
 t j |  d t j |  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 d   } t  j j | d d d d  } | j } d } | d |  } d. d0 d d d i f g } | | k } | st j d1 | f d2 | | f  d	 t j |  d
 t j |  d t j |  d d t j   k st j	 |  rt j |  n d d t j |  i } d3 d | i } t
 t j |    d  } } } } } d  S)4Nc             S   s   t  j d  S)Nr   )rT   rU   )rD   r   r   r   r   s   s    ztest_frame_getargs.<locals>.f1aTr   rD   r   Q%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.getargs
}(var=%(py4)s)
} == %(py9)sr
   r,   r$   r   fr1r   r   assert %(py11)sr   c             W   s   t  j d  S)Nr   )rT   rU   )rD   r   r   r   r   r   x   s    ztest_frame_getargs.<locals>.f2bcr   fr2c             [   s   t  j d  S)Nr   )rT   rU   )rD   r   r   r   r   r   }   s    ztest_frame_getargs.<locals>.f3r   fr3c             _   s   t  j d  S)Nr   )rT   rU   )rD   r   r   r   r   r   r      s    ztest_frame_getargs.<locals>.f4dfr4)rD   r   )r   )r   r   )rD   r   r   r   )r   r   )r   )r   r   )rD   r   )r   )r   r   )rD   r   r   )r   r   )r   )r   r   )r   r   rW   r   r   r   r   r   r   r   r   r   )r   r   r   r3   rK   r   re   r9   r   r   r   r   r   r   r   r   r   r   test_frame_getargsr   s`    	   	      	         	         !	         r   c               @   s   e  Z d  Z d d   Z d S)TestExceptionInfoc             C   s  yD d } | s= d
 d t  j |  i } t t  j |    d  } Wn! t k
 rg t j j   } Yn X| j } |   } | s d d d t  j |  d d t j	   k s t  j
 |  r t  j |  n d d	 t  j |  i } t t  j |    d  } } d  S)NFr   assert %(py1)sr'   zBassert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.getrepr
}()
}r
   r   excir   r   )r   r   r   r   r   r   ExceptionInfogetreprr   r   r   )selfrJ   @py_format2r   r   r3   r   r   r   r   test_bad_getsource   s        
	 	  b  z$TestExceptionInfo.test_bad_getsourceN)r<   r=   r>   r   r   r   r   r   r      s   r   c               @   s   e  Z d  Z d d   Z d S)TestTracebackEntryc             C   s#  yD d } | s= d d t  j |  i } t t  j |    d  } Wn! t k
 rg t j j   } Yn X| j d } | j   } t	 |  } d } | | k } | sy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  S)NFr   assert %(py1)sr'   r      r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)srR   r$   r   lenr*   assert %(py8)srI   zelse: assert Falser   rE   %(py1)s in %(py4)sr
   assert %(py6)sr   )r   )r   r   )rE   )r   r   )r   r   r   r   r   r   r   	traceback	getsourcer   r   r   r   r   )r   rJ   r   r   entryrR   r5   rK   r6   r4   rL   r3   r   r   r   r   test_getsource   s4        
        
   C   z!TestTracebackEntry.test_getsourceN)r<   r=   r>   r   r   r   r   r   r      s   r   )rz   r   _pytest.assertion.rewrite	assertionrewriter   r   rT   r   r;   rC   rD   rM   rS   r[   rj   rm   r   r   r   r   r   r   r   r   r   r   <module>   s$     	