Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_zipapp.cpython-39.opt-2.pyc

a

XC?h�?�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZGdd�dej�Z
Gdd�dej�Zedkr�e��dS)	�N)�
requires_zlib)�patchc@seZdZdd�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�
ZipAppTestcCs&t��}|�|j�t�|j�|_dS�N��tempfileZTemporaryDirectoryZ
addCleanupZcleanup�pathlib�Path�name�tmpdir��selfr�r�5/opt/alt/python39/lib64/python3.9/test/test_zipapp.py�setUps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��0}|�d|���|�d	|���Wd�n1s�0YdS)
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�n1s�0YdS)
NcSs
|jdkS)Nz.pyc)�suffix��pathrrr�skip_pyc_files<szBZipAppTest.test_create_archive_with_filter.<locals>.skip_pyc_filesrr�test.pyztest.pycr��filterr")
rrrrrr&r'r(r)ZassertNotIn)r
r0rrr+rrr�test_create_archive_with_filter9s

z*ZipAppTest.test_create_archive_with_filtercCs�dd�}|jd}|��|d��|d��|d��|dd��|jd}tj|||d	�t�|d
��D}|�t|�	��d�|�
d|�	��|�
d|�	��Wd�n1s�0YdS)NcSs|jddkS)Nr�dummy)�partsr.rrr�skip_dummy_dirOszIZipAppTest.test_create_archive_filter_exclude_dir.<locals>.skip_dummy_dirrrr1r5ztest2.pyrr2r"�)rrrrrr&r'�assertEqual�lenr)r()r
r7rrr+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��0}dD]}|�|�|�j	tj
�qVWd�n1s�0YdS)	Nrrr1rT)Z
compressedr")rr1)rrrrrr&r'r9ZgetinfoZ
compress_typeZZIP_DEFLATED)r
rrr+r
rrr�$test_create_archive_with_compressionhs

�z/ZipAppTest.test_create_archive_with_compressioncCsl|jd}|��|d��|jd}|�tj��$t�t|�t|��Wd�n1s^0YdS)Nr�foo.pyr�rrr�assertRaisesr�ZipAppErrorrrrrrr�test_no_mainws

zZipAppTest.test_no_maincCsp|jd}|��|d��|jd}|�tj��(tjt|�t|�dd�Wd�n1sb0YdS)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��2}|�d|�	��|�d|�
d��Wd�n1s�0YdS)	Nrr>rrCrDr"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�n1s�0YdS)
Nrr>zbar.pyrrCrDr"�r)rrrrrrr&r'r9r)�countr*rrr�test_main_only_written_once�s

z&ZipAppTest.test_main_only_written_oncec
Cs�|jd}|��|jd}gd�}|D]t}|j|d��T|�tj��(tjt|�t|�|d�Wd�n1st0YWd�q(1s�0Yq(dS)Nrr)
�r!zfoo:z:barz12:barza.b.c.:dz.a:bza:b.za:.bza:silly namerD)rrZsubTestr@rrArr)r
rrZproblemsrErrr�test_main_validation�s

zZipAppTest.test_main_validationcCs||jd}|��|d��|jd}t�t|�t|��|�d��"}|�|�d�d�Wd�n1sn0YdS)Nrrr�rbr8�#!)	rrrrrr�openZassertNotEqualrG�r
rr�frrr�test_default_no_shebang�s

z"ZipAppTest.test_default_no_shebangcCs�|jd}|��|d��|jd}tjt|�t|�dd�|�d��2}|�|�d�d�|�d	|�	��Wd�n1s�0YdS)
Nrrr�python�ZinterpreterrNr8rOspython
)
rrrrrrrPr9rG�readlinerQrrr�test_custom_interpreter�s

z"ZipAppTest.test_custom_interpretercCsR|jd}|��|d��t��}tjt|�|dd�|�|�	��
d��dS)NrrrTrUs	#!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�NrrrrTrU�rrrrrrr9�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)NrrrrTrU�changed.pyz�	python2.7r\�r
rr�
new_targetrrr�test_modify_shebang�s


zZipAppTest.test_modify_shebangcCst|jd}|��|d��|jd}tjt|�t|�dd�t��}tjt|�|dd�|�|�	��
d��dS)NrrrrTrUra�#!python2.7
)rrrrrrr#r$rrXrYrbrrr�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.pyzrTrUra)rrrrrr9r])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)	NrrrrTrUrrare)rrrr#r$rrrr%rrXrY)r
rrZtemp_archivercrrr�test_read_from_fileobjs


z!ZipAppTest.test_read_from_fileobjcCs||jd}|��|d��|jd}tjt|�t|�dd�|jd}tjt|�t|�dd�|�t�t|��d�dS)NrrrrTrUr`r\rbrrr�test_remove_shebangs


zZipAppTest.test_remove_shebangcCs�|jd}|��|d��t��}tjt|�|dd�t��}|�d�tj||dd�|�d�t	�
|d��&}|�t|�
��dh�Wd�n1s�0YdS)NrrrTrUrr")rrrr#r$rrrr%r&r'r9�setr))r
rrrcr+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.s

z%ZipAppTest.test_shebang_is_executablecCsZ|jd}|��|d��|jd}tjt|�t|�dd�|�|��jtj	@�dS)NrrrrU)
rrrrrrZassertFalserlrmrnrrrr�!test_no_shebang_is_not_executable9s

z,ZipAppTest.test_no_shebang_is_not_executableN)"�__name__�
__module__�__qualname__rrr r,r4r;r<rr=rBrFrHrKrMrSrWrZr^r_rdrfrgrhrirk�unittestZskipIf�sys�platformrorprrrrrsB			
		
			
�
	�rc@sZeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	d
e
jd�dd��Zdd�Z
dS)�ZipAppCmdlineTestcCs&t��}|�|j�t�|j�|_dSrrrrrrrIszZipAppCmdlineTest.setUpcCs8|jd}|��|d��|jd}t�||�|Sr)rrrrrrrrr�make_archiveNs

zZipAppCmdlineTest.make_archivecCsN|jd}|��|d��t|�g}t�|�|�d�}|�|���dS)Nrrz.pyz)	rrrrrrEZwith_suffixrr)r
r�argsrrrr�test_cmdline_createWs



z%ZipAppCmdlineTest.test_cmdline_createcCs@|��}|jd}t|�dt|�g}t�|�|�|���dS�N�
target.pyz�-o)rxrrrrErr)r
�originalrryrrr�test_cmdline_copyas


z#ZipAppCmdlineTest.test_cmdline_copycCsj|��}|jd}t|�dt|�g}|�t��}t�|�Wd�n1sN0Y|�|jj	�dSr{�
rxrrr@�
SystemExitrrEr�	exception�code�r
r~rry�cmrrr�test_cmdline_copy_inplaceis
(z+ZipAppCmdlineTest.test_cmdline_copy_inplacecCsn|��}|jd}t|�dt|�ddg}|�t��}t�|�Wd�n1sR0Y|�|jj	�dS)Nr|r}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�n1s>0Y|�|jjd�|�|�	�d�dS)N�--inforzInterpreter: <none>
)
rxrr@r�rrEr9r�r�rX)r
Zmock_stdoutrryr�rrr�test_info_command}s(z#ZipAppCmdlineTest.test_info_commandcCs\|jd}t|�dg}|�t��}t�|�Wd�n1s@0Y|�|jj�dS)Nz	dummy.pyzr�)	rrr@r�rrErr�r�)r
rryr�rrr�test_info_error�s

(z!ZipAppCmdlineTest.test_info_errorN)rqrrrsrrxrzrr�r�rr#�StringIOr�r�rrrrrwEs	




rw�__main__)r#rrlrurrtrr&Ztest.supportrZ
unittest.mockrZTestCaserrwrqrErrrr�<module>s8M