Your IP : 216.73.216.52


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_zipapp.cpython-310.opt-2.pyc

o

0�i�?�@s�	ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZGdd�dej�Z
Gdd�dej�ZedkrIe��dSdS)	�N)�
requires_zlib)�patchc@seZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
�dd��Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Ze�ejd1kd2�d3d4��Z e�ejd1kd2�d5d6��Z!d7S)8�
ZipAppTestcC�&t��}|�|j�t�|j�|_dS�N��tempfileZTemporaryDirectoryZ
addCleanupZcleanup�pathlibZPath�name�tmpdir��selfr�r�7/opt/alt/python310/lib64/python3.10/test/test_zipapp.py�setUp�zZipAppTest.setUpcCsN|jd}|��|d��|jd}t�t|�t|��|�|���dS�N�source�__main__.py�
source.pyz�r�mkdir�touch�zipapp�create_archive�str�
assertTrue�is_file�r
r�targetrrr�test_create_archives

zZipAppTest.test_create_archivecCsF|jd}|��|d��|jd}t�||�|�|���dSr)rrrrrrrrrrr� test_create_archive_with_pathlib!s

z+ZipAppTest.test_create_archive_with_pathlibcCs�|jd}|��|d��|d��|d��|dd��t��}t�t|�|�|�d�t	�
|d��}|�d|���|�d	|���Wd�dS1sVwYdS)
Nrr�fooZbarz__init__.pyr�rzfoo/zbar/)
rrr�io�BytesIOrrr�seek�zipfile�ZipFile�assertIn�namelist�r
rr�zrrr� test_create_archive_with_subdirs*s

"�z+ZipAppTest.test_create_archive_with_subdirscCs�dd�}|jd}|��|d��|d��|d��|jd}tj|||d�t�|d	��!}|�d|���|�d|���|�	d|���Wd�dS1sVwYdS)
NcSs
|jdkS)Nz.pyc)�suffix��pathrrr�skip_pyc_files<s
zBZipAppTest.test_create_archive_with_filter.<locals>.skip_pyc_filesrr�test.pyztest.pycr��filterr#)
rrrrrr'r(r)r*ZassertNotIn)r
r1rrr,rrr�test_create_archive_with_filter9s

"�z*ZipAppTest.test_create_archive_with_filtercCs�dd�}|jd}|��|d��|d��|d��|dd��|jd}tj|||d	�t�|d
��#}|�t|�	��d�|�
d|�	��|�
d|�	��Wd�dS1s`wYdS)NcSs|jddkS)Nr�dummy)�partsr/rrr�skip_dummy_dirOszIZipAppTest.test_create_archive_filter_exclude_dir.<locals>.skip_dummy_dirrrr2r6ztest2.pyrr3r#�)rrrrrr'r(�assertEqual�lenr*r))r
r8rrr,rrr�&test_create_archive_filter_exclude_dirKs

"�z1ZipAppTest.test_create_archive_filter_exclude_dircCsH|jd}|��|d��t�t|��|jd}|�|���dSrr)r
rZexpected_targetrrr�"test_create_archive_default_target_s

z-ZipAppTest.test_create_archive_default_targetcCs�|jd}|��|d��|d��|jd}tj||dd�t�|d��}dD]
}|�|�|�j	tj
�q+Wd�dS1sDwYdS)	Nrrr2rT)Z
compressedr#)rr2)rrrrrr'r(r:ZgetinfoZ
compress_typeZZIP_DEFLATED)r
rrr,r
rrr�$test_create_archive_with_compressionhs

��"�z/ZipAppTest.test_create_archive_with_compressioncCsn|jd}|��|d��|jd}|�tj��t�t|�t|��Wd�dS1s0wYdS)Nr�foo.pyr�rrr�assertRaisesr�ZipAppErrorrrrrrr�test_no_mainws

"�zZipAppTest.test_no_maincCsr|jd}|��|d��|jd}|�tj��tjt|�t|�dd�Wd�dS1s2wYdS)Nrrr�
pkg.mod:fn��mainr@rrrr�test_main_and_main_py�s

"�z ZipAppTest.test_main_and_main_pycCs�|jd}|��|d��|jd}tjt|�t|�dd�t�t|�d��}|�d|�	��|�d|�
d��Wd�dS1sEwYdS)	Nrr?rrDrEr#rspkg.mod.fn())rrrrrrr'r(r)r*�readr+rrr�test_main_written�s

"�zZipAppTest.test_main_writtencCs�|jd}|��|d��|d��|jd}tjt|�t|�dd�t�t|�d��}|�d|�	��
d	��Wd�dS1sEwYdS)
Nrr?zbar.pyrrDrEr#�r)rrrrrrr'r(r:r*�countr+rrr�test_main_only_written_once�s

"�z&ZipAppTest.test_main_only_written_oncec
Cs�|jd}|��|jd}gd�}|D]:}|j|d��*|�tj��tjt|�t|�|d�Wd�n1s:wYWd�n1sIwYqdS)Nrr)
�r"zfoo:z:barz12:barza.b.c.:dz.a:bza:b.za:.bza:silly namerE)rrZsubTestrArrBrr)r
rrZproblemsrFrrr�test_main_validation�s

�����zZipAppTest.test_main_validationcCs~|jd}|��|d��|jd}t�t|�t|��|�d��}|�|�d�d�Wd�dS1s8wYdS)Nrrr�rbr9�#!)	rrrrrr�openZassertNotEqualrH�r
rr�frrr�test_default_no_shebang�s

"�z"ZipAppTest.test_default_no_shebangcCs�|jd}|��|d��|jd}tjt|�t|�dd�|�d��}|�|�d�d�|�d	|�	��Wd�dS1sBwYdS)
Nrrr�python�ZinterpreterrOr9rPspython
)
rrrrrrrQr:rH�readlinerRrrr�test_custom_interpreter�s

"�z"ZipAppTest.test_custom_interpretercCsR|jd}|��|d��t��}tjt|�|dd�|�|�	��
d��dS)NrrrUrVs	#!python
)rrrr$r%rrrr�getvalue�
startswithrrrr�test_pack_to_fileobj�s
zZipAppTest.test_pack_to_fileobjcCsZ|jd}|��|d��|jd}tjt|�t|�dd�|�t�t|��d�dS�NrrrrUrV�rrrrrrr:�get_interpreterrrrr�test_read_shebang�s

zZipAppTest.test_read_shebangcCsV|jd}|��|d��|jd}t�t|�t|��|�t�t|��d�dSrr]rrrr�test_read_missing_shebang�s

z$ZipAppTest.test_read_missing_shebangcCs||jd}|��|d��|jd}tjt|�t|�dd�|jd}tjt|�t|�dd�|�t�t|��d�dS)NrrrrUrV�changed.pyz�	python2.7r]�r
rr�
new_targetrrr�test_modify_shebang��


zZipAppTest.test_modify_shebangcCst|jd}|��|d��|jd}tjt|�t|�dd�t��}tjt|�|dd�|�|�	��
d��dS)NrrrrUrVrb�#!python2.7
)rrrrrrr$r%rrYrZrcrrr�test_write_shebang_to_fileobj�s

z(ZipAppTest.test_write_shebang_to_fileobjcCsh|jd}|��|d��|jd}|jd}tj||dd�tj||dd�|�t�|�d�dS)Nrrztarget1.pyzztarget2.pyzrUrVrb)rrrrrr:r^)r
rZtarget1Ztarget2rrr�test_read_from_pathobj�s


z!ZipAppTest.test_read_from_pathobjcCs~|jd}|��|d��|jd}t��}tjt|�|dd�t��}|�d�tj||dd�|�	|�
��d��dS)	NrrrrUrVrrbrg)rrrr$r%rrrr&rrYrZ)r
rrZtemp_archiverdrrr�test_read_from_fileobjs


z!ZipAppTest.test_read_from_fileobjcCs||jd}|��|d��|jd}tjt|�t|�dd�|jd}tjt|�t|�dd�|�t�t|��d�dS)NrrrrUrVrar]rcrrr�test_remove_shebangrfzZipAppTest.test_remove_shebangcCs�|jd}|��|d��t��}tjt|�|dd�t��}|�d�tj||dd�|�d�t	�
|d��}|�t|�
��dh�Wd�dS1sPwYdS)NrrrUrVrr#)rrrr$r%rrrr&r'r(r:�setr*)r
rrrdr,rrr�test_content_of_copied_archives


"�z)ZipAppTest.test_content_of_copied_archiveZwin32z*Windows does not support an executable bitcCsZ|jd}|��|d��|jd}tjt|�t|�dd�|�|��jtj	@�dSr\)
rrrrrrr�stat�st_mode�S_IEXECrrrr�test_shebang_is_executable.�

z%ZipAppTest.test_shebang_is_executablecCsZ|jd}|��|d��|jd}tjt|�t|�dd�|�|��jtj	@�dS)NrrrrV)
rrrrrrZassertFalsernrorprrrr�!test_no_shebang_is_not_executable9rrz,ZipAppTest.test_no_shebang_is_not_executableN)"�__name__�
__module__�__qualname__rr r!r-r5r<r=rr>rCrGrIrLrNrTrXr[r_r`rerhrirjrkrm�unittestZskipIf�sys�platformrqrsrrrrrsF			
		
			
�
	�rc@s\eZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	d
e
jd�dd��Zdd�Z
dS)�ZipAppCmdlineTestcCrrrrrrrrIrzZipAppCmdlineTest.setUpcCs8|jd}|��|d��|jd}t�||�|Sr)rrrrrrrrr�make_archiveNs

zZipAppCmdlineTest.make_archivecCsN|jd}|��|d��t|�g}t�|�|�d�}|�|���dS)Nrrz.pyz)	rrrrrrFZwith_suffixrr)r
r�argsrrrr�test_cmdline_createWs



z%ZipAppCmdlineTest.test_cmdline_createcCs@|��}|jd}t|�dt|�g}t�|�|�|���dS�N�
target.pyz�-o)r{rrrrFrr)r
�originalrr|rrr�test_cmdline_copyas


z#ZipAppCmdlineTest.test_cmdline_copycCsj|��}|jd}t|�dt|�g}|�t��
}t�|�Wd�n1s'wY|�|jj	�dSr~�
r{rrrA�
SystemExitrrFr�	exception�code�r
r�rr|�cmrrr�test_cmdline_copy_inplaceis
�z+ZipAppCmdlineTest.test_cmdline_copy_inplacecCsn|��}|jd}t|�dt|�ddg}|�t��
}t�|�Wd�n1s)wY|�|jj	�dS)Nrr�z-mzfoo:barr�r�rrr�test_cmdline_copy_change_mainss
�z/ZipAppCmdlineTest.test_cmdline_copy_change_mainz
sys.stdout)Znew_callablecCsl|��}t|�dg}|�t��
}t�|�Wd�n1swY|�|jjd�|�|�	�d�dS)N�--inforzInterpreter: <none>
)
r{rrAr�rrFr:r�r�rY)r
Zmock_stdoutrr|r�rrr�test_info_command}s�z#ZipAppCmdlineTest.test_info_commandcCs\|jd}t|�dg}|�t��
}t�|�Wd�n1s wY|�|jj�dS)Nz	dummy.pyzr�)	rrrAr�rrFrr�r�)r
rr|r�rrr�test_info_error�s
�z!ZipAppCmdlineTest.test_info_errorN)rtrurvrr{r}r�r�r�rr$�StringIOr�r�rrrrrzEs	




rz�__main__)r$r	rnrxrrwrr'Ztest.supportrZ
unittest.mockrZTestCaserrzrtrFrrrr�<module>s$8M�