
|W#                 @   s  d  d l  Z d  d l j j Z d  d l Z d  d l Z d  d l Z d  d l	 m
 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 e j j d d g  d d    Z e e j d k  Z Gd d   d  Z d  d!   Z e j j  e j d k d" d# d$ d%    Z! e j j  e j d k d" d# d& d'    Z" d( d)   Z# d* d+   Z$ d S),    N)terminalwriterc              C   s   t  j j }  t j } |  | k } | s t j d | f d |  | f  d d t j   k si t j |   rx 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)N==:%(py0)s == %(py4)s
{%(py4)s = %(py2)s.get_terminal_width
}py0xpy2r   py4 assert %(py6)spy6)r   )r   r
   )pyioget_terminal_widthr   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation)r   @py_assert3@py_assert1@py_format5@py_format7 r   E/home/ronny/Projects/pytest-dev/py/testing/io_/test_terminalwriter.pytest_get_terminal_width   s    	      r   c                s  t  j j d  } d d  l } g    |  j | d   f d d    y t j   Wn t | j f k
 rn Yn Xt	    } d } | | k } | sg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 }	 | |	 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fcntlr   ioctlc                 s     j  |   S)N)append)args)lr   r   <lambda>   s    z$test_getdimensions.<locals>.<lambda>   r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)spy1r"   r   r   lenpy3r	   assert %(py8)spy8%(py1)s == %(py4)sr   assert %(py6)s)r   )r%   r)   )r   )r+   r,   )r   testimportorskipstructsetattrr   _getdimensions	TypeErrorerrorr'   r   r   r   r   r   r   r   r   )monkeypatchr   r/   @py_assert2@py_assert5@py_assert4r   @py_format9@py_assert0r   r   r   )r"   r   test_getdimensions   s0               C   r:   c          
   C   s;  t  j j d  } |  j | d d d    |  j d d  t j } |   } d } | | k } | st j d | f d | | f  d
 t j	 |  d d t
 j   k s t j t  r t j	 t  n d d t j	 |  d t j	 |  i } d d | i } t t j |    d } } } } |  j d d d d S)z' Dummy test for get_terminal_width
    r   r   c              W   s
   t  d  S)Nr   )int)r!   r   r   r   r#      s    z-test_terminal_width_COLUMNS.<locals>.<lambda>COLUMNS42*   r   Q%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.get_terminal_width
}()
} == %(py7)spy7r   r   r   r   r	   assert %(py9)spy9NraisingF)r   )r?   rA   )r   r-   r.   r0   setenvr   r   r   r   r   r   r   r   r   r   delenv)r4   r   r   r   @py_assert6r6   @py_format8@py_format10r   r   r   test_terminal_width_COLUMNS   s    	 	       rI   c             C   s  |  j  t d d d    |  j d d d t j 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  } } } d  S)Nr1   c               S   s   d d S)Nr   r   r   r   r   r   r#   "   s    z5test_terminalwriter_defaultwidth_80.<locals>.<lambda>r<   rC   FP   r   1%(py2)s
{%(py2)s = %(py0)s.fullwidth
} == %(py5)sr   twpy5r   r	   assert %(py7)sr@   )r   )rK   rN   )r0   r   rE   r   r   TerminalWriter	fullwidthr   r   r   r   r   r   r   r   )r4   rL   r   r7   r   @py_format6rG   r   r   r   #test_terminalwriter_defaultwidth_80!   s    	    y   rR   c             C   s  |  j  t d d d    |  j d d d t j 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  } } } d  S)Nr1   c               S   s   d S)N
   )rS   rS   r   r   r   r   r   r#   (   s    z9test_terminalwriter_getdimensions_bogus.<locals>.<lambda>r<   rC   FrJ   r   1%(py2)s
{%(py2)s = %(py0)s.fullwidth
} == %(py5)sr   rL   rM   r   r	   assert %(py7)sr@   )r   )rT   rU   )r0   r   rE   r   r   rO   rP   r   r   r   r   r   r   r   r   )r4   rL   r   r7   r   rQ   rG   r   r   r   'test_terminalwriter_getdimensions_bogus'   s    	    y   rV   c             C   s	  |  j  t d d d    |  j d d  t j 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  } } } d  S)Nr1   c               S   s   d S)Nr   )r   r   r   r   r   r   r   r#   /   s    z9test_terminalwriter_getdimensions_emacs.<locals>.<lambda>r<   r=   r>   r   1%(py2)s
{%(py2)s = %(py0)s.fullwidth
} == %(py5)sr   rL   rM   r   r	   assert %(py7)sr@   )r   )rW   rX   )r0   r   rD   r   r   rO   rP   r   r   r   r   r   r   r   r   )r4   rL   r   r7   r   rQ   rG   r   r   r   'test_terminalwriter_getdimensions_emacs-   s    	    y   rY   c             C   s   |  j  t d d d    t j 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  } } } d  S)Nr   c               S   s   d S)Nr>   r   r   r   r   r   r#   5   s    z4test_terminalwriter_computes_width.<locals>.<lambda>r>   r   1%(py2)s
{%(py2)s = %(py0)s.fullwidth
} == %(py5)sr   rL   rM   r   r	   assert %(py7)sr@   )r   )rZ   r[   )r0   r   r   r   rO   rP   r   r   r   r   r   r   r   r   )r4   rL   r   r7   r   rQ   rG   r   r   r   "test_terminalwriter_computes_width4   s    	    y   r\   c           
   C   s   t  j j d d  }  d } t |  |  } | s d d d d t j   k s[ t j |   rj 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 |  i } t	 t j
 |    d  } } d  S)NstringioTr	   z5assert %(py5)s
{%(py5)s = %(py0)s(%(py1)s, %(py3)s)
}r&   rL   r   hasattrr(   rM   )r   r   rO   r^   r   r   r   r   r   r   r   )rL   r5   r7   rQ   r   r   r   )test_terminalwriter_default_instantiation9   s         r_   c             C   s  |  j  t d d d d d i  Gd d   d  } |  j  t d |    zPt j } | j } |   } | s d d	 d
 t j |  d d t j   k s t j	 t  r t j t  n d d t j |  d t j |  i } t
 t j |    d  } } } t j j   } | j } | } | sd d d d t j   k sPt j	 |  r_t j |  n d d t j |  i } t
 t j |    d  } } Wd  |  j   Xd  S)NenvironTERMdumbPATHr	   c               @   s"   e  Z d  Z d Z d d   Z d S)z7test_terminalwriter_dumb_term_no_markup.<locals>.MyFileFc             S   s   d S)NTr   )selfr   r   r   isattyA   s    z>test_terminalwriter_dumb_term_no_markup.<locals>.MyFile.isattyN)__name__
__module____qualname__closedre   r   r   r   r   MyFile?   s   rj   stdoutz]assert %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.stdout
}.isatty
}()
}r   r   sysr   r   z1assert not %(py2)s
{%(py2)s = %(py0)s.hasmarkup
}rL   )r0   osrl   rk   re   r   r   r   r   r   r   r   r   r   rO   	hasmarkupundo)r4   rj   r   r   r6   r   rL   @py_format4r   r   r   'test_terminalwriter_dumb_term_no_markup=   s&    	 	 	  q  	   S  rq   c             C   s  t  j j j t |  j d   d d  } t  j 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)Nxyzwbutf8filer   0%(py2)s
{%(py2)s = %(py0)s.encoding
} == %(py5)sr   rL   rM   r   r	   assert %(py7)sr@   )r   )rv   rw   )r   stdcodecsopenstrjoinr   rO   encodingr   r   r   r   r   r   r   r   )tmpdirfrL   r   r7   r   rQ   rG   r   r   r    test_terminalwriter_file_unicodeK   s    *	    y   r   c              C   s  t  j j d d  }  xd D]} g  } t  j j | j d | } | j |   | d } | j } |   } |  j } | |  } | | 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 t	 j |  d t	 j |  d t	 j |  d d t j   k sVt	 j |  ret	 j |  n d i }
 d d |
 i } t t	 j |    d  } } } }	 } } q Wd  S)Nu   böyrt   latin1r}   r   r   %(py5)s
{%(py5)s = %(py3)s
{%(py3)s = %(py1)s.strip
}()
} == %(py12)s
{%(py12)s = %(py9)s
{%(py9)s = %(py7)s.encode
}(%(py10)s)
}r@   msgr&   rM   rB   py12r(   py10r	   assert %(py14)spy14)zutf8zlatin1)r   )r   r   )r   builtin_totextr   rO   r    linestripencoder   r   r   r   r   r   r   r   )r   r}   r"   rL   r9   r5   r7   @py_assert8@py_assert11rF   @py_format13@py_format15r   r   r   test_unicode_encodingP   s     
 	 	 	       r   r}   asciic             C   sc  t  j j d d  } t  j j j t |  j d   d |  } t  j j	 |  } | j
 |  | j   |  j d  j d  j   j   } d } | | k } | s3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 } | |  } | | 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 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)Nu   hellör   r   wrbr   r   %(py0)s == %(py3)sr   r}   r(   r	   assert %(py5)srM   zunicode-escapeL%(py0)s == %(py8)s
{%(py8)s = %(py4)s
{%(py4)s = %(py2)s.encode
}(%(py6)s)
}r*   r   sr   r   r   assert %(py10)sr   )r   )r   r   )r   )r   r   )r   r   r   rx   ry   rz   r{   r|   r   rO   r   closereadr   r   r   r   r   r   r   r   r   r   )r~   r4   r}   r   r   rL   r   r5   r   rp   rQ   r   r6   @py_assert7r8   @py_format11r   r   r   (test_unicode_on_file_with_ascii_encodingX   s,    *
$   j   
	        r   win32c               @   s   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z e	 j
 j j d  d d    Z e	 j
 j j d  d d    Z d d   Z d d   Z d d   Z d S)TestTerminalWriterc             C   sU   d | j  k rQ | j d d d d  | j d d d d  | j d d d d  d  S)NrL   idpathparamr]   callable)funcargnamesaddcall)rd   metafuncr   r   r   pytest_generate_testsg   s    z(TestTerminalWriter.pytest_generate_testsc                s  | j  d k ru | j d  } | j d   t j t   d d d } t j j |     f d d     nu | j  d	 k r t j j d	 d
    f d d     n< | j  d k r g   t j j  j	    f d d        _
   f d d    _  S)Nr   r~   tmpfilezw+r}   rt   c                  s/    j  j   t j t    d d d j   S)Nrr}   rt   )_fileflushry   rz   r{   	readlinesr   )prL   r   r   getlinesr   s    z7TestTerminalWriter.pytest_funcarg__tw.<locals>.getlinesr]   Tc                  s     j  j d    j  j   S)Nr   )r]   seekr   r   )rL   r   r   r   x   s    r   c                 s<   t  j j   }  |  j d j     |  j d  |  j   S)Nr	   r   )r   r   TextIOwriter|   r   r   )r   )writesr   r   r   ~   s    c                  s   d j       S)Nr	   )r|   r   )r   r   r   r#      s    z7TestTerminalWriter.pytest_funcarg__tw.<locals>.<lambda>)r   getfuncargvaluer|   ry   rz   r{   r   r   rO   r    r   getvalue)rd   requestr~   r   r   )r   r   rL   r   r   pytest_funcarg__twl   s     	z%TestTerminalWriter.pytest_funcarg__twc          
   C   s  | j  d  | 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 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)Nhellor$   r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sr&   r"   r   r   r'   r(   r	   assert %(py8)sr*   r   zhello
%(py1)s == %(py4)sr   assert %(py6)s)r   )r   r   )r   )r   r   )r   r   r'   r   r   r   r   r   r   r   r   )rd   rL   r"   r5   r6   r7   r   r8   r9   r   r   r   r   r   	test_line   s$           
    C   zTestTerminalWriter.test_linec          	   C   s(  x!d D]} | | _  t j j d d  } | j |  | j   } | d } 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 i }	 d d |	 i }
 t t j |
    d  } } } } q Wd  S)Nrt   r   u   böyr   
r   %(py1)s == (%(py3)s + %(py5)s)rM   r&   r(   r   r	   assert %(py8)sr*   )zutf8zlatin1)r   )r   r   )	_encodingr   r   r   r   r   r   r   r   r   r   r   r   r   )rd   rL   r}   r   r"   r9   r7   rF   r5   r   r8   r   r   r   test_line_unicode   s    	
  
   y   z$TestTerminalWriter.test_line_unicodec             C   sS  | j  d d d | 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	 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 } | t }
 |	 |
 } d } | | } | | k } | s-t j d | f d | | f  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)N-rP   <   r$   r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sr&   r"   r   r   r'   r(   r	   assert %(py8)sr*   r   r   7%(py1)s == ((%(py4)s * (%(py6)s - %(py7)s)) + %(py11)s)r@   r   py11r   assert %(py14)sr   )r   )r   r   )r   )r   r   )sepr   r'   r   r   r   r   r   r   r   r   r   )rd   rL   r"   r5   r6   r7   r   r8   r9   r   r   @py_assert9@py_assert10@py_assert12r   r   r   r   r   test_sep_no_title   s.           
   
 
  
      z$TestTerminalWriter.test_sep_no_titlec             C   s  | j  d d d d | 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
 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 } |	 | }
 d } |
 | } d } d } | t } | | } | | } d } | | } | | k } | st j d# | f d$ | | f  d
 t j |  d t j |  d t j |  d t j |  d t j |  d t j |	  d t j |  d d t j   k sOt j t  r^t j t  n d i } d% d | i } t	 t j
 |    d  } } }	 } }
 } } } } } } } } } d  S)&Nr   r   rP   r   r$   r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sr&   r"   r   r   r'   r(   r	   assert %(py8)sr*   r      z hello    r   ^%(py1)s == ((((%(py4)s * %(py6)s) + %(py9)s) + (%(py12)s * (%(py14)s - %(py15)s))) + %(py20)s)rB   r   r   r   Zpy20py15r   assert %(py23)sZpy23)r   )r   r   )r   )r   r   )r   r   r'   r   r   r   r   r   r   r   r   r   )rd   rL   r"   r5   r6   r7   r   r8   r9   r   r   r   r   r   @py_assert13@py_assert16Z@py_assert17@py_assert18Z@py_assert19Z@py_assert21Z@py_format22Z@py_format24r   r   r   test_sep_with_title   s:           
   
  
   
 
 
  
      z&TestTerminalWriter.test_sep_with_titlezsys.platform == 'win32'c             C   s&  | j  d d  } | j } d } | |  } 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)Nr      r$   !=K%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.find
}(%(py4)s)
} != -%(py9)srB   r   r   text2r   r   r	   assert %(py12)sr   )r   )r   r   )
_escapedfindr   r   r   r   r   r   r   r   )rd   rL   r   r   r   r6   r   r   r   r   r   r   r   r   test__escaped   s    	          z TestTerminalWriter.test__escapedc             C   sz  xMd D]E} x<d D]4} | j  d | d d | i  } | j } d } | |  } 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  } } } }
 } }	 q Wq Wt
 j j t d  t
 j j t d  d  S)NTFredgreenr   boldr$   r   K%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.find
}(%(py4)s)
} != -%(py9)srB   r   r   r   r   r   r	   assert %(py12)sr   ztw.markup('x', wronkw=3)ztw.markup('x', wronkw=0))TF)zredzgreen)r   )r   r   )markupr   r   r   r   r   r   r   r   r   r   r-   raises
ValueError)rd   rL   r   colorr   r   r   r6   r   r   r   r   r   r   r   r   test_markup   s     	          "zTestTerminalWriter.test_markupc       	   
   C   sB  d | _  | j d d d | j d d d | j   } t j d k r>| d } t |  } d } | | k } | s2t j d | f d | | f  d t j	 |  d d t
 j   k s t j t  r t j	 t  n d d t j	 |  d t j	 |  i } t j |  d d | i } t t j |    d  } } } } | d } t |  } d } | | k } | s,t j d | f d | | f  d t j	 |  d d t
 j   k st j t  rt j	 t  n d d t j	 |  d t j	 |  i } t j |  d d | i } t t j |    d  } } } } d  S)NTr   r   zx
r   r   r      >=0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} >= %(py7)sr@   r   r'   r   r   z
>assert %(py9)srB   r$   )r   )r   )r   )r   )rn   r   r   r   rl   platformr'   r   r   r   r   r   r   _format_assertmsgr   r   )	rd   rL   r"   r   r   rF   r6   rG   rH   r   r   r   test_line_write_markup   s.    	
        
        z)TestTerminalWriter.test_line_write_markupc       
      C   s  | j  d d d d d | _ | j  d d  | j   } | d } t |  } | d } t |  } | | k } | skt j d | f d | | f  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	 |  d t j	 |  d t j	 |  d t j	 |  i } d d | i }	 t
 t j |	    d  } } } } } d  S)Nr   r   rP   F   r   r$   r   P%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py10)s
{%(py10)s = %(py6)s(%(py8)s)
}r   r'   r   r   r   r   r*   r	   assert %(py12)sr   )r   )r   r   )r   rP   r   r'   r   r   r   r   r   r   r   r   )
rd   rL   r"   r   r   r   r   r6   r   r   r   r   r   test_attr_fullwidth   s    	
  
       z&TestTerminalWriter.test_attr_fullwidthc          
      s%    j  d  d   _ t j t   f d d    d   _   j d    j     j   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  } } }   j d    j   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	  rIt
 j t	  n d d t
 j |  i } d& d | i } t t
 j |    d  } } } | 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    j   j d  } t	 |  } d } | | k } | sK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 } | s{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  S)4Nr   Fc                  s     j  d  S)Nr   )reliner   )rL   r   r   r#      s    z0TestTerminalWriter.test_reline.<locals>.<lambda>Tz0 1 2r   r   r   0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sr&   r"   r   r   r'   r(   r	   assert %(py8)sr*   z0 1 3r$   z0 1 3zJassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.endswith
}(%(py5)s)
}r@   rM   so   %(py1)s == %(py4)sr   assert %(py6)sz0 1 20 1 3so   r   )r   )r   r   )r   )r   r   )r   )r   r   )r   )r   r   )r   )r   r   )r   )r   r   )r   rn   pytestr   r   r   r   r   splitr'   r   r   r   r   r   r   r   r   endswith)rd   rL   r"   r5   r6   r7   r   r8   r9   rF   rG   r   r   r   )rL   r   test_reline   s    		
              
 	    J         
    C   
    C   
    C   zTestTerminalWriter.test_relineN)rf   rg   rh   r   r   r   r   r   r   r   r-   markskipifr   r   r   r   r  r   r   r   r   r   f   s   !!		r   c           
      s  t      G  f d d   d  }  t j j |     } | j d  d g } t  |  }   | 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 |  i } d d | i } t t j |    d  } } } |  `   j   t j j |     } | j d  d g } t  |  }   | k } | sz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 |  i } d d | i } t t j |    d  } } } d  S)Nc                   sF   e  Z d  Z   f d d   Z   f d d   Z   f d d   Z d S)z8test_terminal_with_callable_write_and_flush.<locals>.filc                s     j  d  S)N1)add)rd   )r"   r   r   r#      s    zAtest_terminal_with_callable_write_and_flush.<locals>.fil.<lambda>c                s     j  d  S)Nr  )r  )rd   r   )r"   r   r   r#      s    c                s     j  d  S)N2)r  )rd   r   )r"   r   r   r#      s    N)rf   rg   rh   r   r   __call__r   )r"   r   r   fil   s   r  r   r  r   0%(py0)s == %(py6)s
{%(py6)s = %(py2)s(%(py4)s)
}r   r   r"   r   setr   r	   assert %(py8)sr*   r  )r   )r	  r  )r   )r	  r  )r
  r   r   rO   r   r   r   r   r   r   r   r   r   r   clear)r  rL   r   r6   r   r   r8   r   )r"   r   +test_terminal_with_callable_write_and_flush   s0    		       
	       r  reasonzwin32 has no native ansic              C   s  t  j j d d  }  |  j } | } | s d d d d t j   k sV t j |   re t j |   n d d t j |  i } t	 t j
 |    d  } } d |  _ |  j d d	 d |  j j   } t |  } d
 } t |  } | | k } | st j d | f d | | f  d t j |  d d t j   k sIt j |  rX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 st j t  rt j t  n d d t j |  i }	 d d |	 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 |  rt j |  n d i } d  d | 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 |  rLt j |  n d i } d# d | i } t	 t j
 |    d  } } d  S)$Nr]   Tr	   z1assert not %(py2)s
{%(py2)s = %(py0)s.hasmarkup
}r   rL   r   r   r   zhello
>M%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} > %(py9)s
{%(py9)s = %(py5)s(%(py7)s)
}r@   r&   r   rM   r'   rB   r(   assert %(py11)sr   z[1min%(py1)s in %(py3)sassert %(py5)sz[0m)r  )r  r  )r  )r  r  )r  )r  r  )r   r   rO   rn   r   r   r   r   r   r   r   r   r]   r   r'   r   )rL   r   r   rp   r   r5   rF   r   r7   rH   @py_format12r9   rQ   r   r   r   test_attr_hasmarkup   sB    	   S  
	           j   
   j   r  c              C   s  t  j j   }  d d   |  _ t  j j d d d |  |  j   } | j } d } | |  } d } | } | | k } | s9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  } } } } } } t |  }
 d } t |  } |
 | 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 d t
 j   k sOt j t  r^t j	 t  n d d t j	 |
  i } d& d | i } t t j |    d  }
 } } } d } | | k }
 |
 sUt j d' |
 f d( | | f  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  } | | k }
 |
 st j d* |
 f d+ | | f  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   s   d S)NTr   r   r   r   r   r#      s    z!test_ansi_print.<locals>.<lambda>r   2   ru   r$   r   K%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.find
}(%(py4)s)
} != -%(py9)srB   r   r   r   r   r   r	   assert %(py12)sr   zhello
r   N%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} >= %(py9)s
{%(py9)s = %(py5)s(%(py7)s)
}r@   r&   rM   r'   r(   assert %(py11)sr   z[50mr  %(py1)s in %(py3)sassert %(py5)sz[0m)r   )r  r  )r   )r  r  )r  )r  r  )r  )r  r  )r   r   r   re   
ansi_printr   r   r   r   r   r   r   r   r   r   r'   )r   r   r   r   r6   r   r   r   r   r   r5   rF   r7   rH   r  r9   rp   rQ   r   r   r   test_ansi_print   sL    	                     j   
   j   r  c             C   s  |  j  t j d d  t j j d d  } | j } | s d d d d t j   k se t	 j
 |  rt t	 j |  n d d	 t	 j |  i } t t	 j |    d  } | j d
 d d | j j   } t |  } d } t |  } | | k } | st	 j d | f d | | f  d t	 j |  d d t j   k sKt	 j
 |  rZ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 st	 j
 t  rt	 j t  n d d t	 j |  i }	 d d |	 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
 |  rt	 j |  n d i } d" d | 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
 |  rNt	 j |  n d i } d% d | i } t t	 j |    d  } } d  S)&N	PY_COLORSr  r]   Tr	   z-assert %(py2)s
{%(py2)s = %(py0)s.hasmarkup
}r   rL   r   r   r   zhello
r  M%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} > %(py9)s
{%(py9)s = %(py5)s(%(py7)s)
}r@   r&   r   rM   r'   rB   r(   assert %(py11)sr   z[1mr  %(py1)s in %(py3)sassert %(py5)sz[0m)r  )r!  r"  )r  )r#  r$  )r  )r#  r$  )setitemrm   r`   r   r   rO   rn   r   r   r   r   r   r   r   r   r]   r   r'   r   )r4   rL   r   @py_format3r   r5   rF   r   r7   rH   r  r9   rp   rQ   r   r   r   $test_should_do_markup_PY_COLORS_eq_1   s@    	  S             j   
   j   r'  c       	      C   s  |  j  t j d d  t j j   } d d   | _ t j 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  } } | j d d d | j   } d } | | k } | st j d | f d | | f  d d t	 j
   k sJt j |  rYt j |  n d d t j |  i } d d | i } t t j |    d  } } d  S)Nr   0c               S   s   d S)NTr   r   r   r   r   r#   
  s    z6test_should_do_markup_PY_COLORS_eq_0.<locals>.<lambda>ru   r	   z1assert not %(py2)s
{%(py2)s = %(py0)s.hasmarkup
}r   rL   r   r   r   Tzhello
r   %(py0)s == %(py3)sr   r(   assert %(py5)srM   )r   )r)  r*  )r%  rm   r`   r   r   r   re   rO   rn   r   r   r   r   r   r   r   r   r   r   )	r4   r   rL   r   r   rp   r   r5   rQ   r   r   r   $test_should_do_markup_PY_COLORS_eq_0  s&    	   S  
   j   r+  )%builtinsr   _pytest.assertion.rewrite	assertionrewriter   r   rm   rl   Zpy._ior   ry   r   r   r:   rI   rR   rV   rY   r\   r_   rq   r   r   r  parametrizer   r;   r   r   r   r  r  r  r  r'  r+  r   r   r   r   <module>   s2     	$n--
