
    6\h                       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Zd dlZd dlZd dlZd dlZd dlmZmZmZmZmZmZmZmZmZmZmZmZ d dlZd dlZ	 d dlZn# e$ r dZY nw xY wd dl m!Z! d dl"m#Z# d dl$m%Z%m&Z& d dl"m'Z' e%dz   Z(e%dz   Z)e%d	z   Z*ej+        ,                    d
          Z-ej+        ,                    d          Z.ej+        dd         dk    Z/	 d dl0Z0d dl1Z1dZ2n# e$ r dZ2Y nw xY w	 d dl3Z3n# e$ r dZ3Y nw xY we j4        5                    d e6d                    Z7d Z8d Z9d>dZ:d Z;d>dZ<d Z=d Z> e>            Z?d Z@ G d d          ZA G d deAe jB                  ZC G d d eAe jB                  ZD G d! d"eAe jB                  ZE G d# d$eAe jB                  ZF G d% d&eAe jB                  ZG G d' d(eAe jB                  ZH G d) d*eH          ZI G d+ d,eAe jB                  ZJ G d- d.e jB                  ZK G d/ d0e jB                  ZL G d1 d2eM          ZN e jO        e? d3           G d4 d5eNe jB                              ZP e jO        e- d6           G d7 d8eNe jB                              ZQ G d9 d:e jB                  ZR G d; d<e jB                  ZSeTd=k    r e jU                     dS dS )?    N)make_archiveregister_archive_formatunregister_archive_formatget_archive_formatsErrorunpack_archiveregister_unpack_formatRegistryErrorunregister_unpack_formatget_unpack_formatsSameFileError_GiveupOnFastCopy)support)	os_helper)TESTFNFakePath)warnings_helper2_SRC_DSTdarwinsunos   aixTFzos.chdirzshouldn't call os.chdir()side_effectc                  J    t          t          t          dd          d          )NEXDEV   zInvalid cross-device link)OSErrorgetattrerrno)argskwargss     :/opt/python-3.11.14/usr/lib/python3.11/test/test_shutil.py_fake_renamer&   :   s    
'%"--/J
K
KK    c                 F     t          j                    fd            }|S )Nc                      	 t           j        }t          t           _         | i ||t           _        S # |t           _        w xY wN)osrenamer&   )r#   r$   builtin_renamefuncs      r%   wrapzmock_rename.<locals>.wrap?   sD    	'YN$BI4(((&BIIBI&&&&s	   $4 A)	functoolswraps)r.   r/   s   ` r%   mock_renamer2   >   s8    _T' ' ' ' ' Kr'   c                     t          | t                    rt          j        j        |  } |rdnd}|rdnd}t          | ||          5 }|                    |           ddd           dS # 1 swxY w Y   dS )zWrite *content* to a file located at *path*.

    If *path* is a tuple instead of a string, os.path.join will be used to
    make a path.  If *binary* is true, the file will be opened in binary
    mode.
    wbwNutf-8encoding)
isinstancetupler+   pathjoinopenwrite)r;   contentbinarymoder8   fps         r%   
write_filerC   I   s     $ #w|T""44sD*tt7H	dD8	,	,	, 
                 s   A**A.1A.c                     d }t          |d          }d                    d t          |          D                       }t          | d          5 } |||          D ]}|                    |           	 ddd           dS # 1 swxY w Y   dS )zBCreate a test file with an arbitrary size and random text content.c              3   D   K   | |k    r|V  | |z  } | |k    | r| V  d S d S r*    )totalsteps     r%   chunkszwrite_test_file.<locals>.chunksY   sM      dllJJJTME dll  	KKKKK	 	r'   i    r'   c                 n    g | ]2}t          j        t          j                                                  3S rF   )randomchoicestringascii_lettersencode).0is     r%   
<listcomp>z#write_test_file.<locals>.<listcomp>b   sA     / / / mF$899@@BB / / /r'   r4   N)minr<   ranger=   r>   )r;   sizerI   bufsizechunkfcsizes          r%   write_test_filerZ   W   s       $ooGHH / /$W~~/ / / 0 0E	dD		 QVD'** 	 	EGGENNNN	                 s   %BB
Bc                     t          | t                    rt          j        j        |  } |rdnd}|rdnd}t          | ||          5 }|                                cddd           S # 1 swxY w Y   dS )zReturn contents from a file located at *path*.

    If *path* is a tuple instead of a string, os.path.join will be used to
    make a path.  If *binary* is true, the file will be opened in binary
    mode.
    rbrNr6   r7   )r9   r:   r+   r;   r<   r=   read)r;   r@   rA   r8   rB   s        r%   	read_filer_   i   s     $ #w|T""44sD*tt7H	dD8	,	,	, wwyy                 s   A((A,/A,c                    g }t          t          j        |                     D ]}t          j                            | |          }t          j                            |          ret          j                            |          sF|                    |dz              t          |          D ]}|                    |dz   |z              |                    |           |S )N/)	sortedr+   listdirr;   r<   isdirislinkappendrlistdir)r;   resnamepns        r%   rg   rg   w   s    
Crz$''((  GLLt$$7== 	BGNN1$5$5 	JJtcz"""a[[ + +

4#:>****+ JJtJr'   c                  6   t          t          d          sdS d } d }	 t          j        dt          j                    d          5 }|j        } |                    d           d d d            n# 1 swxY w Y   t          | d          5 }t          j        dt          j                    d          5 }|j        }|                                }|                                }	 t          j	        ||dd           	 d d d            d d d            | t          j        |            |t          j        |           d	S d	S # t          $ rH Y d d d            d d d            | t          j        |            |t          j        |           dS dS w xY w# 1 swxY w Y   	 d d d            n# 1 swxY w Y   | t          j        |            |t          j        |           d S d S # | t          j        |            |t          j        |           w w xY w)
NsendfileFr4   dirdeletes
   0123456789r\   r      T)hasattrr+   tempfileNamedTemporaryFilegetcwdri   r>   r=   filenorm   r   unlinkr    )srcnamedstnamerX   srcdstinfdoutfds          r%   supports_file2file_sendfiler~      s8   2z"" uGG&(29;;uMMM 	#QRfGGGM"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# '4   
	 C,Try{{5QQQ 	 UX(zz||

 KtQ222  	  	  	  	  	  	 
	  
	  
	  
	  
	  
	  W%%%W%%%%%   ! ! ! 	  	  	  	  	  	 
	  
	  
	  
	  
	  
	  W%%%W%%%%% !	  	  	  	  	  	  	  	  	 
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  W%%%W%%%%%  W%%%W%%%% s   (G) A."G) .A22G) 5A26G) 	)F.20F#E:F;F.G) 
FFF.G) FFF	F.F	F."G) .F22G) 5F26G) )/Hc                     t           rxt          j        dk    rht          j        dt          j        z            } |                     d          d                                         d         }t          |d          dk    S dS )	Niz/usr/bin/dump -o %s
      i    T)AIXsysmaxsize
subprocess	getoutput
executablesplitint)hdrsmaxdatas     r%   
_maxdataOKr      sm    
 s{j((!"7#."HII

4  $**,,Q/72*,,tr'   c                       e Zd ZddZdS )BaseTestNc                     t          j        |t          j                              }|                     t
          j        |           |S )zjCreate a temporary directory that will be cleaned up.

        Returns the path of the directory.
        )prefixro   )rs   mkdtempr+   ru   
addCleanupr   rmtree)selfr   ds      r%   r   zBaseTest.mkdtemp   s;    
 F	<<<	(!,,,r'   r*   )__name__
__module____qualname__r   rF   r'   r%   r   r      s(             r'   r   c                      e Zd Zd Zej        d             Zej        d             Z ej	        e
d          d             Z ej	        e
d          d             Zd Z ej        ej        dd	         d
k    d          ej        ej        d                                     Zd Zd Zd Z ej	        ej        d          d             Z ej	        ej        d          d             Z ej        ej        d          d             Zd Zej        d             Z ej	        e
d          d             Z ej	         ee d          d           ej        ej        dk    d          d                         Z!dS )
TestRmTreec                 x   |                                  }t          j                            |d          }t          j        |           t          t          j                            |d          d           t          j        |          }|                     |t                     t          j
        |           d S )Nkillmesomefilefoo)r   r+   r;   r<   mkdirrC   fsencodeassertIsInstancebytesshutilr   )r   tmpvictims      r%   test_rmtree_works_on_bytesz%TestRmTree.test_rmtree_works_on_bytes   s    llnnc8,,
27<<
33U;;;V$$fe,,,fr'   c                    |                                  }t          j                            |d          }t          j        |           t          j                            |d          }t          j        ||           |                     t          t          j	        |           | 
                    t          j                            |                     | 
                    t          j                            |                     g fd}t          j	        ||           |                     t                    d           |                     d         d         t          j        j                   |                     d         d         |           |                     d         d         d         t                     d S )Nro   linkc                  2                         |            d S r*   rf   r#   errorss    r%   onerrorz8TestRmTree.test_rmtree_fails_on_symlink.<locals>.onerror       MM$r'   r   r   r   rq   )r   r+   r;   r<   r   symlinkassertRaisesr    r   r   
assertTrueexistslexistsassertEquallenassertIsre   r   r   r   dir_r   r   r   s        @r%   test_rmtree_fails_on_symlinkz'TestRmTree.test_rmtree_fails_on_symlink   sh   llnnw||C''
w||C((

4'6=$777t,,-----...	  	  	  	  	 dG,,,,Va(((fQilBGN3331t,,,fQil1ow77777r'   c                    |                                  }t          j                            |d          }t          j                            |d          }t          j                            |d          }|||fD ]}t          j        |           t          j                            |d          }t          |d           t          j                            |d          }t          j        ||           t          j                            |d          }t          j        ||           t          j                            |d          }	t          j        ||	           t          j        |           | 	                    t          j        
                    |                     |                     t          j        
                    |                     |                     t          j        
                    |                     d S 	Ndir1dir2dir3file1r   link1link2link3)r   r+   r;   r<   r   rC   r   r   r   assertFalser   r   
r   r   r   r   r   r   r   r   r   r   s
             r%   test_rmtree_works_on_symlinksz(TestRmTree.test_rmtree_works_on_symlinks   s   llnnw||C((w||D&))w||C((tT! 	 	AHQKKKKS'**5%   T7++

4T7++

4T7++

5%   d--...t,,---u--.....r'   zonly relevant on Windowsc                    |                                  }t          j                            |d          }t          j        |           t          j                            |d          }t          j        ||           |                     t          j	        |           | 
                    t          t          j        |           |                     t          j                            |                     |                     t          j                            |                     g fd}t          j        ||           |                     t%                    d           |                     d         d         t          j        j                   |                     d         d         |           |                     d         d         d         t                     d S )Nro   r   c                  2                         |            d S r*   r   r   s    r%   r   z:TestRmTree.test_rmtree_fails_on_junctions.<locals>.onerror   r   r'   r   r   r   rq   )r   r+   r;   r<   r   _winapiCreateJunctionr   r   rw   r   r    r   r   r   r   r   r   r   r   re   r   r   s        @r%   test_rmtree_fails_on_junctionsz)TestRmTree.test_rmtree_fails_on_junctions   s   llnnw||C''
w||C((tT***	($///'6=$777t,,-----...	  	  	  	  	 dG,,,,Va(((fQilBGN3331t,,,fQil1ow77777r'   c                    |                                  }t          j                            |d          }t          j                            |d          }t          j                            |d          }|||fD ]}t          j        |           t          j                            |d          }t          |d           t          j                            |d          }t          j        ||           t          j                            |d          }t          j        ||           t          j                            |d          }	t          j        ||	           t          j	        |           | 
                    t          j                            |                     |                     t          j                            |                     |                     t          j                            |                     d S r   )r   r+   r;   r<   r   rC   r   r   r   r   r   r   r   r   s
             r%   test_rmtree_works_on_junctionsz)TestRmTree.test_rmtree_works_on_junctions  s   llnnw||C((w||D&))w||C((tT! 	 	AHQKKKKS'**5%   T7++tU+++T7++tU+++T7++ue,,,d--...t,,---u--.....r'   c                 :   t          j        |                                           }|                     t          t
          j        |           t          j        |d           |                                 }t          |dfd           t          j	        
                    |d          }|                     t                    5 }t          j        |           d d d            n# 1 swxY w Y   |                     |j        j        |           |                     t          j	                            |                     t          j        |d           |                     t          j	                            |                     g fd}t          j        ||           |                     t#                    d           |                     d	         d	         t          j                   |                     d	         d
         |           |                     d	         d         d
         t                     |                     d	         d         d
         j        |           |                     d
         d	         t          j                   |                     d
         d
         |           |                     d
         d         d
         t                     |                     d
         d         d
         j        |           d S )Nro   Tignore_errorststfile c                  2                         |            d S r*   r   r   s    r%   r   z.TestRmTree.test_rmtree_errors.<locals>.onerror,  r   r'   r   rq   r   r   )rs   mktempr   r   FileNotFoundErrorr   r   rC   r+   r;   r<   NotADirectoryErrorr   	exceptionfilenamer   r   r   r   scandirr   rmdir)r   r   tmpdircmr   r   s        @r%   test_rmtree_errorszTestRmTree.test_rmtree_errors  s   ?t||~~666+V]HEEEhd3333 FI&+++7<<	22122 	$bM(###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$.999x00111hd3333x00111	  	  	  	  	 h0000Va(((fQilBJ///1x000fQil1o/ABBB1a18<<<fQilBH---1x000fQil1o/ABBB1a18<<<<<s   C&&C*-C*N   cygwinz2This test can't be run on Cygwin (issue #1071513).c                 z   d| _         t          j        t                     |                     t
          j        t                     t          j                            t          d          | _	        t          j                            t          d          | _
        t          j        | j	                   t          j        | j
                   t          j        t                    j        }t          j        | j	                  j        }t          j        | j
                  j        }t          j        t          j        z  }t          j        | j	        |           t          j        | j
        |           t          j        t          |           |                     t          j        t          |           |                     t          j        | j	        |           |                     t          j        | j
        |           t          j        t          | j                   |                     | j         dd           d S )Nr   abr   r   z1Expected call to onerror function did not happen.)
errorStater+   r   r   r   r   r   r;   r<   child_file_pathchild_dir_pathr   create_empty_filestatst_modeS_IREADS_IEXECchmodcheck_args_to_onerrorr   )r   old_dir_modeold_child_file_modeold_child_dir_modenew_modes        r%   test_on_errorzTestRmTree.test_on_error:  s   
 
v...!w||FC88 gll6377#D$8999
$%%%wv. gd&:;;CWT%899A<,
%x000
$h///
"""&,777$"68KLLL$"57IJJJfd&@AAAA!L	N 	N 	N 	N 	Nr'   c                    | j         dk     r|t          j        u r|                     || j                   nl|t          j        u r|                     || j                   nB|                     |t          j                   | 	                    |t          | j        g           |                     t          |d         t                               | xj         dz  c_         d S |                     |t          j                   |                     |t                     |                     t          |d         t                               d| _         d S )Nrq   r   r   r   )r   r+   rw   r   r   r   r   r   rc   assertInr   r   
issubclassr    )r   r.   argexcs       r%   r   z TestRmTree.check_args_to_onerrorY  s"    ?Qry    d&:;;;;!!  d&9::::dBJ///cFD,?#@AAAOOJs1vw77888OOq OOOOT28,,,S&)))OOJs1vw77888DOOOr'   c                    	 t           j        fd}|t           _        t          j        t                     t	          t          dfd           t          j        t                     t           _        d S # t           _        w xY w)Nc                 L    | t           k    rt                       |           S r*   )r   r    )fnr#   r$   
orig_lstats      r%   raiserzFTestRmTree.test_rmtree_does_not_choke_on_failing_lstat.<locals>.raiserw  s#    <<!))O%:b>>)r'   r   )r+   lstatr   r   rC   r   r   )r   r   r   s     @r%   +test_rmtree_does_not_choke_on_failing_lstatz6TestRmTree.test_rmtree_does_not_choke_on_failing_lstatt  s    	"J* * * * *
 BHHV...M&!!!!BHHHzBH!!!!s   A&A7 7Bc                 b   t           j        t           j        t           j        t           j        ht           j        k    o/t           j        t           j        v ot           j        t           j        v }|r| 	                    t          j                   | 	                    t          j        j                   |                                 }t           j                            |d          }t          j        |           	 t          j        } G d dt&                    fd}|t          _        |                     t          j        |           |t          _        d S # |t          _        w xY w|                     t          j                   |                     t          j        j                   d S )Nr   c                       e Zd ZdS )HTestRmTree.test_rmtree_uses_safe_fd_version_if_available.<locals>.CalledN)r   r   r   rF   r'   r%   Calledr    s          r'   r  c                      r*   rF   )r#   r$   r  s     r%   _raiserzITestRmTree.test_rmtree_uses_safe_fd_version_if_available.<locals>._raiser  s     Lr'   )r+   r=   r   rw   r   supports_dir_fdrc   supports_fdsupports_follow_symlinksr   r   _use_fd_functionsr   avoids_symlink_attacksr   r;   r<   r   _rmtree_safe_fd	Exceptionr   r   )r   r
  tmp_dirr   real_rmtreer  r  s         @r%   -test_rmtree_uses_safe_fd_version_if_availablez8TestRmTree.test_rmtree_uses_safe_fd_version_if_available  sn    grw	28D/0 DZ2>9D  W(CC 	  	COOF4555OOFM@AAAllnnGWc**AHQKKK5$4-----Y---! ! ! ! !)0&!!&&-;;;)4&&&&4444V5666V]ABBBBBs   <AE E)zrequires safe rmtreec                    |                                  }t          j                            |d          }t          j        |           t          j                            |d          }t          j        |           fd}dt          j        t          d|          5 |                     t                    5  t          j
        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     t          j                            |                     |                     d           dg fd}t          j        t          d|          5 t          j
        ||           d d d            n# 1 swxY w Y   |                     t                    d           |                     d         d         |           |                     d         d	         |           |                     d	         d         |           |                     d	         d	         |           |                     d           d S )
Nr   r   c                 2     |            dz  t           )Nr   r    )fdclose_count
orig_closes    r%   closez4TestRmTree.test_rmtree_fails_on_close.<locals>.close  s    JrNNN1KMr'   r   r  rq   c                  2                         |            d S r*   r   r   s    r%   r   z6TestRmTree.test_rmtree_fails_on_close.<locals>.onerror  r   r'   r   r   )r   r+   r;   r<   r   r   	swap_attrr   r    r   r   r   rd   r   r   r   )	r   r   r   r   r  r   r  r   r  s	         @@@r%   test_rmtree_fails_on_closez%TestRmTree.test_rmtree_fails_on_close  s    llnnw||C((
w||D&))
	 	 	 	 	 	 r7E22 	$j""7++ $ $d###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	d++,,,a(((	  	  	  	  	 r7E22 	1jM$0000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1Va(((fQilE***1t,,,fQilE***1t,,,a(((((sH   #C6>CC6C#	#C6&C#	'C66C:=C:-FFFzdir_fd is not supportedc                    |                                  }d}t          j                            ||          }t          j        |t          j                  }|                     t          j        |           t          j        |           t          j        t          j                            |d                     t          t          j                            |dd          d           | 
                    t          j                            |                     t          j        ||           |                     t          j                            |                     d S )Nr   subdirr   r   dir_fd)r   r+   r;   r<   r=   O_RDONLYr   r  r   rC   r   r   r   r   r   )r   r  r   fullnamer  s        r%   test_rmtree_with_dir_fdz"TestRmTree.test_rmtree_with_dir_fd  s   ,,..7<<00"+..&)))

h1122227<<(J??GGGx00111fV,,,,1122222r'   zdir_fd is supportedc                 "   |                                  }|                     t                    5  t          j        |d           d d d            n# 1 swxY w Y   |                     t          j                            |                     d S )Nr   r  )	r   r   NotImplementedErrorr   r   r   r+   r;   r   )r   r  s     r%   #test_rmtree_with_dir_fd_unsupportedz.TestRmTree.test_rmtree_with_dir_fd_unsupported  s    ,,..233 	- 	-M'!,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-w//00000s   AAAc                     t          j        |                                           \  }}t          j        |           |                     t          t          j        |           t          j	        |           d S Nr   )
rs   mkstempr   r+   r  r   r   r   r   remove)r   handler;   s      r%   test_rmtree_dont_delete_filez'TestRmTree.test_rmtree_dont_delete_file  s]    'DLLNN;;;
,fmTBBB
	$r'   c                    t          j        t                     	 t           j                            t          d          }t           j                            t          d          }t          j        |           t          j        ||           |                     t          t          j	        |           t          j	        |d           t          j	        t          d           d S # t          j	        t          d           w xY w)NcheeseshopTr   )
r+   r   r   r;   r<   r   r   r    r   r   r   rz   r{   s      r%   test_rmtree_on_symlinkz!TestRmTree.test_rmtree_on_symlink  s     		6',,vx00C',,vv..CHSMMMJsC   gv}c:::M#T2222M&555555FM&55555s   B/C' 'Dc                    t          j        t                     	 t           j                            t          d          }t           j                            t          d          }t          j        |           t          t           j                            |d          d                                           t          j        ||           | 	                    t          t          j        |           t          j        |d           t          j        t          d           d S # t          j        t          d           w xY w)Nr,  r-  spamr4   Tr   )r+   r   r   r;   r<   r=   r  r   r   r   r    r   r   r.  s      r%   test_rmtree_on_junctionz"TestRmTree.test_rmtree_on_junction  s    
		6',,vx00C',,vv..CHSMMMc6**D1177999"3,,,gv}c:::M#T2222M&555555FM&55555s   C/D' 'Emkfiforequires os.mkfifo()vxworks%fifo requires special path on VxWorksc                    t          j        t                     	 |                     t                    5  t          j        t                     d d d            n# 1 swxY w Y   |                     t           j        	                    t                               t          j
        t                     n# t          j
        t                     w xY wt          j        t                     t          j        t           j                            t          d                     t          j        t                     |                     t           j        	                    t                               d S )Nmypipe)r+   r3  r   r   r   r   r   r   r;   r   rw   r   r<   r   r   s    r%   test_rmtree_on_named_pipez$TestRmTree.test_rmtree_on_named_pipe  sD    		&	""#566 & &f%%%& & & & & & & & & & & & & & &OOBGNN622333IfBIf

	"',,vx00111f//00000s.   B7 AB7 AB7 "A#:B7 7C)"r   r   r   r   r   skip_unless_symlinkr   r   unittest
skipUnlessr   r   r   r   skipIfr   platformskip_if_dac_overrideskip_unless_working_chmodr   r   r   r  r   r
  r  r!  r$  r*  r/  r2  rr   r+   r:  rF   r'   r%   r   r      s          "8 8 #"8$ "/ / #"/* X"<==8 8 >=8& X"<==/ / >=/*= = =B X_S\"1"%1IK K#(N N )( $#K KN6     6" " " C C C0 X13IJJ )  ) KJ )D X13LMM3 3 NM3 X_V-/DEE1 1 FE1   "6 6 #"6 X"<==6 6 >=6 XX..0FGGX_S\Y.;= =1 1= = HG1 1 1r'   r   c                      e Zd Zd Zd Zej        d             Zd Zd Z	d Z
ej                            d          d             Zd	 Z ej         eed
          d          ej         ej        ej        dk    d          d                                     Zd Zej        d             Zej        d             Zd Zd ZdS )TestCopyTreec           	         |                                  }t          j                            |                                  d          }|                     t
          j        |           |                     t
          j        t          j                            |                     t          |dfd           t          j	        t          j                            |d                     t          |ddfd           t          j
        ||           |                     t          j                            t          j                            |d                               |                     t          j                            t          j                            |d                               |                     t          j                            t          j                            |dd                               t          |df          }|                     |d           t          |ddf          }|                     |d           d S )Ndestinationtest.txt123test_dir456)r   r+   r;   r<   r   r   r   dirnamerC   r   copytreer   isfilerd   r_   r   r   src_dirdst_diractuals       r%   test_copytree_simplez!TestCopyTree.test_copytree_simple  s   ,,..',,t||~~}==w///rww'?'?@@@GZ(%000
gz22333GZ4e<<<)))rw||GZ'H'HIIJJJbgll7J&G&GHHIIIrw||GZ4>(@ (@ A A 	B 	B 	BGZ011'''GZ<=='''''r'   c           	      P   |                                  }|                                  }|                     t          j        |           |                     t          j        |           t	          |dfd           t          j        t
          j                            |d                     t          j        t
          j                            |d                     t	          |ddfd           t	          |ddfd           t          j	        ||d           | 
                    t
          j                            t
          j                            |d                               | 
                    t
          j                            t
          j                            |d                               | 
                    t
          j                            t
          j                            |dd                               t          |df          }|                     |d           t          |ddf          }|                     |d           |                     t                     5  t          j	        ||d	           d d d            d S # 1 swxY w Y   d S )
Nznonexisting.txtrG  existing_dirzexisting.txtzwill be replacedzhas been replacedT)dirs_exist_okF)r   r   r   r   rC   r+   r   r;   r<   rK  r   rL  rd   r_   r   r   FileExistsErrorrM  s       r%   test_copytree_dirs_exist_okz(TestCopyTree.test_copytree_dirs_exist_ok  s   ,,..,,..w///w///G./777
g~66777
g~66777G^^<>PQQQG^^<>QRRR====rw||G=N'O'OPPQQQbgll7N&K&KLLMMMrw||G^4B(D (D E E 	F 	F 	FG%6788'''G^^DEE!4555// 	C 	COGWEBBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cs   6JJ"Jc           	         |                                  }t          j                            |d          }t          j                            |d          }t          j                            |d          }t          j        |           t          j        |           t          |dfd           t          j                            |d          }t          j                            |d          }t          j        t          j                            |d          |           t          t          d          r,t          j        |t          j
        t          j        z             t          t          d	          r4t          t          d
          rt          j        |t          j                   t          j        |          }t          j        ||d           |                     t          j                            t          j                            |dd                               t          j        t          j                            |dd                    }t          j        dk    r|                    d          r
|dd          }|                     |t          j                            |d                     t          j        |          }	t          t          d          r |                     |	j        |j                   t          t          d	          r"|                     |	j        |j                   d S d S )Nrz   r{   subzfile.txtr   r   zsub/linklchmodlchflags	UF_NODUMPTsymlinksntz\\?\   )r   r+   r;   r<   r   rC   r   rr   rY  r   S_IRWXUS_IRWXOrZ  r[  r   r   rK  r   re   readlinkri   
startswithr   r   st_flags)
r   r  rN  rO  sub_dirsrc_linkdst_linksrc_statrP  dst_stats
             r%   test_copytree_symlinksz#TestCopyTree.test_copytree_symlinks7  s   ,,..',,w..',,w..',,w..

GZ(%0007<<007<<44

27<<44	 	 	2x   	=Iht| ;<<<2z"" 	2wt['A'A 	2K$.1118H%%48888rw||GUF'K'KLLMMMRW\\'5&AABB 7d??v00;;?ABBZFgz!B!BCCC8H%%2x   	AX-x/?@@@2z"" 	CX.0ABBBBB	C 	Cr'   c           
      0   t           j        j        }t           j        j        }|                                 }	  ||                                 d          }t          |dfd           t          |dfd           t          j         ||d                     t          |ddfd           t          j         ||d                     t          |ddfd           t          j         ||dd                     t          j         ||dd	                     t          |dddfd           t          |dd	d
fd           	 t          j        dd          }t          j	        |||           | 
                     | ||d                               |                      | ||d                               |                      | ||d                               t          j        |           n# t          j        |           w xY w	 t          j        dd          }t          j	        |||           |                      | ||d                               |                      | ||dd	                               |                      | ||dd                               t          j        |           n# t          j        |           w xY w	 d }t          j	        |||           |                      | ||dd	d
                               |                      | ||dd                               t          j        |           n# t          j        |           w xY w	 t          j        |           t          j        t           j                            |                     d S # t          j        |           t          j        t           j                            |                     w xY w)NrE  rF  rG  ztest.tmprH  rI  	test_dir2r  subdir2ztest.pyz*.tmpignorezsubdir*c                 r   g }|D ]}t           j                            | |          }t           j                            |          r4|                                d         dk    r|                    |           ut           j                            |          d         dv r|                    |           |S )Nr   r  z.py)r+   r;   r<   rd   r   rf   splitext)rz   namesrh   ri   r;   s        r%   _filterz8TestCopyTree.test_copytree_with_exclude.<locals>._filter  s    C % - -!w||C66GMM$// - JJLL,88JJt,,,,W--d33B7EBBJJt,,,Jr'   )r+   r;   r<   r   r   rC   r   r   ignore_patternsrK  r   r   r   rJ  )r   r<   r   rN  rO  patternsrs  s          r%   test_copytree_with_excludez'TestCopyTree.test_copytree_with_excludeW  s   w|,,..:	4d4<<>>=99G,e444,e444HTT':..///Z8%@@@HTT';//000j95AAAHTT';99:::HTT';	::;;;h
CUKKKiCUKKK'!1';GGBBBBttGZ'@'@ A ABBB  Wj(A(A!B!BCCC  Wk(B(B!C!CDDDg&&&&g&&&&'!1'9EEBBBB  Wj(A(A!B!BCCC  Wk9(M(M!N!NOOO  Wk8(L(L!M!MNNNg&&&&g&&&&'
 
 
 AAAA   Wk9-6)8 )8 "9 "9 : : :  Wk8(L(L!M!MNNN g&&&&g&&&&&M'"""M"'//'2233333 M'"""M"'//'223333sX   D
O B$G< 'O <HO B&K <O K''O +A-M- O -NO APc           
          t           j        j        }t           j        j        }                                 } ||d          }t          j         ||                     t          j         ||d                     t          j        t           j                            |dd                     t          |dddfd           g  fd} |                                 d          }t          j        |||            	                     | ||ddd                                |                                 d          }t          j        t          j        |          ||            	                     | ||ddd                                |                                 d          }t          t          j        |                    d	         }                     |t           j                   t          j        |||            	                     | ||ddd                                                    t#                    d
           d S )NsourcerH  r  rF  rI  c                 X                        |                                | t                                         |t                                         t          |          t          t          |                               |D ]}                    |t                     g S r*   )rf   r   strlistr   r   set)rz   rr  ri   invokationsr   s      r%   _ignorez?TestCopyTree.test_copytree_arg_types_of_ignore.<locals>._ignore  s    s###!!#s+++!!%...SZZSZZ999 1 1%%dC0000Ir'   rE  rn  r   	   )r+   r;   r<   r   r   r   rC   r   rK  r   pathlibPathr{  r   r   DirEntryr   r   )	r   r<   r   r  rN  r~  rO  src_dir_entryr}  s	   `       @r%   !test_copytree_arg_types_of_ignorez.TestCopyTree.test_copytree_arg_types_of_ignore  sq   w|,,..$w))
g
gz**+++
gz8<<===GZ:>FFF	 	 	 	 	 	 $t||~~}559999ttGZ$. 0  0 1 1 	2 	2 	2 $t||~~}55W--wwGGGGttGZ$. 0  0 1 1 	2 	2 	2 $t||~~}55RZ0011!4mR[999ww????ttGZ$. 0  0 1 1 	2 	2 	2 	[))1-----r'   c           	         |                                  }t          j                            |d          }t          j        |           t          j                            |d          }|                     t          j        |           t          j        |d           t          |dfd           t          j        t          j                            |d          d           t          |dfd           t          j        t          j                            |d          d           t          j         |	          }|                     t          j        |           t          j        |d           t          j        ||           |                     t          j        |          j        t          j        |          j                   |                     t          j        t          j                            |d                    j        t          j        t          j                            |d                    j                   |                     t          j        t          j                            |d                    j        t          j        t          j                            |d                    j                   t          j                            |t          j                            |          d
                   }|                     t          j        |          j        t          j        |          j                   d S )Nrx  rE  i  zpermissive.txtrG  zrestrictive.txtrI  i  r   r   )r   r+   r;   r<   r   r   r   r   r   rC   rs   r   rK  r   r   r   r   )r   r  rN  rO  restrictive_subdirrestrictive_subdir_dsts         r%   !test_copytree_retains_permissionsz.TestCopyTree.test_copytree_retains_permissions  s   ,,..',,w11
',,w66w///
%   G-.666
g'788%@@@G./777
g'8995AAA%-':::	(*<===
#U+++)))))12773C3C3KLLLg7G!H!HIIQ'"',,w8H"I"IJJR	T 	T 	Tg7H!I!IJJR'"',,w8I"J"JKKS	U 	U 	U!#g.0gmm<N.O.OPQ.R"T "T!344<'"899A	C 	C 	C 	C 	Cr'   zos.chmodc                    |                                  }t          j                            |                                  d          }|                     t
          j        |           |                     t
          j        t          j                            |                     t          d          |_	        | 
                    t
          j                  5  t          j        ||           d d d            d S # 1 swxY w Y   d S )NrE  zka-boom)r   r+   r;   r<   r   r   r   rJ  PermissionErrorr   r   r   rK  )r   
mock_patchrN  rO  s       r%   test_copytree_winerrorz#TestCopyTree.test_copytree_winerror  s   
 ,,..',,t||~~}==w///rww'?'?@@@!0!;!;
v|,, 	. 	.OGW---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   C::C>C>c                      fd}g                                   t          j                                                    t          t          j                            d          dd          5 }|                                 d d d            n# 1 swxY w Y   t          j	        |            
                    t                    d           d S )	Nc                 n                        d                                | t                                         |t                                         | t          j                            d                                         |t          j                            d                     d S Nr   )rf   r   rz  r   r+   r;   r<   )r   r   r{   flagr   rz   s     r%   custom_cpfunzETestCopyTree.test_copytree_custom_copy_function.<locals>.custom_cpfun  s    KK!!!S)))!!!S)))QS% 8 8999QS% 8 899999r'   r   r   r5   r6   r7   copy_functionr   )r   rs   r   r=   r+   r;   r<   r  r   rK  r   r   )r   r  rX   r{   r  rz   s   `  @@@r%   "test_copytree_custom_copy_functionz/TestCopyTree.test_copytree_custom_copy_function  s   	: 	: 	: 	: 	: 	: 	: 	: llnno$,,..111"',,sE**C'BBB 	aGGIII	 	 	 	 	 	 	 	 	 	 	 	 	 	 	S====TA&&&&&s   :BB"Br3  r4  r5  r6  c                    t          j        t                     	 t           j                            t          d          }t          j        |           t           j                            |d          }	 t          j        |           n/# t          $ r"}|                     d|z             Y d }~nd }~ww xY w	 t          j	        t          t                     |                     d           nq# t          j        $ r_}|j        d         }|                     t          |          d           |d         \  }}}|                     d|z  |           Y d }~nd }~ww xY wt          j        t          d	           t          j        t          d	           d S # t          j        t          d	           t          j        t          d	           w xY w)
Nr  r8  os.mkfifo(): %sz$shutil.Error should have been raisedr   r   z`%s` is a named pipeTr   )r+   r   r   r;   r<   r3  r  skipTestr   rK  TESTFN2failr   r#   r   r   r   )r   r  pipeer   rz   r{   	error_msgs           r%   test_copytree_named_pipez%TestCopyTree.test_copytree_named_pipe  s   
 		7W\\&(33FHV7<<11D5	$" 5 5 5/!3444444445B000 		@AAAA < K K K  Va000&,Qi#S)  !7$!>	JJJJJJJJ	K M&5555M'666666 M&5555M'66666sa   AF 5B
 	F 

B6B1,F 1B66F :C/ F /E>AEF EF 8Gc                    |                                  }t          j                            |                                  d          }t	          |dfd           t          j        t          j                            |d                     t	          |ddfd           g fd}t          j        |||           |                     t                    d           d S )	NrE  rF  rG  rH  rI  c                 6                         | |f           d S r*   r   )rz   r{   copieds     r%   _copyz6TestCopyTree.test_copytree_special_func.<locals>._copy   s    MM3*%%%%%r'   r  rq   )
r   r+   r;   r<   rC   r   r   rK  r   r   )r   rN  rO  r  r  s       @r%   test_copytree_special_funcz'TestCopyTree.test_copytree_special_func  s    ,,..',,t||~~}==GZ(%000
gz22333GZ4e<<<	& 	& 	& 	& 	& 	>>>>Va(((((r'   c                    |                                  }t          j                            |d          }t	          |d           t          j                            |d          }t          j        |           ||fD ]h}t          j        dt          j                            |d                     t          j        |t          j                            |d                     it          j                            |                                  d          }|                     t          t          j
        ||           t          j                            |                                  d          }t          j
        ||d	
           t          j        |          D ]2\  }}}|                     d|           |                     d|           3t          j                            |                                  d          }t          j
        ||d	           |                     dt          j        |                     d S )NrF  abcdir_a
IDONTEXISTbrokenvalidrE  destination2T)ignore_dangling_symlinksdestination3r\  )r   r+   r;   r<   rC   r   r   r   r   r   rK  walkassertNotInr   rc   )	r   rN  
valid_filer  r   rO  rootdirsfiless	            r%   test_copytree_dangling_symlinksz,TestCopyTree.test_copytree_dangling_symlinks&  s   ,,..W\\':66
:u%%%Wg..
% 	= 	=AJ|RW\\!X%>%>???Jz27<<7#;#;<<<< ',,t||~~}==%'7CCC ',,t||~~~>>4HHHH!#!1!1 	* 	*D$Xu---MM'5)))) ',,t||~~~>>48888j"*W"5"566666r'   c           	      D   |                                  }t          j                            |                                  d          }t          j        t          j                            |d                     t          t          j                            |dd          d          5  	 d d d            n# 1 swxY w Y   t          j        t          j                            |d          t          j                            |d          d           t          j        ||d	           | 	                    t          j        
                    t          j                            |d                               |                     dt          j        t          j                            |d                               t          j                            |                                  d
          }t          j        ||d	           |                     t          j        
                    t          j                            |d                               |                     dt          j        t          j                            |d                               d S )NrE  real_dirrF  r4   link_to_dirTtarget_is_directoryFr\  r  )r   r+   r;   r<   r   r=   r   r   rK  r   re   r   rc   r   )r   rN  rO  s      r%   test_copytree_symlink_dirz&TestCopyTree.test_copytree_symlink_dirA  s   ,,..',,t||~~}==
gz22333"',,w
J??FF 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	

27<<447<<77'+	- 	- 	- 	- 	59999Wm(L(LMMNNNj"*RW\\'=-Q-Q"R"RSSS',,t||~~~>>48888rw||G]'K'KLLMMMj"*RW\\'=-Q-Q"R"RSSSSSs   (B66B:=B:c                 V   |                                  }|dz   }|                     t          j        |d           t          j                            |d          }t          |d           t          j        ||          }| 	                    dgt	          j
        |                     d S )NdestTr   )r   r   r   r   r+   r;   r<   rC   rK  r   rc   )r   rN  rO  rz   rvs        r%   test_copytree_return_valuez'TestCopyTree.test_copytree_return_valueU  s    ,,..F"w555gll7E**3_Wg..%"*R..11111r'   c                    |                                  }|                     t          j        |d           t          j                            |dd          }t          j                            |dd          }t	          j        |           t          j                            |d          }t          |d           t          j	        ||          }| 
                    dgt	          j        |                     d S )NTr   tpg
somevendorz1.0pol)r   r   r   r   r+   r;   r<   makedirsrC   rK  r   rc   )r   base_dirrN  rO  rz   r  s         r%   test_copytree_subdirectoryz'TestCopyTree.test_copytree_subdirectory_  s    <<>>xtDDD',,xd33',,we<<
Ggll7E**3_Wg..%"*R..11111r'   N)r   r   r   rQ  rV  r   r;  rj  rv  r  r  r<  mockpatchr  r  r=  rr   r+   r>  r   r?  r  r  r  r  r  r  rF   r'   r%   rC  rC  	  s       ( ( (&C C C2 "C C #"C>?4 ?4 ?4B(. (. (.TC C C6 ]$$. . %$.' ' '$ XX..0FGG"X_S\Y.;= =7 7= = #" HG7.) ) ) "7 7 #"74 "T T #"T&2 2 2
2 
2 
2 
2 
2r'   rC  c                   l   e Zd Zej        d             Z ej         ee	d          p
e	j
        dk    d          ej        d                         Z ej         ee	d          d          ej        d                         Zej        d             Z ej         ee	d	          o eed
          o eed          d          d             Zej        d             Zej        ej        ej        d                                     Zd Zd Zej        d             Z ej         ee	d          d          d             Zej        d             Zej        d             Zd Zd Zd Zd Zej        d             Z ej         ee	d          d          d             Z ej        d              Z! ej         ee	d!          d"           ej        e"j#        d#k    d$          d%                         Z$d& Z%d' Z& ej        e'pe(pe)d(           ej        e*d)          d*                         Z+d+ Z,d,S )-TestCopyc                 b   |                                  }t          j                            |d          }t          j                            |d          }t          j                            |d          }t          j                            |d          }t	          |d           t	          |d           t          j        ||           t          j        ||           t          j        |t          j        t          j	        z             t          j        |t          j
                   |                     t          j        |          j        t          j        |          j                   t          j        ||           |                     t          j        |          j        t          j        |          j                   t          j        |t          j
                   t          j        ||           |                     t          j        |          j        t          j        |          j                   t          j        |t          j
                   t          j        ||           |                     t          j        |          j        t          j        |          j                   t          j        |t          j
                   t          j        ||           |                     t          j        |          j        t          j        |          j                   d S )Nr   barbazquux)r   r+   r;   r<   rC   r   r   r   r`  S_IRWXGra  assertNotEqualr   r   copymoder   r   r  rz   r{   rf  rg  s         r%   test_copymode_follow_symlinksz&TestCopy.test_copymode_follow_symlinkso  s>   ,,..gll7E**gll7E**7<<//7<<0033

3!!!

3!!!
dl4</000
dl###BGCLL0"'#,,2FGGGS!!!-rws||/CDDD 	dl####&&&-rws||/CDDD
dl###X&&&-rws||/CDDD
dl###(+++-rws||/CDDDDDr'   rY  r^  zrequires os.lchmodc                     t           j        dk    rt           j        nt           j        }|                                 }t           j                            |d          }t           j                            |d          }t           j                            |d          }t           j                            |d          }t          |d           t          |d           t          j        ||           t          j        ||           t          j        |t          j
        t          j        z             t          j        |t          j
                    ||t          j        t          j        z              ||t          j                   t          j	        |          j        }t          j        ||d           |                     t          j        |          j        t          j        |          j                   |                     t          j	        |          j        |            ||t          j                   t          j        ||d           |                     t          j	        |          j        t          j	        |          j                    ||t          j                   t          j        ||d           |                     t          j	        |          j        t          j	        |          j                   d S )Nr^  r   r  r  r  Ffollow_symlinks)r+   ri   r   rY  r   r;   r<   rC   r   r   r`  r  ra  r   r   r  r   r   )r   _lchmodr  rz   r{   rf  rg  old_modes           r%    test_copymode_symlink_to_symlinkz)TestCopy.test_copymode_symlink_to_symlink  sQ    !goo"((29,,..gll7E**gll7E**7<<//7<<0033

3!!!

3!!!
dl4</000
dl###$,t|3444$,'''73<<'(EBBBB(++3(++3	5 	5 	5-x888$,'''#u====-rws||/CDDD$,'''Xu====-rws||/CDDDDDr'   z requires os.lchmod to be missingc                    |                                  }t          j                            |d          }t          j                            |d          }t          j                            |d          }t          j                            |d          }t	          |d           t	          |d           t          j        ||           t          j        ||           t          j        ||d           d S )Nr   r  r  r  Fr  )r   r+   r;   r<   rC   r   r   r  r  s         r%   *test_copymode_symlink_to_symlink_wo_lchmodz3TestCopy.test_copymode_symlink_to_symlink_wo_lchmod  s     ,,..gll7E**gll7E**7<<//7<<0033

3!!!

3!!!(EBBBBBBr'   c                    |                                  }t          j                            |d          }t          j                            |d          }t          j                            |d          }t          j                            |d          }t	          |d           t          j        |          }t          j        ||j        |j        dz
  f           t	          |d           | 	                    t          j        |          j        t          j        |          j                   t          j
        ||           t          j
        ||           t          t          d          r t          j        |t
          j                   n/t          j        dk    rt          j        |t
          j                   t          t          d          r4t          t
          d	          rt          j        |t
          j                   t          j        |          }t          t          d          st          j        dk    rIt'          j        ||d
           | 	                    |j        t          j        |          j                   t'          j        ||d           t          j        |          }t          j        t          j        v r:dD ]7}	|                     t1          ||	          t1          ||	          dz              8t          t          d          st          j        dk    r |                     |j        |j                   t          t          d          r0t          |d          r |                     |j        |j                   t'          j        ||d           |                     t9          t          j        |          j        t          j        |          j        z
            dk                d S )Nr   r  r  quxg      E@rY  r^  rZ  r[  Tr  Fst_atimest_mtimer   rd  g?)r   r+   r;   r<   rC   r   utimer  r  r  r   rr   rY  ra  ri   r   rZ  r[  r   r   copystatr   r	  assertLessEqualr!   r   rd  r   abs)
r   r  rz   r{   rf  rg  rh  src_link_statdst_link_statattrs
             r%   test_copystat_symlinkszTestCopy.test_copystat_symlinks  sU   ,,..gll7E**gll7E**7<<//7<<//373<<
x((4/1 	2 	2 	23BGCLL1273<<3HIII

3!!!

3!!!2x   	-Ih----W__HXt|,,,2z"" 	2wt['A'A 	2K$.111**2x   	MBGtOOOHhEEEE 5rws||7KLLL(EBBBB**8r222. G G$$W]D%A%A%,]D%A%AA%EG G G G2x   	KBGtOO]2M4IJJJ2z"" 	Mw}j'I'I 	M]3]5KLLL#u====BGCLL1BGCLL4IIJJ  	! 	! 	! 	! 	!r'   chflags
EOPNOTSUPPENOTSUPz)requires os.chflags, EOPNOTSUPP & ENOTSUPc                 x   |                                  }t          j                            |d          }t          j                            |d          }t	          |d           t	          |d           d }t          j        }	 t          j        t          j        fD ],} ||          t          _        t          j
        ||           - |t          j        t          j        z             t          _        |                     t          t          j
        ||           |t          _        d S # |t          _        w xY w)Nr   file2xxxc                 8     t                      dd fd
}|S )NTr  c                    _         r*   )r"   )r;   flagsr  errexs      r%   _chflags_raiserzlTestCopy.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser.<locals>._chflags_raiser  s    r'   r  )r  r  r  s   ` @r%   make_chflags_raiserzSTestCopy.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser  s@    B@D         #"r'   )r   r+   r;   r<   rC   r  r"   r  r  r   r  r   r    )r   r   r   r  r  old_chflagsr  s          r%   -test_copystat_handles_harmless_chflags_errorsz6TestCopy.test_copystat_handles_harmless_chflags_errors  s   
 VW--VW--5%   5%   	# 	# 	# j	%'6 . .0055
u----,,U-=-MNNBJgvuEEE$BJJJBJ$$$$s   BD+ +D9c                   	
 |                                  }t          j                            |d          
t	          
d           t          j                            |d          }t	          |d           t          j        
|           t          j        
dd           t          j        
dd           t          j        
|           |                     t          t          j
        
                    t          t          j
        |                               |                     t          j        
d          t          j        |d                     t          j        |           t	          |d           t          t          j        d          		fd}	 t          j        |t          _        t          j        
|           |                     dt          j
        |                     t          _        n# t          _        w xY wd	d

fd
}	 t          j
        |t          _
        t          j        
|           t          _
        n# t          _
        w xY wt          j                            |d          
t          j                            |d          }t	          

           t	          ||           t          j        
dd           t          j        |dd           t          j        |d           t          j                            |d          }t          j                            |d          }t	          ||           t	          ||           t          j        
|           t          j        ||           |                     t          j        |d          d           |                     t          j        |d          d           d S )Nr   r  user.foo   42zuser.bar   43EPERMc                 .    |dk    r | ||fi | d S )Nr  rF   )fnamer  valr$   orig_setxattros_errors       r%   _raise_on_user_fooz3TestCopy.test_copyxattr.<locals>._raise_on_user_foo  s5    z!!eT399&99999r'   Tr  c                ^    | k    rt          t          j        d           | |          S )NzOperation not supportedr  )r    r"   r  )r  r  orig_listxattrrz   s     r%   _raise_on_srcz.TestCopy.test_copyxattr.<locals>._raise_on_src,  s4    ||em-FGGG!>%IIIIr'   the_originalthe_original_rozuser.the_values   fiddlyi$  the_copythe_copy_ro)r   r+   r;   r<   rC   r   
_copyxattrsetxattrr   rb   	listxattrgetxattrr(  r    r"   r  r   r   r  )r   r  r{   r   r  srcrodstror  r  r  rz   s          @@@@r%   test_copyxattrzTestCopy.test_copyxattr  s   ,,..gll7E**3gll7E**3 	#s###
CU+++
CU+++#s###S 1 122F2<;L;L4M4MNNNC,,C,,	. 	. 	. 		#35;00	: 	: 	: 	: 	: 	:
	(KM,BKc3'''MM*bl3&7&7888'BKK-BK''''48 	J 	J 	J 	J 	J 	J 	J 	J	*\N(BLc3''')BLL>BL)))) gll7N33W&78835%   
C)9555
E+Y777
gll7J//Wm4435%   S!!!u%%%S*:;;YGGGU,<==yIIIIIs   $AH H!-I I)c                 p   |                                  }t          j                            |d          }t          j                            |d          }t	          |d           t          j        ||           t          j        |dd           t          j        |ddd           t          j                            |d          }t          j                            |d	          }t	          |d           t          j        ||           t          j        ||d           | 	                    t          j
        |dd          d           |                     t          t          j
        |d           t          j        ||d           | 	                    t          j
        |d          d           d S )
Nr   r  ztrusted.foor  r  Fr  r  r  )r   r+   r;   r<   rC   r   r	  r   r  r   r  r   r    )r   r  rz   rf  r{   rg  s         r%   test_copyxattr_symlinksz TestCopy.test_copyxattr_symlinksH  sr    ,,..gll7E**7<<//3

3!!!
C...
HmUEJJJJgll7E**7<<//3

3!!!(HeDDDDX}eTTTV[\\\'2;]CCC(C????S-88%@@@@@r'   c                    d}|                                  }t          ||fd           t          j                            ||          }|                                  } |||           t          j                            ||          }||fS )NrF  r  )r   rC   r+   r;   r<   )r   methodr  r   r   tmpdir2r  s          r%   
_copy_filezTestCopy._copy_fileb  s{    FE?E***VU++,,..ugWe,,u~r'   c                 6   |                      t          j                  \  }}|                     t          j                            |                     |                     t	          j        |          j	        t	          j        |          j	                   d S r*   )
r  r   copyr   r+   r;   r   r   r   r   )r   r   r  s      r%   	test_copyzTestCopy.test_copyl  sk    v{33uu--.../1GHHHHHr'   c                    |                                  }t          j                            |d          }t          j                            |d          }t          j                            |d          }t	          |d           t          j        ||           t          t          d          r,t          j        |t          j	        t          j
        z             t          j        ||d           |                     t          j                            |                     |                     t!          |          t!          |                     t          j        |           t          j        ||d           |                     t          j                            |                     |                     t          j        |          t          j        |                     t          t          d          rF|                     t          j        |          j        t          j        |          j                   d S d S )Nr   r  r  rY  Tr  F)r   r+   r;   r<   rC   r   rr   rY  r   r`  ra  r   r  r   re   r   r_   r(  r   rb  r   r   )r   r  rz   r{   rf  s        r%   test_copy_symlinkszTestCopy.test_copy_symlinksr  s   ,,..gll7E**gll7E**7<<//3

3!!!2x   	=Iht| ;<<<Hc48888,,---33888
	#Hc59999s++,,,S))2;x+@+@AAA2x   	4RXh//7Xc]]24 4 4 4 4	4 	4r'   r  zrequires os.utimec                 h   |                      t          j                  \  }}|                     t          j                            |                     t	          j        |          }t	          j        |          }|                     |j	        |j	                   dD ]7}| 
                    t          ||          t          ||          dz              8t          t          d          rDt          |d          r6|                     t          |d          t          |d                     d S d S d S )Nr  r   r  rd  )r  r   copy2r   r+   r;   r   r   r   r   r  r!   rr   )r   r   r  
file1_stat
file2_statr  s         r%   
test_copy2zTestCopy.test_copy2  s3    v|44uu--...WU^^
WU^^
+Z-?@@@* 	@ 	@D  T!:!:!(T!:!:Q!>@ @ @ @2y!! 	>gj*&E&E 	>WZ<<$Z<<> > > > >	> 	> 	> 	>r'   c                    |                                  }t          j                            |d          }t          j                            |d          }t          j                            |d          }t	          |d           t          j        ||           t          t          d          r,t          j        |t          j	        t          j
        z             t          t          d          r4t          t          d          rt          j        |t          j                   t          j        |          }t          j        |          }t          j        ||d           |                     t          j                            |                     |                     t'          |          t'          |                     t          j        |           t          j        ||d	           |                     t          j                            |                     |                     t          j        |          t          j        |                     t          j        |          }t          j        t          j        v r:d
D ]7}|                     t5          ||          t5          ||          dz              8t          t          d          r@|                     |j        |j                   |                     |j        |j                   t          t          d          r2t          |d          r$|                     |j        |j                   d S d S d S )Nr   r  r  rY  rZ  r[  Tr  Fr  r   rd  )r   r+   r;   r<   rC   r   rr   rY  r   r`  ra  rZ  r[  r   r   r  r   re   r   r_   r(  r   rb  r  r	  r  r!   r   r  rd  )	r   r  rz   r{   rf  rh  r  ri  r  s	            r%   test_copy2_symlinkszTestCopy.test_copy2_symlinks  s   ,,..gll7E**gll7E**7<<//3

3!!!2x   	=Iht| ;<<<2z"" 	2wt['A'A 	2K$.11173<<**XsD9999,,---33888
	#XsE::::s++,,,S))2;x+@+@AAA8C==8r222. B B$$W]D%A%A%,Xt%<%<q%@B B B B2x   	D]2H4DEEE 0(2BCCC2z"" 	Hw}j'I'I 	H]3X5FGGGGG	H 	H 	H 	Hr'   c                    |                                  }t          j                            |d          }t          j                            |d          }t	          |d           t          j        |dd           t          j        ||           |                     t          j	        |d          t          j	        |d                     t          j
        |           d S )Nr   r  r  r  )r   r+   r;   r<   rC   r	  r   r  r   r  r(  )r   r  rz   r{   s       r%   test_copy2_xattrzTestCopy.test_copy2_xattr  s    ,,..gll7E**gll7E**3
CU+++S#C,,C,,	. 	. 	. 		#r'   c                 (   t           j        t           j        fD ]}|                                 }|                                 }t          j                            |d          }t          |d            |||          }|                     |t          j                            |d                      ||t          j                            |d                    }|                     |t          j                            |d                     d S )Nr   r  )	r   r  r  r   r+   r;   r<   rC   r   )r   r   rN  rO  rz   r  s         r%   test_copy_return_valuezTestCopy.test_copy_return_value  s    ;- 	? 	?BllnnGllnnG',,w..CsE"""C!!BRgu!=!=>>>Cgu5566BRgu!=!=>>>>	? 	?r'   c                 D    |                      t          j                   d S r*   )_test_copy_dirr   r  r9  s    r%   test_copy_dirzTestCopy.test_copy_dir  s    FK(((((r'   c                 D    |                      t          j                   d S r*   )r&  r   r  r9  s    r%   test_copy2_dirzTestCopy.test_copy2_dir  s    FL)))))r'   c                    |                                  }t          j                            |d          }|                                  }t          j                            |d          }t	          |d           t
          j        dk    rt          }nt          }| 	                    ||||           | 	                    ||||            |||           d S Nr   does_not_exist/win32)
r   r+   r;   r<   rC   r   r?  r  IsADirectoryErrorr   )r   	copy_funcrN  src_filer   r{   r  s          r%   r&  zTestCopy._test_copy_dir  s    ,,..7<<//||~~gll7$5668U###<7""!CC#C#y$888 	#y$444	(D!!!!!r'   c                    |                                  }t          j                            |d          }t          j                            |d          }t          j                            |d          }t          j                            |d          }t	          |d           t          j        ||           t          j        ||d           |                     t          j        	                    |                     | 
                    t          j        |          t          j        |                     t          j        ||           |                     t          j        	                    |                     d S )Nrz   r{   rg  r   r   Fr  )r   r+   r;   r<   rC   r   r   copyfiler   re   r   rb  r   )r   r  rz   r{   rg  r   s         r%   test_copyfile_symlinkszTestCopy.test_copyfile_symlinks  s    ,,..gll7E**gll7E**7<<44w||GV,,3

3h>>>>x00111T**BK,A,ABBBc""",,-----r'   r   zrequires os.linkc                 r   t          j        t                     t           j                            t          d          }t           j                            t          d          }	 t          |dd          5 }|                    d           d d d            n# 1 swxY w Y   	 t          j        ||           n/# t          $ r"}| 	                    d|z             Y d }~nd }~ww xY w| 
                    t          j        t          j        ||           t          |dd          5 }|                     |                                d           d d d            n# 1 swxY w Y   t          j        |           t          j        t          d	
           d S # t          j        t          d	
           w xY w)Nr,  r-  r5   r6   r7   cheddarzos.link(): %sr]   Tr   )r+   r   r   r;   r<   r=   r>   r   r  r  r   r   r   r2  r   r^   r(  r   )r   rz   r{   rX   r  s        r%   'test_dont_copy_file_onto_link_to_itselfz0TestCopy.test_dont_copy_file_onto_link_to_itself  s    	gll68,,gll66**	6c3111 #Q	"""# # # # # # # # # # # # # # #3S!!!!" 3 3 3o1222222223f2FOS#NNNc3111 6Q  95556 6 6 6 6 6 6 6 6 6 6 6 6 6 6IcNNNM&555555FM&55555s   %F 7BF BF  B!F %B; :F ;
C'C"F "C''AF ()EF E!!F $E!%F F6c                    t          j        t                     t           j                            t          d          }t           j                            t          d          }	 t          |dd          5 }|                    d           d d d            n# 1 swxY w Y   t          j        d|           |                     t          j
        t          j        ||           t          |dd          5 }|                     |                                d           d d d            n# 1 swxY w Y   t          j        |           t          j        t          d	           d S # t          j        t          d	           w xY w)
Nr,  r-  r5   r6   r7   r5  r]   Tr   )r+   r   r   r;   r<   r=   r>   r   r   r   r   r2  r   r^   r(  r   )r   rz   r{   rX   s       r%   *test_dont_copy_file_onto_symlink_to_itselfz3TestCopy.test_dont_copy_file_onto_symlink_to_itself  s    	gll68,,gll66**	6c3111 #Q	"""# # # # # # # # # # # # # # #
 Jx%%%f2FOS#NNNc3111 6Q  95556 6 6 6 6 6 6 6 6 6 6 6 6 6 6IcNNNM&555555FM&55555sU   %E( 7BE( BE(  B!AE( 7)D, E( ,D00E( 3D04E( (Fr3  r4  r5  r6  c                    	 t          j        t                     n/# t          $ r"}|                     d|z             Y d }~nd }~ww xY w	 |                     t          j        t          j        t          t                     |                     t          j        t          j        t          t                     t          j        t                     d S # t          j        t                     w xY w)Nr  )r+   r3  r   r  r  r   r   SpecialFileErrorr2  r  __file__r(  )r   r  s     r%   test_copyfile_named_pipez!TestCopy.test_copyfile_named_pipe*  s    	1If 	1 	1 	1MM+a/00000000	1	f5 &B B Bf5 &6C C C IfBIfs!    
AAAA,C C.c                    |                                  }|                                  }t          j                            |d          }t          j                            |d          }t	          |d           t          j        ||          }|                     t          j                            |                     | 	                    t          |          t          |                     d S )Nr  r   )r   r+   r;   r<   rC   r   r2  r   r   r   r_   )r   rN  rO  dst_filer0  r  s         r%   test_copyfile_return_valuez#TestCopy.test_copyfile_return_value:  s    ,,..,,..7<<//7<<//8U###_Xx00r**+++8,,i.A.ABBBBBr'   c                 p   |                                  }t          j                            |d          }t	          |d           |                     t          t          j        ||           |                     t          t          j        ||           | 
                    t          |          d           d S r  )r   r+   r;   r<   rC   r   r   r   r2  r   r   r_   )r   rN  r0  s      r%   test_copyfile_same_filez TestCopy.test_copyfile_same_fileE  s     ,,..7<<//8U###-(HMMM%(HEEE8,,e44444r'   zMOn MACOS, Solaris and Windows the errors are not confusing (though different)zNot valid on AIX, see gh-92670c                    |                                  }t          j                            |d          }t          j                            |d          }t	          |d           |                     t          t          j        ||           d S )Nr   r,  )	r   r+   r;   r<   rC   r   r   r   r2  )r   rN  r0  r{   s       r%   test_copyfile_nonexistent_dirz&TestCopy.test_copyfile_nonexistent_dirQ  so     ,,..7<<//gll7$5668U###+V_hLLLLLr'   c                     |                                  }t          j                            |d          }|                                  }t          j                            |d          }t	          |d           t
          j        dk    rt          }nt          }| 	                    |t          j        ||           | 	                    |t          j        ||           | 	                    |t          j        ||           d S r+  )r   r+   r;   r<   rC   r   r?  r  r.  r   r   r2  )r   rN  r0  r   r{   r  s         r%   test_copyfile_copy_dirzTestCopy.test_copyfile_copy_dir^  s     ,,..7<<//||~~gll7$5668U###<7""!CC#C#v===#v'BBB#vg>>>>>r'   N)-r   r   r   r   r;  r  r<  r=  rr   r+   ri   r  r>  r  r  r"   r  skip_unless_xattrr  skip_unless_dac_overrider  r  r  r  r  r   r"  r$  r'  r)  r&  r3  r6  r8  r   r?  r<  r?  rA  MACOSSOLARISr   r   rC  rE  rF   r'   r%   r  r  k  s        "E E #"E< XX..A"'T/CWXX"E E #" YXE< X_WWR**,NOO"
C 
C #" PO
C "(! (! #"(!T XY// 3 553 	22DF F% %	F F%6  =J =J ! =J~ " 'A A (' !  #"A.  I I I "4 4 #"40 XW--/BCC> > DC>  " H  H #" HD  
 
 ! 

? 
? 
?) ) )* * *" " "$ ". . #".  XV,,.@AA6 6 BA6& "6 6 #"6( XX..0FGGX_S\Y.;= = = = HG	C 	C 	C
5 
5 
5 X_U0g0  3B  C  C X_S:;;M M <;	 C  C
M? ? ? ? ?r'   r  c                      e Zd Z ej                    d             Zd Zd$dZ ej                     ej	         e
j        d          d          d                         Z ej                    d             Z ej                     ej	         e
j        d	          d
          d                         Z ej                     ej	         e
j        d          d          d                         Zd Z ej                    d             Z ej                     ej	        ed          d                         Zd Zd Z ej                    d             Zd Zd Z ej                    d             Zd Zd Zd Zd Z ej                    d             Z ej                    d             Z  ej!                     ej"        e#o
 e$             d          d                          Z% ej                    d!             Z&d" Z'd#S )%TestArchivesc                    |                      d          \  }}|                                 }t          j        |           t          j                            |          }t          j                            t          j                            |          d          }t          j	        |          5  t          5  t          j                            |          }t          |d|d          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     ||dz              |                     t          j                            |                     |                     t!          j        |                     t!          j        |d          5 }|                     |                                g d           d d d            n# 1 swxY w Y   t          j	        |          5  t          5  t          |d|d          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     ||d	z              |                     t          j                            |                     |                     t!          j        |                     t!          j        |d
          5 }|                     |                                g d           d d d            d S # 1 swxY w Y   d S )Nr   archivegztar..tar.gzzr:gz)rO  z./subz./sub2z./file1z./file2z./sub/file3tar.tarr]   )_create_filesr   r+   r   r;   rJ  r<   basenamer   
change_cwdno_chdirabspathr   r   r   rL  tarfile
is_tarfiler=   assertCountEqualgetnames)	r   root_dirr  r  work_dirrel_base_name	base_nametarballtfs	            r%   test_make_tarballzTestArchives.test_make_tarballu  s    "//33(,,..
7??7++RW%5%5g%>%>	JJ!(++ 	J 	JX 	J 	J66I"='8SIIG	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J
 	)i"7888w//000*733444\'6** 	Ib!!"++--#H #H #HI I I	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I !(++ 	H 	HX 	H 	H"=%3GGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H)f"4555w//000*733444\'3'' 	H2!!"++--#G #G #GH H H	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs   1D92C7+D7C;	;D>C;	?DDD +GGG6H4>HH4H!	!H4$H!	%H44H8;H8+K>>LLc                     t          j        |          5 }|                                }|                                 t	          |          cd d d            S # 1 swxY w Y   d S r*   )rX  r=   r[  sortr:   )r   r;   rQ  rr  s       r%   _tarinfozTestArchives._tarinfo  s    \$ 	 3LLNNEJJLLL<<	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   7AA Adistc                    |                                  }t          j                            ||          }t          j        |d           t          |dfd           t          |dfd           t          j        t          j                            |d                     t          |ddfd           t          j        t          j                            |d                     |rt          |d	fd           ||fS )
NT)exist_okr   r  r  rX  file3sub2outer)r   r+   r;   r<   r  rC   r   )r   r  r\  rf  s       r%   rS  zTestArchives._create_files  s    <<>>w||Hh//
D4((((D'?E***D'?E***
dE**+++D%)5111
dF++,,, 	3'*E222!!r'   rQ  zNeed the tar command to runc                    |                                  \  }}t          j                            |                                 d          }t
          5  t          |d||          }d d d            n# 1 swxY w Y   |                     ||dz              |                     t          j        	                    |                     t          j                            |d          }ddd|g}t          j        dk    r^dd l}t          |                                d                             d	          d                   d
k    r|                    dd           t!          j        ||t           j                   |                     t          j        	                    |                     |                     |                     |          |                     |                     t
          5  t          |d||          }d d d            n# 1 swxY w Y   |                     ||dz              |                     t          j        	                    |                     t
          5  t          |d||d          }d d d            n# 1 swxY w Y   |                     ||dz              |                     t          j        	                    |                     d S )NrM  rN  rP  zarchive2.tarrQ  z-cfr   r   rO     r   z--no-mac-metadatacwdstdoutrR  Tdry_run)rS  r+   r;   r<   r   rV  r   r   r   rL  r   r?  r   mac_verr   insertr   
check_callDEVNULLre  )r   r\  r  r_  r`  tarball2tar_cmdr?  s           r%   test_tarfile_vs_tarz TestArchives.test_tarfile_vs_tar  sk    "//11(GLL;;	 	K 	K"9gxJJG	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	)i"7888w//000 7<<.99%:<8## OOO8##%%a(..s33A6772==q"5666g8%/%7	9 	9 	9 	9 	x00111w//x1H1HIII  	I 	I"9eXxHHG	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I)f"4555w//000  	1 	1"9eXx+/1 1 1G	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	)f"4555w//00000s6   A00A47A40HHH,JJJc                 L   |                                  \  }}|                                 }t          j        |           t          j                            |          }t          j                            t          j                            |          d          }t          j	        |          5  t          5  t          j                            |          }t          |d|          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     ||dz              |                     t          j                            |                     |                     t!          j        |                     t!          j        |          5 }|                     |                                g d           d d d            n# 1 swxY w Y   t          j	        |          5  t          5  t          j                            |          }t          |d||          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     ||dz              |                     t          j                            |                     |                     t!          j        |                     t!          j        |          5 }|                     |                                g d           d d d            d S # 1 swxY w Y   d S )NrM  zip.zip)dist/	dist/sub/
dist/sub2/
dist/file1
dist/file2dist/sub/file3rk  )r}  r~  r  r  r  r  )rS  r   r+   r   r;   rJ  r<   rT  r   rU  rV  rW  r   r   r   rL  zipfile
is_zipfileZipFilerZ  namelist)	r   r\  r  r  r]  r^  r_  rh   zfs	            r%   test_make_zipfilezTestArchives.test_make_zipfile  s_    "//11(,,..
7??7++RW%5%5g%>%>	JJ!(++ 	? 	?X 	? 	?66I}eX>>C	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	i&0111s++,,,*3//000_S!! 	R!!"++--    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 !(++ 	I 	IX 	I 	I66I}eXxHHC	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	i&0111s++,,,*3//000_S!! 	DR!!"++--C C CD D D	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds   0D81C5)D5C9	9D<C9	=DDD+GGG3I;2H9-I9H=	=I H=	III!+LL Lr{  zNeed the zip command to runc                    |                                  \  }}t          j                            |                                 d          }t
          5  t          |d||          }d d d            n# 1 swxY w Y   |                     ||dz              |                     t          j        	                    |                     t          j                            |d          }dddd|g}t          j        ||t          j                   |                     t          j        	                    |                     t          j        |          5 }|                                }d d d            n# 1 swxY w Y   t          j        |          5 }|                                }	d d d            n# 1 swxY w Y   |                     t!          |          t!          |	                     d S )NrM  r{  r|  zarchive2.zipz-qz-rrn  )rS  r+   r;   r<   r   rV  r   r   r   rL  r   ru  rv  r  r  r  rb   )
r   r\  r  r_  rM  archive2zip_cmdr  rr  names2s
             r%   test_zipfile_vs_zipz TestArchives.test_zipfile_vs_zip  sf    "//11(GLL;;	 	I 	I"9eXxHHG	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	)f"4555w//000 7<<.99$nh?g8%/%7	9 	9 	9 	9 	x00111_W%% 	"KKMME	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"_X&& 	#"[[]]F	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#v77777s6   A00A47A4E55E9<E9F55F9<F9unzipzNeed the unzip command to runc                 .   |                                  \  }}t          j                            |                                 d          }t
          5  t          |d||          }d d d            n# 1 swxY w Y   |                     ||dz              |                     t          j        	                    |                     dd|g}t          j        |          5  	 t          j        |t          j                   n{# t          j        $ ri}|j                            d          }d	|v r|                     d
           d}|                     |                    ||                     Y d }~nd }~ww xY wd d d            d S # 1 swxY w Y   d S )NrM  r{  r|  r  z-t)stderrreplace)r   zunrecognized option: tzunzip doesn't support -tz{}

**Unzip Output**
{})rS  r+   r;   r<   r   rV  r   r   r   rL  r   rU  r   check_outputSTDOUTCalledProcessErroroutputdecoder  r  format)	r   r\  r  r_  rM  r  r   detailsmsgs	            r%   test_unzip_zipfilezTestArchives.test_unzip_zipfile  s#    "//11(GLL;;	 	I 	I"9eXxHHG	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	)f"4555w//000 D'*!(++ 	4 	44'
8IJJJJJ0 4 4 4*++9+==+w66MM"<===2		#**S'22333333334	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4sO   A00A47A4F
! DF
E:AE50F
5E::F

FFc                     |                                  }t          j                            |d          }|                     t
          t          |d           d S )NrM  r  )r   r+   r;   r<   r   
ValueErrorr   )r   r   r_  s      r%   test_make_archivezTestArchives.test_make_archive5  sD    GLL33	*lIuEEEEEr'   c                 J   t           r5t          j        d          d         }t          j        d          d         }ndx}}|                                 \  }}t          j                            | 	                                d          }t          |d||||          }|                     t          j                            |                     t          |d||          }|                     t          j                            |                     t          |d||||          }|                     t          j                            |                     t          |d||dd          }|                     t          j                            |                     d S )	Nr   r  rM  r{  ownergrouprQ  	kjhkjhkjgoihohoh)UID_GID_SUPPORTgrpgetgrgidpwdgetpwuidrS  r+   r;   r<   r   r   r   rL  )r   r  r  r\  r  r_  rh   s          r%   test_make_archive_owner_groupz*TestArchives.test_make_archive_owner_group:  sk     	#LOOA&ELOOA&EE""EE!//11(GLL;;	9eXxu!&( ( (s++,,,9eXx@@s++,,,9eXx!&e5 5 5s++,,,9eXx!,I? ? ?s++,,,,,r'   Requires grp and pwd supportc           
      D   |                                  \  }}t          j                            |                                 d          }t          j        d          d         }t          j        d          d         }t          j
        |          5  t          5  t          |d|d||          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     t          j                            |                     t          j        |          }	 |                                D ]8}|                     |j        d           |                     |j        d           9	 |                                 d S # |                                 w xY w)NrM  r   rN  rf  r  )rS  r+   r;   r<   r   r  r  r  r  r   rU  rV  r   r   rL  rX  r=   
getmembersr   uidgidr  )	r   r\  r  r_  r  r  archive_namerM  members	            r%   test_tarfile_root_ownerz$TestArchives.test_tarfile_root_ownerV  s    "//11(GLL;;	Q"Q"!(++ 	B 	BX 	B 	B'	7Hf.35B B BL	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B
 	|44555 ,|,,	!,,.. 0 0  Q///  Q////0 MMOOOOOGMMOOOOsC   CB<0C<C 	 CC 	CCC%AF	 	Fc                    t          j                    }|                                 }d }g fd}t          d|g d           	 t	          j        t           d|          5 	 t          dd|           n# t          $ r Y nw xY wd d d            n# 1 swxY w Y   |                     t          j                    |           |                     ||g           t          d           d S # t          d           w xY w)Nc                      t                      r*   )RuntimeError)r#   kws     r%   _breaksz3TestArchives.test_make_archive_cwd.<locals>._breaksp  s    .. r'   c                 H                         |             |            d S r*   r   )r;   r  
orig_chdirs    r%   _chdirz2TestArchives.test_make_archive_cwd.<locals>._chdirs  s+    KKJtr'   r  xxx filechdir)r\  )
r+   ru   r   r   r   r  r   r  r   r   )r   current_dirr\  r  r  r  r  s        @@r%   test_make_archive_cwdz"TestArchives.test_make_archive_cwdm  so   ikk<<>>	! 	! 	!	 	 	 	 	 	 	 wJ???		-"2w77 : AAAAA    D              
 RY[[+666THk#:;;;%e,,,,,%e,,,,sU   C/ #B%A87B8
BBBBC/ BC/ BAC/ /D c                 r   |                                  }t          j        |          5  t          5  |                     t          dd          d           |                     t          j        	                    d                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NtestrQ  ztest.tar
r   r   rU  rV  r   r   r   r+   r;   rL  r   r\  s     r%   test_make_tarfile_in_curdirz(TestArchives.test_make_tarfile_in_curdir  s   <<>>!(++ 	8 	8X 	8 	8\&%88*EEEOOBGNN:66777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	85   B,ABB,B	B,B	B,,B03B0c                 r   |                                  }t          j        |          5  t          5  |                     t          dd          d           |                     t          j        	                    d                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  r{  ztest.zipr  r  s     r%   test_make_zipfile_in_curdirz(TestArchives.test_make_zipfile_in_curdir  s     <<>>!(++ 	8 	8X 	8 	8\&%88*EEEOOBGNN:66777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8r  c                    |                      t          t          dd           |                      t          t          dd d           |                      t          t          dd ddg           t          dd dgd           d	 t                      D             }|                     d|           t          d           d
 t                      D             }|                     d|           d S )Nr  r   c                      t           S r*   xrF   r'   r%   <lambda>z;TestArchives.test_register_archive_format.<locals>.<lambda>      Q r'   c                      t           S r*   r  rF   r'   r%   r  z;TestArchives.test_register_archive_format.<locals>.<lambda>  r  r'   )r   rq   )r   rq   r   c                      t           S r*   r  rF   r'   r%   r  z;TestArchives.test_register_archive_format.<locals>.<lambda>  s    q r'   r  c                     g | ]\  }}|S rF   rF   rP   ri   paramss      r%   rR   z=TestArchives.test_register_archive_format.<locals>.<listcomp>      BBBLD&4BBBr'   c                     g | ]\  }}|S rF   rF   r  s      r%   rR   z=TestArchives.test_register_archive_format.<locals>.<listcomp>  r  r'   )r   	TypeErrorr   r   r   r   r  )r   formatss     r%   test_register_archive_formatz)TestArchives.test_register_archive_format  s    )%<eQGGG)%<eYY	 	 	)%<eYY!9-	/ 	/ 	/ 	 yy6(JGGGBB,?,A,ABBBeW%%%!%(((BB,?,A,ABBB(((((r'   c           	         |                      t          j        t           d           dD ]-}|                     |          5  |                                 }t          j                            |d          }| 	                    t                    5 }t          t          d||           d d d            n# 1 swxY w Y   |                     |j        j        t          j                   |                     |j        j        |           |                     t          j                            t           d                     t'          j        |          \  }}t          j        |           | 	                    t,                    5 }t          t          d||           d d d            n# 1 swxY w Y   |                     |j        j        t          j                   |                     |j        j        |           |                     t          j                            t           d                     d d d            n# 1 swxY w Y   /d S )NrR  FTrq  nonexistingrQ  r   r   r   rw   r   subTestr   r+   r;   r<   r   r   r   r   r   r"   ENOENTr   r   r   rs   r'  r  r   ENOTDIRr   rr  r  nonexisting_filer   tmp_fdtmp_files          r%   test_make_tarfile_rootdir_nodirz,TestArchives.test_make_tarfile_rootdir_nodir  s   	(V///:::$ 	B 	BGg.. B B,,..#%7<<#G#G &&'899 SR 0@'RRRRS S S S S S S S S S S S S S S  !3U\BBB  !68HIII  6!@!@AAA#+#3#@#@#@    &&'9:: Kb 'JJJJK K K K K K K K K K K K K K K  !3U]CCC  !6AAA  6!@!@AAAB B B B B B B B B B B B B B B	B 	B]   AIB8,I8B<<I?B< CIF2&I2F66I9F6:BII	I	c           	         |                      t          j        t           d           dD ]-}|                     |          5  |                                 }t          j                            |d          }| 	                    t                    5 }t          t          d||           d d d            n# 1 swxY w Y   |                     |j        j        t          j                   |                     |j        j        |           |                     t          j                            t           d                     t'          j        |          \  }}t          j        |           | 	                    t,                    5 }t          t          d||           d d d            n# 1 swxY w Y   |                     |j        j        t          j                   |                     |j        j        |           |                     t          j                            t           d                     d d d            n# 1 swxY w Y   /d S )Nr|  r  rq  r  r{  r   r  r  s          r%   test_make_zipfile_rootdir_nodirz,TestArchives.test_make_zipfile_rootdir_nodir  s    		(V///:::$ 	B 	BGg.. B B,,..#%7<<#G#G &&'899 SR 0@'RRRRS S S S S S S S S S S S S S S  !3U\BBB  !68HIII  6!@!@AAA#+#3#@#@#@    &&'9:: Kb 'JJJJK K K K K K K K K K K K K K K  !3U]CCC  !6AAA  6!@!@AAAB B B B B B B B B B B B B B B	B 	Br  c                      | j         |d fi |  | j         |t          j        fi |  | j         |t          fi | d S )Nc                     | S r*   rF   r;   s    r%   r  z3TestArchives.check_unpack_archive.<locals>.<lambda>  s     r'   )#check_unpack_archive_with_converterr  r  r   )r   r  r$   s      r%   check_unpack_archivez!TestArchives.check_unpack_archive  s}    00%%	1 	1)/	1 	1 	100GL	, 	,$*	, 	, 	,00LLVLLLLLr'   c                    |                                  \  }}t          |          }|                    d           t          j                            |                                 d          }t          ||||          }|                                 }	t           ||           ||	          fi | | 	                    t          |	          |           |                                 }
t           ||           ||
          fd|i| | 	                    t          |
          |           | 
                    t          j                  5  t           |t                    fi | d d d            n# 1 swxY w Y   | 
                    t                    5  t           |t                    fddi| d d d            d S # 1 swxY w Y   d S )Nrk  rM  r  r  )rS  rg   r(  r+   r;   r<   r   r   r   r   r   r   	ReadErrorr   r  )r   r  	converterr$   r\  r  expectedr_  r   r  tmpdir3s              r%   r  z0TestArchives.check_unpack_archive_with_converter  sh   !//11(H%%   GLL;;		68XFF ,,..yy**IIg,>,>II&III'**H555 ,,..yy**IIg,>,> 	! 	!v 	!	! 	! 	!'**H555v/00 	8 	899V,,77777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8z** 	F 	F99V,,EEUEfEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs$   E77E;>E;GGGc                     |                      |d           |                      |d           t          j        |           5  |                      |           d d d            d S # 1 swxY w Y   d S )Nfully_trustedfilterdata)r  r   check_no_warnings)r   r  s     r%   check_unpack_tarballz!TestArchives.check_unpack_tarball  s    !!&!AAA!!&!888.t44 	. 	.%%f---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   A&&A*-A*c                 0    |                      d           d S )NrQ  r  r9  s    r%   test_unpack_archive_tarz$TestArchives.test_unpack_archive_tar  s    !!%(((((r'   c                 0    |                      d           d S )NrN  r  r9  s    r%   test_unpack_archive_gztarz&TestArchives.test_unpack_archive_gztar      !!'*****r'   c                 0    |                      d           d S )Nbztarr  r9  s    r%   test_unpack_archive_bztarz&TestArchives.test_unpack_archive_bztar  r  r'   z(AIX MAXDATA must be 0x20000000 or largerc                 0    |                      d           d S )Nxztarr  r9  s    r%   test_unpack_archive_xztarz&TestArchives.test_unpack_archive_xztar  s     	!!'*****r'   c                     |                      d           |                     t                    5  |                      dd           d d d            d S # 1 swxY w Y   d S )Nr{  r  r  )r  r   r  r9  s    r%   test_unpack_archive_zipz$TestArchives.test_unpack_archive_zip  s    !!%(((y)) 	< 	<%%eF%;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   AAAc                     t                      } fd}t          dddg|dg           t          dd                                t          t          ddg|           t          d           t          ddg|                                ddgd	ft                                                      ddgd	ft                                 t          d                                t                      |           d S )
Nc                                          |d                                | d                                |d           d S )Nr   	stuff.booxx)r   )r   extract_dirextrar   s      r%   _booz/TestArchives.test_unpack_registry.<locals>._boo  sK    UA&&&X{333[$/////r'   Booz.booz.b2)r	  r   r  r  Boo2r   )	r   r	   r   r   r
   r   r   r  r   )r   r  r
  s   `  r%   test_unpack_registryz!TestArchives.test_unpack_registry
  s   $&&	0 	0 	0 	0 	0
 	uvuotl^LLL{D))) 	-)?!(D	* 	* 	* 	!'''vx666vx,.@.B.BCCC%&2.0B0D0DEEE 	!(((+--w77777r'   N)rf  )(r   r   r   r   requires_zlibrb  re  rS  r<  r=  r   whichry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  requires_bz2r  requires_lzmar>  r   r   r  r  r  rF   r'   r%   rK  rK  q  s        W!H !H !HF     " " " " WXe,,68 8*1 *18 8 *1X W"D "D "DH WXe,,68 88 88 8 80 WXg..8: :4 4: : 4,F F F
 W- - -6 WX*HII  JI *- - -,8 8 8 W8 8 8) ) ) B B B* WB B B.M M MF F F0. . .) ) ) W+ + + W+ + + WX_S--/YZZ+ + [Z + W< < <
8 8 8 8 8r'   rK  c                       e Zd Z ej         eed          d          d             Z ej        ed           ej         ee	d          d          d                         Z
dS )	TestMisc
disk_usagez)disk_usage not available on this platformc                 "   t          j        t          j                            t
                              }dD ]+}|                     t          ||          t                     ,| 	                    |j
        d           | 	                    |j        d           |                     |j        d           |                     |j
        |j                   | 	                    |j
        |j                   t          j        t
                     d S )N)rG   usedfreer   )r   r  r+   r;   rJ  r;  r   r!   r   assertGreaterrG   r  assertGreaterEqualr  )r   usager  s      r%   test_disk_usagezTestMisc.test_disk_usage'  s     !"'//(";";<<- 	= 	=D!!'%"6"6<<<<5;***5:q)))
A...UZ8885;
333 	(#####r'   r  chownzrequires os.chownc                                                       }t          j        |          t          d                                t
                    5  t          j                   d d d            n# 1 swxY w Y                        t                    5  t          j        d           d d d            n# 1 swxY w Y                        t                    5  t          j        d           d d d            n# 1 swxY w Y                        t                    5  t          j        d           d d d            n# 1 swxY w Y                        t                    5  t          j        d           d d d            n# 1 swxY w Y   t          j                    }t          j                    }d fd		}t          j        ||            |||           t          j        |            ||           t          j        |            ||           t          j        |            ||
           t          j        |||            ||||           t          j        ||            |||           t          j        ||            |||           t          j        ||            |||
           	 t          j        |          d         }t          j        |          d         }t          j        ||            |||           t          j        |||            ||||           d S # t"          $ r Y d S w xY w)Nr   ztesting chown functionznon-existing username)userznon-existing groupname)r     spamgQ	@c                     t          j                  }|                    ||j                   |                    ||j                   d S d S r*   )r+   r   r   st_uidst_gid)r;   r  r  sr   r   s       r%   check_chownz(TestMisc.test_chown.<locals>.check_chownO  sY    !!A  ah///  ah///// r'   )r  r   )NN)r   rs   r   rC   r   r  r   r  LookupErrorr  r+   getuidgetgidr  r  r  r  KeyError)r   rJ  r  r  r$  r  r  r   s   `      @r%   
test_chownzTestMisc.test_chown6  s    ,,..?w///85666z** 	# 	#L"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# {++ 	A 	AL(?@@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A {++ 	C 	CL)ABBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C y)) 	, 	,L7+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, y)) 	) 	)L4(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) ikkikk	0 	0 	0 	0 	0 	0 	0 	XsC(((Hc3'''Xs###Hc"""XC((((Hc"""XS))))H#&&&&Wc3'''GS#&&&Wc"""GS!!!W3''''GS!!!WC((((G%%%%
	+<$$Q'DL%%a(E
 L4///K#s+++L$...Kc*****  	 	 	DD	sl   A77A;>A;B??CC$DDD,EEE3FFF 4M 
M*)M*N)r   r   r   r<  r=  rr   r   r  r  r+   r)  rF   r'   r%   r  r  %  s        X66DF F$ $F F$ X*HIIXW--/BCC:+ :+ DC JI:+ :+ :+r'   r  c                   N   e Zd Zd Zd Zd Zd Zd Zej	        d             Z
d Zd Z ej        ej        d	k    d
          d             Zd Zd Zd Zd Zd Zd Z ej        ej        d	k    d          d             Z ej        ej        d	k    d          d             ZdS )	TestWhichc                    |                      d          | _        t          j        | j        dd          | _        t          j        | j        j        t          j	                   | 
                    | j        j                   t
          j                            | j        j                  \  | _        | _        | j        | _        t
          j        | _        d| _        d S )NTmp)r   z.Exero   r   suffixz.EXE)r   temp_dirrs   rt   	temp_filer+   r   ri   r   S_IXUSRr   r  r;   r   ro   fileenv_pathcurdirextr9  s    r%   setUpzTestWhich.setUpw  s    E22 "4<A<BD D D 	$dl333,--- gmmDN,?@@$)ir'   c                     t          j        | j        | j                  }|                     || j        j                   d S Nr  )r   r  r3  ro   r   r1  ri   r   r  s     r%   
test_basiczTestWhich.test_basic  s;    \$)$(333T^011111r'   c                     t          j        | j        j        | j                  }|                     || j        j                   d S r9  )r   r  r1  ri   r0  r   r:  s     r%   test_absolute_cmdzTestWhich.test_absolute_cmd  s@     \$.-DMBBBT^011111r'   c                    t           j                            | j                  \  }}t           j                            || j                  }t          j        |          5  t          j	        || j
                  }|                     ||           d d d            n# 1 swxY w Y   t          j        | j                  5  t          j	        ||          }|                     |           d d d            d S # 1 swxY w Y   d S r9  )r+   r;   r   ro   r<   r3  r   rU  r   r  r0  r   assertIsNone)r   r  tail_dirrelpathr  s        r%   test_relative_cmdzTestWhich.test_relative_cmd  sn     W]]4844(',,x33!x000 	* 	*gDM:::BR)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* !tx000 	" 	"gH555Bb!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s$   "2B  B$'B$,C>>DDc                    t           j                            | j                  }t	          j        | j                  5  t          j        | j        |          }t          j
        dk    r?|                     |t           j                            | j        | j                             n|                     |           d d d            d S # 1 swxY w Y   d S )Nr  r-  )r+   r;   rJ  ro   r   rU  r   r  r3  r   r?  r   r<   r5  r?  )r   r  r  s      r%   test_cwdzTestWhich.test_cwd  s    7??48,,!tx000 	& 	&dih777B|w&&  RW\\$+ty%I%IJJJJ !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   B CCCc                 T   t          j        | j        j        t          j                   t          j        | j        j        t           j                  r|                     d           t          j
        | j        | j        t           j                  }|                     |           d S )Nzcan't set the file read-only)r;   rA   )r+   r   r1  ri   r   r   accessW_OKr  r   r  r3  ro   r?  r:  s     r%   test_non_matching_modez TestWhich.test_non_matching_mode  s     	$dl3339T^("'22 	:MM8999\$)$(AAA"r'   c                 X   t           j                            | j                  \  }}t	          j        |          5  t          j        | j        |          }| 	                    |t           j        
                    || j                             d d d            d S # 1 swxY w Y   d S r9  )r+   r;   r   ro   r   rU  r   r  r3  r   r<   )r   r  r@  r  s       r%   test_relative_pathzTestWhich.test_relative_path  s    W]]4844(!x000 	D 	Ddih777BRh	!B!BCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds   ABB#&B#c                 f    t          j        d| j                  }|                     |           d S )Nzfoo.exer  )r   r  ro   r?  r:  s     r%   test_nonexistent_filezTestWhich.test_nonexistent_file  s2    \)$(333"r'   r-  zpathext check is Windows-onlyc                     t          j        | j        d d         | j                  }|                     || j        j        d d         | j        z              d S )Nr  )r   r  r3  ro   r   r1  ri   r6  r:  s     r%   test_pathext_checkingzTestWhich.test_pathext_checking  sU    
 \$)CRC.tx888T^0"5@AAAAAr'   c                     t          j                    5 }| j        |d<   t          j        | j                  }|                     || j        j                   d d d            d S # 1 swxY w Y   d S NPATH)	r   EnvironmentVarGuardr4  r   r  r3  r   r1  ri   r   envr  s      r%   test_environ_pathzTestWhich.test_environ_path  s    *,, 	6-CKdi((BR!4555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   AA%%A),A)c           	         t          j                    5 }d|d<   t          j                            d| j        d          5  t          j        t          d| j                  5  t          j	        | j                  5  t          j        | j                  }|                     |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   rR  
os.confstrTreturn_valuecreatedefpath)r   rS  r<  r  r  ro   r   r  r+   rU  r   r  r3  r?  rT  s      r%   test_environ_path_emptyz!TestWhich.test_environ_path_empty  s   *,, 	&CK$$\,0 % 2 2 & &"2y$(;;& & %dh//& & \$),,!!"%%%& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s}   -C=!C%"C</B7	+C7B;;C>B;?CC%CC%CC%C=%C)	)C=,C)	-C==DDc           	         t           j                            | j        j                  }t
          j        dk    rUt           j        }t          |t                    rt          j
        |          }t           j                            ||          }t          j                    5 }t           j        |d<   t          j                            d| j        d          5  t'          j        t           d| j                  5  t+          j        | j                  }|                     |           t          j        | j                  5  t+          j        | j                  }|                     ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr-  rR  rX  TrY  r\  )r+   r;   rT  r1  ri   r   r?  r5  r9   r   r   r<   r   rS  pathsepr<  r  r  ro   r   r  r   r  r3  r?  rU  r   )r   expected_cwdr5  rU  r  s        r%   test_environ_path_cwdzTestWhich.test_environ_path_cwd  s   w''(;<<<7""YF,.. -V,,7<<==L *,, 	7*CK$$\,0 % 2 2 	7 	7"2y$(;;	7 	7 \$),,!!"%%% )$(33 7 7di00B$$R6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   "7G!F,:AF0E>	2F>FFFF	F,FF,FF, G,F0	0G3F0	4GGGc                 @   t          j                    5 }|                    dd            t          j                            dt          d          5  t          j        t          d| j
                  5  t          j        | j                  }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     || j        j                   t          j                            d| j
        d          5  t          j        t          dd          5  t          j        | j                  }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     || j        j                   d d d            d S # 1 swxY w Y   d S )NrR  rX  T)r   r[  r\  rY  r   )r   rS  popr<  r  r  r  r   r  r+   ro   r   r  r3  r   r1  ri   rT  s      r%   test_environ_path_missingz#TestWhich.test_environ_path_missing  s   *,, 	6GGFD!!! $$\z,0 % 2 2 - -"2y$(;;- - \$),,- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - R!4555 $$\,0 % 2 2 - -"2y"55- - \$),,- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - R!4555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   >F!B03BB0BB0 B!B0$F0B4	4F7B4	8A
FEE8EEEEEFE	F"E	##FFFc                 ~   t           j                            | j                  }t	          j        | j                  5  t	          j                    5 }| j        |d<   t          j	        | j
        d          }|                     |           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  rR  r   )r+   r;   rJ  ro   r   rU  rS  r4  r   r  r3  r?  )r   r  rU  r  s       r%   test_empty_pathzTestWhich.test_empty_path  s(   7??48,,!tx000 	" 	"*,,	"03-CKdib111Bb!!!		" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s5   B2;BB2B	B2!B	"B22B69B6c                     t          j                    5 }|                    dd            t          j        | j                  }|                     |           d d d            d S # 1 swxY w Y   d S rQ  )r   rS  rc  r   r  r3  r?  rT  s      r%   test_empty_path_no_PATHz!TestWhich.test_empty_path_no_PATH  s    *,, 	"GGFD!!!di((Bb!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   AA&&A*-A*ztest specific to Windowsc                    d}t          j        | j        d|          }t          j        |j        t          j                   |                     |j	                   t          j
                            |j                  }t          j
                            |          d         }t          j                    5 }||d<   t          j        || j                  }|                     ||j                   d d d            d S # 1 swxY w Y   d S )N.xyzTmp2r.  r   PATHEXTr  )rs   rt   r0  r+   r   ri   r   r2  r   r  r;   rT  rq  r   rS  r   r  r   r   r6  temp_filexyzprogramrU  r  s         r%   test_pathextzTestWhich.test_pathext  s2   2t}:@N N N
"DL111*+++ '""<#455'""7++A.*,, 	4 C	NgDM:::BR!2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   9<DD	Dc                    d}t          j        | j        d|          }|                     |j                   t
          j                            |j                  }t
          j        	                    |          d         }t          j                    5 }| d|d<   t          j        || j                  }|                     ||j                   d d d            d S # 1 swxY w Y   d S )Nrj  rk  r.  r   ;rl  r  )rs   rt   r0  r   r  r+   r;   rT  ri   rq  r   rS  r   r  r   rm  s         r%   test_pathext_with_empty_strz%TestWhich.test_pathext_with_empty_str  s!   2t}:@N N N*+++ '""<#455'""7++A.*,, 	4 #YYYC	NgDM:::BR!2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   ?C!!C%(C%N)r   r   r   r7  r;  r=  rB  rD  r   r@  rH  rJ  rL  r<  r=  r   r?  rO  rV  r]  ra  rd  rf  rh  rp  rs  rF   r'   r%   r+  r+  u  s         2 2 2
2 2 2" " "
& 
& 
& #  $#D D D  
 X08: :B B: :B6 6 6	& 	& 	&7 7 7,6 6 6$" " "" " " X02LMM4 4 NM4" X02LMM4 4 NM4 4 4r'   r+  c                       e Zd Zd ZdS )TestWhichBytesc                 z   t                               |            t          j        | j                  | _        t          j        | j                  | _        t          j        | j        j                  | j        _        t          j        | j                  | _        t          j        | j	                  | _	        d S r*   )
r+  r7  r+   r   ro   r3  r1  ri   r5  r6  r9  s    r%   r7  zTestWhichBytes.setUp0  s}    ;tx((K	**	 k$.*=>>k$+..;tx((r'   N)r   r   r   r7  rF   r'   r%   ru  ru  /  s#        ) ) ) ) )r'   ru  c                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	e
d             Ze
d	             Zd
 Ze
d             Zd Ze
d             Zd Z ej        ej        j        d          d             Zd Zd Zd Zd Zej        e
d                         Zej        e
d                         Zej        e
d                         Z ej        e
d                         Z!d Z"d Z#e
d             Z$e
d             Z%d Z&e
d             Z'ej        d             Z(ej        d              Z)ej*         ej         e+ed!          o e+e,d"          o e+e,d#          d$          d%                         Z-d&S )'TestMovec                    d}|                                  | _        |                                  | _        t          j                            | j        |          | _        t          j                            | j        |          | _        t          | j        d          5 }|	                    d           d d d            d S # 1 swxY w Y   d S )Nr   r4   r  )
r   rN  rO  r+   r;   r<   r0  r>  r=   r>   )r   r   rX   s      r%   r7  zTestMove.setUp;  s    ||~~||~~T\8<<T\8<<$-&& 	!GGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   CCCc                    t          |d          5 }|                                }d d d            n# 1 swxY w Y   t          j        ||           t          |d          5 }|                     ||                                           d d d            n# 1 swxY w Y   |                     t          j                            |                     d S Nr\   )	r=   r^   r   mover   r   r+   r;   r   )r   rz   r{   real_dstrX   contentss         r%   _check_move_filezTestMove._check_move_fileD  s)   #t__ 	 vvxxH	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 C(D!! 	1QXqvvxx000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1,,-----s   266")BBBc                 @   t          t          j        |                    }t          j        ||           |                     |t          t          j        |                               |                     t          j                            |                     d S r*   )	rb   r+   rc   r   r|  r   r   r;   r   )r   rz   r{   r}  r~  s        r%   _check_move_dirzTestMove._check_move_dirL  sy    "*S//**C6"*X*>*>#?#?@@@,,-----r'   c                 R    |                      | j        | j        | j                   d S r*   )r  r0  r>  r9  s    r%   test_move_filezTestMove.test_move_fileR  s&    dmT]DMJJJJJr'   c                 R    |                      | j        | j        | j                   d S r*   )r  r0  rO  r>  r9  s    r%   test_move_file_to_dirzTestMove.test_move_file_to_dirV  s&    dmT\4=IIIIIr'   c                 z    t          j        | j                  }|                     || j        | j                   d S r*   )r  r  r0  r  rO  r>  )r   rz   s     r%   "test_move_file_to_dir_pathlike_srcz+TestMove.test_move_file_to_dir_pathlike_srcZ  s5    l4=))c4<?????r'   c                 z    t          j        | j                  }|                     | j        || j                   d S r*   )r  r  rO  r  r0  r>  r   r{   s     r%   "test_move_file_to_dir_pathlike_dstz+TestMove.test_move_file_to_dir_pathlike_dst_  s5    l4<((dmS$-@@@@@r'   c                 .    |                                   d S r*   )r  r9  s    r%   test_move_file_other_fsz TestMove.test_move_file_other_fsd  s     	r'   c                 .    |                                   d S r*   )r  r9  s    r%   test_move_file_to_dir_other_fsz'TestMove.test_move_file_to_dir_other_fsi  s     	""$$$$$r'   c                     t          j        |                                           }	 |                     | j        ||           t          j        |           d S # t          j        |           w xY wr&  )rs   r   r   r  rN  r   r   r   rO  s     r%   test_move_dirzTestMove.test_move_dirn  si    /dllnn555	&  w@@@W%%%%%IW%%%%s   A A1c                 .    |                                   d S r*   )r  r9  s    r%   test_move_dir_other_fszTestMove.test_move_dir_other_fsv  s     	r'   c           
          |                      | j        | j        t          j                            | j        t          j                            | j                                       d S r*   )r  rN  rO  r+   r;   r<   rT  r9  s    r%   test_move_dir_to_dirzTestMove.test_move_dir_to_dir{  sX    T\4<GLLrw'7'7'E'EFF	H 	H 	H 	H 	Hr'   c                 .    |                                   d S r*   )r  r9  s    r%   test_move_dir_to_dir_other_fsz&TestMove.test_move_dir_to_dir_other_fs  s     	!!#####r'   c           
          |                      | j        t          j        j        z   | j        t          j                            | j        t          j                            | j                                       d S r*   )r  rN  r+   r;   seprO  r<   rT  r9  s    r%   test_move_dir_sep_to_dirz!TestMove.test_move_dir_sep_to_dir  sa    T\BGK7GLLrw'7'7'E'EFF	H 	H 	H 	H 	Hr'   zrequires os.path.altsepc           
          |                      | j        t          j        j        z   | j        t          j                            | j        t          j                            | j                                       d S r*   )r  rN  r+   r;   altseprO  r<   rT  r9  s    r%   test_move_dir_altsep_to_dirz$TestMove.test_move_dir_altsep_to_dir  sa    T\BGN:DLGLLrw'7'7'E'EFF	H 	H 	H 	H 	Hr'   c                     t          | j        d          5  	 d d d            n# 1 swxY w Y   |                     t          j        t          j        | j        | j                   d S )Nr4   )r=   r>  r   r   r   r|  r0  rO  r9  s    r%   "test_existing_file_inside_dest_dirz+TestMove.test_existing_file_inside_dest_dir  s    $-&& 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	&,T]DLQQQQQs   $((c                     t           j                            | j        d          }|                     t
          j        t
          j        | j        |           d S Nr  )r+   r;   r<   rN  r   r   r   r|  r  s     r%   test_dont_move_dir_in_itselfz%TestMove.test_dont_move_dir_in_itself  s?    gll4<//&,T\3GGGGGr'   c           	         t          j        t                     	 dD ]\  }}t           j                            t          |          }t           j                            t          |          }|                     t          j        ||          d|d|d           	 t          j	        t                     d S # t          j	        t                     w xY w)N))srcdirzsrcdir/dest)_destinsrc() wrongly concluded that dst (z) is not in src ()r  )
r+   r   r   r;   r<   r   r   
_destinsrcr   r   r.  s      r%   test_destinsrc_false_negativez&TestMove.test_destinsrc_false_negative  s    
	%7 I ISgll63//gll63// 1#s ; ; ;>Acc333"H   I I I II V$$$$$IV$$$$   BB: :Cc           	         t          j        t                     	 dD ]\  }}t           j                            t          |          }t           j                            t          |          }|                     t          j        ||          d|d|d           	 t          j	        t                     d S # t          j	        t                     w xY w)N))r  zsrc/dest)r  z
srcdir.newr  z) is in src (r  r  )
r+   r   r   r;   r<   r   r   r  r   r   r.  s      r%   test_destinsrc_false_positivez&TestMove.test_destinsrc_false_positive  s    
	%N D DSgll63//gll63//  !23!<!<!<9<ccc!C ! D D D DD V$$$$$IV$$$$r  c                    t           j                            | j        d          }t          j        | j        |           t          j        || j                   | 	                    t           j        
                    | j                             | 	                    t           j                            | j        | j                             d S r  )r+   r;   r<   rN  r   r0  r   r|  r>  r   re   samefiler  s     r%   test_move_file_symlinkzTestMove.test_move_file_symlink  s     gll4<//

4=#&&&C'''t}55666((FFGGGGGr'   c                    d}t           j                            | j        |          }t          j        | j        |           t          j        || j                   t           j                            | j        |          }| 	                    t           j        
                    |                     | 	                    t           j                            | j        |                     d S r  )r+   r;   r<   rN  r   r0  r   r|  rO  r   re   r  )r   r   r{   
final_links       r%   test_move_file_symlink_to_dirz&TestMove.test_move_file_symlink_to_dir  s     gll4<22

4=#&&&C&&&W\\$,99
z22333((
CCDDDDDr'   c                 <   t           j                            | j        d          }t           j                            | j        d          }t          j        ||           t           j                            | j        d          }t          j        ||           |                     t           j        	                    |                     | 
                    t           j                            |          t           j                            |                     d S Nr  r  r  )r+   r;   r<   rN  r   rO  r   r|  r   re   r   realpathr   rz   r{   rg  s       r%   test_move_dangling_symlinkz#TestMove.test_move_dangling_symlink  s     gll4<//gll4<//

37<<f55C"""x00111))#..0@0@0J0JKKKKKr'   c                 *   t           j                            | j        d          }t           j                            | j        d          }t          j        |           t          j        ||           t           j                            | j        d          }t          j        ||           | 	                    t           j        
                    |                     | 	                    t           j                            ||                     d S r  )r+   r;   r<   rN  r   r   rO  r   r|  r   re   r  r  s       r%   test_move_dir_symlinkzTestMove.test_move_dir_symlink  s     gll4<//gll4<//


37<<f55C"""x00111((h7788888r'   c           	          t          j        | j        | j                  }|                     |t
          j                            | j        t
          j                            | j                                       d S r*   )	r   r|  r0  rO  r   r+   r;   r<   rT  r:  s     r%   test_move_return_valuezTestMove.test_move_return_value  sg    [55T\27+;+;DM+J+JKK	M 	M 	M 	M 	Mr'   c                     t          j        | j        t          j                            | j        d                    }|                     |t          j                            | j        d                     d S r  )r   r|  r0  r+   r;   r<   rO  r   r:  s     r%    test_move_as_rename_return_valuez)TestMove.test_move_as_rename_return_value  sU    [T\5(I(IJJRW\\$,>>?????r'   c                     g fd}t          j        | j        | j        |           |                     t                    d           d S )Nc                 6                         | |f           d S r*   r   rz   r{   moveds     r%   r  z7TestMove.test_move_file_special_function.<locals>._copy      LL#s$$$$$r'   r  r   )r   r|  r0  rO  r   r   r   r  r  s     @r%   test_move_file_special_functionz(TestMove.test_move_file_special_function  s^    	% 	% 	% 	% 	%DM4<uEEEEUQ'''''r'   c                 z   g fd}t          j        t          j                            | j        d                     t          j        t          j                            | j        d                     t          j        | j        | j        |           | 	                    t                    d           d S )Nc                 6                         | |f           d S r*   r   r  s     r%   r  z6TestMove.test_move_dir_special_function.<locals>._copy  r  r'   childchild1r  r   )r   r   r+   r;   r<   rN  r   r|  rO  r   r   r  s     @r%   test_move_dir_special_functionz'TestMove.test_move_dir_special_function  s    	% 	% 	% 	% 	%#BGLLw$G$GHHH#BGLLx$H$HIIIDL$,eDDDDUQ'''''r'   c                 N   |                                  | _        t          j                            t          j                            | j                  t          j                            | j                                                            }|                     | j        |           	 t          j
        | j        |           |                     t          j                            |                     t          j        |           d S # t          j        |           w xY wr*   )r   rN  r+   r;   r<   rJ  rT  upperr  r   r|  r   rd   r   r  s     r%   test_move_dir_caseinsensitivez&TestMove.test_move_dir_caseinsensitive  s     ||~~',,--  ..44668 8 	DL'222	Kg...OOBGMM'22333HWBHWs   ,AD D$c                    t           j                            | j        d          }t           j                            | j        d          }t          j        | j        |d           t          j        ||           |                     t           j        	                    |                     |                     t           j        
                    | j        |                     |                     t           j                            |                     t          j        | j        |d           |                     t          j                  5  t          j        ||           d d d            n# 1 swxY w Y   |                     t           j        
                    | j        |                     |                     t           j                            |                     d S )N	linktodirTr  )r+   r;   r<   rN  rO  r   r   r|  r   re   r  r   r   r   r   )r   r{   rz   rg  s       r%   "_test_move_symlink_to_dir_into_dirz+TestMove._test_move_symlink_to_dir_into_dir		  s   gll4<557<<k::

4<$????Cx00111((x@@AAA,,--- 	
4<$????v|,, 	" 	"KS!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"((x@@AAAs++,,,,,s   E55E9<E9c                 :    |                      | j                   d S r*   )r  rO  r9  s    r%   !test_move_symlink_to_dir_into_dirz*TestMove.test_move_symlink_to_dir_into_dir	  s    //=====r'   c                     t           j                            | j        d          }t          j        | j        |d           |                     |           d S )NotherlinktodirTr  )r+   r;   r<   rN  r   rO  r  r  s     r%   ,test_move_symlink_to_dir_into_symlink_to_dirz5TestMove.test_move_symlink_to_dir_into_symlink_to_dir	  sM    gll4<)9::

4<$????//44444r'   rZ  SF_IMMUTABLE	UF_OPAQUEzrequires lchflagsc                    	 t          j        t                     t          j        t          t          j                   |                     t          t          j	        t          t                     |                     t          t          j                    v            t          j        t          t          j                   t          j        t           j                            t          d                     t          j        t          t          j                   |                     t          t          j	        t          t                     |                     t          t          j                    v            t           j                            t                    r=t          j        t          t          j                   t          j        t                     t           j                            t                    r?t          j        t          t          j                   t          j        t                     d S d S # t           j                            t                    r=t          j        t          t          j                   t          j        t                     t           j                            t                    r>t          j        t          t          j                   t          j        t                     w w xY w)Nr  )r+   r   
TESTFN_SRCrZ  r   r  r   r  r   r|  
TESTFN_DSTr   rc   r  r   r   r;   r<   r   r   r9  s    r%   test_move_dir_permission_deniedz(TestMove.test_move_dir_permission_denied%	  s   	-HZ   K
D$5666 ov{J
SSSZ2:<<7888 K
DN333'Z(I(IJJJK
D$5666 ov{J
SSSZ2:<<7888w~~j)) -J777 ,,,w~~j)) -J777 ,,,,,- - w~~j)) -J777 ,,,w~~j)) -J777 ,,,,-s   E8I   CLN).r   r   r   r7  r  r  r  r  r  r  r2   r  r  r  r  r  r  r  r<  r=  r+   r;   r  r  r  r  r  r  r   r;  r  r  r  r  r  r  r  r  r  r  r  r  rG  rr   r   r  rF   r'   r%   rx  rx  9  s         . . .. . .K K KJ J J@ @ @
A A A
   [ % % [%& & &   [H H H
 $ $ [$H H H X)BCCH H DCHR R RH H H

% 
% 
%
% 
% 
% "H H [ #"H "E E [ #"E "L L [ #"L "9 9 [ #"9M M M
@ @ @ ( ( [( ( ( [(  $ - - [-" "> > #"> "5 5 #"5
 'XZ00 8$WT>::8$WT;77,. .- -	. . ('
- - -r'   rx  c                       e Zd Z G d de          Zd Z ej        ed          d             Z	 ej        ed          d             Z
 ej        ed          d             ZdS )	TestCopyFilec                   4    e Zd ZdZdZdZddZd Zd Zd Z	dS )	TestCopyFile.FauxFNTc                 "    || _         || _        d S r*   )_raise_in_exit_suppress_at_exit)r   raise_in_exitsuppress_at_exits      r%   __init__zTestCopyFile.Faux.__init__N	  s    "/D%5D"""r'   c                     dS )Nr   rF   )r   r#   s     r%   r^   zTestCopyFile.Faux.readQ	  s    2r'   c                     d| _         d S )NT)_enteredr9  s    r%   	__enter__zTestCopyFile.Faux.__enter__S	  s     DMMMr'   c                 ^    |||f| _         | j        rd| _        t          d          | j        S )NTCannot close)_exited_withr  _raisedr    r  )r   exc_typeexc_valexc_tbs       r%   __exit__zTestCopyFile.Faux.__exit__U	  s:     ('6 9D" .#n---))r'   r  )
r   r   r   r  r  r  r  r^   r  r  rF   r'   r%   Fauxr  J	  sd        	6 	6 	6 	6	 	 		! 	! 	!	* 	* 	* 	* 	*r'   r  c                    dd}t          j        t          d|          5  |                     t                    5  t          j        dd           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr]   c                 0    | dk    rt          d          d S )NsrcfilezCannot open "srcfile"r  )r   rA   s     r%   _openz4TestCopyFile.test_w_source_open_fails.<locals>._open]	  s$    9$$5666 %$r'   r=   r  destfiler]   )r   r  r   r   r    r2  )r   r  s     r%   test_w_source_open_failsz%TestCopyFile.test_w_source_open_fails\	  s   	 	 	 	
 vvu55 	7 	7""7++ 7 7	:6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s4   A5AA5A!	!A5$A!	%A55A9<A9zskipped on macOSc                    |                                  d	fd	}t          j        t          d|          5  t          j        dd           d d d            n# 1 swxY w Y   |                     j                   |                     j        d         t          u            | 	                    j        d         j
        d           d S )
Nr]   c                 B    | dk    rS | dk    rt          d          d S )Nr  r  Cannot open "destfile"r  )r   rA   r  s     r%   r  z2TestCopyFile.test_w_dest_open_fails.<locals>._openj	  s5    9$$:%%6777 &%r'   r=   r  r  r   r   )r  r  )r  r   r  r   r2  r   r  r  r    r   r#   )r   r  r  s     @r%   test_w_dest_open_failsz#TestCopyFile.test_w_dest_open_failsf	  s   ))++	 	 	 	 	 	 vvu55 	3 	3OIz222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3())),Q/7:;;;-a054	6 	6 	6 	6 	6s   AA Ac                 0   |                                  |                      d          d
fd	}t          j        t          d|          5  t          j        dd           d d d            n# 1 swxY w Y   |                     j                   |                     j                   |                     j                   |                     j        d         t          u            | 
                    j        d         j        d	           d S )NTr]   c                 (    | dk    rS | dk    rS d S Nr  r  rF   r   rA   r  r  s     r%   r  z3TestCopyFile.test_w_dest_close_fails.<locals>._open}	  +    9$$:%% &%r'   r=   r  r  r   r   )r  r  )r  r   r  r   r2  r   r  r  r  r    r   r#   r   r  r  r  s     @@r%   test_w_dest_close_failsz$TestCopyFile.test_w_dest_close_failsx	  sQ   ))++99T??	 	 	 	 	 	 	 vvu55 	3 	3OIz222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3())))***())),Q/7:;;;-a05*	, 	, 	, 	, 	,s   A00A47A4c                 r   |                      d          |                                  dfd	}t          j        t          d|          5  |                     t
                    5  t          j        dd           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     j                   |                     j                   | 	                    j
                   |                     j        d         d u            |                     j
                   d S )	NTr]   c                 (    | dk    rS | dk    rS d S r  rF   r   s     r%   r  z5TestCopyFile.test_w_source_close_fails.<locals>._open	  r  r'   r=   r  r  r   r  )r  r   r  r   r   r    r2  r   r  r   r  r  r  s     @@r%   test_w_source_close_failsz&TestCopyFile.test_w_source_close_fails	  s    ))D//99;;	 	 	 	 	 	 	 vvu55 	7 	7""7++ 7 7	:6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	())))***)***,Q/47888(((((s6   B")B?B"B	B"B	B""B&)B&N)r   r   r   objectr  r  r<  r>  rH  r  r  r  rF   r'   r%   r  r  H	  s        * * * * *v * * *$7 7 7 X_U.//6 6 0/6" X_U.//, , 0/,( X_U.//) ) 0/) ) )r'   r  c                       e Zd ZdZed             Zed             Zd Zej	        d             Z
d Zd Zd Zd	 Z ej        ej        d
k    d          d             ZdS )TestCopyFileObji    c                 :    t          t          | j                   d S r*   )rZ   r   FILESIZEclss    r%   
setUpClasszTestCopyFileObj.setUpClass	  s    -----r'   c                 j    t          j        t                     t          j        t                     d S r*   )r   rw   r   r  r  s    r%   tearDownClasszTestCopyFileObj.tearDownClass	  s*       !!!!!r'   c                 8    t          j        t                     d S r*   r   rw   r  r9  s    r%   tearDownzTestCopyFileObj.tearDown	      !!!!!r'   c              #      K   t          t          d          5 }t          t          d          5 }||fV  d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S Nr\   r4   r=   r   r  r.  s      r%   	get_fileszTestCopyFileObj.get_files	        &$ 	!3gt$$ !Cj   ! ! ! ! ! ! ! ! ! ! ! ! ! ! !	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!3   AAAA	AA		AA Ac                    t          |d          5 }t          |d          5 }|                     |                                |                                           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r{  )r=   r   r^   )r   rz   r{   fsrcfdsts        r%   assert_files_eqzTestCopyFileObj.assert_files_eq	  s    #t__ 	;c4 ;D  diikk:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s4   B;A)B)A-	-B0A-	1BBBc                     |                                  5 \  }}t          j        ||           d d d            n# 1 swxY w Y   |                     t          t
                     d S r*   )r  r   copyfileobjr  r   r  r.  s      r%   test_contentzTestCopyFileObj.test_content	  s    ^^ 	)#ssC(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)VW-----s   :>>c                     |                                  5 \  }}t          j        ||           d d d            d S # 1 swxY w Y   d S r*   )r  r   r   r.  s      r%   test_file_not_closedz$TestCopyFileObj.test_file_not_closed	  s    ^^ 	"#ssC(((	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   ;??c                 D   |                                  5 \  }}t          j        ||           |                     |                                | j                   |                     |                                | j                   d d d            d S # 1 swxY w Y   d S r*   )r  r   r   r   tellr  r.  s      r%   test_file_offsetz TestCopyFileObj.test_file_offset	  s    ^^ 	8#ssC(((SXXZZ777SXXZZ777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   A3BBBr^  zWindows onlyc                    t           j                            d          5 }t          j        t
          t                     d d d            n# 1 swxY w Y   |                     |j        d         d         d           t          j
        t          j                    d          5 }|                    d           d d d            n# 1 swxY w Y   |j        }|                     t           j        |           t           j                            d          5 }t          j        |t                     d d d            n# 1 swxY w Y   |                     |j        d         d         d           t          j
        t          j                    d          5 }	 d d d            n# 1 swxY w Y   |j        }|                     t           j        |           t           j                            d          5 }t          j        |t                     d d d            n# 1 swxY w Y   |                     |t                     d S )	Nzshutil._copyfileobj_readintor   rq   i   Frn   s   foor   )r<  r  r  r   r2  r   r  r   	call_argsrs   rt   r+   ru   r>   ri   r   r   rw   r  )r   mrX   r  s       r%   test_win_implzTestCopyFileObj.test_win_impl	  s    ]  !?@@ 	-AOFG,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-
 	Q*O<<< (RY[[GGG 	1GGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 		(%000]  !?@@ 	,AOE7+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,Q*A... (RY[[GGG 	1	 	 	 	 	 	 	 	 	 	 	 	 	 	 		(%000]  !?@@ 	,AOE7+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	UG,,,,,sY    AAA%CCCD??EEF&&F*-F*7HH"%H"N)r   r   r   r  classmethodr  r  r  
contextlibcontextmanagerr  r  r!  r#  r&  r<  r>  r+   ri   r*  rF   r'   r%   r	  r	  	  s        H. . [. " " ["" " " ! ! !
; ; ;
. . .
" " "8 8 8 X_RW_n55- - 65- - -r'   r	  c                       e Zd ZdZdZdZdZed             Zed             Z	d Z
ej        d             Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd ZdS )_ZeroCopyFileTestz#Tests common to all zero-copy APIs.i   r'   r   c                     t          t          | j                   t          t          d          5 }|                                | _        d d d            d S # 1 swxY w Y   d S r{  )rZ   r   r  r=   r^   FILEDATA)r  rX   s     r%   r  z_ZeroCopyFileTest.setUpClass	  s    ---&$ 	516688CL	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   AAAc                 8    t          j        t                     d S r*   )r   rw   r   r  s    r%   r  z_ZeroCopyFileTest.tearDownClass	  s         r'   c                 8    t          j        t                     d S r*   r  r9  s    r%   r  z_ZeroCopyFileTest.tearDown	  r  r'   c              #      K   t          t          d          5 }t          t          d          5 }||fV  d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r  r  r.  s      r%   r  z_ZeroCopyFileTest.get_files
  r  r  c                      t          d          )Nzmust be implemented in subclass)r#  )r   r#   r$   s      r%   zerocopy_funz_ZeroCopyFileTest.zerocopy_fun
  s    !"CDDDr'   c                     |                                   |                                  |                                  |                                  d S r*   )r  r  r  r7  r9  s    r%   resetz_ZeroCopyFileTest.reset
  sB    

r'   c                    |                                  5 \  }}|                     ||           d d d            n# 1 swxY w Y   |                     t          t          d          | j                   |                                  5 \  }}t          j                            d          5 }t          j
        t          t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NTr@   zshutil.copyfileobj)r  r6  r   r_   r  r1  r<  r  r  r   r2  r   )r   rz   r{   r)  s       r%   test_regular_copyz#_ZeroCopyFileTest.test_regular_copy
  s   ^^ 	(#sc3'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(74888$-HHH^^ 	 #s$$%9:: 1a0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 sC   ;??	#C0, CC0C	C0C	 C00C47C4c                    |                      | j                   |                                 5 \  }}|                     t          t
          f          5  |                     ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     t          t          d          | j
                   d S )NTr:  )r   r8  r  r   r    r   r6  r   r_   r   r1  r.  s      r%   test_same_filez _ZeroCopyFileTest.test_same_file
  s.   
###^^ 	,#s""G->#?@@ , ,!!#s+++, , , , , , , , , , , , , , ,	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	6$777GGGGGs5   %BA7+B7A;	;B>A;	?BBBc                     t          j        t          j                              }|                     t
                    5 }t          j        |d           d d d            n# 1 swxY w Y   |                     |j	        j
        |           d S )Nr   new)rs   r   r+   ru   r   r   r   r2  r   r   r   )r   ri   r   s      r%   test_non_existent_srcz'_ZeroCopyFileTest.test_non_existent_src%
  s    29;;///011 	)ROD%(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	).55555s   A##A'*A'c                    t           dz   t           dz   |                     fd           |                     fd           t          d          5  	 d d d            n# 1 swxY w Y   t          d          5 }t          d          5 }|                     ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     t          d          d	           d S )
Nrz   r{   c                  ,    t          j                   S r*   r   rw   )rx   s   r%   r  z3_ZeroCopyFileTest.test_empty_file.<locals>.<lambda>.
      	 0 9 9 r'   c                  ,    t          j                   S r*   rC  )ry   s   r%   r  z3_ZeroCopyFileTest.test_empty_file.<locals>.<lambda>/
  rD  r'   r4   r\   Tr:  r'   )r   r   r=   r6  r   r_   )r   rz   r{   ry   rx   s      @@r%   test_empty_filez!_ZeroCopyFileTest.test_empty_file+
  s   5.5.9999:::9999:::'4   	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 '4   	,Cgt$$ ,!!#s+++, , , , , , , , , , , , , , ,	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	74888#>>>>>sH   A%%A),A) CB4(C4B8	8C;B8	<CCCc                     t           j                            | j        t                    5  |                     t          t          j        t          t                     d d d            d S # 1 swxY w Y   d S )Nr   )
r<  r  r  
PATCHPOINTZeroDivisionErrorr   r   r2  r   r  r9  s    r%   test_unhandled_exceptionz*_ZeroCopyFileTest.test_unhandled_exception9
  s    ]  -> ! @ @ 	@ 	@/$ovw@ @ @	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s   2A++A/2A/c                    t           j                            | j        t	          t
          j        d                    5  |                                 5 \  }}|                     t                    5  | 
                    ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S Nyor   )r<  r  r  rH  r    r"   EINVALr  r   r   r6  r.  s      r%   test_exception_on_first_callz._ZeroCopyFileTest.test_exception_on_first_call?
  s    ]  -4U\4-H-H ! J J 	0 	0!! 0Zc3&&'899 0 0%%c3///0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0sY   CB,2B	B,BB,BB, C,B0	0C3B0	4CCCc                 V   t           j                            | j        t	          t
          j        d                    5  |                                 5 \  }}|                     t          | j	        ||           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S rL  )
r<  r  r  rH  r    r"   ENOSPCr  r   r6  r.  s      r%   test_filesystem_fullz&_ZeroCopyFileTest.test_filesystem_fullI
  sA    ]  -4U\4-H-H ! J J 	H 	H!! HZc3!!'4+<c3GGGH H H H H H H H H H H H H H H	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs5   B&B:BB
	
BB
	BB"%B"N)r   r   r   __doc__r  r1  rH  r+  r  r  r  r,  r-  r  r6  r8  r;  r=  r@  rF  rJ  rO  rR  rF   r'   r%   r/  r/  	  s        -- HHJ5 5 [5 ! ! [!" " " ! ! !
E E E       H H H6 6 6? ? ?@ @ @0 0 0H H H H Hr'   r/  zos.sendfile() not supportedc                   H    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZdS )TestZeroCopySendfileos.sendfilec                 ,    t          j        ||          S r*   )r   _fastcopy_sendfile)r   r  r  s      r%   r6  z!TestZeroCopySendfile.zerocopy_funV
  s    (t444r'   c                    t          j        | j                  5 }t          t          d          5 }|                     t                    5  |                     ||           d d d            n# 1 swxY w Y   t          j	        ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   | 
                    t          t          d          | j                   d S )Nr4   Tr:  )ioBytesIOr1  r=   r  r   r   r6  r   r   r   r_   r.  s      r%   test_non_regular_file_srcz.TestZeroCopySendfile.test_non_regular_file_srcY
  s   Z&& 	-#gt$$ -&&'899 0 0%%c3///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"3,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	74888$-HHHHHsX   B1BA."B.A22B5A26BB1B	B1!B	"B11B58B5c                    t          t          d          5 }t          j                    5 }|                     t
                    5  |                     ||           d d d            n# 1 swxY w Y   t          j        ||           |	                    d           | 
                    |                                | j                   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr\   r   )r=   r   rZ  r[  r   r   r6  r   r   seekr   r^   r1  r.  s      r%   test_non_regular_file_dstz.TestZeroCopySendfile.test_non_regular_file_dstb
  s   &$ 	<3 <&&'899 0 0%%c3///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"3,,,  T];;;< < < < < < < < < < < < < < <	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<sY   C.CA(C(A,,C/A,0AC
C.C	C.C	C..C25C2c                    fd}g t           j        t          j                            dd|          5  |                                 5 \  }}|                     t                    5 }t          j	        ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   | 
                    |j        j        t          j                   d S )Nc                  v    s                     d             | i |S t          t          j        d          )NrM  )rf   r    r"   EBADF)r#   r$   r  orig_sendfiles     r%   rm   zDTestZeroCopySendfile.test_exception_on_second_call.<locals>.sendfilel
  sD     1D!!!$}d5f555ek4000r'   rV  T)r[  r   )r+   rm   r<  r  r  r  r   r    r   rX  r   r   r"   rb  )r   rm   rz   r{   r   r  rc  s        @@r%   test_exception_on_second_callz2TestZeroCopySendfile.test_exception_on_second_callk
  s   	1 	1 	1 	1 	1 	1 ]  t-5 ! 7 7 	8 	8!! 8Zc3&&w// 82-c37778 8 8 8 8 8 8 8 8 8 8 8 8 8 88 8 8 8 8 8 8 8 8 8 8 8 8 8 8	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	+U[99999sY   B<B%,BB%BB%BB%B<%B)	)B<,B)	-B<<C C c                 h   t           j                            dt                    5 }|                                 5 \  }}t          j        ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     t          t          d          | j
                   d S )Nos.fstatr   Tr:  )r<  r  r  r    r  r   rX  r   r_   r  r1  r   r)  rz   r{   s       r%   test_cant_get_sizez'TestZeroCopySendfile.test_cant_get_size}
  s    ]   AA 	 Q!!  Zc3)#s333                             	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	74888$-HHHHHs4   A8A!A8!A%	%A8(A%	)A88A<?A<c                    t           j                                        }d|_        t           j                            d|          5 }|                                 5 \  }}t          j        ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     t          t          d          | j                   d S )Ni  rf  rZ  Tr:  )r<  r  Mockst_sizer  r  r   rX  r   r_   r  r1  r   r  r)  rz   r{   s        r%   test_small_chunksz&TestZeroCopySendfile.test_small_chunks
  s1   
 }!!## ]  $ ?? 	 1!!  Zc3)#s333                             	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	74888$-HHHHHs6   BB5BB	BB		BBBc                    t           j                                        }| j        dz   |_        t           j                            d|          5 }|                                 5 \  }}t          j        ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   | 	                    t          t          d          | j                   d S )Ni  @rf  rj  Tr:  )r<  r  rk  r  rl  r  r  r   rX  r   r_   r  r1  rm  s        r%   test_big_chunkz#TestZeroCopySendfile.test_big_chunk
  s9   
 }!!##}(9:]  $ ?? 	 1!!  Zc3)#s333                             	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	74888$-HHHHHs6   B $B	=B 	B	B B	B  B$'B$c                    t           j                            dt                    5 }|                     t          t
          j        t          t                     |j	        d         d         }| 
                    |t          j                            t                               t          j        t                     t!          t          dd           |                     t          j        t          dz              |                     t          t
          j        t          t          dz              |j	        d         d         }| 
                    |d	           d d d            d S # 1 swxY w Y   d S )
NrV  r   r   r   s   helloTr:  3i   )r<  r  r  rI  r   r   r2  r   r  r(  r   r+   r;   getsizer   rw   rC   r   )r   r)  	blocksizes      r%   test_blocksize_argz'TestZeroCopySendfile.test_blocksize_arg
  sw   ]  -> ! @ @ 	1CD/$ovw@ @ @Aq)I Y(?(?@@@W%%%w6666OOI,gm<<</$ow#G G GAq)IY000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   D2E&&E*-E*c                    	 t           j                            | j        t	          t
          j        d                    5 }|                                 5 \  }}|                     t                    5  t          j        ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t           j                            | j                  5 }t          j        t          t                     d d d            n# 1 swxY w Y   dt          _        d S # dt          _        w xY w)NrM  r   T)r<  r  r  rH  r    r"   ENOTSOCKr  r   r   r   rX  r2  r   r  _USE_CP_SENDFILErg  s       r%   test_file2file_not_supportedz1TestZeroCopySendfile.test_file2file_not_supported
  s   
	+$$O ' = = % ? ?  BC^^%% <#s**+<== < <1#s;;;< < < < < < < < < < < < < < << < < < < < < < < < < < < < <                              $$T_55 $000$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ '+F###dF#****s   >D7  CB,3B	B,BB,BB, C,B0	0C3B0	4C7D7 CD7 
C'D7 2 DD7 D""D7 %D"&D7 7EN)r   r   r   rH  r6  r\  r_  rd  rh  rn  rp  ru  ry  rF   r'   r%   rU  rU  R
  s        J5 5 5I I I< < <: : :$I I II I II I I1 1 1$+ + + + +r'   rU  z
macOS onlyc                       e Zd ZdZd ZdS )TestZeroCopyMACOSzposix._fcopyfilec                 B    t          j        ||t          j                  S r*   )r   _fastcopy_fcopyfileposix_COPYFILE_DATAr.  s      r%   r6  zTestZeroCopyMACOS.zerocopy_fun
  s    )#sE4HIIIr'   N)r   r   r   rH  r6  rF   r'   r%   r{  r{  
  s-        #JJ J J J Jr'   r{  c                      e Zd Zd Zd Zd Z ej         ej	        e
j                                                  d           ej         eed          d          d                         Z ej        ej        d          d	             Zd
S )TestGetTerminalSizec                     t          j                    }|                     |j        d           |                     |j        d           dS )zCheck if get_terminal_size() returns a meaningful value.

        There's no easy portable way to actually check the size of the
        terminal, so let's check if it returns something sensible instead.
        r   N)r   get_terminal_sizer  columnslines)r   rU   s     r%   test_does_not_crashz'TestGetTerminalSize.test_does_not_crash
  sH     '))a000
A.....r'   c                    t          j                    5 }d|d<   |d= t          j                    }ddd           n# 1 swxY w Y   |                     |j        d           t          j                    5 }|d= d|d<   t          j                    }ddd           n# 1 swxY w Y   |                     |j        d           dS )z.Check if environment variables have precedence777COLUMNSLINESNi	  888ix  )r   rS  r   r  r   r  r  r   rU  rU   s      r%   test_os_environ_firstz)TestGetTerminalSize.test_os_environ_first
  s<    *,, 	."C	NG+--D	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	s+++*,, 	.I CL+--D	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	S)))))s!   <A A 5BB!$B!c                    t          j                    5 }d|d<   d|d<   t          j                    }d d d            n# 1 swxY w Y   |                     |j        d           |                     |j        d           d S )Nr  r  yyyr  r   )r   rS  r   r  r  r  r  r  s      r%   test_bad_environz$TestGetTerminalSize.test_bad_environ
  s    *,, 	."C	N CL+--D	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	a000
A.....s   >AAz
not on ttyr  zneed os.get_terminal_size()c                    	 t          j        ddg                                                                          }n7# t          t
          t           j        f$ r |                     d           Y nw xY wt          |d                   t          |d                   f}t          j
                    5 }|d= |d= t          j                    }ddd           n# 1 swxY w Y   |                     ||           dS )	zCheck if stty returns the same results ignoring env

        This test will fail if stdin and stdout are connected to
        different terminals with different sizes. Nevertheless, such
        situations should be pretty rare.
        sttyrU   zstty invocation failedr   r   r  r  N)r   r  r  r   r   r  r  r  r   r   rS  r   r  r   )r   rU   r  rU  rP  s        r%   test_stty_matchz#TestGetTerminalSize.test_stty_match
  s2   	4*FF+;<<CCEEKKMMDD!?-/ 	4 	4 	4MM233333	4 QLL#d1g,,/*,, 	0GI-//F	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0
 	6*****s!   := 1A10A11CCCzWASI has no /dev/nullc                    t          j                    5 }|d= |d= t          j        t          dd           5  t          j        d          }d d d            n# 1 swxY w Y   |                     |j        d           |                     |j	        d           t          t          j        dd	
          5 }t          j        t          d|          5  t          j        d          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |j        d           |                     |j	        d           d d d            d S # 1 swxY w Y   d S )Nr  r  
__stdout__)
      )fallbackr  r  r5   r6   r7   )   (   r  r  )r   rS  r   r  r   r   r  r   r  r  r=   r+   devnull)r   rU  rU   rX   s       r%   test_fallbackz!TestGetTerminalSize.test_fallback  s{   *,, 	-GI "3d;; C C/BBBC C C C C C C C C C C C C C CT\2...TZ,,, bj#888 CA"3a88C C/BBBC C C C C C C C C C C C C C C C C C C C C C C C C C C C C C T\2...TZ,,,!	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s}   "EAEA	EA	 AE5D
C3'D
3C77D
:C7;D
>E
D	ED	9EEEN)r   r   r   r  r  r  r<  r=  r+   isattyr   r  rv   rr   r  r>  r   is_wasir  rF   r'   r%   r  r  
  s        / / /* * */ / / X3>#8#8#:#:;;\JJX%89968 8+ +8 8 KJ+* X_W_&=>>- - ?>- - -r'   r  c                       e Zd ZdZd ZdS )PublicAPITestsz>Ensures that the correct values are exposed in the public API.c                 F   |                      t          t          d                     g d}t          t          d          st          j        dk    r|                    d           |                     t          t          j                  t          |                     d S )N__all__)r   r2  r  r  r  r  rK  r|  r   r   r:  	ExecErrorr   r   r   r   r   r	   r   r   rt  r  r  r  r   statvfsr^  r  )	r   rr   r   r+   ri   rf   r   r|  r  )r   
target_apis     r%   test_module_all_attributez(PublicAPITests.test_module_all_attribute#  s    	22333< < <
 2y!! 	,RW__l+++V^,,c*oo>>>>>r'   N)r   r   r   rS  r  rF   r'   r%   r  r     s)        HH? ? ? ? ?r'   r  __main__)F)Vr<  unittest.mockr   rs   r   r   r+   os.pathr"   r0   r  r   rK   rM   r,  rZ  r   r   r   r   r   r   r	   r
   r   r   r   r   rX  r  r~  ImportErrorr  r   test.supportr   test.support.os_helperr   r   r   r  r  r  r?  rc  rH  rI  r   r  r  r  r   r  r  AssertionErrorrV  r&   r2   rC   rZ   r_   rg   r~   SUPPORTS_SENDFILEr   r   TestCaser   rC  r  rK  r  r+  ru  rx  r  r	  r  r/  r>  rU  r{  r  r  r   mainrF   r'   r%   <module>r     s          



  				                  				6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6  LLLL   EEE       " " " " " " 3 3 3 3 3 3 3 3 ( ( ( ( ( (
3,f_
f_
))
,
!
!'
*
*	l2A2%JJJJJJOO   OOONNNN   GGG =z"N#>??  A AL L L	 	 	   ) ) )$   
 
 
& & &: 0/11   	 	 	 	 	 	 	 	K1 K1 K1 K1 K18, K1 K1 K1\
`2 `2 `2 `2 `28X. `2 `2 `2DC? C? C? C? C?x* C? C? C?Lq8 q8 q8 q8 q88X. q8 q8 q8hM+ M+ M+ M+ M+x* M+ M+ M+`w4 w4 w4 w4 w4(+ w4 w4 w4t) ) ) ) )Y ) ) )L- L- L- L- L-x* L- L- L-^Y) Y) Y) Y) Y)8$ Y) Y) Y)xG- G- G- G- G-h' G- G- G-TaH aH aH aH aH aH aH aHH &&(EFFs+ s+ s+ s+ s+,h.? s+ s+ GFs+l UL))J J J J J)8+< J J *)JL- L- L- L- L-(+ L- L- L-^? ? ? ? ?X& ? ? ?$ zHMOOOOO s6   &A+ +A54A5)
C4 4C>=C>D DD