
Y]c           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l m Z e j d d e d d d e e e d  r d  d l Z d	 Z n d
 Z e  j e  j k Z e e d  Z e j d4 k rd Z n d Z d e
 j f d     YZ g  Z d e f d     YZ e j e  d e f d     YZ e j e  d e f d     YZ  e j e   d e f d     YZ! e j e!  d e f d     YZ" e j e"  e	 j# d    Z$ d   Z% d d5 d     YZ& d  e& e f d!     YZ' e j e'  d" e f d#     YZ( e j e(  d$ e f d%     YZ) e j e)  d& e f d'     YZ* e j e*  d( e& e f d)     YZ+ e j e+  d* e f d+     YZ, e j e,  d, e f d-     YZ- e j e-  d. e f d/     YZ. e j e.  d0 e f d1     YZ/ e  j0 e  j1 k	 rne j e/  n  d2   Z2 e d3 k re2   n  d S(6   iN(   t   test_supportt   ignoret   categoryt   messaget   mktempt   modulet   stati   i    t   spawnlt   openbsd3t   openbsd4i0   id   t   TCc           B   s,   e  Z e j d   Z d d  Z d   Z RS(   s   [a-zA-Z0-9_-]{6}$c         C   sA   | d  k r t j   } n  |  j d | | d | d f  d  S(   Ns   %s raised %s: %si    i   (   t   Nonet   syst   exc_infot   fail(   t   selft   whatt   ei(    (    s#   lib/python2.7/test/test_tempfile.pyt   failOnException-   s    c   	      C   s   t  j j |  \ } } | t |   } | t |  t |  } |  j t  j j |  t  j j |  d | | f  |  j | | d | | f  |  j | | d | | f  | t |  t |  t |  !} |  j |  j j |  d |  d  S(   Ns   file '%s' not in directory '%s's"   file '%s' does not begin with '%s's    file '%s' does not end with '%s's6   random string '%s' does not match /^[a-zA-Z0-9_-]{6}$/(	   t   ost   patht   splitt   lent   assertEqualt   abspatht
   assertTruet	   str_checkt   match(	   R   t   namet   dirt   pret   suft   ndirt   nbaset   npret   nsuf(    (    s#   lib/python2.7/test/test_tempfile.pyt	   nameCheck2   s    $#N(   t   __name__t
   __module__t   ret   compileR   R   R   R$   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR
   )   s   t   test_exportsc           B   s   e  Z d    Z RS(   c         C   s   t  j } i d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d	 6d d
 6d d 6d d 6} g  } x: | D]2 } | d d k ri | | k ri | j |  qi qi W|  j t |  d k d |  d  S(   Ni   t   NamedTemporaryFilet   TemporaryFilet   mkstempt   mkdtempR   t   TMP_MAXt   gettempprefixt
   gettempdirt   tempdirt   templatet   SpooledTemporaryFilei    t   _s   unexpected keys: %s(   t   tempfilet   __dict__t   appendR   R   (   R   t   dictt   expectedt   unexpt   key(    (    s#   lib/python2.7/test/test_tempfile.pyR)   G   s&    	
(   R%   R&   R)   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR)   F   s   t   test__RandomNameSequencec           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z e j e	 e
 d  d  d    Z RS(   s6   Test the internal iterator object _RandomNameSequence.c         C   s   t  j   |  _ d  S(   N(   R5   t   _RandomNameSequencet   r(   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   setUpf   s    c         C   s)   |  j  j   } |  j | d d d  d  S(   Nt    (   R>   t   nextR$   (   R   t   s(    (    s#   lib/python2.7/test/test_tempfile.pyt   test_get_six_char_stri   s    c         C   sf   i  } |  j  } xP t t  D]B } | j   } |  j | d d d  |  j | |  d | | <q Wd  S(   NR@   i   (   R>   t   xranget
   TEST_FILESRA   R$   t   assertNotIn(   R   R8   R>   t   iRB   (    (    s#   lib/python2.7/test/test_tempfile.pyt	   test_manyn   s    	c         C   sY   d } |  j  } y/ x( | D]  } | d 7} | d k r Pq q WWn |  j d  n Xd  S(   Ni    i   i   t	   iteration(   R>   R   (   R   RG   R>   RB   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_supports_itery   s    	
t   forks!   os.fork is required for this testc         C   s   t  j   \ } } d  } z t  j   } | sy t  j |  t  j | t |  j  j d   t  j |  t  j	 d  n  t |  j  } t  j
 | t |   j d  } Wd  | r y t  j | t j  Wn t k
 r n Xt  j | d  n  t  j |  t  j |  X|  j | |  d  S(   Nt   asciii    (   R   t   pipeR   RK   t   closet   writeRA   R>   t   encodet   _exitt   readR   t   decodet   killt   signalt   SIGKILLt   EnvironmentErrort   waitpidt   assertNotEqual(   R   t   read_fdt   write_fdt   pidt   parent_valuet   child_value(    (    s#   lib/python2.7/test/test_tempfile.pyt   test_process_awareness   s(    "%(   R%   R&   t   __doc__R?   RC   RH   RJ   t   unittestt
   skipUnlesst   hasattrR   R_   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR<   c   s   				t   test__candidate_tempdir_listc           B   s    e  Z d  Z d   Z d   Z RS(   s3   Test the internal function _candidate_tempdir_list.c         C   sJ   t  j   } |  j t |  d k  x | D] } |  j | t  q, Wd  S(   Ni    (   R5   t   _candidate_tempdir_listt   assertFalseR   t   assertIsInstancet
   basestring(   R   t   candt   c(    (    s#   lib/python2.7/test/test_tempfile.pyt   test_nonempty_list   s    c      
   C   s   t  j    } x< d D]4 } t j |  } | s t j j |  | | <q q Wt j   } x< d D]4 } t j |  } | s t  n  |  j	 | |  qa Wy t j
   } Wn# t t j f k
 r t j } n X|  j	 | |  Wd  QXd  S(   Nt   TMPDIRt   TEMPt   TMP(   Rl   Rm   Rn   (   Rl   Rm   Rn   (   t   supportt   EnvironmentVarGuardR   t   getenvR   R   R5   Re   t
   ValueErrort   assertInt   getcwdt   AttributeErrort   errort   curdir(   R   t   envt   envnamet   dirnameRi   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_wanted_dirs   s      	(   R%   R&   R`   Rk   R{   (    (    (    s#   lib/python2.7/test/test_tempfile.pyRd      s   		t   TestGetDefaultTempdirc           B   s   e  Z d  Z d   Z RS(   s   Test _get_default_tempdir().c            sp  t  j    zO f d   } t j t  d |  %t  j   |  j t j   g   d    t j t d   Y |  j	 t
   } t  j   Wd  QX|  j | j j t j  |  j t j   g   Wd  QX   f d   } t j t d |  [   |  j	 t
   } t  j   Wd  QX|  j | j j t j  |  j t j   g   Wd  QXWd  QXWd  t j   Xd  S(   Nc              s     g S(   N(    (    (   t   our_temp_directory(    s#   lib/python2.7/test/test_tempfile.pyt   our_candidate_list   s    Re   c          _   s   t  d   d  S(   Ni(   t   OSError(   t   argst   kwargs(    (    s#   lib/python2.7/test/test_tempfile.pyt   raise_OSError   s    t   openc             s     |  |   }  | _  | S(   N(   RO   (   R   R   t   fp(   t	   orig_openR   (    s#   lib/python2.7/test/test_tempfile.pyt
   bad_writer   s    	(   R5   R-   Ro   t	   swap_attrt   _get_default_tempdirR   R   t   listdirt   iot   assertRaisest   IOErrort	   exceptiont   errnot   ENOENTt   shutilt   rmtree(   R   R~   t   cmR   (    (   R   R}   R   s#   lib/python2.7/test/test_tempfile.pyt   test_no_files_left_behind   s(    

	)(   R%   R&   R`   R   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR|      s   t   test__get_candidate_namesc           B   s    e  Z d  Z d   Z d   Z RS(   s0   Test the internal function _get_candidate_names.c         C   s#   t  j   } |  j | t  j  d  S(   N(   R5   t   _get_candidate_namesRg   R=   (   R   t   obj(    (    s#   lib/python2.7/test/test_tempfile.pyt   test_retval	  s    c         C   s/   t  j   } t  j   } |  j | | k  d  S(   N(   R5   R   R   (   R   t   at   b(    (    s#   lib/python2.7/test/test_tempfile.pyt   test_same_thing  s    (   R%   R&   R`   R   R   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR     s   	c          c   sF   t  j   }  z% t j t  d |   
 d  VWd  QXWd  t j |   Xd  S(   NR1   (   R5   R-   Ro   R   R   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   _inside_empty_temp_dir  s
    c             s   t  j t d   f d    S(   NR   c              s
   t     S(   N(   t   iter(    (   t   names(    s#   lib/python2.7/test/test_tempfile.pyt   <lambda>%  R@   (   Ro   R   R5   (   R   (    (   R   s#   lib/python2.7/test/test_tempfile.pyt   _mock_candidate_names"  s    	t   TestBadTempdirc           B   s#   e  Z d    Z d   Z d   Z RS(   c      
   C   s   t     t j t j  j } } | t j t j Bt j BM} t j	 t j |  z t j
 t j t j  r} |  j d  n  |  j t   } |  j   Wd  QX|  j | j j t j t j f  |  j t j t j  g   Wd  t j	 t j |  XWd  QXd  S(   Ns!   can't set the directory read-only(   R   R   R   R5   R1   t   st_modet   S_IWUSRt   S_IWGRPt   S_IWOTHt   chmodt   accesst   W_OKt   skipTestR   R   t	   make_tempRs   R   R   t   EPERMt   EACCESR   R   (   R   t   oldmodet   modeR   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_read_only_directory*  s    
" c         C   s   t    t t j j t j d  } t j t d |  @ |  j t	   } |  j
   Wd  QX|  j | j j t j  Wd  QXWd  QXd  S(   Nt   nonexistentR1   (   R   R   R   t   joinR5   R1   Ro   R   R   R   R   R   R   R   R   (   R   R1   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_nonexisting_directory9  s    
c         C   s   t     t j j t j d  } t | d  j   t j	 t d |  I |  j
 t   } |  j   Wd  QX|  j | j j t j t j f  Wd  QXWd  QXd  S(   Nt   filet   wbR1   (   R   R   R   R   R5   R1   R   RN   Ro   R   R   R   R   Rs   R   R   t   ENOTDIRR   (   R   R1   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_non_directoryA  s    
(   R%   R&   R   R   R   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR   (  s   		t   test__mkstemp_innerc           B   s   e  Z d  Z d d d     YZ d d d d d  Z d   Z d   Z d   Z e	 j
 e d	  d
    Z e	 j
 e d  d    Z e	 j
 e d  d    Z d   Z d   Z d   Z RS(   s*   Test the internal function _mkstemp_inner.t	   mkstempedc           B   sG   e  Z e j Z e j Z e j Z	 e j
 Z d    Z d   Z d   Z RS(   c         C   sC   | r |  j  } n	 |  j } t j | | | |  \ |  _ |  _ d  S(   N(   t   _bflagst   _tflagsR5   t   _mkstemp_innert   fdR   (   R   R   R   R   t   bint   flags(    (    s#   lib/python2.7/test/test_tempfile.pyt   __init__T  s     	c         C   s   t  j |  j |  d  S(   N(   R   RO   R   (   R   t   str(    (    s#   lib/python2.7/test/test_tempfile.pyRO   Z  s    c         C   s$   |  j  |  j  |  j |  j  d  S(   N(   t   _closeR   t   _unlinkR   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   __del__]  s    (   R%   R&   R5   t   _bin_openflagsR   t   _text_openflagsR   R   RN   R   t   unlinkR   R   RO   R   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR   N  s   						R@   i   c         C   sk   | d  k r t j   } n  y |  j | | | |  } Wn |  j d  n X|  j | j | | |  | S(   NR   (   R   R5   R0   R   R   R$   R   (   R   R   R   R   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt	   do_createa  s    c         C   s   |  j    j d  |  j  d d  j d  |  j  d d  j d  |  j  d d d d  j d  |  j  d d d d  j d  d  S(   Nt   blatR   R   R   R   t   aas   .txt(   R   RO   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt
   test_basicl  s
    c         C   s7   t  t  } x$ | D] } |  j d d  | | <q Wd  S(   NR   R   (   t   rangeRE   R   (   R   t   extantRG   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_basic_manyt  s    c         C   s>   t  j   } z |  j d |  j d  Wd  t j |  Xd  S(   NR   R   (   R5   R-   R   RO   R   t   rmdir(   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_choose_directoryz  s    s   os.stat not availablec         C   sj   |  j    } t j t j | j  j  } d } t j d k rV | d ?} | d
 } n  |  j | |  d  S(   Ni  t   win32t   os2emxi   i   i   i@   (   R   R   i	   iI   (	   R   R   t   S_IMODER   R   R   R   t   platformR   (   R   R   R   R9   t   user(    (    s#   lib/python2.7/test/test_tempfile.pyt   test_file_mode  s    
s   os.spawnl not availablec         C   s  t  j r d } n d } |  j   } d | j } y
 t } Wn t k
 r[ t j d } n Xt j	 j
 t j	 j t j	 j |   d  } t j d
 k r d t j } d | } n	 t j } t j t j t j | | | |  } |  j | d k  d |  |  j | d k d	 |  d  S(   Nt   vt   qs   %di    s   tf_inherit_check.pyR   s   "%s"s$   child process caught fatal signal %ds    child process reports failure %d(   R   (   Ro   t   verboseR   R   t   __file__t	   NameErrorR   t   argvR   R   R   Rz   R   R   t
   executableR   t   P_WAITRf   (   R   R   R   R   t   met   testert	   decoratedt   retval(    (    s#   lib/python2.7/test/test_tempfile.pyt   test_noinherit  s&    		
$		$s   text mode not availablec         C   s   |  j  d d  j d  d  S(   NR   i    s   blat
(   R   RO   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_textmode  s    c         C   s"   t  j t  j   t  j d t  j  S(   NR@   (   R5   R   R0   R2   R   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR     s    c         C   s   t     t d d d  o |  j   \ } } t j |  |  j | j d   |  j   \ } } t j |  |  j | j d   Wd  QXWd  QXd  S(   Nt   aaat   bbb(   R   R   R   R   RN   R   t   endswith(   R   t   fd1t   name1t   fd2t   name2(    (    s#   lib/python2.7/test/test_tempfile.pyt!   test_collision_with_existing_file  s    
c         C   s   t    u t d d d  \ t j   } |  j | j d   |  j   \ } } t j |  |  j | j d   Wd  QXWd  QXd  S(   NR   R   (	   R   R   R5   R-   R   R   R   R   RN   (   R   R   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt&   test_collision_with_existing_directory  s    
(    N(   R%   R&   R`   R   R   R   R   R   R   Ra   Rb   t   has_statR   t
   has_spawnlR   t   has_textmodeR   R   R   R   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR   K  s   			%		t   test_gettempprefixc           B   s    e  Z d  Z d   Z d   Z RS(   s   Test gettempprefix().c         C   s9   t  j   } |  j | t  |  j t |  d k  d  S(   Ni    (   R5   R/   Rg   Rh   R   R   (   R   t   p(    (    s#   lib/python2.7/test/test_tempfile.pyt   test_sane_template  s    c         C   s   t  j   d } t  j d d  } zj t j j | |  } y  t j | t j t j B } Wn |  j	 d  n Xt j
 |  t j |  Wd  t j |  Xd  S(   Ns
   xxxxxx.xxxt   prefixR@   s   os.open(   R5   R/   R-   R   R   R   R   t   O_RDWRt   O_CREATR   RN   R   R   (   R   R   t   dR   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_usable_template  s     (   R%   R&   R`   R   R   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR     s   	t   test_gettempdirc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   Test gettempdir().c         C   s_   t  j   } |  j t j j |  p0 | t j k d |  |  j t j j |  d |  d  S(   Ns   %s is not an absolute paths   %s is not a directory(   R5   R0   R   R   R   t   isabsRw   t   isdir(   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_directory_exists  s
    $c         C   sL   y' t  j   } | j d  | j   Wn |  j d t  j    n Xd  S(   NR   s   create file in %s(   R5   R*   RO   RN   R   R0   (   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_directory_writable
  s    c         C   s/   t  j   } t  j   } |  j | | k  d  S(   N(   R5   R0   R   (   R   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR     s    (   R%   R&   R`   R   R   R   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR     s   			t   test_mkstempc           B   s2   e  Z d  Z d d d d  Z d   Z d   Z RS(   s   Test mkstemp().R@   c   	      C   s   | d  k r t j   } n  yo t j d | d | d |  \ } } t j j |  \ } } t j j |  } |  j | | d | | f  Wn |  j	 d  n Xz |  j
 | | | |  Wd  t j |  t j |  Xd  S(   NR   R   t   suffixs+   Directory '%s' incorrectly returned as '%s'R,   (   R   R5   R0   R,   R   R   R   R   R   R   R$   RN   R   (	   R   R   R   R   R   R   R    R!   t   adir(    (    s#   lib/python2.7/test/test_tempfile.pyR   $  s    $c         C   sj   |  j    |  j  d d  |  j  d d  |  j  d d d d  |  j  d d d d  |  j  d d  d  S(	   NR   R   R   R   R   s   .txtR   t   .(   R   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR   6  s    
c         C   s5   t  j   } z |  j d |  Wd  t j |  Xd  S(   NR   (   R5   R-   R   R   R   (   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR   ?  s    N(   R%   R&   R`   R   R   R   R   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR   !  s   		t   test_mkdtempc           B   sq   e  Z d  Z d   Z d d d d  Z d   Z d   Z d   Z e	 j
 e d  d    Z d	   Z d
   Z RS(   s   Test mkdtemp().c         C   s
   t  j   S(   N(   R5   R-   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR   M  s    R@   c         C   s   | d  k r t j   } n  y" t j d | d | d |  } Wn |  j d  n Xy |  j | | | |  | SWn t j |    n Xd  S(   NR   R   R   R-   (   R   R5   R0   R-   R   R$   R   R   (   R   R   R   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR   P  s    "c         C   s   t  j |  j    t  j |  j d d   t  j |  j d d   t  j |  j d d d d   t  j |  j d d d d   d  S(   NR   R   R   R   R   s   .txt(   R   R   R   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR   _  s
    c         C   so   t  t  } z+ x$ | D] } |  j d d  | | <q WWd  x- | D]% } t | t  rA t j |  qA qA WXd  S(   NR   R   (   R   RE   R   t
   isinstanceRh   R   R   (   R   R   RG   (    (    s#   lib/python2.7/test/test_tempfile.pyR   g  s    c         C   s>   t  j   } z t j |  j d |   Wd  t j |  Xd  S(   NR   (   R5   R-   R   R   R   (   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR   r  s    s   os.stat not availablec         C   s   |  j    } ze t j t j |  j  } | d M} d } t j d	 k r` | d ?} | d } n  |  j | |  Wd  t j |  Xd  S(   Ni  i  R   R   i   i   i   i@   (   R   R   i	   iI   (	   R   R   R   R   R   R   R   R   R   (   R   R   R   R9   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt	   test_modez  s    

c         C   s   t    u t d d d  \ t j d t  } | j   |  j | j j d   t j	   } |  j | j d   Wd  QXWd  QXd  S(   NR   R   t   delete(
   R   R   R5   R*   t   FalseRN   R   R   R   R-   (   R   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR     s    

c         C   sq   t    b t d d d  I t j   } |  j | j d   t j   } |  j | j d   Wd  QXWd  QXd  S(   NR   R   (   R   R   R5   R-   R   R   (   R   t   dir1t   dir2(    (    s#   lib/python2.7/test/test_tempfile.pyR     s    
N(   R%   R&   R`   R   R   R   R   R   R   Ra   Rb   R   R  R   R   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR   J  s   					t   test_mktempc           B   sT   e  Z d  Z d   Z d   Z d d	 d     YZ d d d  Z d   Z d   Z RS(
   s   Test mktemp().c         C   s   t  j   |  _ d  S(   N(   R5   R-   R   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR?     s    c         C   s)   |  j  r% t j |  j   d  |  _  n  d  S(   N(   R   R   R   R   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   tearDown  s    	t   mktempedc           B   s,   e  Z e j Z e j Z d    Z d   Z	 RS(   c         C   sG   t  j d | d | d |  |  _ t j t j |  j |  j d   d  S(   NR   R   R   i  (   R5   R   R   R   RN   R   R   (   R   R   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR     s    !c         C   s   |  j  |  j  d  S(   N(   R   R   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR     s    (
   R%   R&   R   R   R   R5   R   R   R   R   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR	    s   			R@   c         C   sS   y |  j  |  j | |  } Wn |  j d  n X|  j | j |  j | |  | S(   NR   (   R	  R   R   R$   R   (   R   R   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR     s    c         C   sZ   |  j    |  j  d d  |  j  d d  |  j  d d d d  |  j  d d d d  d  S(   NR   R   R   R   R   s   .txt(   R   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR     s
    
c         C   s7   t  t  } x$ | D] } |  j d d  | | <q Wd  S(   NR   R   (   R   RE   R   (   R   R   RG   (    (    s#   lib/python2.7/test/test_tempfile.pyRH     s    (    (	   R%   R&   R`   R?   R  R	  R   R   RH   (    (    (    s#   lib/python2.7/test/test_tempfile.pyR    s   				t   test_NamedTemporaryFilec           B   sk   e  Z d  Z d d d e d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z RS(   s   Test NamedTemporaryFile().R@   c      	   C   sw   | d  k r t j   } n  y( t j d | d | d | d |  } Wn |  j d  n X|  j | j | | |  | S(   NR   R   R   R  R*   (   R   R5   R0   R*   R   R$   R   (   R   R   R   R   R  R   (    (    s#   lib/python2.7/test/test_tempfile.pyR     s    c         C   sZ   |  j    |  j  d d  |  j  d d  |  j  d d d d  |  j  d d d d  d  S(   NR   R   R   R   R   s   .txt(   R   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR     s
    
c         C   s6   t  j   } |  j t j j | j  d | j  d  S(   Ns$   NamedTemporaryFile %s does not exist(   R5   R*   R   R   R   t   existsR   (   R   t   f(    (    s#   lib/python2.7/test/test_tempfile.pyt   test_creates_named  s    c         C   st   t  j   } zS t  j d |  } | j d  | j   |  j t j j | j	  d | j	  Wd  t j
 |  Xd  S(   NR   R   s(   NamedTemporaryFile %s exists after close(   R5   R-   R*   RO   RN   Rf   R   R   R  R   R   (   R   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_del_on_close  s    
c         C   s   t  j   } d  } zb t  j d | d t  } | j } | j d  | j   |  j t	 j
 j | j  d | j  Wd  | d  k	 r t	 j |  n  t	 j |  Xd  S(   NR   R  R   s)   NamedTemporaryFile %s missing after close(   R5   R-   R   R*   R  R   RO   RN   R   R   R   R  R   R   (   R   R   t   tmpR  (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_dis_del_on_close  s    	
c         C   sV   t  j   } | j d  | j   y | j   | j   Wn |  j d  n Xd  S(   Ns   abc
RN   (   R5   R*   RO   RN   R   (   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_multiple_close  s    

c            sp   t  j   #   |  j t j j   j   Wd  QX|  j t j j   j     f d   } |  j t	 |  d  S(   Nc              s      Wd  QXd  S(   N(    (    (   R  (    s#   lib/python2.7/test/test_tempfile.pyt
   use_closed-  s    (
   R5   R*   R   R   R   R  R   Rf   R   Rr   (   R   R  (    (   R  s#   lib/python2.7/test/test_tempfile.pyt   test_context_manager(  s
    "c            s   t  j  t  j } g       f d   } d   } | t  _ | t  _ z- |  j t t j  |  j t    d  Wd   t  _ | t  _ Xd  S(   Nc            s    |     j  |   d  S(   N(   R7   (   R   (   t   closedt	   old_close(    s#   lib/python2.7/test/test_tempfile.pyRN   7  s    
c          W   s   t     d  S(   N(   Rr   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   fdopen:  s    i   (	   R   RN   R  R   Rr   R5   R*   R   R   (   R   t
   old_fdopenRN   R  (    (   R  R  s#   lib/python2.7/test/test_tempfile.pyt   test_no_leak_fd2  s    						c      	   C   sh   t  j   } |  j t j |  |  j t   t  j d d d |  Wd  QX|  j t	 j
 |  g   d  S(   NR   R   (    (   R5   R-   t
   addCleanupRo   R   R   t	   TypeErrorR*   R   R   R   (   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_bad_modeE  s
    N(   R%   R&   R`   R   t   TrueR   R   R  R  R  R  R  R  R  (    (    (    s#   lib/python2.7/test/test_tempfile.pyR
    s   						
	t   test_SpooledTemporaryFilec           B   s   e  Z d  Z d d d d d  Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   Test SpooledTemporaryFile().i    R@   c      	   C   s^   | d  k r t j   } n  y( t j d | d | d | d |  } Wn |  j d  n X| S(   Nt   max_sizeR   R   R   R3   (   R   R5   R0   R3   R   (   R   R  R   R   R   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR   S  s    (c         C   sN   |  j    } |  j | j  |  j  d d d d d d  } |  j | j  d  S(   NR  id   R   R   R   s   .txt(   R   Rf   t   _rolled(   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyR   ^  s    c         C   s   t  j   } z t  j d d d |  } |  j | j  | j d d  |  j | j  | j } | j   |  j t	 j
 j |  d |  Wd  t	 j |  Xd  S(   NR  i
   R   s   blat i   s*   SpooledTemporaryFile %s exists after close(   R5   R-   R3   Rf   R  RO   R   R   RN   R   R   R  R   (   R   R   R  t   filename(    (    s#   lib/python2.7/test/test_tempfile.pyR  e  s    	
c         C   sj   |  j  d d  } |  j | j  x1 t d  D]# } | j d d  | j d  q/ W|  j | j  d  S(   NR  i   i   i    t   xi   t   xxxxxxxxxxxxxxxxxxxx(   R   Rf   R  R   t   seekRO   (   R   R  RG   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_rewrite_smallt  s    c         C   s}   |  j  d d  } |  j | j  | j d  |  j | j  | j d  |  j | j  | j d  |  j | j  d  S(   NR  i   R!  i   i
   R"  t
   xxxxxxxxxx(   R   Rf   R  RO   R   (   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_write_sequential}  s    c         C   sF   |  j    } | j d  | j d  | j   } |  j | d  d  S(   NR!  t   yt   zi    t   xyz(   R!  R'  R(  (   R   t
   writelinesR#  RR   R   (   R   R  t   buf(    (    s#   lib/python2.7/test/test_tempfile.pyt   test_writelines  s
    c         C   sY   |  j  d d  } | j d d d	 f  |  j | j  | j d  |  j | j  d  S(
   NR  i#   R!  i   i
   i   R"  R%  t   xxxxx(   R   R*  Rf   R  RO   R   (   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_writelines_sequential  s
    c         C   s   |  j  d d  } | j d	  | j d  |  j | j  |  j t | j    d g d  | j d  |  j | j  | j d  |  j t | j    d g d d d g  d  S(
   NR  i   s   abc
i   i    s   x
ys   x
R'  s   abc
abc
abc
abc
abc
(	   R   RO   R#  Rf   R  R   t   listt
   xreadlinesR   (   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_xreadlines  s    #c         C   sc   |  j  d d  } |  j | j  | j d d  |  j | j  | j d  |  j | j  d  S(   NR  i   id   i    R!  (   R   Rf   R  R#  RO   R   (   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_sparse  s    c         C   sO   |  j  d d  } |  j | j  |  j | j   d k  |  j | j  d  S(   NR  i   i    (   R   Rf   R  R   t   fileno(   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_fileno  s    c         C   sf   t  j   } | j d  |  j | j  | j   y | j   | j   Wn |  j d  n Xd  S(   Ns   abc
RN   (   R5   R3   RO   Rf   R  RN   R   (   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyt#   test_multiple_close_before_rollover  s    

c         C   sl   t  j d d  } | j d  |  j | j  | j   y | j   | j   Wn |  j d  n Xd  S(   NR  i   s   abc
RN   (   R5   R3   RO   R   R  RN   R   (   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyt"   test_multiple_close_after_rollover  s    

c         C   s   |  j  d d  } | j } | j } | j } | d d  | d d  | d d  |  j | d  d d d d k  d  S(   NR  i   R   i#   R   i    iF   (   R   RR   RO   R#  R   (   R   R  RR   RO   R#  (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_bound_methods  s    			c         C   s
  t  j d d  } | j d  |  j | j  |  j | j d  |  j | j  |  j	 t
   | j Wd  QX|  j	 t
   | j Wd  QX| j d  |  j | j  |  j | j d  |  j | j  |  j	 t
   | j Wd  QX|  j	 t
   | j Wd  QXd  S(   NR  i
   R!  s   w+bR%  (   R5   R3   RO   Rf   R  R   R   t   assertIsNoneR   R   Ru   t   newlinest   encodingR   t   assertIsNotNone(   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_properties  s"    c            sn   t  j d d  '   |  j   j  |  j   j  Wd  QX|  j   j    f d   } |  j t |  d  S(   NR  i   c              s      Wd  QXd  S(   N(    (    (   R  (    s#   lib/python2.7/test/test_tempfile.pyR    s    (   R5   R3   Rf   R  R  R   R   Rr   (   R   R  (    (   R  s#   lib/python2.7/test/test_tempfile.pyt$   test_context_manager_before_rollover  s    c            s   t  j d d  N   |  j   j    j d    j   |  j   j  |  j   j  Wd  QX|  j   j    f d   } |  j t	 |  d  S(   NR  i   s   abc
c              s      Wd  QXd  S(   N(    (    (   R  (    s#   lib/python2.7/test/test_tempfile.pyR    s    (
   R5   R3   Rf   R  RO   t   flushR   R  R   Rr   (   R   R  (    (   R  s#   lib/python2.7/test/test_tempfile.pyt$   test_context_manager_during_rollover  s    
c            s   t  j d d      j d    j   |  j   j     |  j   j  Wd  QX|  j   j    f d   } |  j t	 |  d  S(   NR  i   s   abc
c              s      Wd  QXd  S(   N(    (    (   R  (    s#   lib/python2.7/test/test_tempfile.pyR    s    (
   R5   R3   RO   R>  R   R  Rf   R  R   Rr   (   R   R  (    (   R  s#   lib/python2.7/test/test_tempfile.pyt#   test_context_manager_after_rollover	  s    
N(   R%   R&   R`   R   R   R   R  R$  R&  R,  R.  R1  R2  R4  R5  R6  R7  R<  R=  R?  R@  (    (    (    s#   lib/python2.7/test/test_tempfile.pyR  P  s$   										
							t   test_TemporaryFilec           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   Test TemporaryFile().c         C   s)   y t  j   Wn |  j d  n Xd  S(   NR+   (   R5   R+   R   (   R   (    (    s#   lib/python2.7/test/test_tempfile.pyR     s    c         C   s}   t  j   } t  j d |  } | j d  y t j |  Wn: t j   } | j   t j |  |  j	 d |  n Xd  S(   NR   R   R   (
   R5   R-   R+   RO   R   R   R   R   RN   R   (   R   R   R  R   (    (    s#   lib/python2.7/test/test_tempfile.pyt   test_has_no_name&  s    
c         C   sV   t  j   } | j d  | j   y | j   | j   Wn |  j d  n Xd  S(   Ns   abc
RN   (   R5   R+   RO   RN   R   (   R   R  (    (    s#   lib/python2.7/test/test_tempfile.pyR  7  s    

(   R%   R&   R`   R   RB  R  (    (    (    s#   lib/python2.7/test/test_tempfile.pyRA    s   		c           C   s   t  j t   d  S(   N(   Ro   t   run_unittestt   test_classes(    (    (    s#   lib/python2.7/test/test_tempfile.pyt	   test_mainH  s    t   __main__(   R   R	   (    (3   R5   R   R   R   RU   R   R   R'   t   warningst
   contextlibRa   t   testR    Ro   t   filterwarningst   RuntimeWarningR%   Rc   R   R   R   R   R   R   R   RE   t   TestCaseR
   RD  R)   R7   R<   Rd   R|   R   t   contextmanagerR   R   R   R   R   R   R   R   R  R
  R  RA  R*   R+   RE  (    (    (    s#   lib/python2.7/test/test_tempfile.pyt   <module>   sx   		I')
	# &W9k*	