Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_shutil.cpython-35.opt-2.pyc



���](+�@siddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddlm
Z
mZmZmZmZmZmZmZmZmZmZddlZddlZddlZddlmZddlmZmZm Z edZ!y"ddl"Z"ddl#Z#dZ$Wne%k
rvdZ$YnXd	d
�Z&dd�Z'dd
d�Z(ddd�Z)dd�Z*Gdd�dej+�Z,Gdd�dej+�Z-Gdd�dej+�Z.Gdd�dej+�Z/Gdd�dej+�Z0Gdd�dej+�Z1e2dkreej3�dS) �N)�	ExitStack)�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�check_warnings�captured_stdout�2TFcOstttdd�d��dS)NZEXDEV�zInvalid cross-device link)�OSError�getattr�errno)�args�kwargs�r�0/opt/alt/python35/lib64/python3.5/test_shutil.py�_fake_rename%srcs%tj���fdd��}|S)Ncs4z#tj}tt_�||�SWd|t_XdS)N)�os�renamer)rrZbuiltin_rename)�funcrr�wrap*s
		zmock_rename.<locals>.wrap)�	functools�wraps)rrr)rr�mock_rename)s!r"c	CsWt|t�r!tjj|�}t||r3dnd��}|j|�WdQRXdS)N�wb�w)�
isinstance�tupler�path�join�open�write)r'Zcontent�binary�fprrr�
write_file4sr-c	CsTt|t�r!tjj|�}t||r3dnd��}|j�SWdQRXdS)N�rb�r)r%r&rr'r(r)�read)r'r+r,rrr�	read_file@sr1cCs�g}x�ttj|��D]�}tjj||�}tjj|�r�tjj|�r�|j|d�x9t|�D]}|j|d|�qzWq|j|�qW|S)N�/)	�sortedr�listdirr'r(�isdir�islink�append�rlistdir)r'�res�name�p�nrrrr8Ls%r8cs�eZdZ�fdd�Z�fdd�Zdd�Zdd�Zejd	d
��Z	ejdd��Z
d
d�Zej
eed�d�ejejdd�dkd�ejeed�o�ej�dkd�dd����Zdd�Zdd�Zej
eed�d�ejdd ���Zej
eed!�d"�ejd#d$���Zejeed!�d%�ejd&d'���Zejd(d)��Zej
eed*�o�eed+�o�eed,�d-�d.d/��Zejd0d1��Zejejej
eed�o>ej�dkd2�d3d4����Zejd5d6��Z ejd7d8��Z!ejd9d:��Z"ejd;d<��Z#d=d>�Z$d?d@�Z%dAdB�Z&ejdCdD��Z'dEdF�Z(dGdH�Z)ej*j+dI�dJdK��Z,ejej-dLkdM�ej
eedN�dO�dPdQ���Z.ejdRdS��Z/ejdTdU��Z0ej
eedV�dW�dXdY��Z1ej
eedV�dW�ejdZd[���Z2d\d]�Z3ejd^d_��Z4ejd`da��Z5dbdc�Z6ej
eed�d�ddde��Z7ej
eed�d�ej
eedf�dg�dhdi���Z8ej9djdk��Z:dldm�Z;dndodp�Z<ej9ej
e=j>dq�dr�dsdt���Z?ej9dudv��Z@ej9ej
e=j>dw�dx�dydz���ZAej9ej
e=j>d{�d|�d}d~���ZBdd��ZCej9d�d���ZDej9ej
eEd��d�d����ZFd�d��ZGd�d��ZHej9d�d���ZId�d��ZJd�d��ZKd�d��ZLej9d�d���ZMejNd�d���ZOejPd�d���ZQej9d�d���ZRd�d��ZSej
ee=d��d��d�d���ZTej
eEd��ej
eed��d��d�d����ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZY�S)��
TestShutilcs tt|�j�g|_dS)N)�superr=�setUp�tempdirs)�self)�	__class__rrr?[szTestShutil.setUpcsOtt|�j�x5|jrJ|jj�}tj|tjdk�qWdS)N�nt�cygwin)rCrD)	r>r=�tearDownr@�pop�shutil�rmtreerr:)rA�d)rBrrrE_szTestShutil.tearDowncCs tj�}|jj|�|S)N)�tempfile�mkdtempr@r7)rArIrrrrKfszTestShutil.mkdtempc	Cs�|j�}tjj|d�}tj|�ttjj|d�d�tj|�}|j|t�tj	dk}|r�|j
t�nt��t
j|�WdQRXdS)NZkillmeZsomefile�foorC)rKrr'r(�mkdirr-�fsencode�assertIsInstance�bytesr:ZassertWarns�DeprecationWarningrrGrH)rA�tmpZvictim�winrrr�test_rmtree_works_on_bytesos
z%TestShutil.test_rmtree_works_on_bytescs2|j�}tjj|d�}tj|�tjj|d�}tj||�|jttj	|�|j
tjj|��|j
tjj|��g��fdd�}tj	|d|�|j
t��d�|j�ddtjj�|j
�dd|�|j�dddt�dS)	N�dir�linkcs�j|�dS)N)r7)r)�errorsrr�onerror�sz8TestShutil.test_rmtree_fails_on_symlink.<locals>.onerrorrX�r�)rKrr'r(rM�symlink�assertRaisesrrGrH�
assertTrue�exists�lexists�assertEqual�len�assertIsr6rO)rArRZdir_rVrXr)rWr�test_rmtree_fails_on_symlinkzs
z'TestShutil.test_rmtree_fails_on_symlinkc
Cs_|j�}tjj|d�}tjj|d�}tjj|d�}x$|||fD]}tj|�q[Wtjj|d�}t|d�tjj|d�}tj||�tjj|d�}tj||�tjj|d�}	tj||	�tj|�|j	tjj
|��|jtjj
|��|jtjj
|��dS)	N�dir1�dir2�dir3�file1rL�link1�link2�link3)rKrr'r(rMr-r[rGrH�assertFalser^r])
rArRrdrerfrIrgrhrirjrrr�test_rmtree_works_on_symlinks�s$

z(TestShutil.test_rmtree_works_on_symlinkscs&tj�}|jttj|�tj|dd�|j�}t|dfd�tj	j
|d�}|jt��}tj|�WdQRX|tj	j
|d�g}|j|j
j|�|jtj	j|��tj|dd�|jtj	j|��g��fdd�}tj|d|�|jt��d	�|j�d
d
tj�|j�d
d|�|j�d
d	dt�|j�d
d	dj|�|j�dd
tj�|j�dd|�|j�dd	dt�|j�dd	dj|�dS)N�
ignore_errorsTZtstfile�z*.*cs�j|�dS)N)r7)r)rWrrrX�sz.TestShutil.test_rmtree_errors.<locals>.onerrorrXrZrrY)rJ�mktempr\�FileNotFoundErrorrGrHrKr-rr'r(�NotADirectoryError�assertIn�	exception�filenamer]r^r`rarbr4rO�rmdir)rArt�tmpdir�cmZ
possible_argsrXr)rWr�test_rmtree_errors�s2zTestShutil.test_rmtree_errors�chmodzrequires os.chmod()N�rDz2This test can't be run on Cygwin (issue #1071513).�geteuidrz9This test can't be run reliably as root (issue #1076467).cCssd|_tjt�|jtjt�tjjtd�|_	tjjtd�|_
tj|j	�tj|j
�tj
t�j}tj
|j	�j}tj
|j
�j}t
jt
jB}tj|j	|�tj|j
|�tjt|�|jtjt|�|jtj|j	|�|jtj|j
|�tjtd|j�|j|jdd�dS)Nr�a�brX�z1Expected call to onerror function did not happen.)�
errorStaterrMr�
addCleanuprGrHr'r(�child_file_path�child_dir_pathr�create_empty_file�stat�st_mode�S_IREAD�S_IEXECry�check_args_to_onerrorr`)rAZold_dir_modeZold_child_file_modeZold_child_dir_modeZnew_moderrr�
test_on_error�s(	
zTestShutil.test_on_errorcCs�|jdkr�|tjkr4|j||j�nQ|tjkrY|j||j�n,|j|tj�|j	|t
|jg�|jt|dt
��|jd7_nF|j|tj�|j|t
�|jt|dt
��d|_dS)NrZrrYr~)rr�unlinkr`r�rur�rbr4rrrr]�
issubclassr)rAr�arg�excrrrr��sz TestShutil.check_args_to_onerrorcsfzUtj��fdd�}|t_tjt�ttdfd�tjt�Wd�t_XdS)Ncs&|tkrt��n
�|�SdS)N)rr)�fnrr)�
orig_lstatrr�raiserszFTestShutil.test_rmtree_does_not_choke_on_failing_lstat.<locals>.raiserrL)r�lstatrMrr-rGrH)rAr�r)r�r�+test_rmtree_does_not_choke_on_failing_lstats		
z6TestShutil.test_rmtree_does_not_choke_on_failing_lstatzrequires os.chmodcCs|j�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}t|d�t|d�tj||�tj||�tj|tjtj	B�tj|tj
�|jtj|�jtj|�j�t
j||�|jtj|�jtj|�j�tjdkrtj|tj
�t
j||�|jtj|�jtj|�j�tj|tj
�t
j||�|jtj|�jtj|�j�tj|tj
�t
j||�|jtj|�jtj|�j�dS)NrL�bar�baz�quuxrC)rKrr'r(r-r[ryr��S_IRWXU�S_IRWXG�S_IRWXO�assertNotEqualr�rG�copymoder`r:)rA�tmp_dir�src�dst�src_link�dst_linkrrr�test_copymode_follow_symlinkss0

((((z(TestShutil.test_copymode_follow_symlinks�lchmodzrequires os.lchmodcCs|j�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}t|d�t|d�tj||�tj||�tj|tjtj	B�tj|tj�tj
|tjtj	B�tj
|tj�tj
||dd�|jtj|�jtj|�j�|jtj|�jtj|�j�tj
|tj�tj
||dd�|jtj|�jtj|�j�tj
|tj�tj
||dd�|jtj|�jtj|�j�dS)NrLr�r�r��follow_symlinksF)rKrr'r(r-r[ryr�r�r�r�r�rGr�r`r�r�r�)rAr�r�r�r�r�rrr� test_copymode_symlink_to_symlink3s.

((z+TestShutil.test_copymode_symlink_to_symlinkz requires os.lchmod to be missingcCs�|j�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}t|d�t|d�tj||�tj||�tj||dd�dS)NrLr�r�r�r�F)rKrr'r(r-r[rGr�)rAr�r�r�r�r�rrr�*test_copymode_symlink_to_symlink_wo_lchmodQs

z5TestShutil.test_copymode_symlink_to_symlink_wo_lchmodc
Cs�|j�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}t|d�tj|�}tj||j|jdf�t|d�|j	tj|�jtj|�j�tj
||�tj
||�ttd�rtj|tj
�ttd�rDttd�rDtj|tj�tj|�}ttd�r�tj||d	d
�|j	|jtj|�j�tj||d	d�tj|�}tjtjkrx4dD],}	|jt||	�t||	�d�q�Wttd�r*|j|j|j�ttd�r^t|d�r^|j|j|j�tj||d	d�|jttj|�jtj|�j�dk�dS)NrLr�r��quxgE@r��lchflags�	UF_NODUMPr�TF�st_atime�st_mtimerY�st_flagsg�������?)r�r�)rKrr'r(r-r��utimer�r�r�r[�hasattrr�r�r�r�r�rG�copystatr��supports_follow_symlinks�assertLessEqualrr`r�r]�abs)
rAr�r�r�r�r��src_stat�
src_link_statZ
dst_link_stat�attrrrr�test_copystat_symlinks_sD

(
+z!TestShutil.test_copystat_symlinks�chflags�
EOPNOTSUPP�ENOTSUPz)requires os.chflags, EOPNOTSUPP & ENOTSUPcCs�|j�}tjj|d�}tjj|d�}t|d�t|d�dd�}tj}zrx9tjtjfD]%}||�t_t	j
||�q{W|tjtj�t_|jtt	j
||�Wd|t_XdS)Nrg�file2�xxxcs(t��dd��fdd�}|S)Nr�Tcs��_��dS)N)r)r'�flagsr�)�err�exrr�_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)
rKrr'r(r-r�rr�r�rGr�r\r)rArvrgr�r�Zold_chflagsr�rrr�-test_copystat_handles_harmless_chflags_errors�s

	z8TestShutil.test_copystat_handles_harmless_chflags_errorscsN|j�}tjj|d��t�d�tjj|d�}t|d�tj�|�tj�dd�tj�dd�tj�|�|jt	tj
���t	tj
|���|jtj�d�tj|d��tj|�t|d�t
tjd����fdd	�}z?tj�|t_tj�|�|jdtj
|��Wd�t_Xd
d��fdd
�}z&tj
�|t_
tj�|�Wd�t_
Xtjj|d��t���tj�dd�tjj|d�}t||�tj�|�|jtj|d�d�dS)NrLr�zuser.foos42zuser.bars43�EPERMcs,|dkr��n�||||�dS)Nzuser.foor)�fnamer��valr)�
orig_setxattr�os_errorrr�_raise_on_user_foo�s	z5TestShutil.test_copyxattr.<locals>._raise_on_user_foor�Tcs.|�krttjd���|d|�S)NzOperation not supportedr�)rrr�)r�r�)�orig_listxattrr�rr�
_raise_on_src�sz0TestShutil.test_copyxattr.<locals>._raise_on_srcZthe_originalzuser.the_valuesfiddlyZthe_copy)rKrr'r(r-rG�
_copyxattr�setxattrr`r3�	listxattr�getxattr�removerrr�rrr�)rAr�r�r�r�r)r�r�r�r�r�test_copyxattr�sH

.

		
		


zTestShutil.test_copyxattrzroot privileges requiredcCsM|j�}tjj|d�}tjj|d�}t|d�tj||�tj|dd�tj|dddd�tjj|d�}tjj|d	�}t|d�tj||�tj||dd�|j	tj
|ddd�d�|jttj
|d�tj||dd�|j	tj
|d�d�dS)
NrLr�ztrusted.foos42s43r�Fr�r�)
rKrr'r(r-r[r�rGr�r`r�r\r)rAr�r�r�r�r�rrr�test_copyxattr_symlinks�s 

"z"TestShutil.test_copyxattr_symlinkscCsu|j�}tjj|d�}tjj|d�}tjj|d�}t|d�tj||�ttd�r�tj|tj	tj
B�tj||dd�|j
tjj|��|jt|�t|��tj|�tj||dd�|jtjj|��|jtj|�tj|��ttd�rq|jtj|�jtj|�j�dS)NrLr�r�r�r�TF)rKrr'r(r-r[r�r�r�r�r�rG�copyrkr6r`r1r�r]�readlinkr�r�)rAr�r�r�r�rrr�test_copy_symlinks�s$

"zTestShutil.test_copy_symlinksc	CsT|j�}tjj|d�}tjj|d�}tjj|d�}t|d�tj||�ttd�r�tj|tj	tj
B�ttd�r�ttd�r�tj|tj�tj|�}tj
|�}tj||dd�|jtjj|��|jt|�t|��tj|�tj||dd	�|jtjj|��|jtj|�tj|��tj
|�}tjtjkr�x4dD],}|jt||�t||�d�q�Wttd�r|j|j|j�|j|j|j�ttd�rPt|d
�rP|j|j|j�dS)NrLr�r�r�r�r�r�TFr�r�rYr�)r�r�)rKrr'r(r-r[r�r�r�r�r�r�r�r�rG�copy2rkr6r`r1r�r]r�r�r�r�rr�r�r�)	rAr�r�r�r�r�r��dst_statr�rrr�test_copy2_symlinks
s:

"
zTestShutil.test_copy2_symlinkscCs�|j�}tjj|d�}tjj|d�}t|d�tj|dd�tj||�|jtj	|d�tj	|d��tj
|�dS)NrLr�zuser.foos42)rKrr'r(r-r�rGr�r`r�r�)rAr�r�r�rrr�test_copy2_xattr0s
zTestShutil.test_copy2_xattrcCs�|j�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}t|d�tj||�tj||dd�|jtjj	|��|j
tj|�tj|��tj||�|jtjj	|��dS)Nr�r�r�rVrLr�F)
rKrr'r(r-r[rG�copyfiler]r6r`r�rk)rAr�r�r�r�rVrrr�test_copyfile_symlinks=s
"z!TestShutil.test_copyfile_symlinkscs-tjtjtjtjhtjkoHtjtjkoHtjtjk}|r|j	t
j�|j	t
jj
�|j�}tjj|d�}tj|�zTt
j}Gdd�dt���fdd�}|t
_|j�t
j|�Wd|t
_Xn#|jt
j�|jt
jj
�dS)Nr|c@seZdZdS)zHTestShutil.test_rmtree_uses_safe_fd_version_if_available.<locals>.CalledN)�__name__�
__module__�__qualname__rrrr�Called[sr�cs
��dS)Nr)rr)r�rr�_raiser\szITestShutil.test_rmtree_uses_safe_fd_version_if_available.<locals>._raiser)rr)r�r�ru�supports_dir_fdr4�supports_fdr�r]rG�_use_fd_functionsrH�avoids_symlink_attacksrKr'r(rM�_rmtree_safe_fd�	Exceptionr\rk)rAr�r�rIZreal_rmtreer�r)r�r�-test_rmtree_uses_safe_fd_version_if_availableNs&
		
z8TestShutil.test_rmtree_uses_safe_fd_version_if_availablecCsFtj�\}}tj|�|jttj|�tj|�dS)N)	rJ�mkstempr�closer\rqrGrHr�)rA�handler'rrr�test_rmtree_dont_delete_filefs
z'TestShutil.test_rmtree_dont_delete_filecCsttj�}tjjtj�d�}|jtj|�|jtjtjj|��t	|dfd�tj
tjj|d��t	|ddfd�tj||�|jtjj
tjj|d���|jtjjtjj|d���|jtjj
tjj|dd���t|df�}|j|d�t|ddf�}|j|d�dS)N�destinationztest.txt�123�test_dir�456)rJrKrr'r(r�rGrH�dirnamer-rM�copytreer]�isfiler5r1r`)rA�src_dir�dst_dir�actualrrr�test_copytree_simplems ((
zTestShutil.test_copytree_simplec	Cs|j�}tjj|d�}tjj|d�}tjj|d�}tj|�tj|�t|dfd�tjj|d�}tjj|d�}tjtjj|d�|�ttd�r�tj|t	j
t	jB�ttd	�rtt	d
�rtj|t	j
�tj|�}tj||dd�|jtjjtjj|dd���|jtjtjj|dd��tjj|d��tj|�}ttd�r�|j|j|j�ttd	�r�|j|j|j�dS)
Nr�r��subzfile.txtrLrVzsub/linkr�r�r��symlinksT)rKrr'r(rMr-r[r�r�r�r�r�r�r�r�rGr�r]r6r`r�r�r�)	rAr�r�r�Zsub_dirr�r�r�r�rrr�test_copytree_symlinks�s2

+$z!TestShutil.test_copytree_symlinksc#Cs�tjj}tjj}tj�}z�|tj�d�}t|dfd�t|dfd�tj||d��t|ddfd�tj||d��t|ddfd�tj||dd��tj||dd	��t|dddfd�t|dd	d
fd�z�tj	dd�}tj
||d|�|j|||d���|j|||d���|j|||d���Wdtj
|�Xz�tj	dd
�}tj
||d|�|j|||d���|j|||dd	���|j|||dd���Wdtj
|�Xzgdd�}tj
||d|�|j|||dd	d
���|j|||dd���Wdtj
|�XWdtj
|�tj
tjj|��XdS)Nr�ztest.txtr�ztest.tmpr�r�Z	test_dir2�subdirZsubdir2ztest.pyz*.tmp�ignorezsubdir*cSs�g}x�|D]|}tjj||�}tjj|�r`|j�ddkr`|j|�q
tjj|�ddkr
|j|�q
W|S)NrYr�z.py���r�)rr'r(r5�splitr7�splitext)r��namesr9r:r'rrr�_filter�s
z6TestShutil.test_copytree_with_exclude.<locals>._filter)rr'r(r^rJrKr-rMrG�ignore_patternsr�r]rkrHr�)rAr(r^r�r��patternsr�rrr�test_copytree_with_exclude�sL #
#
z%TestShutil.test_copytree_with_excludecCstj�}tjj|d�}tj|�tjj|d�}|jtj|�tj	|d�t
|dfd�tj	tjj|d�d�t
|dfd�tj	tjj|d�d�tjd	|�}tj	|d�tj||�|jtj
|�jtj
|�j�|jtj
tjj|d��jtj
tjj|d��j�|jtj
tjj|d��jtj
tjj|d��j�tjj|tjj|�d
�}|jtj
|�jtj
|�j�dS)N�sourcer�i�zpermissive.txtr�zrestrictive.txtr�i�rUrY)rJrKrr'r(rMr�rGrHryr-r�r`r�r�r�)rAr�r�r�Zrestrictive_subdirZrestrictive_subdir_dstrrr�!test_copytree_retains_permissions�s,
($"$"z,TestShutil.test_copytree_retains_permissionszos.chmodc
Cs�tj�}tjjtj�d�}|jtj|�|jtjtjj|��t	d�|_
|jtj��tj
||�WdQRXdS)Nr�zka-boom)rJrKrr'r(r�rGrHr��PermissionErrorZside_effectr\rr�)rAZ
mock_patchr�r�rrr�test_copytree_winerror�sz!TestShutil.test_copytree_winerrorrCztemporarily disabled on WindowsrVzrequires os.linkcCs�tjt�tjjtd�}tjjtd�}z�t|d��}|jd�WdQRXtj||�|jt	j
t	j||�t|d��}|j|j
�d�WdQRXtj|�Wdt	jtdd�XdS)N�cheese�shopr$�cheddarr/rmT)rrMrr'r(r)r*rVr\rGr
r�r`r0r�rH)rAr�r��frrr�'test_dont_copy_file_onto_link_to_itselfs
z2TestShutil.test_dont_copy_file_onto_link_to_itselfcCs�tjt�tjjtd�}tjjtd�}z�t|d��}|jd�WdQRXtjd|�|jt	j
t	j||�t|d��}|j|j
�d�WdQRXtj|�Wdt	jtdd�XdS)Nrrr$rr/rmT)rrMrr'r(r)r*r[r\rGr
r�r`r0r�rH)rAr�r�rrrr�*test_dont_copy_file_onto_symlink_to_itselfs
z5TestShutil.test_dont_copy_file_onto_symlink_to_itselfc
Cs�tjt�zttjjtd�}tjjtd�}tj|�tj||�|jttj	|�tj	|dd�Wdtj	tdd�XdS)NrrrmT)
rrMrr'r(r[r\rrGrH)rAr�r�rrr�test_rmtree_on_symlink+s

z!TestShutil.test_rmtree_on_symlink�mkfifozrequires os.mkfifo()cCs^tjt�z<|jtjtjtt�|jtjtjtt�Wdtj	t�XdS)N)
rrrr\rG�SpecialFileErrorr��TESTFN2�__file__r�)rArrr�test_copyfile_named_pipe:s
z#TestShutil.test_copyfile_named_pipecCstjt�z�tjjtd�}tj|�tjj|d�}tj|�ytjtt�Wnrtj	k
r�}zO|j
d}|jt|�d�|d\}}}|jd||�WYdd}~XnX|j
d�Wdtjtdd�tjtdd�XdS)	Nr�ZmypiperrYz`%s` is a named pipez$shutil.Error should have been raisedrmT)rrMrr'r(rrGr�r
rrr`ra�failrH)rAr��pipe�erWr�r�Z	error_msgrrr�test_copytree_named_pipeEs 



'z#TestShutil.test_copytree_named_pipecs�|j�}tjj|j�d�}t|dfd�tjtjj|d��t|ddfd�g��fdd�}tj||d|�|jt	��d	�dS)
Nr�ztest.txtr�r�r�cs�j||f�dS)N)r7)r�r�)�copiedrr�_copydsz4TestShutil.test_copytree_special_func.<locals>._copy�
copy_functionrZ)
rKrr'r(r-rMrGr�r`ra)rAr�r�rr)rr�test_copytree_special_func[sz%TestShutil.test_copytree_special_funccCs)|j�}tjj|j�d�}tjdtjj|d��tjtjj|d��t|ddfd�|jtt	j
||�tjj|j�d�}t	j
||dd�|jdtj|��tjj|j�d	�}t	j
||d
d�|j
dtj|��dS)Nr�Z
IDONTEXISTztest.txtr�r��destination2�ignore_dangling_symlinksTZdestination3r�)rKrr'r(r[rMr-r\rrGr��assertNotInr4rr)rAr�r�rrr�test_copytree_dangling_symlinksjsz*TestShutil.test_copytree_dangling_symlinksc
Cs�|j�}tjj|j�d�}tjtjj|d��ttjj|dd�d��WdQRXtjtjj|d�tjj|d�dd�tj||dd	�|j	tjj
tjj|d���|jdtjtjj|d���tjj|j�d
�}tj||dd�|j
tjj
tjj|d���|jdtjtjj|d���dS)Nr�Zreal_dirztest.txtr$Zlink_to_dirZtarget_is_directoryTr�Fr)rKrr'r(rMr)r[rGr�rkr6rrr4r])rAr�r�rrr�test_copytree_symlink_dirs"(((z$TestShutil.test_copytree_symlink_dircCsrd}|j�}t||fd�tjj||�}|j�}|||�tjj||�}||fS)Nztest.txtr�)rKr-rr'r()rA�methodr�rvrg�tmpdir2r�rrr�
_copy_file�s
zTestShutil._copy_filecCs]|jtj�\}}|jtjj|��|jtj|�j	tj|�j	�dS)N)
rrGr�r]rr'r^r`r�r�)rArgr�rrr�	test_copy�szTestShutil.test_copyr�zrequires os.utimecCs�|jtj�\}}|jtjj|��tj|�}tj|�}|j|j	|j	�x4dD],}|j
t||�t||�d�qlWttd�r�t|d�r�|jt|d�t|d��dS)Nr�r�rYr�r�)r�r�)
rrGr�r]rr'r^r�r`r�r�rr�)rArgr�Z
file1_statZ
file2_statr�rrr�
test_copy2�s
zTestShutil.test_copy2c	$Cs�|jd�\}}|j�}tj|�tjj|�}tjjtjj|�d�}tj	|��,tjj
|�}t|d|d�}WdQRX|j||d�|j
tjj|��|j
tj|��tj|d��/}|j|j�dddd	d
dg�WdQRXtj	|��t|d|d�}WdQRX|j||d
�|j
tjj|��|j
tj|��tj|d��/}|j|j�dddd	d
dg�WdQRXdS)Nrn�archive�gztar�.z.tar.gzzr:gzz./subz./sub2z./file1z./file2z./sub/file3�tarz.tarr/)�
_create_filesrKrrur'r�r(�basenamer�
change_cwd�abspathrr`r]r��tarfileZ
is_tarfiler)�assertCountEqual�getnames)	rA�root_dir�base_dirr�work_dir�
rel_base_name�	base_name�tarballZtfrrr�test_make_tarball�s0
!		zTestShutil.test_make_tarballc	Cs=tj|��'}|j�}|j�t|�SWdQRXdS)N)r*r)r,�sortr&)rAr'r%r�rrr�_tarinfo�s
zTestShutil._tarinfo�distcCs�|j�}tjj||�}tj|dd�t|dfd�t|dfd�tjtjj|d��t|ddfd�tjtjj|d��|r�t|d	fd�||fS)
N�exist_okTrgr�r�r�Zfile3Zsub2�outer)rKrr'r(�makedirsr-rM)rAr.r-r6rrrr&�szTestShutil._create_filesr%zNeed the tar command to runcCs{|j�\}}tjj|j�d�}t|d||�}|j||d�|jtjj|��tjj|d�}ddd|g}t	j
|d|dt	j�|jtjj|��|j|j|�|j|��t|d||�}|j||d	�|jtjj|��t|d||d
d�}|j||d	�|jtjj|��dS)Nr"r#z.tar.gzzarchive2.tarr%z-cf�cwd�stdoutz.tar�dry_runT)
r&rr'r(rKrr`r]r��
subprocess�
check_call�DEVNULLr5)rAr-r.r1r2Ztarball2Ztar_cmdrrr�test_tarfile_vs_tar�s$
"	zTestShutil.test_tarfile_vs_tarc	$Cs�|j�\}}|j�}tj|�tjj|�}tjjtjj|�d�}tj	|��)tjj
|�}t|d|�}WdQRX|j||d�|j
tjj|��|j
tj|��tj|��2}|j|j�dddddd	d
g�WdQRXtj	|��,tjj
|�}t|d||�}WdQRX|j||d�|j
tjj|��|j
tj|��tj|��/}|j|j�dddddd	g�WdQRXdS)Nr"�zipz.zipzdist/z	dist/sub/z
dist/sub2/z
dist/file1z
dist/file2zdist/sub/file3r8)r&rKrrur'r�r(r'rr(r)rr`r]r��zipfile�
is_zipfile�ZipFiler+�namelist)	rAr-r.rr/r0r1r9�zfrrr�test_make_zipfiles4
!			zTestShutil.test_make_zipfilerAzNeed the zip command to runc
Cs8|j�\}}tjj|j�d�}t|d||�}|j||d�|jtjj|��tjj|d�}dddd|g}t	j
|d|dt	j�|jtjj|��tj
|��}|j�}WdQRXtj
|��}|j�}	WdQRX|jt|�t|	��dS)	Nr"rAz.zipzarchive2.zipz-qz-rr:r;)r&rr'r(rKrr`r]r�r=r>r?rBrDrEr3)
rAr-r.r1r"Zarchive2�zip_cmdrFr�Znames2rrr�test_zipfile_vs_zip4s
zTestShutil.test_zipfile_vs_zip�unzipzNeed the unzip command to runc	Cs|j�\}}tjj|j�d�}t|d||�}|j||d�|jtjj|��dd|g}t	j
|��~ytj|dtj
�Wn\tjk
r}z9|jjdd�}d	}|j|j||��WYdd}~XnXWdQRXdS)
Nr"rAz.ziprJz-t�stderrrW�replacez{}

**Unzip Output**
{})r&rr'r(rKrr`r]r�rr(r=�check_output�STDOUT�CalledProcessError�output�decoder�format)	rAr-r.r1r"rHr�Zdetails�msgrrr�test_unzip_zipfileNszTestShutil.test_unzip_zipfilecCs;|j�}tjj|d�}|jtt|d�dS)Nr"r�)rKrr'r(r\�
ValueErrorr)rArvr1rrr�test_make_archivedszTestShutil.test_make_archivec	CsFtr/tjd�d}tjd�d}n
d}}|j�\}}tjj|j	�d�}t
|d||d|d|�}|jtjj|��t
|d||�}|jtjj|��t
|d||d|d|�}|jtjj|��t
|d||dddd	�}|jtjj|��dS)
Nr�rootr"rA�owner�groupr%Z	kjhkjhkjgZoihohoh)
�UID_GID_SUPPORT�grp�getgrgid�pwd�getpwuidr&rr'r(rKrr]r�)rArYrXr-r.r1r9rrr�test_make_archive_owner_groupis"
	z(TestShutil.test_make_archive_owner_groupzRequires grp and pwd supportc	Cs|j�\}}tjj|j�d�}tjd�d}tjd�d}t	j
|��&t|d|dd|d|�}WdQRX|jtjj
|��tj|�}zAx:|j�D],}|j|jd�|j|jd�q�WWd|j�XdS)Nr"rr#r6rXrY)r&rr'r(rKr[r\r]r^rr(rr]r�r*r)Z
getmembersr`�uid�gidr�)	rAr-r.r1rYrX�archive_namer"�memberrrr�test_tarfile_root_owner�sz"TestShutil.test_tarfile_root_ownercCs�tj�}dd�}td|gd�zLytddd|j��Wntk
r_YnX|jtj�|�Wdtd�XdS)Nc_s
t��dS)N)�RuntimeError)r�kwrrr�_breaks�sz1TestShutil.test_make_archive_cwd.<locals>._breaksr�zxxx filer-)r�getcwdrrrKr�r`r)rAZcurrent_dirrgrrr�test_make_archive_cwd�s
z TestShutil.test_make_archive_cwdcCsY|j�}tj|��7|jtdd�d�|jtjjd��WdQRXdS)N�testr%ztest.tar)	rKrr(r`rr]rr'r�)rAr-rrr�test_make_tarfile_in_curdir�sz&TestShutil.test_make_tarfile_in_curdircCsY|j�}tj|��7|jtdd�d�|jtjjd��WdQRXdS)NrjrAztest.zip)	rKrr(r`rr]rr'r�)rAr-rrr�test_make_zipfile_in_curdir�sz&TestShutil.test_make_zipfile_in_curdirc	Cs�|jttdd�|jttddd�d�|jttddd�d
dg�tddd�dgd	�d
d�t�D�}|jd|�td�dd�t�D�}|jd|�dS)Nr�rYcSstS)N)�xrrrr�<lambda>�sz9TestShutil.test_register_archive_format.<locals>.<lambda>cSstS)N)rmrrrrrn�srZr~cSstS)N)rmrrrrrn�szxxx filecSsg|]\}}|�qSrr)�.0r:�paramsrrr�
<listcomp>�s	z;TestShutil.test_register_archive_format.<locals>.<listcomp>cSsg|]\}}|�qSrr)ror:rprrrrq�s	)rYrZ)rYrZr~)rYrZ)r\�	TypeErrorrrrrrr)rA�formatsrrr�test_register_archive_format�s

z'TestShutil.test_register_archive_formatc	Cs�|j�\}}t|�}|jd�tjj|j�d�}t||||�}|j�}t||�|j	t|�|�|j�}t||d|�|j	t|�|�|j
tjtt
�|j
ttt
dd�dS)Nr8r"rRr�)r&r8r�rr'r(rKrrr`r\rG�	ReadErrorrrU)	rArRr-r.�expectedr1rtrZtmpdir3rrr�check_unpack_archive�s

zTestShutil.check_unpack_archivecCs|jd�dS)Nr%)rw)rArrr�test_unpack_archive_tar�sz"TestShutil.test_unpack_archive_tarcCs|jd�dS)Nr#)rw)rArrr�test_unpack_archive_gztar�sz$TestShutil.test_unpack_archive_gztarcCs|jd�dS)N�bztar)rw)rArrr�test_unpack_archive_bztar�sz$TestShutil.test_unpack_archive_bztarcCs|jd�dS)N�xztar)rw)rArrr�test_unpack_archive_xztar�sz$TestShutil.test_unpack_archive_xztarcCs|jd�dS)NrA)rw)rArrr�test_unpack_archive_zip�sz"TestShutil.test_unpack_archive_zipcs�t�}�fdd�}tdddg|dg�tdd	��jttd
dg|�td�td
dg|��jd
dgdft���jddgdft��td
��jt�|�dS)
Ncs4�j|d��j|d��j|d�dS)NrYz	stuff.boo�xx)r`)rt�extract_dir�extra)rArr�_boo�sz-TestShutil.test_unpack_registry.<locals>._booZBooz.booz.b2r�rYz	stuff.boorZBoo2rn)r�rY)	rr	rr\r
rrrrr`)rArsr�r)rAr�test_unpack_registry�s	



zTestShutil.test_unpack_registry�
disk_usagez)disk_usage not available on this platformcCs~tjtj��}|j|jd�|j|jd�|j|jd�|j|j|j�|j|j|j�dS)Nr)	rGr�rrhZ
assertGreater�total�used�assertGreaterEqual�free)rA�usagerrr�test_disk_usageszTestShutil.test_disk_usage�chownzrequires os.chownc(s��j�}tjd|��t�d��jt��tj��WdQRX�jt��tj�dd�WdQRX�jt��tj�dd�WdQRX�jt	��tj�d�WdQRX�jt	��tj�d�WdQRXt
j�}t
j�}dd��fd	d
�}tj�||�|�||�tj�|�|�|�tj�d|�|�|�tj�d|�|�d|�tj|||�||||�tj||�|||�tj|d|�|||�tj|d|�||d|�t
j|�d}tj|�d}tj�||�|�||�tj|||�||||�dS)
NrUztesting chown function�userznon-exising usernamerYznon-exising groupnamesspamg��Q�	@csQtj��}|dk	r.�j||j�|dk	rM�j||j�dS)N)rr�r`�st_uid�st_gid)r'r`ra�s)rtrArr�check_chown1s
z*TestShutil.test_chown.<locals>.check_chownrar)rKrJror-r\rUrGr��LookupErrorrrr�getuid�getgidr]r^r[r\)rAr�r`rar�r�rYr)rtrAr�
test_chownsL




zTestShutil.test_chowncCs�x�tjtjfD]�}|j�}|j�}tjj|d�}t|d�|||�}|j|tjj|d��||tjj|d��}|j|tjj|d��qWdS)NrLr�)	rGr�r�rKrr'r(r-r`)rAr�r�r�r��rvrrr�test_copy_return_valueQs
z!TestShutil.test_copy_return_valuecCs�|j�}|j�}tjj|d�}tjj|d�}t|d�tj||�}|jtjj|��|j	t
|�t
|��dS)Nr�rL)rKrr'r(r-rGr�r]r^r`r1)rAr�r��dst_file�src_filer�rrr�test_copyfile_return_value]s
z%TestShutil.test_copyfile_return_valuecCsd|j�}tjj|d�}t|d�|jttj||�|jt	tj||�dS)NrL)
rKrr'r(r-r\r
rGr�r)rAr�r�rrr�test_copyfile_same_filehs

z"TestShutil.test_copyfile_same_filecCs�|j�}|d}|jtj|d�tjj|d�}t|d�tj||�}|j	dgtj
|��dS)N�destTrL)rKr�rGrHrr'r(r-r�r`r4)rAr�r�r�r�rrr�test_copytree_return_valuers

z%TestShutil.test_copytree_return_value)Zr�r�r�r?rErKrTr�skip_unless_symlinkrcrlrx�unittest�
skipUnlessr�r�skipIf�sys�platformr{r�r�r�r�r�r�r�rr�Zskip_unless_xattrr�r�r�r�r�r�r�r�r�r�r�rZmockZpatchrr:rr	r
rrrrrrr r!Z
requires_zlibr3r5r&rG�whichr@rGrIrTrVr_rZrdrirkrlrtrwrxryZrequires_bz2r{Z
requires_lzmar}r~r�r�r�r�r�r�r�rr)rBrr=Ys�	$$ 
)8$#
A*'
'*$%!	*:
r=c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zej	e
ed�olej�dkd
�dd��Z
dd�Zdd�Zejejdkd�dd��Zdd�Zdd�Zdd�ZdS)�	TestWhichcCs�tjdd�|_|jtj|jd�tjd|jdddd�|_tj	|jj
tj�|j|jj
�tjj|jj
�\|_|_dS)N�prefixZTmpTrU�suffixz.Exe)rJrK�temp_dirr�rGrH�NamedTemporaryFile�	temp_filerryr:r��S_IXUSRr�r'r�rU�file)rArrrr?szTestWhich.setUpcCs5tj|jd|j�}|j||jj�dS)Nr')rGr�r�rUr`r�r:)rAr�rrr�
test_basic�szTestWhich.test_basiccCs8tj|jjd|j�}|j||jj�dS)Nr')rGr�r�r:r�r`)rAr�rrr�test_absolute_cmd�szTestWhich.test_absolute_cmdcCs�tjj|j�\}}tjj||j�}tjd|��-tj	|d|j
�}|j||�WdQRXtjd|j��'tj	|d|�}|j|�WdQRXdS)Nr')
rr'r�rUr(r�rr(rGr�r�r`�assertIsNone)rAr.�tail_dir�relpathr�rrr�test_relative_cmd�szTestWhich.test_relative_cmdcCs�tjj|j�}tjd|j��atj|jd|�}t	j
dkrz|j|tjjtj
|j��n
|j|�WdQRXdS)Nr'�win32)rr'r�rUrr(rGr�r�r�r�r`r(�curdirr�)rAr.r�rrr�test_cwd�s(zTestWhich.test_cwdr{rznon-root user requiredcCsvtj|jjtj�tj|jjtj�rA|jd�t	j
|jd|jdtj�}|j
|�dS)Nzcan't set the file read-onlyr'�mode)rryr�r:r�r��access�W_OK�skipTestrGr�r�rUr�)rAr�rrr�test_non_matching_mode�s

$z TestWhich.test_non_matching_modecCsstjj|j�\}}tjd|��?tj|jd|�}|j	|tjj
||j��WdQRXdS)Nr')rr'r�rUrr(rGr�r�r`r()rAr.r�r�rrr�test_relative_path�szTestWhich.test_relative_pathcCs)tjdd|j�}|j|�dS)Nzfoo.exer')rGr�rUr�)rAr�rrr�test_nonexistent_file�szTestWhich.test_nonexistent_filer�zpathext check is Windows-onlycCsMtj|jdd�d|j�}|j||jjdd�d�dS)N�r'z.EXE���r�)rGr�r�rUr`r�r:)rAr�rrr�test_pathext_checking�s%zTestWhich.test_pathext_checkingc
CsOtj��<}|j|d<tj|j�}|j||jj�WdQRXdS)N�PATH)	r�EnvironmentVarGuardrUrGr�r�r`r�r:)rA�envr�rrr�test_environ_path�s
zTestWhich.test_environ_pathcCs~tjj|j�}tjd|j��Mtj��9}|j|d<tj|j	dd�}|j
|�WdQRXWdQRXdS)Nr'r�rn)rr'r�rUrr(r�rGr�r�r�)rAr.r�r�rrr�test_empty_path�s
zTestWhich.test_empty_pathc
CsItj��6}|jdd�tj|j�}|j|�WdQRXdS)Nr�)rr�rFrGr�r�r�)rAr�r�rrr�test_empty_path_no_PATH�sz!TestWhich.test_empty_path_no_PATHN)r�r�r�r?r�r�r�r�r�r�r�rr{r�r�r�r�r�r�r�r�r�r�rrrrr�}s
$	r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
e	dd��Zdd�Ze	dd��Z
dd�Ze	dd��Zdd�Zejejjd�dd��Zdd�Zd d!�Zd"d#�Zd$d%�Zeje	d&d'���Zeje	d(d)���Zeje	d*d+���Zeje	d,d-���Z d.d/�Z!d0d1�Z"e	d2d3��Z#e	d4d5��Z$d6S)7�TestMovec	Cs�d}tj�|_tj�|_tjj|j|�|_tjj|j|�|_t	|jd��}|j
d�WdQRXdS)NrLr#sspam)rJrKr�r�rr'r(r�r�r)r*)rArtrrrrr?�szTestMove.setUpc
CsCx<|j|jfD](}y|r/tj|�WqYqXqWdS)N)r�r�rGrH)rArIrrrrE�szTestMove.tearDowncCs�t|d��}|j�}WdQRXtj||�t|d��}|j||j��WdQRX|jtjj|��dS)Nr.)	r)r0rG�mover`rkrr'r^)rAr�r��real_dstr�contentsrrr�_check_move_file�szTestMove._check_move_filecCsattj|��}tj||�|j|ttj|���|jtjj|��dS)N)	r3rr4rGr�r`rkr'r^)rAr�r�r�r�rrr�_check_move_dir�szTestMove._check_move_dircCs |j|j|j|j�dS)N)r�r�r�)rArrr�test_move_fileszTestMove.test_move_filecCs |j|j|j|j�dS)N)r�r�r�r�)rArrr�test_move_file_to_dirszTestMove.test_move_file_to_dircCs|j�dS)N)r�)rArrr�test_move_file_other_fs
sz TestMove.test_move_file_other_fscCs|j�dS)N)r�)rArrr�test_move_file_to_dir_other_fssz'TestMove.test_move_file_to_dir_other_fscCsJtj�}z|j|j||�Wdytj|�WnYnXXdS)N)rJror�r�rGrH)rAr�rrr�
test_move_dirszTestMove.test_move_dircCs|j�dS)N)r�)rArrr�test_move_dir_other_fsszTestMove.test_move_dir_other_fscCs>|j|j|jtjj|jtjj|j���dS)N)r�r�r�rr'r(r')rArrr�test_move_dir_to_dir$szTestMove.test_move_dir_to_dircCs|j�dS)N)r�)rArrr�test_move_dir_to_dir_other_fs)sz&TestMove.test_move_dir_to_dir_other_fscCsH|j|jtjj|jtjj|jtjj|j���dS)N)r�r�rr'�sepr�r(r')rArrr�test_move_dir_sep_to_dir.sz!TestMove.test_move_dir_sep_to_dirzrequires os.path.altsepcCsH|j|jtjj|jtjj|jtjj|j���dS)N)r�r�rr'�altsepr�r(r')rArrr�test_move_dir_altsep_to_dir2sz$TestMove.test_move_dir_altsep_to_dircCs@t|jd��WdQRX|jtjtj|j|j�dS)Nr#)r)r�r\rGrr�r�r�)rArrr�"test_existing_file_inside_dest_dir7sz+TestMove.test_existing_file_inside_dest_dircCs;tjj|jd�}|jtjtj|j|�dS)Nr�)rr'r(r�r\rGrr�)rAr�rrr�test_dont_move_dir_in_itself=sz%TestMove.test_dont_move_dir_in_itselfc
Cs�tjt�zqxjdgD]_\}}tjjt|�}tjjt|�}|jtj||�dd||f�qWWdtjtdd�XdS)N�srcdir�srcdir/destrSz?_destinsrc() wrongly concluded that dst (%s) is not in src (%s)rmT)r�r�)	rrMrr'r(r]rG�
_destinsrcrH)rAr�r�rrr�test_destinsrc_false_negativeBs
z&TestMove.test_destinsrc_false_negativec
Cs�tjt�ztxmdd	gD]_\}}tjjt|�}tjjt|�}|jtj||�dd||f�qWWdtjtdd�XdS)
Nr��src/dest�
srcdir.newrSz;_destinsrc() wrongly concluded that dst (%s) is in src (%s)rmT)r�r�)r�r�)	rrMrr'r(rkrGr�rH)rAr�r�rrr�test_destinsrc_false_positiveNs
z&TestMove.test_destinsrc_false_positivecCs�tjj|jd�}tj|j|�tj||j�|j	tjj
|j��|j	tjj|j|j��dS)Nr�)rr'r(r�r[r�rGr�r�r]r6�samefile)rAr�rrr�test_move_file_symlinkZs
zTestMove.test_move_file_symlinkcCs�d}tjj|j|�}tj|j|�tj||j�tjj|j|�}|j	tjj
|��|j	tjj|j|��dS)Nr�)rr'r(r�r[r�rGr�r�r]r6r�)rArtr�Z
final_linkrrr�test_move_file_symlink_to_dircsz&TestMove.test_move_file_symlink_to_dircCs�tjj|jd�}tjj|jd�}tj||�tjj|jd�}tj||�|jtjj	|��tj
dkr�|jtjj|�tj
|��n(|jtjj|�tjj|��dS)Nr�r�r�rC)rr'r(r�r[r�rGr�r]r6r:r`�realpathr�)rAr�r�r�rrr�test_move_dangling_symlinkns(z#TestMove.test_move_dangling_symlinkcCs�tjj|jd�}tjj|jd�}tj|�tj||�tjj|jd�}tj||�|j	tjj
|��|j	tjj||��dS)Nr�r�r�)rr'r(r�rMr[r�rGr�r]r6r�)rAr�r�r�rrr�test_move_dir_symlink}s
zTestMove.test_move_dir_symlinkcCsMtj|j|j�}|j|tjj|jtjj|j���dS)N)	rGr�r�r�r`rr'r(r')rAr�rrr�test_move_return_value�s	zTestMove.test_move_return_valuecCsMtj|jtjj|jd��}|j|tjj|jd��dS)Nr�)rGr�r�rr'r(r�r`)rAr�rrr� test_move_as_rename_return_value�s'z)TestMove.test_move_as_rename_return_valuecsNg��fdd�}tj|j|jd|�|jt��d�dS)Ncs�j||f�dS)N)r7)r�r�)�movedrrr�sz7TestMove.test_move_file_special_function.<locals>._copyrrY)rGr�r�r�r`ra)rArr)r�r�test_move_file_special_function�sz(TestMove.test_move_file_special_functioncs�g��fdd�}tjtjj|jd��tjtjj|jd��tj|j|jd|�|j	t
��d�dS)Ncs�j||f�dS)N)r7)r�r�)r�rrr�sz6TestMove.test_move_dir_special_function.<locals>._copyZchildZchild1rr~)rr�rr'r(r�rGr�r�r`ra)rArr)r�r�test_move_dir_special_function�sz'TestMove.test_move_dir_special_functionN)%r�r�r�r?rEr�r�r�r�r"r�r�r�r�r�r�r�r�r�rr'r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�rrrrr��s<	$
r�c@s�eZdZdZGdd�de�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�ZdS)�TestCopyFileFc@sXeZdZdZdZdZdddd�Zdd�Zdd	�Zd
d�Z	dS)zTestCopyFile.FauxFNTcCs||_||_dS)N)�_raise_in_exit�_suppress_at_exit)rAZ
raise_in_exitZsuppress_at_exitrrr�__init__�s	zTestCopyFile.Faux.__init__cGsdS)Nrnr)rArrrrr0�szTestCopyFile.Faux.readcCs
d|_dS)NT)�_entered)rArrr�	__enter__�szTestCopyFile.Faux.__enter__cCs7|||f|_|jr0d|_td��|jS)NTzCannot close)�_exited_withr��_raisedrr�)rA�exc_type�exc_val�exc_tbrrr�__exit__�s
		zTestCopyFile.Faux.__exit__)
r�r�r�r�r�r�r�r0r�r�rrrr�Faux�sr�cCs|jrt`dS)N)�_deleterGr))rArrrrE�s	zTestCopyFile.tearDowncCs|t_d|_dS)NT)rGr)r�)rArrrr�_set_shutil_open�s	zTestCopyFile._set_shutil_opencCs9ddd�}|j|�|jttjdd�dS)Nr/cSs|dkrtd��dS)N�srcfilezCannot open "srcfile")r)rtr�rrr�_open�sz4TestCopyFile.test_w_source_open_fails.<locals>._openr��destfile)r�r\rrGr�)rAr�rrr�test_w_source_open_fails�s
z%TestCopyFile.test_w_source_open_failscs�|j��d�fdd�}|j|�tjdd�|j�j�|j�jdtk�|j�jdj	d	�dS)
Nr/cs,|dkr�S|dkr(td��dS)Nr�r�zCannot open "destfile")r)rtr�)r�rrr��s
z2TestCopyFile.test_w_dest_open_fails.<locals>._openr�r�rrY�Cannot open "destfile")r�)
r�r�rGr�r]r�r�rr`r)rAr�r)r�r�test_w_dest_open_fails�s
z#TestCopyFile.test_w_dest_open_failscs�|j��|jd��d��fdd�}|j|�tjdd�|j�j�|j�j�|j�j�|j�jdtk�|j	�jdj
d
�dS)NTr/cs$|dkr�S|dkr �SdS)Nr�r�r)rtr�)r�r�rrr��s
z3TestCopyFile.test_w_dest_close_fails.<locals>._openr�r�rrY�Cannot close)r)r�r�rGr�r]r�r�r�rr`r)rAr�r)r�r�r�test_w_dest_close_fails�s
z$TestCopyFile.test_w_dest_close_failscs�|jd��|j��d��fdd�}|j|�|jttjdd�|j�j�|j�j�|j�j	�|j�j
ddk�|j�j	�dS)NTr/cs$|dkr�S|dkr �SdS)Nr�r�r)rtr�)r�r�rrr��s
z5TestCopyFile.test_w_source_close_fails.<locals>._openr�r�r)r�r�r\rrGr�r]r�rkr�r�)rAr�r)r�r�r�test_w_source_close_fails�s
	z&TestCopyFile.test_w_source_close_failscCs�tj�|_|jtj|jd�tjjtjj	|j�tjj
|j�j��}|j|j|�z0tj
|j|�|jtjj|��Wdtj|�XdS)NT)rJrKr�r�rGrHrr'r(r�r'�upperr�r�r]r5ru)rAr�rrr�test_move_dir_caseinsensitives	z*TestCopyFile.test_move_dir_caseinsensitiveN)
r�r�r�r��objectr�rEr�r�r�rrrrrrrr��s
r�c@s�eZdZdd�Zdd�Zdd�Zejej	e
jj��d�eje
ed�d	�d
d���Zdd
�ZdS)�
TermsizeTestscCs6tj�}|j|jd�|j|jd�dS)Nr)rG�get_terminal_sizer��columns�lines)rA�sizerrr�test_does_not_crashsz!TermsizeTests.test_does_not_crashcCs�tj��$}d|d<|d=tj�}WdQRX|j|jd�tj��$}|d=d|d<tj�}WdQRX|j|jd�dS)NZ777�COLUMNS�LINESi	Z888ix)rr�rGrr`rr	)rAr�r
rrr�test_os_environ_first(s

z#TermsizeTests.test_os_environ_firstc
Cs`tj��'}d|d<d|d<tj�}WdQRX|j|jd�|j|jd�dS)Nr�rZyyyr
r)rr�rGrr�rr	)rAr�r
rrr�test_bad_environ7s

zTermsizeTests.test_bad_environz
not on ttyrzneed os.get_terminal_size()cCs�y%tjddg�j�j�}Wn(ttjfk
rO|jd�YnXt|d�t|d�f}tj	��!}|d=|d=t
j�}WdQRX|j||�dS)NZsttyr
zstty invocation failedrYrr
r)
r=rMrQr�rprOr��intrr�rGrr`)rAr
rvr�r�rrr�test_stty_match?s
% zTermsizeTests.test_stty_matchc Cs�tj���}|d=|d=tjtdd��tjdd
�}WdQRX|j|jd�|j|jd�t	t
jd��6}tjtd|��tjdd�}WdQRXWdQRX|j|jd�|j|jd	�WdQRXdS)Nr
r�
__stdout__�fallback�
�r$��()rr)rr)rr�Z	swap_attrr�rGrr`rr	r)r�devnull)rAr�r
rrrr�
test_fallbackVs zTermsizeTests.test_fallbackN)r�r�r�rrrr�r�r�isattyr�r�filenor�rrrrrrrs
!rc@seZdZdd�ZdS)�PublicAPITestscCs�|jttd��dddddddd	d
ddd
dddddddddddddg}ttd�s�tjdkr�|jd�|jttj�t|��dS)N�__all__�copyfileobjr�r�r�r�r�r�r�rHrr�	ExecErrorrrrrrr	rrr�r�r�rr
�statvfsrCr�)	r]r�rGrr:r7r`�setr)rAZ
target_apirrr�test_module_all_attributems	
z(PublicAPITests.test_module_all_attributeN)r�r�r�r"rrrrrjsr�__main__)4r�Z
unittest.mockrGrJr�r�rZos.pathrr r=�
contextlibrrrrrrrr	r
rrr
r*rB�warningsrjrZtest.supportrrrr
r[r]rZ�ImportErrorrr"r-r1r8ZTestCaser=r�r�r�rrr��mainrrrr�<module>sTL



�����)d�xM