HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_zipapp.cpython-37.pyc
B

��g�?�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZGdd�dej
�ZGdd�dej
�Zed	kr�e��dS)
z#Test harness for the zipapp module.�N)�
requires_zlib)�patchc@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
edd��Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Ze�ej d2kd3�d4d5��Z!e�ej d2kd3�d6d7��Z"d8S)9�
ZipAppTestz!Test zipapp module functionality.cCs&t��}|�|j�t�|j�|_dS)N)�tempfile�TemporaryDirectory�
addCleanup�cleanup�pathlib�Path�name�tmpdir)�selfr�r�,/usr/local/lib/python3.7/test/test_zipapp.py�setUpszZipAppTest.setUpcCsN|jd}|��|d��|jd}t�t|�t|��|�|���dS)N�sourcez__main__.pyz
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�||�|�|���dS)Nrz__main__.pyz
source.pyz)rrrrrrr)r
rrrrr� test_create_archive_with_pathlib!s

z+ZipAppTest.test_create_archive_with_pathlibc	Cs�|jd}|��|d��|d��|d��|dd��t��}t�t|�|�|�d�t	�
|d��&}|�d|���|�d	|���WdQRXdS)
Nrz__main__.py�fooZbarz__init__.pyr�rzfoo/zbar/)
rrr�io�BytesIOrrr�seek�zipfile�ZipFile�assertIn�namelist)r
rr�zrrr� test_create_archive_with_subdirs*s

z+ZipAppTest.test_create_archive_with_subdirsc	Cs�dd�}|jd}|��|d��|d��|d��|jd}tj|||d�t�|d	��6}|�d|���|�d|���|�	d|���WdQRXdS)
NcSs
|jdkS)Nz.pyc)�suffix)�pathrrr�skip_pyc_files<szBZipAppTest.test_create_archive_with_filter.<locals>.skip_pyc_filesrz__main__.pyztest.pyztest.pycz
source.pyz)�filterr)
rrrrrr!r"r#r$ZassertNotIn)r
r)rrr%rrr�test_create_archive_with_filter9s

z*ZipAppTest.test_create_archive_with_filterc	Cs�dd�}|jd}|��|d��|d��|d��|dd��|jd}tj|||d	�t�|d
��:}|�t|�	��d�|�
d|�	��|�
d|�	��WdQRXdS)NcSs|jddkS)Nr�dummy)�parts)r(rrr�skip_dummy_dirOszIZipAppTest.test_create_archive_filter_exclude_dir.<locals>.skip_dummy_dirrz__main__.pyztest.pyr,ztest2.pyz
source.pyz)r*r�)rrrrrr!r"�assertEqual�lenr$r#)r
r.rrr%rrr�&test_create_archive_filter_exclude_dirKs

z1ZipAppTest.test_create_archive_filter_exclude_dircCsH|jd}|��|d��t�t|��|jd}|�|���dS)Nrz__main__.pyz
source.pyz)rrrrrrrr)r
rZexpected_targetrrr�"test_create_archive_default_target_s

z-ZipAppTest.test_create_archive_default_targetc	Cs�|jd}|��|d��|d��|jd}tj||dd�t�|d��*}x"dD]}|�|�|�j	tj
�qXWWdQRXdS)	Nrz__main__.pyztest.pyz
source.pyzT)Z
compressedr)z__main__.pyztest.py)rrrrrr!r"r0ZgetinfoZ
compress_typeZZIP_DEFLATED)r
rrr%rrrr�$test_create_archive_with_compressionhs


z/ZipAppTest.test_create_archive_with_compressionc	CsX|jd}|��|d��|jd}|�tj��t�t|�t|��WdQRXdS)Nrzfoo.pyz
source.pyz)rrr�assertRaisesr�ZipAppErrorrr)r
rrrrr�test_no_mainws

zZipAppTest.test_no_mainc	Cs\|jd}|��|d��|jd}|�tj��tjt|�t|�dd�WdQRXdS)Nrz__main__.pyz
source.pyzz
pkg.mod:fn)�main)rrrr5rr6rr)r
rrrrr�test_main_and_main_py�s

z ZipAppTest.test_main_and_main_pyc	Cs�|jd}|��|d��|jd}tjt|�t|�dd�t�t|�d��(}|�d|�	��|�d|�
d��WdQRXdS)	Nrzfoo.pyz
source.pyzz
pkg.mod:fn)r8rz__main__.pyspkg.mod.fn())rrrrrrr!r"r#r$�read)r
rrr%rrr�test_main_written�s

zZipAppTest.test_main_writtenc	Cs�|jd}|��|d��|d��|jd}tjt|�t|�dd�t�t|�d��}|�d|�	��
d	��WdQRXdS)
Nrzfoo.pyzbar.pyz
source.pyzz
pkg.mod:fn)r8r�z__main__.py)rrrrrrr!r"r0r$�count)r
rrr%rrr�test_main_only_written_once�s

z&ZipAppTest.test_main_only_written_oncecCs�|jd}|��|jd}ddddddd	d
ddg
}xT|D]L}|j|d
��6|�tj��tjt|�t|�|d
�WdQRXWdQRXq:WdS)Nrz
source.pyz�rzfoo:z:barz12:barza.b.c.:dz.a:bza:b.za:.bza:silly name)r8)rrZsubTestr5rr6rr)r
rrZproblemsr8rrr�test_main_validation�s


zZipAppTest.test_main_validationc	Csh|jd}|��|d��|jd}t�t|�t|��|�d��}|�|�d�d�WdQRXdS)Nrz__main__.pyz
source.pyz�rbr/s#!)	rrrrrr�openZassertNotEqualr:)r
rr�frrr�test_default_no_shebang�s

z"ZipAppTest.test_default_no_shebangc	Cs||jd}|��|d��|jd}tjt|�t|�dd�|�d��(}|�|�d�d�|�d	|�	��WdQRXdS)
Nrz__main__.pyz
source.pyz�python)�interpreterrAr/s#!spython
)
rrrrrrrBr0r:�readline)r
rrrCrrr�test_custom_interpreter�s

z"ZipAppTest.test_custom_interpretercCsR|jd}|��|d��t��}tjt|�|dd�|�|�	��
d��dS)Nrz__main__.pyrE)rFs	#!python
)rrrrrrrrr�getvalue�
startswith)r
rrrrr�test_pack_to_fileobj�s
zZipAppTest.test_pack_to_fileobjcCsZ|jd}|��|d��|jd}tjt|�t|�dd�|�t�t|��d�dS)Nrz__main__.pyz
source.pyzrE)rF)rrrrrrr0�get_interpreter)r
rrrrr�test_read_shebang�s

zZipAppTest.test_read_shebangcCsV|jd}|��|d��|jd}t�t|�t|��|�t�t|��d�dS)Nrz__main__.pyz
source.pyz)rrrrrrr0rL)r
rrrrr�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)Nrz__main__.pyz
source.pyzrE)rFzchanged.pyzz	python2.7)rrrrrrr0rL)r
rr�
new_targetrrr�test_modify_shebang�s


zZipAppTest.test_modify_shebangcCst|jd}|��|d��|jd}tjt|�t|�dd�t��}tjt|�|dd�|�|�	��
d��dS)Nrz__main__.pyz
source.pyzrE)rFz	python2.7s#!python2.7
)rrrrrrrrrrIrJ)r
rrrOrrr�test_write_shebang_to_fileobj�s

z(ZipAppTest.test_write_shebang_to_fileobjcCsh|jd}|��|d��|jd}|jd}tj||dd�tj||dd�|�t�|�d�dS)Nrz__main__.pyztarget1.pyzztarget2.pyzrE)rFz	python2.7)rrrrrr0rL)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)	Nrz__main__.pyz
source.pyzrE)rFrz	python2.7s#!python2.7
)rrrrrrrrr rrIrJ)r
rrZtemp_archiverOrrr�test_read_from_fileobjs


z!ZipAppTest.test_read_from_fileobjcCs||jd}|��|d��|jd}tjt|�t|�dd�|jd}tjt|�t|�dd�|�t�t|��d�dS)Nrz__main__.pyz
source.pyzrE)rFzchanged.pyz)rrrrrrr0rL)r
rrrOrrr�test_remove_shebangs


zZipAppTest.test_remove_shebangc	Cs�|jd}|��|d��t��}tjt|�|dd�t��}|�d�tj||dd�|�d�t	�
|d��}|�t|�
��dh�WdQRXdS)Nrz__main__.pyrE)rFrr)rrrrrrrrr r!r"r0�setr$)r
rrrOr%rrr�test_content_of_copied_archives


z)ZipAppTest.test_content_of_copied_archive�win32z*Windows does not support an executable bitcCsZ|jd}|��|d��|jd}tjt|�t|�dd�|�|��jtj	@�dS)Nrz__main__.pyz
source.pyzrE)rF)
rrrrrrr�stat�st_mode�S_IEXEC)r
rrrrr�test_shebang_is_executable.s

z%ZipAppTest.test_shebang_is_executablecCsZ|jd}|��|d��|jd}tjt|�t|�dd�|�|��jtj	@�dS)Nrz__main__.pyz
source.pyz)rF)
rrrrrrZassertFalserXrYrZ)r
rrrrr�!test_no_shebang_is_not_executable9s

z,ZipAppTest.test_no_shebang_is_not_executableN)#�__name__�
__module__�__qualname__�__doc__rrrr&r+r2r3rr4r7r9r;r>r@rDrHrKrMrNrPrQrRrSrTrV�unittestZskipIf�sys�platformr[r\rrrrrs:					
			

rc@s^eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
dejd�dd��Z
dd�ZdS)�ZipAppCmdlineTestz$Test zipapp module command line API.cCs&t��}|�|j�t�|j�|_dS)N)rrrrr	r
rr)r
rrrrrIszZipAppCmdlineTest.setUpcCs8|jd}|��|d��|jd}t�||�|S)Nrz__main__.pyz
source.pyz)rrrrr)r
rrrrr�make_archiveNs

zZipAppCmdlineTest.make_archivecCsN|jd}|��|d��t|�g}t�|�|�d�}|�|���dS)Nrz__main__.pyz.pyz)	rrrrrr8Zwith_suffixrr)r
r�argsrrrr�test_cmdline_createWs



z%ZipAppCmdlineTest.test_cmdline_createcCs@|��}|jd}t|�dt|�g}t�|�|�|���dS)Nz
target.pyzz-o)rerrrr8rr)r
�originalrrfrrr�test_cmdline_copyas


z#ZipAppCmdlineTest.test_cmdline_copyc	CsV|��}|jd}t|�dt|�g}|�t��}t�|�WdQRX|�|jj	�dS)Nz
target.pyzz-o)
rerrr5�
SystemExitrr8r�	exception�code)r
rhrrf�cmrrr�test_cmdline_copy_inplaceis
z+ZipAppCmdlineTest.test_cmdline_copy_inplacec	CsZ|��}|jd}t|�dt|�ddg}|�t��}t�|�WdQRX|�|jj	�dS)Nz
target.pyzz-oz-mzfoo:bar)
rerrr5rjrr8rrkrl)r
rhrrfrmrrr�test_cmdline_copy_change_mainss
z/ZipAppCmdlineTest.test_cmdline_copy_change_mainz
sys.stdout)Znew_callablec	CsX|��}t|�dg}|�t��}t�|�WdQRX|�|jjd�|�|�	�d�dS)Nz--inforzInterpreter: <none>
)
rerr5rjrr8r0rkrlrI)r
Zmock_stdoutrrfrmrrr�test_info_command}sz#ZipAppCmdlineTest.test_info_commandc	CsH|jd}t|�dg}|�t��}t�|�WdQRX|�|jj�dS)Nz	dummy.pyzz--info)	rrr5rjrr8rrkrl)r
rrfrmrrr�test_info_error�s

z!ZipAppCmdlineTest.test_info_errorN)r]r^r_r`rrergrirnrorr�StringIOrprqrrrrrdEs	


rd�__main__)r`rr	rXrbrrarr!Ztest.supportrZ
unittest.mockrZTestCaserrdr]r8rrrr�<module>s 8M