403Webshell
Server IP : 118.27.122.248  /  Your IP : 216.73.217.130
Web Server : Apache
System : Linux web0264.sh.tyo1 4.18.0-553.79.1.lve.el7h.x86_64 #1 SMP Wed Oct 15 16:34:46 UTC 2025 x86_64
User : c9415830 ( 11735)
PHP Version : 8.4.17
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python36/lib64/python3.6/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python36/lib64/python3.6/test/__pycache__/test_shutil.cpython-36.opt-2.pyc
3

�
�^�-�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZmZmZmZmZmZmZmZmZmZddlZddlZddlZddl
Z
ddlmZddlmZm Z edZ!yddl"Z"ddl#Z#dZ$Wne%k
�rdZ$YnXd	d
�Z&dd�Z'd d
d�Z(d!dd�Z)dd�Z*Gdd�dej+�Z,Gdd�dej+�Z-Gdd�dej+�Z.Gdd�dej+�Z/Gdd�dej+�Z0Gdd�dej+�Z1e2dk�r�ej3�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�FakePath�2TFcOstttdd�d��dS)NZEXDEV�zInvalid cross-device link)�OSError�getattr�errno)�args�kwargs�r�0/opt/alt/python36/lib64/python3.6/test_shutil.py�_fake_rename'srcstj���fdd��}|S)Ncs$ztj}tt_�||�S|t_XdS)N)�os�renamer)rrZbuiltin_rename)�funcrr�wrap,s

zmock_rename.<locals>.wrap)�	functools�wraps)rrr)rr�mock_rename+sr!c	CsBt|t�rtjj|�}t||r"dnd��}|j|�WdQRXdS)N�wb�w)�
isinstance�tupler�path�join�open�write)r&Zcontent�binary�fprrr�
write_file6s
r,c	Cs<t|t�rtjj|�}t||r"dnd��
}|j�SQRXdS)N�rb�r)r$r%rr&r'r(�read)r&r*r+rrr�	read_fileBs
r0cCs�g}x|ttj|��D]j}tjj||�}tjj|�rttjj|�rt|j|d�x.t|�D]}|j|d|�qXWq|j|�qW|S)N�/)	�sortedr�listdirr&r'�isdir�islink�append�rlistdir)r&�res�name�p�nrrrr7Nsr7cs�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*��oHeed+��oHeed,�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;d�dodp�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��ZLd�d��ZMej9d�d���ZNejOd�d���ZPejQd�d���ZRej9d�d���ZSd�d��ZTej
ee=d��d��d�d���ZUej
eEd��ej
eed��d��d�d����ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZ�Z[S)��
TestShutilcstt|�j�g|_dS)N)�superr<�setUp�tempdirs)�self)�	__class__rrr>]szTestShutil.setUpcs:tt|�j�x&|jr4|jj�}tj|tjdk�qWdS)N�nt�cygwin)rBrC)	r=r<�tearDownr?�pop�shutil�rmtreerr9)r@�d)rArrrDas
zTestShutil.tearDowncCstj�}|jj|�|S)N)�tempfile�mkdtempr?r6)r@rHrrrrJhszTestShutil.mkdtempcCsX|j�}tjj|d�}tj|�ttjj|d�d�tj|�}|j|t�t	j
|�dS)NZkillmeZsomefile�foo)rJrr&r'�mkdirr,�fsencode�assertIsInstance�bytesrFrG)r@�tmpZvictimrrr�test_rmtree_works_on_bytesqs

z%TestShutil.test_rmtree_works_on_bytescs�|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)r6)r)�errorsrr�onerror�sz8TestShutil.test_rmtree_fails_on_symlink.<locals>.onerror)rU�r�)rJrr&r'rL�symlink�assertRaisesrrFrG�
assertTrue�exists�lexists�assertEqual�len�assertIsr5rN)r@rPZdir_rSrUr)rTr�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�file1rK�link1�link2�link3)rJrr&r'rLr,rXrFrG�assertFalser[rZ)
r@rPrarbrcrHrdrerfrgrrr�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)NT)�
ignore_errorsZtstfile�z*.*cs�j|�dS)N)r6)r)rTrrrU�sz.TestShutil.test_rmtree_errors.<locals>.onerror)rUrWrrV)rI�mktemprY�FileNotFoundErrorrFrGrJr,rr&r'�NotADirectoryError�assertInZ	exception�filenamerZr[r]r^r_r3rN�rmdir)r@rp�tmpdir�cmZ
possible_argsrUr)rTr�test_rmtree_errors�s2zTestShutil.test_rmtree_errors�chmodzrequires os.chmod()N�rCz2This test can't be run on Cygwin (issue #1071513).�geteuidrz9This test can't be run reliably as root (issue #1076467).cCs
d|_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
|�tjt|jd�|j|jdd�dS)Nr�a�b)rU�z1Expected call to onerror function did not happen.)�
errorStaterrLr�
addCleanuprFrGr&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_modeZold_child_file_modeZold_child_dir_modeZnew_moderrr�
test_on_error�s(

zTestShutil.test_on_errorcCs�|jdkr�|tjkr$|j||j�n:|tjkr>|j||j�n |j|tj�|j	|t
|jg�|jt|dt
��|jd7_n4|j|tj�|j|t
�|jt|dt
��d|_dS)NrWrrVrz)r{r�unlinkr]r}rqr~r_r3rorrZ�
issubclassr)r@r�arg�excrrrr��s


z TestShutil.check_args_to_onerrorcsLz>tj��fdd�}|t_tjt�ttdfd�tjt�Wd�t_XdS)Ncs|tkrt��n�|�SdS)N)rr)�fnrr)�
orig_lstatrr�raiserszFTestShutil.test_rmtree_does_not_choke_on_failing_lstat.<locals>.raiserrK)r�lstatrLrr,rFrG)r@r�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�tjdk�r�tj|tj
�t
j||�|jtj|�jtj|�j�tj|tj
�t
j||�|jtj|�jtj|�j�tj|tj
�t
j||�|jtj|�jtj|�j�dS)NrK�bar�baz�quuxrB)rJrr&r'r,rXrur��S_IRWXU�S_IRWXG�S_IRWXO�assertNotEqualr�rF�copymoder]r9)r@�tmp_dir�src�dst�src_link�dst_linkrrr�test_copymode_follow_symlinkss0

z(TestShutil.test_copymode_follow_symlinks�lchmodzrequires os.lchmodcCsp|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)NrKr�r�r�F)�follow_symlinks)rJrr&r'r,rXrur�r�r�r�r�rFr�r]r�r�r�)r@r�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)NrKr�r�r�F)r�)rJrr&r'r,rXrFr�)r@r�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�r�tj|tj
�ttd�r�ttd�r�tj|tj�tj|�}ttd��r tj||d	d
�|j	|jtj|�j�tj||dd
�tj|�}tjtjk�rtx*dD]"}	|jt||	�t||	�d��qNWttd��r�|j|j|j�ttd��r�t|d��r�|j|j|j�tj||dd
�|jttj|�jtj|�j�dk�dS)NrKr�r��quxgE@r��lchflags�	UF_NODUMPT)r�F�st_atime�st_mtimerV�st_flagsg�������?)r�r�)rJrr&r'r,r��utimer�r�r�rX�hasattrr�r�r�r�r�rF�copystatr��supports_follow_symlinks�assertLessEqualrr]r�rZ�abs)
r@r�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}zTx*tjtjfD]}||�t_t	j
||�qVW|tjtj�t_|jtt	j
||�Wd|t_XdS)Nrd�file2�xxxcst��dd���fdd�
}|S)NT)r�cs��_��dS)N)r)r&�flagsr�)�err�exrr�_chflags_raiser�sznTestShutil.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser.<locals>._chflags_raiser)r)r�r�r)r�r�r�make_chflags_raiser�szUTestShutil.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser)
rJrr&r'r,r�rr�r�rFr�rYr)r@rrrdr�r�Zold_chflagsr�rrr�-test_copystat_handles_harmless_chflags_errors�s


z8TestShutil.test_copystat_handles_harmless_chflags_errorscs�|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
�
}ztj
�|t_
tj�|�Wd�t_
Xtjj|d��t���tj�dd�tjj|d�}t||�tj�|�|jtj|d�d�dS)NrKr�zuser.foos42zuser.bars43�EPERMcs"|dkr��n�|||f|�dS)Nzuser.foor)�fnamer��valr)�
orig_setxattr�os_errorrr�_raise_on_user_foo�sz5TestShutil.test_copyxattr.<locals>._raise_on_user_fooT)r�cs |�krttjd���||d�S)NzOperation not supported)r�)rrr�)r�r�)�orig_listxattrr�rr�
_raise_on_src�sz0TestShutil.test_copyxattr.<locals>._raise_on_srcZthe_originalzuser.the_valuesfiddlyZthe_copy)rJrr&r'r,rF�
_copyxattr�setxattrr]r2�	listxattr�getxattr�removerrr�ror�)r@r�r�r�r�r)r�r�r�r�r�test_copyxattr�sH

 




zTestShutil.test_copyxattrzroot privileges requiredcCs�|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)
NrKr�ztrusted.foos42s43F)r�r�r�)
rJrr&r'r,rXr�rFr�r]r�rYr)r@r�r�r�r�r�rrr�test_copyxattr_symlinks�s 

z"TestShutil.test_copyxattr_symlinkscCs|j�}tjj|d�}tjj|d�}tjj|d�}t|d�tj||�ttd�rftj|tj	tj
B�tj||dd�|j
tjj|��|jt|�t|��tj|�tj||dd�|jtjj|��|jtj|�tj|��ttd��r|jtj|�jtj|�j�dS)NrKr�r�r�T)r�F)rJrr&r'r,rXr�r�r�r�r�rF�copyrhr5r]r0r�rZ�readlinkr�r�)r@r�r�r�r�rrr�test_copy_symlinks�s$


zTestShutil.test_copy_symlinksc	Cs�|j�}tjj|d�}tjj|d�}tjj|d�}t|d�tj||�ttd�rftj|tj	tj
B�ttd�r�ttd�r�tj|tj�tj|�}tj
|�}tj||dd�|jtjj|��|jt|�t|��tj|�tj||d	d�|jtjj|��|jtj|�tj|��tj
|�}tjtjk�rZx*dD]"}|jt||�t||�d��q4Wttd��r�|j|j|j�|j|j|j�ttd��r�t|d
��r�|j|j|j�dS)NrKr�r�r�r�r�T)r�Fr�r�rVr�)r�r�)rJrr&r'r,rXr�r�r�r�r�r�r�r�rF�copy2rhr5r]r0r�rZr�r�r�r�rr�r�r�)	r@r�r�r�r�r�r��dst_statr�rrr�test_copy2_symlinks
s:






zTestShutil.test_copy2_symlinkscCsr|j�}tjj|d�}tjj|d�}t|d�tj|dd�tj||�|jtj	|d�tj	|d��tj
|�dS)NrKr�zuser.foos42)rJrr&r'r,r�rFr�r]r�r�)r@r�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�rSrKF)r�)
rJrr&r'r,rXrF�copyfilerZr5r]r�rh)r@r�r�r�r�rSrrr�test_copyfile_symlinks=s
z!TestShutil.test_copyfile_symlinkscs�tjtjtjtjhtjko0tjtjko0tjtjk}|r�|j	t
j�|j	t
jj
�|j�}tjj|d�}tj|�z<t
j}Gdd�dt���fdd�}|t
_|j�t
j|�Wd|t
_Xn|jt
j�|jt
jj
�dS)Nrxc@seZdZdS)zHTestShutil.test_rmtree_uses_safe_fd_version_if_available.<locals>.CalledN)�__name__�
__module__�__qualname__rrrr�Called[sr�cs��dS)Nr)rr)r�rr�_raiser\szITestShutil.test_rmtree_uses_safe_fd_version_if_available.<locals>._raiser)rr(r�r�rq�supports_dir_fdr3�supports_fdr�rZrF�_use_fd_functionsrGZavoids_symlink_attacksrJr&r'rLZ_rmtree_safe_fd�	ExceptionrYrh)r@r�r�rHZreal_rmtreer�r)r�r�-test_rmtree_uses_safe_fd_version_if_availableNs&

z8TestShutil.test_rmtree_uses_safe_fd_version_if_availablecCs4tj�\}}tj|�|jttj|�tj|�dS)N)	rIZmkstempr�closerYrnrFrGr�)r@Zhandler&rrr�test_rmtree_dont_delete_filefs
z'TestShutil.test_rmtree_dont_delete_filecCstj�}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)rIrJrr&r'r|rFrG�dirnamer,rL�copytreerZ�isfiler4r0r])r@�src_dir�dst_dir�actualrrr�test_copytree_simplems 
zTestShutil.test_copytree_simplec	Csl|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	�r�tt	d
�r�tj|t	j
�tj|�}tj||dd�|jtjjtjj|dd���|jtjtjj|dd��tjj|d��tj|�}ttd��rL|j|j|j�ttd	��rh|j|j|j�dS)
Nr�r��subzfile.txtrKrSzsub/linkr�r�r�T)�symlinks)rJrr&r'rLr,rXr�r�r�r�r�r�r�r�rFr�rZr5r]r�r�r�)	r@r�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
|�XzJdd�}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*cSsjg}x`|D]X}tjj||�}tjj|�rD|j�ddkrD|j|�q
tjj|�ddkr
|j|�q
W|S)NrVr�z.py���r�)rr&r'r4�splitr6�splitext)r��namesr8r9r&rrr�_filter�s
z6TestShutil.test_copytree_with_exclude.<locals>._filter)rr&r'r[rIrJr,rLrF�ignore_patternsr�rZrhrGr�)r@r'r[r�r�Zpatternsr�rrr�test_copytree_with_exclude�sL

z%TestShutil.test_copytree_with_excludecCsjtj�}tjj|d�}tj|�tjj|d�}|jtj|�tj	|d�t
|dfd�tj	tjj|d�d�t
|dfd�tj	tjj|d�d�tj|d	�}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�)rRrV)rIrJrr&r'rLr|rFrGrur,r�r]r�r�r�)r@r�r�r�Zrestrictive_subdirZrestrictive_subdir_dstrrr�!test_copytree_retains_permissions�s,
z,TestShutil.test_copytree_retains_permissionszos.chmodc
Csptj�}tjjtj�d�}|jtj|�|jtjtjj|��t	d�|_
|jtj��tj
||�WdQRXdS)Nr�zka-boom)rIrJrr&r'r|rFrGr��PermissionErrorZside_effectrYrr�)r@Z
mock_patchr�r�rrr�test_copytree_winerror�s
z!TestShutil.test_copytree_winerrorrBztemporarily disabled on WindowsrSzrequires os.linkc'Cs�tjt�tjjtd�}tjjtd�}z�t|d��}|jd�WdQRXytj||�Wn0tk
r�}z|j	d|�WYdd}~XnX|j
tjtj
||�t|d��}|j|j�d�WdQRXtj|�Wdtjtdd�XdS)	N�cheese�shopr#�cheddarz
os.link(): %sr.T)rj)rrLrr&r'r(r)rSr��skipTestrYrFr
r�r]r/r�rG)r@r�r��f�errr�'test_dont_copy_file_onto_link_to_itselfs
 z2TestShutil.test_dont_copy_file_onto_link_to_itselfcCs�tjt�tjjtd�}tjjtd�}ztt|d��}|jd�WdQRXtjd|�|jt	j
t	j||�t|d��}|j|j
�d�WdQRXtj|�Wdt	jtdd�XdS)Nr�r�r#r�r.T)rj)rrLrr&r'r(r)rXrYrFr
r�r]r/r�rG)r@r�r�r�rrr�*test_dont_copy_file_onto_symlink_to_itselfs
z5TestShutil.test_dont_copy_file_onto_symlink_to_itselfc
Csttjt�zTtjjtd�}tjjtd�}tj|�tj||�|jttj	|�tj	|dd�Wdtj	tdd�XdS)Nr�r�T)rj)
rrLrr&r'rXrYrrFrG)r@r�r�rrr�test_rmtree_on_symlink.s

z!TestShutil.test_rmtree_on_symlink�mkfifozrequires os.mkfifo()cCs~ytjt�Wn0tk
r>}z|jd|�WYdd}~XnXz,|jtjtjtt	�|jtjtjt
t�Wdtjt�XdS)Nzos.mkfifo(): %s)rrrr�r�rYrF�SpecialFileErrorr��TESTFN2�__file__r�)r@rrrr�test_copyfile_named_pipe=s z#TestShutil.test_copyfile_named_pipec'Cstjt�z�tjjtd�}tj|�tjj|d�}ytj|�Wn0tk
rp}z|jd|�WYdd}~XnXytj	tt
�Wn\tjk
r�}z>|jd}|j
t|�d�|d\}}}|j
d||�WYdd}~XnX|jd�Wdtjtdd	�tjt
dd	�XdS)
Nr�Zmypipezos.mkfifo(): %srrVz`%s` is a named pipez$shutil.Error should have been raisedT)rj)rrLrr&r'rr�r�rFr�rrrr]r^�failrG)r@r��piperrTr�r�Z	error_msgrrr�test_copytree_named_pipeKs&

 
"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)r6)r�r�)�copiedrr�_copymsz4TestShutil.test_copytree_special_func.<locals>._copy)�
copy_functionrW)
rJrr&r'r,rLrFr�r]r^)r@r�r�r
r)rr�test_copytree_special_funcds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
||dd
�|j
dtj|��dS)Nr�Z
IDONTEXISTztest.txtr�r��destination2T)Zignore_dangling_symlinksZdestination3)r�)rJrr&r'rXrLr,rYrrFr��assertNotInr3ro)r@r�r�rrr�test_copytree_dangling_symlinksssz*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_dirT)Ztarget_is_directoryF)r�r)rJrr&r'rLr(rXrFr�rhr5ror3rZ)r@r�r�rrr�test_copytree_symlink_dir�s
z$TestShutil.test_copytree_symlink_dircCsPd}|j�}t||fd�tjj||�}|j�}|||�tjj||�}||fS)Nztest.txtr�)rJr,rr&r')r@�methodr�rrrd�tmpdir2r�rrr�
_copy_file�s
zTestShutil._copy_filecCsB|jtj�\}}|jtjj|��|jtj|�j	tj|�j	�dS)N)
rrFr�rZrr&r[r]r�r�)r@rdr�rrr�	test_copy�szTestShutil.test_copyr�zrequires os.utimecCs�|jtj�\}}|jtjj|��tj|�}tj|�}|j|j	|j	�x(dD] }|j
t||�t||�d�qLWttd�r�t|d�r�|jt|d�t|d��dS)Nr�r�rVr�r�)r�r�)
rrFr�rZrr&r[r�r]r�r�rr�)r@rdr�Z
file1_statZ
file2_statr�rrr�
test_copy2�s


zTestShutil.test_copy2c	$Csf|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)Nrk�archive�gztar�.z.tar.gzzr:gzz./subz./sub2z./file1z./file2z./sub/file3�tarz.tarr.)�
_create_filesrJrrqr&r�r'�basenamer�
change_cwd�abspathrr]rZr��tarfileZ
is_tarfiler(�assertCountEqual�getnames)	r@�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|�SQRXdS)N)r!r(r#�sortr%)r@r&rr�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)
NT)�exist_okrdr�r�r�Zfile3Zsub2�outer)rJrr&r'�makedirsr,rL)r@r%r$r-rrrr�szTestShutil._create_filesrzNeed the tar command to runcCs|j�\}}tjj|j�d�}t|d||�}|j||d�|jtjj|��tjj|d�}ddd|g}t	j
||t	jd�|jtjj|��|j|j|�|j|��t|d||�}|j||d�|jtjj|��t|d||d	d
�}|j||d�|jtjj|��dS)Nrrz.tar.gzzarchive2.tarrz-cf)�cwd�stdoutz.tarT)Zdry_run)
rrr&r'rJrr]rZr��
subprocess�
check_call�DEVNULLr,)r@r$r%r(r)Ztarball2Ztar_cmdrrr�test_tarfile_vs_tar�s$

zTestShutil.test_tarfile_vs_tarc	$Csl|j�\}}|j�}tj|�tjj|�}tjjtjj|�d�}tj	|��tjj
|�}t|d|�}WdQRX|j||d�|j
tjj|��|j
tj|��tj|��$}|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/file3r/)rrJrrqr&r�r'rrrr rr]rZr��zipfileZ
is_zipfile�ZipFiler"�namelist)	r@r$r%rr&r'r(r8�zfrrr�test_make_zipfiles4


zTestShutil.test_make_zipfiler7zNeed the zip command to runc
Cs�|j�\}}tjj|j�d�}t|d||�}|j||d�|jtjj|��tjj|d�}dddd|g}t	j
||t	jd�|jtjj|��tj
|��}|j�}WdQRXtj
|��}|j�}	WdQRX|jt|�t|	��dS)Nrr7z.zipzarchive2.zipz-qz-r)r1r2)rrr&r'rJrr]rZr�r3r4r5r8r9r:r2)
r@r$r%r(rZarchive2�zip_cmdr;r�Znames2rrr�test_zipfile_vs_zip=s
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
|��vytj|tj
d�WnZtjk
r�}z<|jjdd�}d	|kr�|jd
�d}|j|j||��WYdd}~XnXWdQRXdS)Nrr7z.zipr?z-t)�stderr�replace)rTzunrecognized option: tzunzip doesn't support -tz{}

**Unzip Output**
{})rrr&r'rJrr]rZr�rrr3�check_outputZSTDOUT�CalledProcessError�output�decoder�r	�format)	r@r$r%r(rr=r�Zdetails�msgrrr�test_unzip_zipfileWs

zTestShutil.test_unzip_zipfilecCs*|j�}tjj|d�}|jtt|d�dS)Nrr�)rJrr&r'rY�
ValueErrorr)r@rrr(rrr�test_make_archiveoszTestShutil.test_make_archivecCs�tr"tjd�d}tjd�d}nd}}|j�\}}tjj|j	�d�}t
|d||||d�}|jtjj|��t
|d||�}|jtjj|��t
|d||||d�}|jtjj|��t
|d||ddd�}|jtjj|��dS)	Nr�rootrr7)�owner�grouprZ	kjhkjhkjgZoihohoh)
�UID_GID_SUPPORT�grp�getgrgid�pwd�getpwuidrrr&r'rJrrZr�)r@rMrLr$r%r(r8rrr�test_make_archive_owner_groupts"



z(TestShutil.test_make_archive_owner_groupzRequires grp and pwd supportc	Cs�|j�\}}tjj|j�d�}tjd�d}tjd�d}t	j
|��t|d|d||d�}WdQRX|jtjj
|��tj|�}z2x,|j�D] }|j|jd�|j|jd�q�WWd|j�XdS)Nrrrr-)rLrM)rrr&r'rJrOrPrQrRrrrrZr�r!r(Z
getmembersr]�uid�gidr�)	r@r$r%r(rMrLZarchive_namer�memberrrr�test_tarfile_root_owner�s

z"TestShutil.test_tarfile_root_ownercCsntj�}dd�}td|gd�z@ytdd|j�d�Wntk
rJYnX|jtj�|�Wdtd�XdS)Nc_s
t��dS)N)�RuntimeError)r�kwrrr�_breaks�sz1TestShutil.test_make_archive_cwd.<locals>._breaksr�zxxx file)r$)r�getcwdrrrJr�r]r)r@Zcurrent_dirrZrrr�test_make_archive_cwd�sz TestShutil.test_make_archive_cwdcCsF|j�}tj|��*|jtdd�d�|jtjjd��WdQRXdS)N�testrztest.tar)	rJrrr]rrZrr&r�)r@r$rrr�test_make_tarfile_in_curdir�sz&TestShutil.test_make_tarfile_in_curdircCsF|j�}tj|��*|jtdd�d�|jtjjd��WdQRXdS)Nr]r7ztest.zip)	rJrrr]rrZrr&r�)r@r$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�rVcSstS)N)�xrrrr�<lambda>�sz9TestShutil.test_register_archive_format.<locals>.<lambda>cSstS)N)r`rrrrra�srWrzcSstS)N)r`rrrrra�szxxx filecSsg|]\}}|�qSrr)�.0r9�paramsrrr�
<listcomp>�sz;TestShutil.test_register_archive_format.<locals>.<listcomp>cSsg|]\}}|�qSrr)rbr9rcrrrrd�s)rVrW)rVrWrz)rVrW)rY�	TypeErrorrrrorr)r@�formatsrrr�test_register_archive_format�s
z'TestShutil.test_register_archive_formatcCs.|j|dd��|j|tj�|j|t�dS)NcSs|S)Nr)r&rrrra�sz1TestShutil.check_unpack_archive.<locals>.<lambda>)�#check_unpack_archive_with_converter�pathlibZPathr)r@rFrrr�check_unpack_archive�szTestShutil.check_unpack_archivec
Cs�|j�\}}t|�}|jd�tjj|j�d�}t||||�}|j�}t||�|j	t|�|�|j�}	t||	|d�|j	t|	�|�|j
tjtt
�|j
ttt
dd�dS)Nr/r)rFr�)rr7r�rr&r'rJrrr]rYrFZ	ReadErrorrrI)
r@rFZ	converterr$r%�expectedr(rprZtmpdir3rrrrh�s

z.TestShutil.check_unpack_archive_with_convertercCs|jd�dS)Nr)rj)r@rrr�test_unpack_archive_tar�sz"TestShutil.test_unpack_archive_tarcCs|jd�dS)Nr)rj)r@rrr�test_unpack_archive_gztar�sz$TestShutil.test_unpack_archive_gztarcCs|jd�dS)NZbztar)rj)r@rrr�test_unpack_archive_bztar�sz$TestShutil.test_unpack_archive_bztarcCs|jd�dS)NZxztar)rj)r@rrr�test_unpack_archive_xztar�sz$TestShutil.test_unpack_archive_xztarcCs|jd�dS)Nr7)rj)r@rrr�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)
Ncs(�j|d��j|d��j|d�dS)NrVz	stuff.boo�xx)r])rpZextract_dir�extra)r@rr�_boosz-TestShutil.test_unpack_registry.<locals>._booZBooz.booz.b2rrrVz	stuff.boorqZBoo2rk)rrrV)	rr	rrYr
rrorr])r@rfrsr)r@r�test_unpack_registrys


zTestShutil.test_unpack_registry�
disk_usagez)disk_usage not available on this platformcCs`tjtjjt��}|j|jd�|j|jd�|j	|j
d�|j	|j|j�|j|j|j
�dS)Nr)rFrurr&r�rZ
assertGreaterZtotalZused�assertGreaterEqualZfree)r@�usagerrr�test_disk_usageszTestShutil.test_disk_usage�chownzrequires os.chownc's�j�}tj|d��t�d��jt��tj��WdQRX�jt��tj�dd�WdQRX�jt��tj�dd�WdQRX�jt	��tj�d�WdQRX�jt	��tj�d�WdQRXt
j�}t
j�}d
��fd	d
�	}tj�||�|�||�tj�|�|�|�tj�|d�|�|�tj�|d�|�|d�tj|||�||||�tj||�|||�tj||d�|||�tj||d�|||d�t
j|�d}tj|�d}tj�||�|�||�tj|||�||||�dS)N)rRztesting chown functionznon-existing username)�userznon-existing groupname)rMsspamg��Q�	@cs:tj��}|dk	r �j||j�|dk	r6�j||j�dS)N)rr�r]�st_uid�st_gid)r&rTrU�s)rpr@rr�check_chownAs

z*TestShutil.test_chown.<locals>.check_chown)rUr)NN)rJrIrlr,rYrIrFry�LookupErrorrer�getuid�getgidrQrRrOrP)r@r�rTrUr~rzrMr)rpr@r�
test_chown&sL




zTestShutil.test_chowncCs�x�tjtjfD]v}|j�}|j�}tjj|d�}t|d�|||�}|j|tjj|d��||tjj|d��}|j|tjj|d��qWdS)NrKr�)	rFr�r�rJrr&r'r,r])r@r�r�r�r��rvrrr�test_copy_return_valueas

z!TestShutil.test_copy_return_valuecCsl|j�}|j�}tjj|d�}tjj|d�}t|d�tj||�}|jtjj|��|j	t
|�t
|��dS)Nr�rK)rJrr&r'r,rFr�rZr[r]r0)r@r�r��dst_file�src_filer�rrr�test_copyfile_return_valuems
z%TestShutil.test_copyfile_return_valuecCsH|j�}tjj|d�}t|d�|jttj||�|jt	tj||�dS)NrK)
rJrr&r'r,rYr
rFr�r)r@r�r�rrr�test_copyfile_same_filexs

z"TestShutil.test_copyfile_same_filecCs\|j�}|d}|jtj|d�tjj|d�}t|d�tj||�}|j	dgtj
|��dS)N�destTrK)rJr|rFrGrr&r'r,r�r]r3)r@r�r�r�r�rrr�test_copytree_return_value�s
z%TestShutil.test_copytree_return_value)r-)\r�r�r�r>rDrJrQr�skip_unless_symlinkr`rirt�unittest�
skipUnlessr�r�skipIf�sys�platformrwr�r�r�r�r�r�r�rr�Zskip_unless_xattrr�r�r�r�r�r�r�r�r�r�r�r�ZmockZpatchr�r9rrrrrrrrrrrZ
requires_zlibr*r,rrF�whichr6r<r>rHrJrSrNrWr\r^r_rgrjrhrlrmZrequires_bz2rnZ
requires_lzmarorprtrxr�r�r�r�r��
__classcell__rr)rArr<[s�		$ 
)8#
A
$
%	
:
r<c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zej	e
ed�oHej�dkd
�dd��Z
dd�Zdd�Zejejdkd�dd��Zdd�Zdd�Zdd�ZdS)�	TestWhichcCsptjdd�|_|jtj|jd�tj|jddd�|_tj	|jj
tj�|j|jj
�tjj|jj
�\|_|_dS)NZTmp)�prefixTz.Exe)rRr��suffix)rIrJ�temp_dirr|rFrGZNamedTemporaryFile�	temp_filerrur9r��S_IXUSRr�r&r�rR�file)r@rrrr>�s
zTestWhich.setUpcCs&tj|j|jd�}|j||jj�dS)N)r&)rFr�r�rRr]r�r9)r@r�rrr�
test_basic�szTestWhich.test_basiccCs(tj|jj|jd�}|j||jj�dS)N)r&)rFr�r�r9r�r])r@r�rrr�test_absolute_cmd�szTestWhich.test_absolute_cmdcCs�tjj|j�\}}tjj||j�}tj|d��"tj	||j
d�}|j||�WdQRXtj|jd��tj	||d�}|j|�WdQRXdS)N)r&)
rr&r�rRr'r�rrrFr�r�r]�assertIsNone)r@r%�tail_dir�relpathr�rrr�test_relative_cmd�szTestWhich.test_relative_cmdcCsltjj|j�}tj|jd��Ftj|j|d�}t	j
dkrT|j|tjjtj
|j��n
|j|�WdQRXdS)N)r&�win32)rr&r�rRrrrFr�r�r�r�r]r'�curdirr�)r@r%r�rrr�test_cwd�s
zTestWhich.test_cwdrwrznon-root user requiredcCsRtj|jjtj�tj|jjtj�r.|jd�t	j
|j|jtjd�}|j
|�dS)Nzcan't set the file read-only)r&�mode)rrur�r9r�r��access�W_OKr�rFr�r�rRr�)r@r�rrr�test_non_matching_mode�s

z TestWhich.test_non_matching_modecCsVtjj|j�\}}tj|d��.tj|j|d�}|j	|tjj
||j��WdQRXdS)N)r&)rr&r�rRrrrFr�r�r]r')r@r%r�r�rrr�test_relative_path�szTestWhich.test_relative_pathcCstjd|jd�}|j|�dS)Nzfoo.exe)r&)rFr�rRr�)r@r�rrr�test_nonexistent_file�szTestWhich.test_nonexistent_filer�zpathext check is Windows-onlycCs:tj|jdd�|jd�}|j||jjdd�d�dS)N�)r&z.EXE���r�)rFr�r�rRr]r�r9)r@r�rrr�test_pathext_checking�szTestWhich.test_pathext_checkingc
Cs>tj��,}|j|d<tj|j�}|j||jj�WdQRXdS)N�PATH)	r�EnvironmentVarGuardrRrFr�r�r]r�r9)r@�envr�rrr�test_environ_path�s

zTestWhich.test_environ_pathcCsdtjj|j�}tj|jd��>tj��*}|j|d<tj|j	dd�}|j
|�WdQRXWdQRXdS)N)r&r�rk)rr&r�rRrrr�rFr�r�r�)r@r%r�r�rrr�test_empty_path�s

zTestWhich.test_empty_pathc
Cs:tj��(}|jdd�tj|j�}|j|�WdQRXdS)Nr�)rr�rErFr�r�r�)r@r�r�rrr�test_empty_path_no_PATH�s
z!TestWhich.test_empty_path_no_PATHN)r�r�r�r>r�r�r�r�r�r�r�rrwr�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	Csbd}tj�|_tj�|_tjj|j|�|_tjj|j|�|_t	|jd��}|j
d�WdQRXdS)NrKr"sspam)rIrJr�r�rr&r'r�r�r(r))r@rpr�rrrr>�s

zTestMove.setUpc
Cs:x4|j|jfD]$}y|r"tj|�WqYqXqWdS)N)r�r�rFrG)r@rHrrrrD�szTestMove.tearDowncCsft|d��}|j�}WdQRXtj||�t|d��}|j||j��WdQRX|jtjj|��dS)Nr-)	r(r/rF�mover]rhrr&r[)r@r�r��real_dstr��contentsrrr�_check_move_fileszTestMove._check_move_filecCsFttj|��}tj||�|j|ttj|���|jtjj|��dS)N)	r2rr3rFr�r]rhr&r[)r@r�r�r�r�rrr�_check_move_dirszTestMove._check_move_dircCs|j|j|j|j�dS)N)r�r�r�)r@rrr�test_move_fileszTestMove.test_move_filecCs|j|j|j|j�dS)N)r�r�r�r�)r@rrr�test_move_file_to_dirszTestMove.test_move_file_to_dircCs|j�dS)N)r�)r@rrr�test_move_file_other_fssz TestMove.test_move_file_other_fscCs|j�dS)N)r�)r@rrr�test_move_file_to_dir_other_fssz'TestMove.test_move_file_to_dir_other_fscCs@tj�}z|j|j||�Wdytj|�WnYnXXdS)N)rIrlr�r�rFrG)r@r�rrr�
test_move_dir$szTestMove.test_move_dircCs|j�dS)N)r�)r@rrr�test_move_dir_other_fs/szTestMove.test_move_dir_other_fscCs,|j|j|jtjj|jtjj|j���dS)N)r�r�r�rr&r'r)r@rrr�test_move_dir_to_dir4szTestMove.test_move_dir_to_dircCs|j�dS)N)r�)r@rrr�test_move_dir_to_dir_other_fs9sz&TestMove.test_move_dir_to_dir_other_fscCs4|j|jtjj|jtjj|jtjj|j���dS)N)r�r�rr&�sepr�r'r)r@rrr�test_move_dir_sep_to_dir>sz!TestMove.test_move_dir_sep_to_dirzrequires os.path.altsepcCs4|j|jtjj|jtjj|jtjj|j���dS)N)r�r�rr&�altsepr�r'r)r@rrr�test_move_dir_altsep_to_dirBsz$TestMove.test_move_dir_altsep_to_dircCs4t|jd��WdQRX|jtjtj|j|j�dS)Nr")r(r�rYrFrr�r�r�)r@rrr�"test_existing_file_inside_dest_dirGs
z+TestMove.test_existing_file_inside_dest_dircCs*tjj|jd�}|jtjtj|j|�dS)Nr�)rr&r'r�rYrFrr�)r@r�rrr�test_dont_move_dir_in_itselfMsz%TestMove.test_dont_move_dir_in_itselfc
Csptjt�zPxJdD]B\}}tjjt|�}tjjt|�}|jtj||�d||fd�qWWdtjtdd�XdS)	N�srcdir�srcdir/destz?_destinsrc() wrongly concluded that dst (%s) is not in src (%s))rGT)rj�r�r�)r�)	rrLrr&r'rZrF�
_destinsrcrG)r@r�r�rrr�test_destinsrc_false_negativeRs
z&TestMove.test_destinsrc_false_negativec
Csptjt�zPxJd
D]B\}}tjjt|�}tjjt|�}|jtj||�d||fd�qWWdtjtdd�XdS)Nr��src/dest�
srcdir.newz;_destinsrc() wrongly concluded that dst (%s) is in src (%s))rGT)rj�r�r��r�r�)r�r�)	rrLrr&r'rhrFr�rG)r@r�r�rrr�test_destinsrc_false_positive^s
z&TestMove.test_destinsrc_false_positivecCs\tjj|jd�}tj|j|�tj||j�|j	tjj
|j��|j	tjj|j|j��dS)Nr�)rr&r'r�rXr�rFr�r�rZr5�samefile)r@r�rrr�test_move_file_symlinkjs
zTestMove.test_move_file_symlinkcCsld}tjj|j|�}tj|j|�tj||j�tjj|j|�}|j	tjj
|��|j	tjj|j|��dS)Nr�)rr&r'r�rXr�rFr�r�rZr5r�)r@rpr�Z
final_linkrrr�test_move_file_symlink_to_dirssz&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�rB)rr&r'r�rXr�rFr�rZr5r9r]�realpathr�)r@r�r�r�rrr�test_move_dangling_symlink~s
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�rLrXr�rFr�rZr5r�)r@r�r�r�rrr�test_move_dir_symlink�s
zTestMove.test_move_dir_symlinkcCs6tj|j|j�}|j|tjj|jtjj|j���dS)N)	rFr�r�r�r]rr&r'r)r@r�rrr�test_move_return_value�szTestMove.test_move_return_valuecCs6tj|jtjj|jd��}|j|tjj|jd��dS)Nr�)rFr�r�rr&r'r�r])r@r�rrr� test_move_as_rename_return_value�sz)TestMove.test_move_as_rename_return_valuecs8g��fdd�}tj|j|j|d�|jt��d�dS)Ncs�j||f�dS)N)r6)r�r�)�movedrrr
�sz7TestMove.test_move_file_special_function.<locals>._copy)rrV)rFr�r�r�r]r^)r@r
r)r�r�test_move_file_special_function�sz(TestMove.test_move_file_special_functioncsdg��fdd�}tjtjj|jd��tjtjj|jd��tj|j|j|d�|j	t
��d�dS)Ncs�j||f�dS)N)r6)r�r�)r�rrr
�sz6TestMove.test_move_dir_special_function.<locals>._copyZchildZchild1)rrz)rrrr&r'r�rFr�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>rDr�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@sXeZdZdZGdd�de�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�ZdS)�TestCopyFileFc@s:eZdZdZdZdZddd�Zdd�Zdd	�Zd
d�Z	dS)
zTestCopyFile.FauxFNTcCs||_||_dS)N)�_raise_in_exit�_suppress_at_exit)r@Z
raise_in_exitZsuppress_at_exitrrr�__init__�szTestCopyFile.Faux.__init__cGsdS)Nrkr)r@rrrrr/�szTestCopyFile.Faux.readcCs
d|_dS)NT)�_entered)r@rrr�	__enter__�szTestCopyFile.Faux.__enter__cCs&|||f|_|jr d|_td��|jS)NTzCannot close)�_exited_withr��_raisedrr�)r@�exc_typeZexc_valZexc_tbrrr�__exit__�s
zTestCopyFile.Faux.__exit__)FT)
r�r�r�r�r�r�r�r/r�r�rrrr�Faux�s
r�cCs|jr
t`dS)N)�_deleterFr()r@rrrrD�szTestCopyFile.tearDowncCs|t_d|_dS)NT)rFr(r�)r@rrrr�_set_shutil_open�szTestCopyFile._set_shutil_opencCs*ddd�}|j|�|jttjdd�dS)Nr.cSs|dkrtd��dS)N�srcfilezCannot open "srcfile")r)rpr�rrr�_open�sz4TestCopyFile.test_w_source_open_fails.<locals>._openr��destfile)r.)r�rYrrFr�)r@r�rrr�test_w_source_open_fails�s

z%TestCopyFile.test_w_source_open_failscsd|j��d	�fdd�	}|j|�tjdd�|j�j�|j�jdtk�|j�jdj	d
�dS)Nr.cs |dkr�S|dkrtd��dS)Nr�r�zCannot open "destfile")r)rpr�)r�rrr��s
z2TestCopyFile.test_w_dest_open_fails.<locals>._openr�r�rrV�Cannot open "destfile")r.)r�)
r�r�rFr�rZr�r�rr]r)r@r�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)rpr�)r�r�rrr��s
z3TestCopyFile.test_w_dest_close_fails.<locals>._openr�r�rrV�Cannot close)r.)r�)r�r�rFr�rZr�r�r�rr]r)r@r�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)rpr�)r�r�rrr�s
z5TestCopyFile.test_w_source_close_fails.<locals>._openr�r�r)r.)r�r�rYrrFr�rZr�rhr�r�)r@r�r)r�r�r�test_w_source_close_failss

z&TestCopyFile.test_w_source_close_failscCs�tj�|_|jtj|jd�tjjtjj	|j�tjj
|j�j��}|j|j|�z$tj
|j|�|jtjj|��Wdtj|�XdS)NT)rIrJr�r|rFrGrr&r'r�r�upperr�r�rZr4rq)r@r�rrr�test_move_dir_caseinsensitives
z*TestCopyFile.test_move_dir_caseinsensitiveN)
r�r�r�r��objectr�rDr�r�r�r�r�r�rrrrr��s
r�c@s^eZdZdd�Zdd�Zdd�Zejej	e
jj��d�eje
ed�d	�d
d���Zdd
�ZdS)�
TermsizeTestscCs(tj�}|j|jd�|j|jd�dS)Nr)rF�get_terminal_sizerv�columns�lines)r@�sizerrr�test_does_not_crash.sz!TermsizeTests.test_does_not_crashcCsttj��}d|d<|d=tj�}WdQRX|j|jd�tj��}|d=d|d<tj�}WdQRX|j|jd�dS)NZ777�COLUMNS�LINESi	Z888ix)rr�rFr�r]r�r�)r@r�r�rrr�test_os_environ_first8s

z#TermsizeTests.test_os_environ_firstc
CsLtj��}d|d<d|d<tj�}WdQRX|j|jd�|j|jd�dS)Nr�r�Zyyyr�r)rr�rFr�rvr�r�)r@r�r�rrr�test_bad_environGs
zTermsizeTests.test_bad_environz
not on ttyr�zneed os.get_terminal_size()cCs�ytjddg�j�j�}Wn&tttjfk
r@|jd�YnXt|d�t|d�f}t	j
��}|d=|d=tj�}WdQRX|j
||�dS)NZsttyr�zstty invocation failedrVrr�r�)r3rBrEr�rmr�rCr��intrr�rFr�r])r@r�rkr�r�rrr�test_stty_matchOs

zTermsizeTests.test_stty_matchcCs�tj���}|d=|d=tjtdd��tjd
d�}WdQRX|j|jd�|j|jd�t	t
jd��,}tjtd|��tjdd�}WdQRXWdQRX|j|jd�|j|jd	�WdQRXdS)Nr�r��
__stdout__�
�)�fallbackr#��()rr)rr)rr�Z	swap_attrr�rFr�r]r�r�r(r�devnull)r@r�r�r�rrr�
test_fallbackgs
 zTermsizeTests.test_fallbackN)r�r�r�r�r�r�r�r�r�isattyr�r�filenor�r�rrrrrr�-s
r�c@seZdZdd�ZdS)�PublicAPITestscCs~|jttd��dddddddd	d
ddd
dddddddddddddg}ttd�sZtjdkrd|jd�|jttj�t|��dS)N�__all__Zcopyfileobjr�r�r�r�r�r�r�rGrrZ	ExecErrorrrrrrr	rrr�ryr�r�r
�statvfsrBru)	rZr�rFrr9r6r]�setr)r@Z
target_apirrr�test_module_all_attribute~s
z(PublicAPITests.test_module_all_attributeN)r�r�r�rrrrrr
{sr
�__main__)F)F)4r�Z
unittest.mockrFrIr�r�rZos.pathrrrir3�
contextlibrrrrrrrr	r
rrr
r!r8�warningsr]rZtest.supportrrrrOrQrN�ImportErrorrr!r,r0r7ZTestCaser<r�r�r�r�r
r��mainrrrr�<module>sd4



<dExN


Youez - 2016 - github.com/yon3zu
LinuXploit