B
    u9a…: ã               @   s¨  d dl Z d dlZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dl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 d dlZd dlZd dlmZ d dlmZmZ ed Zyd dlZd dl Z dZ!W n e"k
rø   dZ!Y nX dd	„ Z#d
d„ Z$ddd„Z%d dd„Z&dd„ Z'G dd„ de j(ƒZ)G dd„ de j(ƒZ*G dd„ de j(ƒZ+G dd„ de j(ƒZ,G dd„ de j(ƒZ-G dd„ de j(ƒZ.e/dkr¤e  0¡  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)Úsupport)ÚTESTFNÚFakePathÚ2TFc              O   s   t ttddƒdƒ‚d S )NZEXDEVé   zInvalid cross-device link)ÚOSErrorÚgetattrÚerrno)ÚargsÚkwargs© r   ú!/usr/lib/python3.7/test_shutil.pyÚ_fake_rename$   s    r   c                s   t  ˆ ¡‡ fdd„ƒ}|S )Nc                 s$   zt j}tt _ˆ | |ŽS |t _X d S )N)ÚosÚrenamer   )r   r   Zbuiltin_rename)Úfuncr   r   Úwrap)   s
    
zmock_rename.<locals>.wrap)Ú	functoolsÚwraps)r   r   r   )r   r   Úmock_rename(   s    r    c          	   C   sB   t | tƒrtjj| Ž } t| |r"dndƒ}| |¡ W d Q R X d S )NÚwbÚw)Ú
isinstanceÚtupler   ÚpathÚjoinÚopenÚwrite)r%   ZcontentÚbinaryÚfpr   r   r   Ú
write_file3   s    
r+   c          	   C   s<   t | tƒrtjj| Ž } t| |r"dndƒ
}| ¡ S Q R X d S )NÚrbÚr)r#   r$   r   r%   r&   r'   Úread)r%   r)   r*   r   r   r   Ú	read_file?   s    
r/   c             C   s„   g }xzt t | ¡ƒD ]h}tj | |¡}tj |¡rrtj |¡sr| |d ¡ x.t|ƒD ]}| |d | ¡ qVW q| |¡ qW |S )Nú/)	Úsortedr   Úlistdirr%   r&   ÚisdirÚislinkÚappendÚrlistdir)r%   ÚresÚnameÚpÚnr   r   r   r6   K   s    r6   c                   s²  e Zd Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zejd	d
„ ƒZ	ejdd„ ƒZ
dd„ Ze eedƒd¡e ejdd… dkd¡e eedƒo”e ¡ dkd¡dd„ ƒƒƒZdd„ Zdd„ Ze eedƒd¡ejdd „ ƒƒZe eed!ƒd"¡ejd#d$„ ƒƒZe eed!ƒd%¡ejd&d'„ ƒƒZejd(d)„ ƒZe eed*ƒoHeed+ƒoHeed,ƒd-¡d.d/„ ƒZejd0d1„ ƒZejeje eedƒo†e ¡ dkd2¡d3d4„ ƒƒƒZejd5d6„ ƒZ ejd7d8„ ƒZ!ejd9d:„ ƒZ"ejd;d<„ ƒZ#d=d>„ Z$d?d@„ Z%dAdB„ Z&ejdCdD„ ƒZ'dEdF„ Z(dGdH„ Z)ej* +dI¡dJdK„ ƒZ,e ej-dLkdM¡e eedNƒdO¡dPdQ„ ƒƒZ.ejdRdS„ ƒZ/ejdTdU„ ƒZ0e eedVƒdW¡dXdY„ ƒZ1e eedVƒdW¡ejdZd[„ ƒƒZ2d\d]„ Z3ejd^d_„ ƒZ4ejd`da„ ƒZ5dbdc„ Z6e eedƒd¡ddde„ ƒZ7e eedƒd¡e eedfƒdg¡dhdi„ ƒƒZ8ej9djdk„ ƒZ:dldm„ Z;d®dodp„Z<ej9e e= >dq¡dr¡dsdt„ ƒƒZ?ej9dudv„ ƒZ@ej9e e= >dw¡dx¡dydz„ ƒƒZAej9e e= >d{¡d|¡d}d~„ ƒƒZBdd€„ ZCej9dd‚„ ƒZDej9e eEdƒ¡d„d…„ ƒƒZFd†d‡„ ZGdˆd‰„ ZHej9dŠd‹„ ƒZIdŒd„ ZJdŽd„ ZKdd‘„ ZLd’d“„ ZMej9d”d•„ ƒZNejOd–d—„ ƒZPejQd˜d™„ ƒZRej9dšd›„ ƒZSdœd„ ZTe ee=džƒdŸ¡d d¡„ ƒZUe eEdƒ¡e eed¢ƒd£¡d¤d¥„ ƒƒZVd¦d§„ ZWd¨d©„ ZXdªd«„ ZYd¬d­„ ZZ‡  Z[S )¯Ú
TestShutilc                s   t t| ƒ ¡  g | _d S )N)Úsuperr;   ÚsetUpÚtempdirs)Úself)Ú	__class__r   r   r=   Z   s    zTestShutil.setUpc                s:   t t| ƒ ¡  x&| jr4| j ¡ }t |tjdk¡ qW d S )N)ÚntÚcygwin)	r<   r;   ÚtearDownr>   ÚpopÚshutilÚrmtreer   r8   )r?   Úd)r@   r   r   rC   ^   s    
zTestShutil.tearDownc             C   s   t  ¡ }| j |¡ |S )N)ÚtempfileÚmkdtempr>   r5   )r?   rG   r   r   r   rI   e   s    zTestShutil.mkdtempc             C   sX   |   ¡ }tj |d¡}t |¡ ttj |d¡dƒ t |¡}|  |t¡ t	 
|¡ d S )NZkillmeZsomefileÚfoo)rI   r   r%   r&   Úmkdirr+   ÚfsencodeÚassertIsInstanceÚbytesrE   rF   )r?   ÚtmpZvictimr   r   r   Útest_rmtree_works_on_bytesn   s    

z%TestShutil.test_rmtree_works_on_bytesc                sä   |   ¡ }tj |d¡}t |¡ tj |d¡}t ||¡ |  ttj	|¡ |  
tj |¡¡ |  
tj |¡¡ g ‰ ‡ fdd„}tj	||d |  tˆ ƒd¡ |  ˆ d d tjj¡ |  ˆ d d |¡ |  ˆ d d d t¡ d S )	NÚdirÚlinkc                 s   ˆ   | ¡ d S )N)r5   )r   )Úerrorsr   r   Úonerror‚   s    z8TestShutil.test_rmtree_fails_on_symlink.<locals>.onerror)rT   é   r   é   )rI   r   r%   r&   rK   ÚsymlinkÚassertRaisesr   rE   rF   Ú
assertTrueÚexistsÚlexistsÚassertEqualÚlenÚassertIsr4   rM   )r?   rO   Zdir_rR   rT   r   )rS   r   Útest_rmtree_fails_on_symlinkw   s    
z'TestShutil.test_rmtree_fails_on_symlinkc       
      C   sú   |   ¡ }tj |d¡}tj |d¡}tj |d¡}x|||fD ]}t |¡ q>W tj |d¡}t|dƒ tj |d¡}t ||¡ tj |d¡}t ||¡ tj |d¡}	t ||	¡ t |¡ |  	tj 
|¡¡ |  tj 
|¡¡ |  tj 
|¡¡ d S )	NÚdir1Údir2Údir3Úfile1rJ   Úlink1Úlink2Úlink3)rI   r   r%   r&   rK   r+   rW   rE   rF   ÚassertFalserZ   rY   )
r?   rO   r`   ra   rb   rG   rc   rd   re   rf   r   r   r   Útest_rmtree_works_on_symlinksŠ   s$    

z(TestShutil.test_rmtree_works_on_symlinksc          	      s¨  t  ¡ }|  ttj|¡ tj|dd |  ¡ }t|dfdƒ tj	 
|d¡}|  t¡}t |¡ W d Q R X |tj	 
|d¡g}|  |jj|¡ |  tj	 |¡¡ tj|dd |  tj	 |¡¡ g ‰ ‡ fdd„}tj||d |  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 )NT)Úignore_errorsZtstfileÚ z*.*c                 s   ˆ   | ¡ d S )N)r5   )r   )rS   r   r   rT   ¶   s    z.TestShutil.test_rmtree_errors.<locals>.onerror)rT   rV   r   rU   )rH   ÚmktemprX   ÚFileNotFoundErrorrE   rF   rI   r+   r   r%   r&   ÚNotADirectoryErrorÚassertInZ	exceptionÚfilenamerY   rZ   r\   r]   r^   ÚscandirrM   Úrmdir)r?   ro   ÚtmpdirÚcmZpossible_argsrT   r   )rS   r   Útest_rmtree_errors    s2    zTestShutil.test_rmtree_errorsÚchmodzrequires os.chmod()Né   rB   z2This test can't be run on Cygwin (issue #1071513).Úgeteuidr   z9This test can't be run reliably as root (issue #1076467).c             C   s
  d| _ t t¡ |  tjt¡ tj td¡| _	tj td¡| _
t | j	¡ t | j
¡ t t¡j}t | j	¡j}t | j
¡j}tjtjB }t | j	|¡ t | j
|¡ t t|¡ |  tjt|¡ |  tj| j	|¡ |  tj| j
|¡ tjt| jd |  | j dd¡ d S )Nr   ÚaÚb)rT   é   z1Expected call to onerror function did not happen.)Ú
errorStater   rK   r   Ú
addCleanuprE   rF   r%   r&   Úchild_file_pathÚchild_dir_pathr   Úcreate_empty_fileÚstatÚst_modeÚS_IREADÚS_IEXECru   Úcheck_args_to_onerrorr\   )r?   Zold_dir_modeZold_child_file_modeZold_child_dir_modeZnew_moder   r   r   Útest_on_errorÄ   s(    

zTestShutil.test_on_errorc             C   sº   | j dk r‚|tjkr$|  || j¡ n:|tjkr>|  || j¡ n |  |tj¡ |  	|t
| jg¡ |  t|d tƒ¡ |  j d7  _ n4|  |tj¡ |  |t
¡ |  t|d tƒ¡ d| _ d S )NrV   r   rU   rz   )r{   r   Úunlinkr\   r}   rq   r~   r^   r2   rn   r   rY   Ú
issubclassr   )r?   r   ÚargÚexcr   r   r   r„   ä   s    


z TestShutil.check_args_to_onerrorc                sL   z>t j‰ ‡ fdd„}|t _t  t¡ ttdfdƒ t t¡ W d ˆ t _X d S )Nc                s   | t krtƒ ‚nˆ | ƒS d S )N)r   r   )Úfnr   r   )Ú
orig_lstatr   r   Úraiser  s    zFTestShutil.test_rmtree_does_not_choke_on_failing_lstat.<locals>.raiserrJ   )r   ÚlstatrK   r   r+   rE   rF   )r?   rŒ   r   )r‹   r   Ú+test_rmtree_does_not_choke_on_failing_lstatÿ   s    
z6TestShutil.test_rmtree_does_not_choke_on_failing_lstatzrequires os.chmodc             C   s„  |   ¡ }tj |d¡}tj |d¡}tj |d¡}tj |d¡}t|dƒ t|dƒ t ||¡ t ||¡ t |tjtj	B ¡ t |tj
¡ |  t |¡jt |¡j¡ t ||¡ |  t |¡jt |¡j¡ tjdkr€t |tj
¡ t ||¡ |  t |¡jt |¡j¡ t |tj
¡ t ||¡ |  t |¡jt |¡j¡ t |tj
¡ t ||¡ |  t |¡jt |¡j¡ d S )NrJ   ÚbarÚbazÚquuxrA   )rI   r   r%   r&   r+   rW   ru   r€   ÚS_IRWXUÚS_IRWXGÚS_IRWXOÚassertNotEqualr   rE   Úcopymoder\   r8   )r?   Útmp_dirÚsrcÚdstÚsrc_linkÚdst_linkr   r   r   Útest_copymode_follow_symlinks  s0    

z(TestShutil.test_copymode_follow_symlinksÚlchmodzrequires os.lchmodc             C   sp  |   ¡ }tj |d¡}tj |d¡}tj |d¡}tj |d¡}t|dƒ t|dƒ t ||¡ t ||¡ t |tjtj	B ¡ t |tj¡ t 
|tjtj	B ¡ t 
|tj¡ tj||dd |  t |¡jt |¡j¡ |  t |¡jt |¡j¡ t 
|tj¡ tj||dd |  t |¡jt |¡j¡ t 
|tj¡ tj||dd |  t |¡jt |¡j¡ d S )NrJ   r   r   r‘   F)Úfollow_symlinks)rI   r   r%   r&   r+   rW   ru   r€   r’   r“   r   r”   rE   r–   r\   r   r   r•   )r?   r—   r˜   r™   rš   r›   r   r   r   Ú test_copymode_symlink_to_symlink0  s.    

z+TestShutil.test_copymode_symlink_to_symlinkz requires os.lchmod to be missingc             C   s€   |   ¡ }tj |d¡}tj |d¡}tj |d¡}tj |d¡}t|dƒ t|dƒ t ||¡ t ||¡ tj||dd d S )NrJ   r   r   r‘   F)rž   )rI   r   r%   r&   r+   rW   rE   r–   )r?   r—   r˜   r™   rš   r›   r   r   r   Ú*test_copymode_symlink_to_symlink_wo_lchmodN  s    

z5TestShutil.test_copymode_symlink_to_symlink_wo_lchmodc       
      C   sò  |   ¡ }tj |d¡}tj |d¡}tj |d¡}tj |d¡}t|dƒ t |¡}t ||j|jd f¡ t|dƒ |  	t |¡jt |¡j¡ t 
||¡ t 
||¡ ttdƒrÂt |tj¡ ttdƒrättdƒrät |tj¡ t |¡}ttdƒr tj||d	d
 |  	|jt |¡j¡ tj||dd
 t |¡}tjtjkrtx*dD ]"}	|  t||	ƒt||	ƒd ¡ qNW ttdƒr|  |j|j¡ ttdƒr¸t|dƒr¸|  |j|j¡ tj||dd
 |  tt |¡jt |¡j ƒdk ¡ d S )NrJ   r   r   Úquxg      E@r   ÚlchflagsÚ	UF_NODUMPT)rž   F)Úst_atimeÚst_mtimerU   Úst_flagsgš™™™™™¹?)rI   r   r%   r&   r+   r€   Úutimer¤   r¥   r•   rW   Úhasattrr   r”   r¢   r£   r   rE   Úcopystatr   Úsupports_follow_symlinksÚassertLessEqualr   r\   r¦   rY   Úabs)
r?   r—   r˜   r™   rš   r›   Úsrc_statÚsrc_link_statZdst_link_statÚattrr   r   r   Útest_copystat_symlinks\  sD    







z!TestShutil.test_copystat_symlinksÚchflagsÚ
EOPNOTSUPPÚENOTSUPz)requires os.chflags, EOPNOTSUPP & ENOTSUPc             C   s¨   |   ¡ }tj |d¡}tj |d¡}t|dƒ t|dƒ dd„ }tj}zTx*tjtjfD ]}||ƒt_t	 
||¡ qVW |tjtj ƒt_|  tt	j
||¡ W d |t_X d S )Nrc   Úfile2Úxxxc                s   t ƒ ‰ddœ‡ ‡fdd„
}|S )NT)rž   c               s   ˆ ˆ_ ˆ‚d S )N)r   )r%   Úflagsrž   )ÚerrÚexr   r   Ú_chflags_raiser“  s    znTestShutil.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser.<locals>._chflags_raiser)r   )r·   r¹   r   )r·   r¸   r   Úmake_chflags_raiser  s    zUTestShutil.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser)rI   r   r%   r&   r+   r±   r   r²   r³   rE   r©   rX   r   )r?   rr   rc   r´   rº   Zold_chflagsr·   r   r   r   Ú-test_copystat_handles_harmless_chflags_errors…  s    


z8TestShutil.test_copystat_handles_harmless_chflags_errorsc                s  |   ¡ }tj |d¡‰tˆdƒ tj |d¡}t|dƒ t ˆ|¡ t ˆdd¡ t ˆdd¡ t ˆ|¡ |  t	t 
ˆ¡ƒt	t 
|¡ƒ¡ |  t ˆd¡t |d¡¡ t |¡ t|dƒ ttjdƒ‰‡‡fdd	„}z.tj‰|t_t ˆ|¡ |  dt 
|¡¡ W d ˆt_X d
dœ‡ ‡fdd„
}ztj
‰ |t_
t ˆ|¡ W d ˆ t_
X tj |d¡‰tj |d¡}tˆˆƒ t||ƒ t ˆdd¡ t |dd¡ t |d¡ tj |d¡}tj |d¡}t||ƒ t||ƒ t ˆ|¡ t ||¡ |  t |d¡d¡ |  t |d¡d¡ d S )NrJ   r   zuser.foos   42zuser.bars   43ÚEPERMc                s"   |dkrˆ‚nˆ | ||f|Ž d S )Nzuser.foor   )Úfnamer¯   Úvalr   )Úorig_setxattrÚos_errorr   r   Ú_raise_on_user_foo¹  s    z5TestShutil.test_copyxattr.<locals>._raise_on_user_fooT)rž   c               s    | ˆkrt tjdƒ‚ˆ | |dS )NzOperation not supported)rž   )r   r   r³   )r½   rž   )Úorig_listxattrr˜   r   r   Ú_raise_on_srcÆ  s    z0TestShutil.test_copyxattr.<locals>._raise_on_srcZthe_originalZthe_original_rozuser.the_values   fiddlyi$  Zthe_copyZthe_copy_ro)rI   r   r%   r&   r+   rE   Ú
_copyxattrÚsetxattrr\   r1   Ú	listxattrÚgetxattrÚremover   r   r¼   rn   ru   r©   )r?   r—   r™   rÁ   rÃ   ZsrcroZdstror   )rÂ   r¿   rÀ   r˜   r   Útest_copyxattr¢  sX    

 






zTestShutil.test_copyxattrzroot privileges requiredc             C   sî   |   ¡ }tj |d¡}tj |d¡}t|dƒ t ||¡ t |dd¡ tj|dddd tj |d¡}tj |d	¡}t|dƒ t ||¡ tj||dd |  	tj
|dddd¡ |  ttj
|d¡ tj||dd |  	t 
|d¡d¡ d S )
NrJ   r   ztrusted.foos   42s   43F)rž   r   r¡   )rI   r   r%   r&   r+   rW   rÅ   rE   rÄ   r\   rÇ   rX   r   )r?   r—   r˜   rš   r™   r›   r   r   r   Útest_copyxattr_symlinksâ  s     

z"TestShutil.test_copyxattr_symlinksc             C   s  |   ¡ }tj |d¡}tj |d¡}tj |d¡}t|dƒ t ||¡ ttdƒrft |tj	tj
B ¡ tj||dd |  tj |¡¡ |  t|ƒt|ƒ¡ t |¡ tj||dd |  tj |¡¡ |  t |¡t |¡¡ ttdƒr|  t |¡jt |¡j¡ d S )NrJ   r   r   r   T)rž   F)rI   r   r%   r&   r+   rW   r¨   r   r€   r’   r”   rE   Úcopyrg   r4   r\   r/   rÈ   rY   Úreadlinkr   r   )r?   r—   r˜   r™   rš   r   r   r   Útest_copy_symlinksû  s$    


zTestShutil.test_copy_symlinksc       	      C   s²  |   ¡ }tj |d¡}tj |d¡}tj |d¡}t|dƒ t ||¡ ttdƒrft |tj	tj
B ¡ ttdƒrˆttdƒrˆt |tj¡ t |¡}t |¡}tj||dd |  tj |¡¡ |  t|ƒt|ƒ¡ t |¡ tj||d	d |  tj |¡¡ |  t |¡t |¡¡ t |¡}tjtjkrZx*d
D ]"}|  t||ƒt||ƒd ¡ q4W ttdƒr†|  |j|j¡ |  |j|j¡ ttdƒr®t|dƒr®|  |j|j¡ d S )NrJ   r   r   r   r¢   r£   T)rž   F)r¤   r¥   rU   r¦   )rI   r   r%   r&   r+   rW   r¨   r   r€   r’   r”   r¢   r£   r   rE   Úcopy2rg   r4   r\   r/   rÈ   rY   rÌ   r§   rª   r«   r   r   r•   r¦   )	r?   r—   r˜   r™   rš   r­   r®   Údst_statr¯   r   r   r   Útest_copy2_symlinks  s:    






zTestShutil.test_copy2_symlinksc             C   sr   |   ¡ }tj |d¡}tj |d¡}t|dƒ t |dd¡ t ||¡ |  t 	|d¡t 	|d¡¡ t 
|¡ d S )NrJ   r   zuser.foos   42)rI   r   r%   r&   r+   rÅ   rE   rÎ   r\   rÇ   rÈ   )r?   r—   r˜   r™   r   r   r   Útest_copy2_xattr5  s    

zTestShutil.test_copy2_xattrc             C   s²   |   ¡ }tj |d¡}tj |d¡}tj |d¡}tj |d¡}t|dƒ t ||¡ tj||dd |  tj 	|¡¡ |  
t |¡t |¡¡ t ||¡ |  tj 	|¡¡ d S )Nr˜   r™   r›   rR   rJ   F)rž   )rI   r   r%   r&   r+   rW   rE   ÚcopyfilerY   r4   r\   rÌ   rg   )r?   r—   r˜   r™   r›   rR   r   r   r   Útest_copyfile_symlinksB  s    
z!TestShutil.test_copyfile_symlinksc                sÖ   t jt jt jt jht jko0t jt jko0t jt jk}|r¸|  	t
j¡ |  	t
jj¡ |  ¡ }t j |d¡}t  |¡ z<t
j}G dd„ dtƒ‰ ‡ fdd„}|t
_|  ˆ t
j|¡ W d |t
_X n|  t
j¡ |  t
jj¡ d S )Nrx   c               @   s   e Zd ZdS )zHTestShutil.test_rmtree_uses_safe_fd_version_if_available.<locals>.CalledN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   ÚCalled`  s    r×   c                 s   ˆ ‚d S )Nr   )r   r   )r×   r   r   Ú_raisera  s    zITestShutil.test_rmtree_uses_safe_fd_version_if_available.<locals>._raiser)r   r'   r€   r†   rq   Úsupports_dir_fdr2   Úsupports_fdrª   rY   rE   Ú_use_fd_functionsrF   Zavoids_symlink_attacksrI   r%   r&   rK   Z_rmtree_safe_fdÚ	ExceptionrX   rg   )r?   rÛ   r—   rG   Zreal_rmtreerØ   r   )r×   r   Ú-test_rmtree_uses_safe_fd_version_if_availableS  s&    

z8TestShutil.test_rmtree_uses_safe_fd_version_if_availablec             C   s4   t  ¡ \}}t |¡ |  ttj|¡ t |¡ d S )N)	rH   Zmkstempr   ÚcloserX   rm   rE   rF   rÈ   )r?   Zhandler%   r   r   r   Útest_rmtree_dont_delete_filek  s    
z'TestShutil.test_rmtree_dont_delete_filec          	   C   s  t  ¡ }tj t  ¡ d¡}|  tj|¡ |  tjtj |¡¡ t	|dfdƒ t 
tj |d¡¡ t	|ddfdƒ t ||¡ |  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Údestinationztest.txtÚ123Útest_dirÚ456)rH   rI   r   r%   r&   r|   rE   rF   Údirnamer+   rK   ÚcopytreerY   Úisfiler3   r/   r\   )r?   Úsrc_dirÚdst_dirÚactualr   r   r   Útest_copytree_simpler  s     
zTestShutil.test_copytree_simplec       	   	   C   sl  |   ¡ }tj |d¡}tj |d¡}tj |d¡}t |¡ t |¡ t|dfdƒ tj |d¡}tj |d¡}t tj |d¡|¡ ttdƒr¤t |t	j
t	jB ¡ ttd	ƒrÆtt	d
ƒrÆt |t	j¡ t |¡}tj||dd |  tj tj |dd¡¡¡ |  t tj |dd¡¡tj |d¡¡ t |¡}ttdƒrL|  |j|j¡ ttd	ƒrh|  |j|j¡ d S )Nr˜   r™   Úsubzfile.txtrJ   rR   zsub/linkr   r¢   r£   T)Úsymlinks)rI   r   r%   r&   rK   r+   rW   r¨   r   r€   r’   r”   r¢   r£   r   rE   rå   rY   r4   r\   rÌ   r   r¦   )	r?   r—   rç   rè   Zsub_dirrš   r›   r­   rÏ   r   r   r   Útest_copytree_symlinks…  s2    




z!TestShutil.test_copytree_symlinksc             C   s$  t jj}t jj}t ¡ }zæ|t ¡ dƒ}t|dfdƒ t|dfdƒ t  ||dƒ¡ t|ddfdƒ t  ||dƒ¡ t|ddfdƒ t  ||ddƒ¡ t  ||dd	ƒ¡ t|dddfdƒ t|dd	d
fdƒ z\t 	dd¡}tj
|||d |  |||dƒƒ¡ |  |||dƒƒ¡ |  |||dƒƒ¡ W d t |¡ X z`t 	dd¡}tj
|||d |  |||dƒƒ¡ |  |||dd	ƒƒ¡ |  |||ddƒƒ¡ W d t |¡ X zJdd„ }tj
|||d |  |||dd	d
ƒƒ¡ |  |||ddƒƒ¡ W d t |¡ X W d t |¡ t t j |¡¡ X d S )Nrà   ztest.txtrá   ztest.tmprâ   rã   Z	test_dir2ÚsubdirZsubdir2ztest.pyz*.tmp)Úignorezsubdir*c             S   sj   g }x`|D ]X}t j | |¡}t j |¡rD| ¡ d dkrD| |¡ q
t j |¡d dkr
| |¡ q
W |S )Néÿÿÿÿrî   z.py)r   r%   r&   r3   Úsplitr5   Úsplitext)r˜   Únamesr7   r8   r%   r   r   r   Ú_filterÉ  s    
z6TestShutil.test_copytree_with_exclude.<locals>._filter)r   r%   r&   rZ   rH   rI   r+   rK   rE   Úignore_patternsrå   rY   rg   rF   rä   )r?   r&   rZ   rç   rè   Zpatternsrô   r   r   r   Útest_copytree_with_exclude¡  sL    

z%TestShutil.test_copytree_with_excludec          	   C   sj  t  ¡ }tj |d¡}t |¡ tj |d¡}|  tj|¡ t 	|d¡ t
|dfdƒ t 	tj |d¡d¡ t
|dfdƒ t 	tj |d¡d¡ t j|d	}t 	|d¡ t ||¡ |  t |¡jt |¡j¡ |  t tj |d¡¡jt tj |d¡¡j¡ |  t tj |d¡¡jt tj |d¡¡j¡ tj |tj |¡d
 ¡}|  t |¡jt |¡j¡ d S )NÚsourcerà   iÿ  zpermissive.txtrá   zrestrictive.txtrã   i€  )rQ   rU   )rH   rI   r   r%   r&   rK   r|   rE   rF   ru   r+   rå   r\   r€   r   rñ   )r?   r—   rç   rè   Zrestrictive_subdirZrestrictive_subdir_dstr   r   r   Ú!test_copytree_retains_permissionsâ  s,    
z,TestShutil.test_copytree_retains_permissionszos.chmodc          	   C   sp   t  ¡ }tj t  ¡ d¡}|  tj|¡ |  tjtj |¡¡ t	dƒ|_
|  tj¡ t ||¡ W d Q R X d S )Nrà   zka-boom)rH   rI   r   r%   r&   r|   rE   rF   rä   ÚPermissionErrorÚside_effectrX   r   rå   )r?   Z
mock_patchrç   rè   r   r   r   Útest_copytree_winerrorü  s    
z!TestShutil.test_copytree_winerrorrA   ztemporarily disabled on WindowsrR   zrequires os.linkc          
   C   sæ   t  t¡ t j td¡}t j td¡}zªt|dƒ}| d¡ W d Q R X yt  ||¡ W n0 tk
rˆ } z|  	d| ¡ W d d }~X Y nX |  
tjtj||¡ t|dƒ}|  | ¡ d¡ W d Q R X t  |¡ W d tjtdd X d S )	NÚcheeseÚshopr"   Úcheddarzos.link(): %sr-   T)ri   )r   rK   r   r%   r&   r'   r(   rR   rù   ÚskipTestrX   rE   r   rÒ   r\   r.   rÈ   rF   )r?   r˜   r™   ÚfÚer   r   r   Ú'test_dont_copy_file_onto_link_to_itself
  s    
 z2TestShutil.test_dont_copy_file_onto_link_to_itselfc          
   C   s°   t  t¡ t j td¡}t j td¡}ztt|dƒ}| d¡ W d Q R X t  d|¡ |  t	j
t	j||¡ t|dƒ}|  | ¡ d¡ W d Q R X t  |¡ W d t	jtdd X d S )Nrü   rý   r"   rþ   r-   T)ri   )r   rK   r   r%   r&   r'   r(   rW   rX   rE   r   rÒ   r\   r.   rÈ   rF   )r?   r˜   r™   r   r   r   r   Ú*test_dont_copy_file_onto_symlink_to_itself  s    
z5TestShutil.test_dont_copy_file_onto_symlink_to_itselfc          
   C   st   t  t¡ zTt j td¡}t j td¡}t  |¡ t  ||¡ |  ttj	|¡ tj	|dd W d tj	tdd X d S )Nrü   rý   T)ri   )
r   rK   r   r%   r&   rW   rX   r   rE   rF   )r?   r˜   r™   r   r   r   Útest_rmtree_on_symlink3  s    

z!TestShutil.test_rmtree_on_symlinkÚmkfifozrequires os.mkfifo()c          
   C   s~   yt  t¡ W n0 tk
r> } z|  d| ¡ W d d }~X Y nX z,|  tjtjtt	¡ |  tjtjt
t¡ W d t  t¡ X d S )Nzos.mkfifo(): %s)r   r  r   rù   rÿ   rX   rE   ÚSpecialFileErrorrÒ   ÚTESTFN2Ú__file__rÈ   )r?   r  r   r   r   Útest_copyfile_named_pipeB  s     z#TestShutil.test_copyfile_named_pipec          
   C   s  t  t¡ zât j td¡}t  |¡ t j |d¡}yt  |¡ W n0 tk
rp } z|  d| ¡ W d d }~X Y nX yt 	tt
¡ W n\ tjk
rÞ } z<|jd }|  t|ƒd¡ |d \}}}|  d| |¡ W d d }~X Y nX |  d¡ W d tjtdd	 tjt
dd	 X d S )
Nrî   Zmypipezos.mkfifo(): %sr   rU   z`%s` is a named pipez$shutil.Error should have been raisedT)ri   )r   rK   r   r%   r&   r  rù   rÿ   rE   rå   r  r   r   r\   r]   ÚfailrF   )r?   rî   Úpiper  rS   r˜   r™   Z	error_msgr   r   r   Útest_copytree_named_pipeP  s&    

 
"z#TestShutil.test_copytree_named_pipec                s€   |   ¡ }tj |   ¡ d¡}t|dfdƒ t tj |d¡¡ t|ddfdƒ g ‰ ‡ fdd„}tj|||d |  t	ˆ ƒd	¡ d S )
Nrà   ztest.txtrá   râ   rã   c                s   ˆ   | |f¡ d S )N)r5   )r˜   r™   )Úcopiedr   r   Ú_copyr  s    z4TestShutil.test_copytree_special_func.<locals>._copy)Úcopy_functionrV   )
rI   r   r%   r&   r+   rK   rE   rå   r\   r]   )r?   rç   rè   r  r   )r  r   Útest_copytree_special_funci  s    z%TestShutil.test_copytree_special_funcc             C   sÒ   |   ¡ }tj |   ¡ d¡}t dtj |d¡¡ t tj |d¡¡ t|ddfdƒ |  tt	j
||¡ tj |   ¡ d¡}t	j
||dd |  dt |¡¡ tj |   ¡ d	¡}t	j
||dd
 |  dt |¡¡ d S )Nrà   Z
IDONTEXISTztest.txtrâ   rã   Údestination2T)Zignore_dangling_symlinksZdestination3)rì   )rI   r   r%   r&   rW   rK   r+   rX   r   rE   rå   ÚassertNotInr2   rn   )r?   rç   rè   r   r   r   Útest_copytree_dangling_symlinksx  s    z*TestShutil.test_copytree_dangling_symlinksc          	   C   s  |   ¡ }tj |   ¡ d¡}t tj |d¡¡ ttj |dd¡dƒ W d Q R X tjtj |d¡tj |d¡dd tj||dd	 |  	tj 
tj |d¡¡¡ |  dt tj |d¡¡¡ tj |   ¡ d
¡}tj||dd	 |  tj 
tj |d¡¡¡ |  dt tj |d¡¡¡ d S )Nrà   Zreal_dirztest.txtr"   Zlink_to_dirT)Ztarget_is_directoryF)rì   r  )rI   r   r%   r&   rK   r'   rW   rE   rå   rg   r4   rn   r2   rY   )r?   rç   rè   r   r   r   Útest_copytree_symlink_dir  s    
z$TestShutil.test_copytree_symlink_dirc             C   sP   d}|   ¡ }t||fdƒ tj ||¡}|   ¡ }|||ƒ tj ||¡}||fS )Nztest.txtrµ   )rI   r+   r   r%   r&   )r?   Úmethodr½   rr   rc   Útmpdir2r´   r   r   r   Ú
_copy_file¡  s    
zTestShutil._copy_filec             C   sB   |   tj¡\}}|  tj |¡¡ |  t |¡j	t |¡j	¡ d S )N)
r  rE   rË   rY   r   r%   rZ   r\   r€   r   )r?   rc   r´   r   r   r   Ú	test_copy«  s    zTestShutil.test_copyr§   zrequires os.utimec             C   s    |   tj¡\}}|  tj |¡¡ t |¡}t |¡}|  |j	|j	¡ x(dD ] }|  
t||ƒt||ƒd ¡ qLW ttdƒrœt|dƒrœ|  t|dƒt|dƒ¡ d S )N)r¤   r¥   rU   r±   r¦   )r  rE   rÎ   rY   r   r%   rZ   r€   r\   r   r«   r   r¨   )r?   rc   r´   Z
file1_statZ
file2_statr¯   r   r   r   Ú
test_copy2²  s    


zTestShutil.test_copy2c       	   
   C   sf  |   d¡\}}|  ¡ }t |¡ tj |¡}tj tj |¡d¡}t 	|¡  tj 
|¡}t|d|dƒ}W d Q R X |  ||d ¡ |  tj |¡¡ |  t |¡¡ t |d¡"}|  | ¡ dddd	d
dg¡ W d Q R X t 	|¡ t|d|dƒ}W d Q R X |  ||d ¡ |  tj |¡¡ |  t |¡¡ t |d¡"}|  | ¡ dddd	d
dg¡ W d Q R X d S )Nrj   ÚarchiveÚgztarÚ.z.tar.gzzr:gzz./subz./sub2z./file1z./file2z./sub/file3Útarz.tarr-   )Ú_create_filesrI   r   rq   r%   rä   r&   Úbasenamer   Ú
change_cwdÚabspathr   r\   rY   ræ   ÚtarfileZ
is_tarfiler'   ÚassertCountEqualÚgetnames)	r?   Úroot_dirÚbase_dirr  Úwork_dirÚrel_base_nameÚ	base_nameÚtarballZtfr   r   r   Útest_make_tarballÄ  s0    


zTestShutil.test_make_tarballc          	   C   s.   t  |¡}| ¡ }| ¡  t|ƒS Q R X d S )N)r"  r'   r$  Úsortr$   )r?   r%   r  ró   r   r   r   Ú_tarinfoè  s    zTestShutil._tarinfoÚdistc             C   s’   |   ¡ }tj ||¡}tj|dd t|dfdƒ t|dfdƒ t tj |d¡¡ t|ddfdƒ t tj |d¡¡ |rŠt|d	fdƒ ||fS )
NT)Úexist_okrc   rµ   r´   rë   Zfile3Zsub2Úouter)rI   r   r%   r&   Úmakedirsr+   rK   )r?   r&  r%  r.  r   r   r   r  î  s    zTestShutil._create_filesr  zNeed the tar command to runc             C   s  |   ¡ \}}tj |  ¡ d¡}t|d||ƒ}|  ||d ¡ |  tj |¡¡ tj |d¡}ddd|g}t	j
||t	jd |  tj |¡¡ |  |  |¡|  |¡¡ t|d||ƒ}|  ||d ¡ |  tj |¡¡ t|d||d	d
}|  ||d ¡ |  tj |¡¡ d S )Nr  r  z.tar.gzzarchive2.tarr  z-cf)ÚcwdÚstdoutz.tarT)Zdry_run)r  r   r%   r&   rI   r   r\   rY   ræ   Ú
subprocessÚ
check_callÚDEVNULLr-  )r?   r%  r&  r)  r*  Ztarball2Ztar_cmdr   r   r   Útest_tarfile_vs_tarü  s$    

zTestShutil.test_tarfile_vs_tarc       	      C   sl  |   ¡ \}}|  ¡ }t |¡ tj |¡}tj tj |¡d¡}t 	|¡ tj 
|¡}t|d|ƒ}W d Q R X |  ||d ¡ |  tj |¡¡ |  t |¡¡ t |¡$}|  | ¡ dddddd	d
g¡ W d Q R X t 	|¡  tj 
|¡}t|d||ƒ}W d Q R X |  ||d ¡ |  tj |¡¡ |  t |¡¡ t |¡"}|  | ¡ dddddd	g¡ W d Q R X d S )Nr  Úzipz.zipzdist/z	dist/sub/z
dist/sub2/z
dist/file1z
dist/file2zdist/sub/file3r0  )r  rI   r   rq   r%   rä   r&   r  r   r   r!  r   r\   rY   ræ   ÚzipfileZ
is_zipfileÚZipFiler#  Únamelist)	r?   r%  r&  r  r'  r(  r)  r7   Úzfr   r   r   Útest_make_zipfile  s4    


zTestShutil.test_make_zipfiler8  zNeed the zip command to runc       
   	   C   sâ   |   ¡ \}}tj |  ¡ d¡}t|d||ƒ}|  ||d ¡ |  tj |¡¡ tj |d¡}dddd|g}t	j
||t	jd |  tj |¡¡ t |¡}| ¡ }W d Q R X t |¡}| ¡ }	W d Q R X |  t|ƒt|	ƒ¡ d S )Nr  r8  z.zipzarchive2.zipz-qz-r)r2  r3  )r  r   r%   r&   rI   r   r\   rY   ræ   r4  r5  r6  r9  r:  r;  r1   )
r?   r%  r&  r)  r  Zarchive2Úzip_cmdr<  ró   Znames2r   r   r   Útest_zipfile_vs_zipB  s    
zTestShutil.test_zipfile_vs_zipÚunzipzNeed the unzip command to runc       	      C   sâ   |   ¡ \}}tj |  ¡ d¡}t|d||ƒ}|  ||d ¡ |  tj |¡¡ dd|g}t	 
|¡v ytj|tjd W nZ tjk
rÒ } z:|jjdd}d	|kr¬|  d
¡ d}|  | ||¡¡ W d d }~X Y nX W d Q R X d S )Nr  r8  z.zipr@  z-t)ÚstderrÚreplace)rS   zunrecognized option: tzunzip doesn't support -tz{}

**Unzip Output**
{})r  r   r%   r&   rI   r   r\   rY   ræ   r   r   r4  Úcheck_outputZSTDOUTÚCalledProcessErrorÚoutputÚdecoderÿ   r
  Úformat)	r?   r%  r&  r)  r  r>  r‰   ZdetailsÚmsgr   r   r   Útest_unzip_zipfile\  s    

zTestShutil.test_unzip_zipfilec             C   s*   |   ¡ }tj |d¡}|  tt|d¡ d S )Nr  rµ   )rI   r   r%   r&   rX   Ú
ValueErrorr   )r?   rr   r)  r   r   r   Útest_make_archivet  s    zTestShutil.test_make_archivec             C   sÞ   t r"t d¡d }t d¡d }nd }}|  ¡ \}}tj |  	¡ d¡}t
|d||||d}|  tj |¡¡ t
|d||ƒ}|  tj |¡¡ t
|d||||d}|  tj |¡¡ t
|d||ddd}|  tj |¡¡ d S )	Nr   Úrootr  r8  )ÚownerÚgroupr  Z	kjhkjhkjgZoihohoh)ÚUID_GID_SUPPORTÚgrpÚgetgrgidÚpwdÚgetpwuidr  r   r%   r&   rI   r   rY   ræ   )r?   rN  rM  r%  r&  r)  r7   r   r   r   Útest_make_archive_owner_groupy  s"    



z(TestShutil.test_make_archive_owner_groupzRequires grp and pwd supportc       	   	   C   sÂ   |   ¡ \}}tj |  ¡ d¡}t d¡d }t d¡d }t	 
|¡ t|d|d||d}W d Q R X |  tj |¡¡ t |¡}z2x,| ¡ D ] }|  |jd¡ |  |jd¡ qŒW W d | ¡  X d S )Nr  r   r  r.  )rM  rN  )r  r   r%   r&   rI   rP  rQ  rR  rS  r   r   r   rY   ræ   r"  r'   Z
getmembersr\   ÚuidÚgidrÞ   )	r?   r%  r&  r)  rN  rM  Zarchive_namer  Úmemberr   r   r   Útest_tarfile_root_owner•  s    

z"TestShutil.test_tarfile_root_ownerc             C   sn   t  ¡ }dd„ }td|g dƒ z@ytdd|  ¡ d W n tk
rJ   Y nX |  t  ¡ |¡ W d tdƒ X d S )Nc              _   s
   t ƒ ‚d S )N)ÚRuntimeError)r   Úkwr   r   r   Ú_breaks®  s    z1TestShutil.test_make_archive_cwd.<locals>._breaksrµ   zxxx file)r%  )r   Úgetcwdr   r   rI   rÜ   r\   r   )r?   Zcurrent_dirr[  r   r   r   Útest_make_archive_cwd¬  s    z TestShutil.test_make_archive_cwdc          	   C   sF   |   ¡ }t |¡* |  tddƒd¡ |  tj d¡¡ W d Q R X d S )NÚtestr  ztest.tar)	rI   r   r   r\   r   rY   r   r%   ræ   )r?   r%  r   r   r   Útest_make_tarfile_in_curdir»  s    z&TestShutil.test_make_tarfile_in_curdirc          	   C   sF   |   ¡ }t |¡* |  tddƒd¡ |  tj d¡¡ W d Q R X d S )Nr^  r8  ztest.zip)	rI   r   r   r\   r   rY   r   r%   ræ   )r?   r%  r   r   r   Útest_make_zipfile_in_curdirÂ  s    z&TestShutil.test_make_zipfile_in_curdirc             C   s˜   |   ttdd¡ |   ttddd„ d¡ |   ttddd„ ddg¡ tddd„ dgd	ƒ d
d„ tƒ D ƒ}|  d|¡ tdƒ dd„ tƒ D ƒ}|  d|¡ d S )Nrµ   rU   c               S   s   t S )N)Úxr   r   r   r   Ú<lambda>Í  ó    z9TestShutil.test_register_archive_format.<locals>.<lambda>c               S   s   t S )N)ra  r   r   r   r   rb  Ï  rc  )rU   rV   )rU   rV   rz   c               S   s   t S )N)ra  r   r   r   r   rb  Ò  rc  zxxx filec             S   s   g | ]\}}|‘qS r   r   )Ú.0r8   Úparamsr   r   r   ú
<listcomp>Ó  s    z;TestShutil.test_register_archive_format.<locals>.<listcomp>c             S   s   g | ]\}}|‘qS r   r   )rd  r8   re  r   r   r   rf  ×  s    )rX   Ú	TypeErrorr   r   rn   r   r  )r?   Úformatsr   r   r   Útest_register_archive_formatÊ  s    
z'TestShutil.test_register_archive_formatc             C   s.   |   |dd„ ¡ |   |tj¡ |   |t¡ d S )Nc             S   s   | S )Nr   )r%   r   r   r   rb  Û  rc  z1TestShutil.check_unpack_archive.<locals>.<lambda>)Ú#check_unpack_archive_with_converterÚpathlibZPathr   )r?   rG  r   r   r   Úcheck_unpack_archiveÚ  s    zTestShutil.check_unpack_archivec       
      C   sÄ   |   ¡ \}}t|ƒ}| d¡ tj |  ¡ d¡}t||||ƒ}|  ¡ }t||ƒ||ƒƒ |  	t|ƒ|¡ |  ¡ }	t||ƒ||	ƒ|d |  	t|	ƒ|¡ |  
tjt|tƒ¡ | j
tt|tƒdd d S )Nr0  r  )rG  rµ   )r  r6   rÈ   r   r%   r&   rI   r   r   r\   rX   rE   Z	ReadErrorr   rJ  )
r?   rG  Z	converterr%  r&  Úexpectedr)  ro   r  Ztmpdir3r   r   r   rj  ß  s    
z.TestShutil.check_unpack_archive_with_converterc             C   s   |   d¡ d S )Nr  )rl  )r?   r   r   r   Útest_unpack_archive_tarô  s    z"TestShutil.test_unpack_archive_tarc             C   s   |   d¡ d S )Nr  )rl  )r?   r   r   r   Útest_unpack_archive_gztar÷  s    z$TestShutil.test_unpack_archive_gztarc             C   s   |   d¡ d S )NZbztar)rl  )r?   r   r   r   Útest_unpack_archive_bztarû  s    z$TestShutil.test_unpack_archive_bztarc             C   s   |   d¡ d S )NZxztar)rl  )r?   r   r   r   Útest_unpack_archive_xztarÿ  s    z$TestShutil.test_unpack_archive_xztarc             C   s   |   d¡ d S )Nr8  )rl  )r?   r   r   r   Útest_unpack_archive_zip  s    z"TestShutil.test_unpack_archive_zipc                s    t ƒ }‡ fd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                s(   ˆ   |d¡ ˆ   | d¡ ˆ   |d¡ d S )NrU   z	stuff.booÚxx)r\   )ro   Zextract_dirÚextra)r?   r   r   Ú_boo  s    z-TestShutil.test_unpack_registry.<locals>._booZBooz.booz.b2)rt  rU   z	stuff.boors  ZBoo2rj   )	r   r   r   rX   r	   r
   rn   r  r\   )r?   rh  ru  r   )r?   r   Útest_unpack_registry  s    


zTestShutil.test_unpack_registryÚ
disk_usagez)disk_usage not available on this platformc             C   s`   t  tj t¡¡}|  |jd¡ |  |jd¡ |  	|j
d¡ |  	|j|j¡ |  |j|j
¡ d S )Nr   )rE   rw  r   r%   rä   r  ZassertGreaterZtotalZusedÚassertGreaterEqualZfree)r?   Úusager   r   r   Útest_disk_usage!  s    zTestShutil.test_disk_usageÚchownzrequires os.chownc          	      s  ˆ  ¡ }tj|d‰ tˆ dƒ ˆ t¡ t ˆ ¡ W d Q R X ˆ t¡ tjˆ dd W d Q R X ˆ t¡ tjˆ dd W d Q R X ˆ t	¡ t ˆ d¡ W d Q R X ˆ t	¡ t ˆ d¡ W d Q R X t
 ¡ }t
 ¡ }d‡ ‡fd	d
„	}t ˆ ||¡ |ˆ ||ƒ t ˆ |¡ |ˆ |ƒ tjˆ |d |ˆ |ƒ tjˆ |d |ˆ |d t |||¡ ||||ƒ t ||¡ |||ƒ tj||d |||ƒ tj||d |||d t |¡d }t |¡d }t ˆ ||¡ |ˆ ||ƒ t |||¡ ||||ƒ d S )N)rQ   ztesting chown functionznon-existing username)Úuserznon-existing groupname)rN  s   spamg…ëQ¸	@c                s:   t  ˆ ¡}|d k	r ˆ ||j¡ |d k	r6ˆ ||j¡ d S )N)r   r€   r\   Úst_uidÚst_gid)r%   rU  rV  Ús)ro   r?   r   r   Úcheck_chownF  s
    
z*TestShutil.test_chown.<locals>.check_chown)rV  r   )NN)rI   rH   rk   r+   rX   rJ  rE   r{  ÚLookupErrorrg  r   ÚgetuidÚgetgidrR  rS  rP  rQ  )r?   rä   rU  rV  r€  r|  rN  r   )ro   r?   r   Ú
test_chown+  sL    




zTestShutil.test_chownc             C   sŒ   x†t jt jfD ]v}|  ¡ }|  ¡ }tj |d¡}t|dƒ |||ƒ}|  |tj |d¡¡ ||tj |d¡ƒ}|  |tj |d¡¡ qW d S )NrJ   r   )	rE   rË   rÎ   rI   r   r%   r&   r+   r\   )r?   rŠ   rç   rè   r˜   Úrvr   r   r   Útest_copy_return_valuef  s    

z!TestShutil.test_copy_return_valuec             C   sl   |   ¡ }|   ¡ }tj |d¡}tj |d¡}t|dƒ t ||¡}|  tj |¡¡ |  	t
|ƒt
|ƒ¡ d S )Nr   rJ   )rI   r   r%   r&   r+   rE   rÒ   rY   rZ   r\   r/   )r?   rç   rè   Údst_fileÚsrc_filer…  r   r   r   Útest_copyfile_return_valuer  s    
z%TestShutil.test_copyfile_return_valuec             C   sH   |   ¡ }tj |d¡}t|dƒ |  ttj||¡ |  t	tj||¡ d S )NrJ   )
rI   r   r%   r&   r+   rX   r   rE   rÒ   r   )r?   rç   rˆ  r   r   r   Útest_copyfile_same_file}  s
    
z"TestShutil.test_copyfile_same_filec             C   s\   |   ¡ }|d }|  tj|d¡ tj |d¡}t|dƒ t ||¡}|  	dgt 
|¡¡ d S )NÚdestTrJ   )rI   r|   rE   rF   r   r%   r&   r+   rå   r\   r2   )r?   rç   rè   r˜   r…  r   r   r   Útest_copytree_return_value‡  s    
z%TestShutil.test_copytree_return_value)r.  )\rÔ   rÕ   rÖ   r=   rC   rI   rP   r   Úskip_unless_symlinkr_   rh   rt   ÚunittestÚ
skipUnlessr¨   r   ÚskipIfÚsysÚplatformrw   r…   r„   rŽ   rœ   rŸ   r    r°   r   r»   Zskip_unless_xattrrÉ   rÊ   rÍ   rÐ   rÑ   rÓ   rÝ   rß   rê   rí   rö   rø   ÚmockÚpatchrû   r8   r  r  r  r	  r  r  r  r  r  r  r  Zrequires_zlibr+  r-  r  rE   Úwhichr7  r=  r?  rI  rK  rT  rO  rX  r]  r_  r`  ri  rl  rj  rn  ro  Zrequires_bz2rp  Zrequires_lzmarq  rr  rv  rz  r„  r†  r‰  rŠ  rŒ  Ú__classcell__r   r   )r@   r   r;   X   s¸   		$ )@#A
$
%	
:
r;   c               @   sÎ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Ze 	e
edƒoHe ¡ dkd¡dd„ ƒZdd„ Zdd„ Ze ejdkd¡dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Ze ejdkd$¡d%d&„ ƒZd'S )(Ú	TestWhichc             C   sp   t jdd| _|  tj| jd¡ t j| jddd| _t 	| jj
tj¡ |  | jj¡ tj | jj
¡\| _| _d S )NZTmp)ÚprefixTz.Exe)rQ   r˜  Úsuffix)rH   rI   Útemp_dirr|   rE   rF   ÚNamedTemporaryFileÚ	temp_filer   ru   r8   r€   ÚS_IXUSRrÞ   r%   rñ   rQ   Úfile)r?   r   r   r   r=   ”  s    
zTestWhich.setUpc             C   s&   t j| j| jd}|  || jj¡ d S )N)r%   )rE   r•  rž  rQ   r\   rœ  r8   )r?   r…  r   r   r   Ú
test_basic   s    zTestWhich.test_basicc             C   s(   t j| jj| jd}|  || jj¡ d S )N)r%   )rE   r•  rœ  r8   rš  r\   )r?   r…  r   r   r   Útest_absolute_cmd¥  s    zTestWhich.test_absolute_cmdc          	   C   sŒ   t j | j¡\}}t j || j¡}tj|d" tj	|| j
d}|  ||¡ W d Q R X tj| jd tj	||d}|  |¡ W d Q R X d S )N)r%   )r   r%   rñ   rQ   r&   rž  r   r   rE   r•  rš  r\   ÚassertIsNone)r?   r&  Útail_dirÚrelpathr…  r   r   r   Útest_relative_cmd«  s    zTestWhich.test_relative_cmdc          	   C   sl   t j | j¡}tj| jdF tj| j|d}t	j
dkrT|  |t j t j| j¡¡ n
|  |¡ W d Q R X d S )N)r%   Úwin32)r   r%   rä   rQ   r   r   rE   r•  rž  r‘  r’  r\   r&   Úcurdirr¡  )r?   r&  r…  r   r   r   Útest_cwd¸  s    
zTestWhich.test_cwdrw   r   znon-root user requiredc             C   sR   t  | jjtj¡ t  | jjt j¡r.|  d¡ t	j
| j| jt jd}|  |¡ d S )Nzcan't set the file read-only)r%   Úmode)r   ru   rœ  r8   r€   r‚   ÚaccessÚW_OKrÿ   rE   r•  rž  rQ   r¡  )r?   r…  r   r   r   Útest_non_matching_modeÄ  s
    
z TestWhich.test_non_matching_modec          	   C   sV   t j | j¡\}}tj|d. tj| j|d}|  	|t j 
|| j¡¡ W d Q R X d S )N)r%   )r   r%   rñ   rQ   r   r   rE   r•  rž  r\   r&   )r?   r&  r¢  r…  r   r   r   Útest_relative_pathÎ  s    zTestWhich.test_relative_pathc             C   s   t jd| jd}|  |¡ d S )Nzfoo.exe)r%   )rE   r•  rQ   r¡  )r?   r…  r   r   r   Útest_nonexistent_fileÔ  s    zTestWhich.test_nonexistent_filer¥  zpathext check is Windows-onlyc             C   s:   t j| jd d… | jd}|  || jjd d… d ¡ d S )Néüÿÿÿ)r%   z.EXE)rE   r•  rž  rQ   r\   rœ  r8   )r?   r…  r   r   r   Útest_pathext_checkingÙ  s    zTestWhich.test_pathext_checkingc          	   C   s>   t  ¡ ,}| j|d< t | j¡}|  || jj¡ W d Q R X d S )NÚPATH)	r   ÚEnvironmentVarGuardrQ   rE   r•  rž  r\   rœ  r8   )r?   Úenvr…  r   r   r   Útest_environ_pathá  s    

zTestWhich.test_environ_pathc             C   sŠ   t  ¡ x}d|d< tjjd| jddP t  td| j¡4 t  | j¡ t	 
| j¡}|  |¡ W d Q R X W d Q R X W d Q R X W d Q R X d S )Nrj   r°  z
os.confstrT)Úreturn_valueÚcreateÚdefpath)r   r±  rŽ  r“  r”  rQ   Ú	swap_attrr   r   rE   r•  rž  r¡  )r?   r²  r…  r   r   r   Útest_environ_path_emptyç  s    

z!TestWhich.test_environ_path_emptyc             C   sæ   t j | jj¡}tjdkrBt j}t|t	ƒr4t  
|¡}t j ||¡}t ¡ ’}t j|d< tjjd| jddh t t d| j¡L t | j¡}|  |¡ t | j¡ t | j¡}|  ||¡ W d Q R X W d Q R X W d Q R X W d Q R X d S )Nr¥  r°  z
os.confstrT)r´  rµ  r¶  )r   r%   r  rœ  r8   r‘  r’  r¦  r#   rN   rL   r&   r   r±  ÚpathseprŽ  r“  r”  rQ   r·  rE   r•  rž  r¡  r   r\   )r?   Zexpected_cwdr¦  r²  r…  r   r   r   Útest_environ_path_cwdò  s     






zTestWhich.test_environ_path_cwdc             C   sÐ   t  ¡ ¾}| dd ¡ tjjdtdd. t  td| j	¡ t
 | j¡}W d Q R X W d Q R X |  || jj¡ tjjd| j	dd, t  tdd¡ t
 | j¡}W d Q R X W d Q R X |  || jj¡ W d Q R X d S )Nr°  z
os.confstrT)rú   rµ  r¶  )r´  rµ  rj   )r   r±  rD   rŽ  r“  r”  rJ  r·  r   rQ   rE   r•  rž  r\   rœ  r8   )r?   r²  r…  r   r   r   Útest_environ_path_missing  s    


 
 z#TestWhich.test_environ_path_missingc          
   C   sd   t j | j¡}tj| jd> t ¡ *}| j|d< tj| j	dd}|  
|¡ W d Q R X W d Q R X d S )N)r%   r°  rj   )r   r%   rä   rQ   r   r   r±  rE   r•  rž  r¡  )r?   r&  r²  r…  r   r   r   Útest_empty_path  s    

zTestWhich.test_empty_pathc          	   C   s:   t  ¡ (}| dd ¡ t | j¡}|  |¡ W d Q R X d S )Nr°  )r   r±  rD   rE   r•  rž  r¡  )r?   r²  r…  r   r   r   Útest_empty_path_no_PATH"  s    
z!TestWhich.test_empty_path_no_PATHztest specific to Windowsc          	   C   sŽ   d}t j| jd|d}t |jtj¡ |  |j	¡ tj
 |j¡}tj
 |¡d }t ¡ ,}||d< tj|| jd}|  ||j¡ W d Q R X d S )Nz.xyzZTmp2)rQ   r˜  r™  r   ZPATHEXT)r%   )rH   r›  rš  r   ru   r8   r€   r  r|   rÞ   r%   r  rò   r   r±  rE   r•  r\   )r?   ZextZtemp_filexyzZprogramr²  r…  r   r   r   Útest_pathext(  s    

zTestWhich.test_pathextN)rÔ   rÕ   rÖ   r=   rŸ  r   r¤  r§  rŽ  r  r¨   r   rw   r«  r¬  r­  r  r‘  r’  r¯  r³  r¸  rº  r»  r¼  r½  r¾  r   r   r   r   r—  ’  s$   	r—  c               @   s,  e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Ze	dd„ ƒZ
e	dd„ ƒZdd„ Ze	dd„ ƒZdd„ Ze	dd„ ƒZdd„ Ze ejjd¡dd„ ƒZdd„ Zd d!„ Zd"d#„ Zd$d%„ Zeje	d&d'„ ƒƒZeje	d(d)„ ƒƒZeje	d*d+„ ƒƒZeje	d,d-„ ƒƒZ d.d/„ Z!d0d1„ Z"e	d2d3„ ƒZ#e	d4d5„ ƒZ$d6S )7ÚTestMovec          	   C   sb   d}t  ¡ | _t  ¡ | _tj | j|¡| _tj | j|¡| _t	| jdƒ}| 
d¡ W d Q R X d S )NrJ   r!   s   spam)rH   rI   rç   rè   r   r%   r&   rˆ  r‡  r'   r(   )r?   ro   r   r   r   r   r=   <  s    

zTestMove.setUpc             C   s:   x4| j | jfD ]$}y|r"t |¡ W q   Y qX qW d S )N)rç   rè   rE   rF   )r?   rG   r   r   r   rC   E  s    zTestMove.tearDownc          	   C   sf   t |dƒ}| ¡ }W d Q R X t ||¡ t |dƒ}|  || ¡ ¡ W d Q R X |  tj |¡¡ d S )Nr,   )	r'   r.   rE   Úmover\   rg   r   r%   rZ   )r?   r˜   r™   Úreal_dstr   Úcontentsr   r   r   Ú_check_move_fileM  s    zTestMove._check_move_filec             C   sF   t t |¡ƒ}t ||¡ |  |t t |¡ƒ¡ |  tj |¡¡ d S )N)	r1   r   r2   rE   rÀ  r\   rg   r%   rZ   )r?   r˜   r™   rÁ  rÂ  r   r   r   Ú_check_move_dirU  s    zTestMove._check_move_dirc             C   s   |   | j| j| j¡ d S )N)rÃ  rˆ  r‡  )r?   r   r   r   Útest_move_file[  s    zTestMove.test_move_filec             C   s   |   | j| j| j¡ d S )N)rÃ  rˆ  rè   r‡  )r?   r   r   r   Útest_move_file_to_dir_  s    zTestMove.test_move_file_to_dirc             C   s   |   ¡  d S )N)rÅ  )r?   r   r   r   Útest_move_file_other_fsc  s    z TestMove.test_move_file_other_fsc             C   s   |   ¡  d S )N)rÆ  )r?   r   r   r   Útest_move_file_to_dir_other_fsh  s    z'TestMove.test_move_file_to_dir_other_fsc             C   s@   t  ¡ }z|  | j||¡ W d yt |¡ W n   Y nX X d S )N)rH   rk   rÄ  rç   rE   rF   )r?   rè   r   r   r   Útest_move_dirm  s    zTestMove.test_move_dirc             C   s   |   ¡  d S )N)rÉ  )r?   r   r   r   Útest_move_dir_other_fsx  s    zTestMove.test_move_dir_other_fsc          
   C   s,   |   | j| jtj | jtj | j¡¡¡ d S )N)rÄ  rç   rè   r   r%   r&   r  )r?   r   r   r   Útest_move_dir_to_dir}  s    zTestMove.test_move_dir_to_dirc             C   s   |   ¡  d S )N)rË  )r?   r   r   r   Útest_move_dir_to_dir_other_fs‚  s    z&TestMove.test_move_dir_to_dir_other_fsc          
   C   s4   |   | jtjj | jtj | jtj | j¡¡¡ d S )N)rÄ  rç   r   r%   Úseprè   r&   r  )r?   r   r   r   Útest_move_dir_sep_to_dir‡  s    z!TestMove.test_move_dir_sep_to_dirzrequires os.path.altsepc          
   C   s4   |   | jtjj | jtj | jtj | j¡¡¡ d S )N)rÄ  rç   r   r%   Úaltseprè   r&   r  )r?   r   r   r   Útest_move_dir_altsep_to_dir‹  s    z$TestMove.test_move_dir_altsep_to_dirc          	   C   s4   t | jdƒ W d Q R X |  tjtj| j| j¡ d S )Nr!   )r'   r‡  rX   rE   r   rÀ  rˆ  rè   )r?   r   r   r   Ú"test_existing_file_inside_dest_dir  s    
z+TestMove.test_existing_file_inside_dest_dirc             C   s*   t j | jd¡}|  tjtj| j|¡ d S )Nr   )r   r%   r&   rç   rX   rE   r   rÀ  )r?   r™   r   r   r   Útest_dont_move_dir_in_itself–  s    z%TestMove.test_dont_move_dir_in_itselfc          
   C   sp   t  t¡ zPxJdD ]B\}}t j t|¡}t j t|¡}| jt ||¡d||f d qW W d tjtdd X d S )N))Úsrcdirzsrcdir/destz?_destinsrc() wrongly concluded that dst (%s) is not in src (%s))rH  T)ri   )	r   rK   r   r%   r&   rY   rE   Ú
_destinsrcrF   )r?   r˜   r™   r   r   r   Útest_destinsrc_false_negative›  s    
z&TestMove.test_destinsrc_false_negativec          
   C   sp   t  t¡ zPxJdD ]B\}}t j t|¡}t j t|¡}| jt ||¡d||f d qW W d tjtdd X d S )N))rÓ  zsrc/dest)rÓ  z
srcdir.newz;_destinsrc() wrongly concluded that dst (%s) is in src (%s))rH  T)ri   )	r   rK   r   r%   r&   rg   rE   rÔ  rF   )r?   r˜   r™   r   r   r   Útest_destinsrc_false_positive§  s    
z&TestMove.test_destinsrc_false_positivec             C   s\   t j | jd¡}t  | j|¡ t || j¡ |  	t j 
| j¡¡ |  	t j | j| j¡¡ d S )Nr   )r   r%   r&   rç   rW   rˆ  rE   rÀ  r‡  rY   r4   Úsamefile)r?   r™   r   r   r   Útest_move_file_symlink³  s
    zTestMove.test_move_file_symlinkc             C   sl   d}t j | j|¡}t  | j|¡ t || j¡ t j | j|¡}|  	t j 
|¡¡ |  	t j | j|¡¡ d S )Nr   )r   r%   r&   rç   rW   rˆ  rE   rÀ  rè   rY   r4   r×  )r?   ro   r™   Z
final_linkr   r   r   Útest_move_file_symlink_to_dir¼  s    z&TestMove.test_move_file_symlink_to_dirc             C   s    t j | jd¡}t j | jd¡}t  ||¡ t j | jd¡}t ||¡ |  t j 	|¡¡ t j
dkr€|  t j |¡t  |¡¡ n|  t j |¡t j |¡¡ d S )Nr   r   r‘   rA   )r   r%   r&   rç   rW   rè   rE   rÀ  rY   r4   r8   r\   ÚrealpathrÌ   )r?   r˜   r™   r›   r   r   r   Útest_move_dangling_symlinkÇ  s    
z#TestMove.test_move_dangling_symlinkc             C   s|   t j | jd¡}t j | jd¡}t  |¡ t  ||¡ t j | jd¡}t ||¡ |  	t j 
|¡¡ |  	t j ||¡¡ d S )Nr   r   r‘   )r   r%   r&   rç   rK   rW   rè   rE   rÀ  rY   r4   r×  )r?   r˜   r™   r›   r   r   r   Útest_move_dir_symlinkÖ  s    
zTestMove.test_move_dir_symlinkc          	   C   s6   t  | j| j¡}|  |tj | jtj | j¡¡¡ d S )N)	rE   rÀ  rˆ  rè   r\   r   r%   r&   r  )r?   r…  r   r   r   Útest_move_return_valueâ  s    zTestMove.test_move_return_valuec             C   s6   t  | jtj | jd¡¡}|  |tj | jd¡¡ d S )Nr   )rE   rÀ  rˆ  r   r%   r&   rè   r\   )r?   r…  r   r   r   Ú test_move_as_rename_return_valueç  s    z)TestMove.test_move_as_rename_return_valuec                s8   g ‰ ‡ fdd„}t j| j| j|d |  tˆ ƒd¡ d S )Nc                s   ˆ   | |f¡ d S )N)r5   )r˜   r™   )Úmovedr   r   r  î  s    z7TestMove.test_move_file_special_function.<locals>._copy)r  rU   )rE   rÀ  rˆ  rè   r\   r]   )r?   r  r   )rß  r   Útest_move_file_special_functionë  s    z(TestMove.test_move_file_special_functionc                sd   g ‰ ‡ fdd„}t  tj | jd¡¡ t  tj | jd¡¡ tj| j| j|d |  	t
ˆ ƒd¡ d S )Nc                s   ˆ   | |f¡ d S )N)r5   )r˜   r™   )rß  r   r   r  ö  s    z6TestMove.test_move_dir_special_function.<locals>._copyZchildZchild1)r  rz   )r   r   r   r%   r&   rç   rE   rÀ  rè   r\   r]   )r?   r  r   )rß  r   Útest_move_dir_special_functionó  s    z'TestMove.test_move_dir_special_functionN)%rÔ   rÕ   rÖ   r=   rC   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à  rá  r   r   r   r   r¿  :  s<   	
r¿  c               @   sX   e Zd ZdZG dd„ deƒZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚTestCopyFileFc               @   s:   e Zd ZdZdZdZddd„Zdd„ Zdd	„ Zd
d„ Z	dS )zTestCopyFile.FauxFNTc             C   s   || _ || _d S )N)Ú_raise_in_exitÚ_suppress_at_exit)r?   Zraise_in_exitZsuppress_at_exitr   r   r   Ú__init__  s    zTestCopyFile.Faux.__init__c             G   s   dS )Nrj   r   )r?   r   r   r   r   r.   	  s    zTestCopyFile.Faux.readc             C   s
   d| _ d S )NT)Ú_entered)r?   r   r   r   Ú	__enter__  s    zTestCopyFile.Faux.__enter__c             C   s&   |||f| _ | jr d| _tdƒ‚| jS )NTzCannot close)Ú_exited_withrã  Ú_raisedr   rä  )r?   Úexc_typeZexc_valZexc_tbr   r   r   Ú__exit__  s
    zTestCopyFile.Faux.__exit__)FT)
rÔ   rÕ   rÖ   ræ  rè  ré  rå  r.   rç  rë  r   r   r   r   ÚFaux  s   
rì  c             C   s   | j r
t`d S )N)Ú_deleterE   r'   )r?   r   r   r   rC     s    zTestCopyFile.tearDownc             C   s   |t _d| _d S )NT)rE   r'   rí  )r?   r   r   r   r   Ú_set_shutil_open  s    zTestCopyFile._set_shutil_openc             C   s*   ddd„}|   |¡ |  ttjdd¡ d S )Nr-   c             S   s   | dkrt dƒ‚d S )NÚsrcfilezCannot open "srcfile")r   )ro   r¨  r   r   r   Ú_open  s    z4TestCopyFile.test_w_source_open_fails.<locals>._openrï  Údestfile)r-   )rî  rX   r   rE   rÒ   )r?   rð  r   r   r   Útest_w_source_open_fails  s    

z%TestCopyFile.test_w_source_open_failsc                sd   |   ¡ ‰ d	‡ fdd„	}|  |¡ t dd¡ |  ˆ j¡ |  ˆ jd tk¡ |  ˆ jd j	d¡ d S )
Nr-   c                s    | dkrˆ S | dkrt dƒ‚d S )Nrï  rñ  zCannot open "destfile")r   )ro   r¨  )rï  r   r   rð  *  s
    z2TestCopyFile.test_w_dest_open_fails.<locals>._openrï  rñ  r   rU   )zCannot open "destfile")r-   )
rì  rî  rE   rÒ   rY   ræ  rè  r   r\   r   )r?   rð  r   )rï  r   Útest_w_dest_open_fails&  s    
z#TestCopyFile.test_w_dest_open_failsc                sˆ   |   ¡ ‰|   d¡‰ d
‡ ‡fdd„	}|  |¡ t dd¡ |  ˆj¡ |  ˆ j¡ |  ˆ j¡ |  ˆjd tk¡ |  	ˆjd j
d	¡ d S )NTr-   c                s   | dkrˆS | dkrˆ S d S )Nrï  rñ  r   )ro   r¨  )rñ  rï  r   r   rð  >  s
    z3TestCopyFile.test_w_dest_close_fails.<locals>._openrï  rñ  r   rU   )zCannot close)r-   )rì  rî  rE   rÒ   rY   ræ  ré  rè  r   r\   r   )r?   rð  r   )rñ  rï  r   Útest_w_dest_close_fails9  s    

z$TestCopyFile.test_w_dest_close_failsc                s†   |   d¡‰|   ¡ ‰ d‡ ‡fdd„	}|  |¡ |  ttjdd¡ |  ˆj¡ |  ˆ j¡ |  ˆ j	¡ |  ˆj
d d k¡ |  ˆj	¡ d S )	NTr-   c                s   | dkrˆS | dkrˆ S d S )Nrï  rñ  r   )ro   r¨  )rñ  rï  r   r   rð  T  s
    z5TestCopyFile.test_w_source_close_fails.<locals>._openrï  rñ  r   )r-   )rì  rî  rX   r   rE   rÒ   rY   ræ  rg   ré  rè  )r?   rð  r   )rñ  rï  r   Útest_w_source_close_failsO  s    

z&TestCopyFile.test_w_source_close_failsc          	   C   s†   t  ¡ | _|  tj| jd¡ tj tj 	| j¡tj 
| j¡ ¡ ¡}|  | j|¡ z$t | j|¡ |  tj |¡¡ W d t |¡ X d S )NT)rH   rI   rç   r|   rE   rF   r   r%   r&   rä   r  Úupperr•   rÀ  rY   r3   rq   )r?   rè   r   r   r   Útest_move_dir_caseinsensitivee  s    
z*TestCopyFile.test_move_dir_caseinsensitiveN)rÔ   rÕ   rÖ   rí  Úobjectrì  rC   rî  rò  ró  rô  rõ  r÷  r   r   r   r   râ  þ  s   
râ  c               @   s^   e Zd Zdd„ Zdd„ Zdd„ Ze e 	e
j ¡ ¡d¡e eedƒd	¡d
d„ ƒƒZdd„ ZdS )ÚTermsizeTestsc             C   s(   t  ¡ }|  |jd¡ |  |jd¡ d S )Nr   )rE   Úget_terminal_sizerx  ÚcolumnsÚlines)r?   Úsizer   r   r   Útest_does_not_crashw  s    z!TermsizeTests.test_does_not_crashc          	   C   st   t  ¡ }d|d< |d= t ¡ }W d Q R X |  |jd¡ t  ¡ }|d= d|d< t ¡ }W d Q R X |  |jd¡ d S )NZ777ÚCOLUMNSÚLINESi	  Z888ix  )r   r±  rE   rú  r\   rû  rü  )r?   r²  rý  r   r   r   Útest_os_environ_first  s    

z#TermsizeTests.test_os_environ_firstc          	   C   sL   t  ¡ }d|d< d|d< t ¡ }W d Q R X |  |jd¡ |  |jd¡ d S )Nrµ   rÿ  Zyyyr   r   )r   r±  rE   rú  rx  rû  rü  )r?   r²  rý  r   r   r   Útest_bad_environ  s    
zTermsizeTests.test_bad_environz
not on ttyrú  zneed os.get_terminal_size()c          
   C   s’   yt  ddg¡ ¡  ¡ }W n& ttt jfk
r@   |  d¡ Y nX t|d ƒt|d ƒf}t	 
¡ }|d= |d= t ¡ }W d Q R X |  ||¡ d S )NZsttyrý  zstty invocation failedrU   r   r   rÿ  )r4  rC  rF  rñ   rl   rù   rD  rÿ   Úintr   r±  rE   rú  r\   )r?   rý  rm  r²  ré   r   r   r   Útest_stty_match˜  s    

zTermsizeTests.test_stty_matchc             C   sÀ   t  ¡ ®}|d= |d= t  tdd ¡ tjdd}W d Q R X |  |jd¡ |  |jd¡ t	t
jdƒ,}t  td|¡ tjd	d}W d Q R X W d Q R X |  |jd
¡ |  |jd¡ W d Q R X d S )Nr   rÿ  Ú
__stdout__)é
   é   )Úfallbackr  r  r"   )é   é(   r	  r
  )r   r±  r·  r‘  rE   rú  r\   rû  rü  r'   r   Údevnull)r?   r²  rý  r   r   r   r   Útest_fallback°  s    
 zTermsizeTests.test_fallbackN)rÔ   rÕ   rÖ   rþ  r  r  rŽ  r  r   Úisattyr‘  r  Úfilenor¨   r  r  r   r   r   r   rù  v  s   
rù  c               @   s   e Zd Zdd„ ZdS )ÚPublicAPITestsc             C   s~   |   ttdƒ¡ dddddddd	d
ddddddddddddddddg}ttdƒsZtjdkrd| d¡ |  ttjƒt|ƒ¡ d S )NÚ__all__ZcopyfileobjrÒ   r–   r©   rË   rÎ   rå   rÀ  rF   r   r  Z	ExecErrorr   r   r   r   r   r   r
   r   rõ   r{  r•  rú  r   ÚstatvfsrA   rw  )	rY   r¨   rE   r   r8   r5   r\   Úsetr  )r?   Z
target_apir   r   r   Útest_module_all_attributeÇ  s    
z(PublicAPITests.test_module_all_attributeN)rÔ   rÕ   rÖ   r  r   r   r   r   r  Ä  s   r  Ú__main__)F)F)1rŽ  Zunittest.mockrE   rH   r‘  r€   r   Zos.pathr   r   rk  r4  r   r   r   r   r   r   r   r	   r
   r   r   r"  r9  r^  r   Ztest.supportr   r   r  rP  rR  rO  ÚImportErrorr   r    r+   r/   r6   ZTestCaser;   r—  r¿  râ  rù  r  rÔ   Úmainr   r   r   r   Ú<module>   s`   4


          D ) ExN
