Your IP : 216.73.216.60


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



��Yf�6�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
Gdd�dej�ZGdd�dej�Z
edkr�ej�dS)	z#Test harness for the zipapp module.�N)�patchc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zejejd,kd-�d.d/��Zejejd,kd-�d0d1��Zd2S)3�
ZipAppTestz!Test zipapp module functionality.cCs5tj�}|j|j�tj|j�|_dS)N)�tempfile�TemporaryDirectory�
addCleanup�cleanup�pathlib�Path�name�tmpdir)�selfr�r
�5/opt/alt/python35/lib64/python3.5/test/test_zipapp.py�setUpszZipAppTest.setUpcCse|jd}|j�|dj�|jd}tjt|�t|��|j|j��dS)N�sourcez__main__.pyz
source.pyz)r�mkdir�touch�zipapp�create_archive�str�
assertTrue�is_file)rr�targetr
r
r�test_create_archives


zZipAppTest.test_create_archivecCsY|jd}|j�|dj�|jd}tj||�|j|j��dS)Nrz__main__.pyz
source.pyz)rrrrrrr)rrrr
r
r� test_create_archive_with_pathlib s


z+ZipAppTest.test_create_archive_with_pathlibc
Cs�|jd}|j�|dj�|dj�|dj�|ddj�tj�}tjt|�|�|jd�t	j
|d��3}|jd|j��|jd	|j��WdQRXdS)
Nrz__main__.py�fooZbarz__init__.pyr�rzfoo/zbar/)
rrr�io�BytesIOrrr�seek�zipfile�ZipFile�assertIn�namelist)rrr�zr
r
r� test_create_archive_with_subdirs)s


z+ZipAppTest.test_create_archive_with_subdirscCs\|jd}|j�|dj�tjt|��|jd}|j|j��dS)Nrz__main__.pyz
source.pyz)rrrrrrrr)rrZexpected_targetr
r
r�"test_create_archive_default_target8s


z-ZipAppTest.test_create_archive_default_targetcCsl|jd}|j�|dj�|jd}|jtj��!tjt|�t|��WdQRXdS)Nrzfoo.pyz
source.pyz)rrr�assertRaisesr�ZipAppErrorrr)rrrr
r
r�test_no_mainAs


zZipAppTest.test_no_maincCsr|jd}|j�|dj�|jd}|jtj��'tjt|�t|�dd�WdQRXdS)Nrz__main__.pyz
source.pyz�mainz
pkg.mod:fn)rrrr'rr(rr)rrrr
r
r�test_main_and_main_pyJs


z ZipAppTest.test_main_and_main_pycCs�|jd}|j�|dj�|jd}tjt|�t|�dd�tjt|�d��6}|jd|j	��|jd|j
d��WdQRXdS)	Nrzfoo.pyz
source.pyzr*z
pkg.mod:fnrz__main__.pyspkg.mod.fn())rrrrrrr r!r"r#�read)rrrr$r
r
r�test_main_writtenSs


"zZipAppTest.test_main_writtencCs�|jd}|j�|dj�|dj�|jd}tjt|�t|�dd�tjt|�d��&}|jd|j	�j
d	��WdQRXdS)
Nrzfoo.pyzbar.pyz
source.pyzr*z
pkg.mod:fnr�z__main__.py)rrrrrrr r!�assertEqualr#�count)rrrr$r
r
r�test_main_only_written_once^s


"z&ZipAppTest.test_main_only_written_oncecCs�|jd}|j�|jd}ddddddd	d
ddg
}xd|D]\}|jd
|��A|jtj��'tjt|�t|�d
|�WdQRXWdQRXqOWdS)Nrz
source.pyz�rzfoo:z:barz12:barza.b.c.:dz.a:bza:b.za:.bza:silly namer*)rrZsubTestr'rr(rr)rrrZproblemsr*r
r
r�test_main_validationos



zZipAppTest.test_main_validationc
Cs�|jd}|j�|dj�|jd}tjt|�t|��|jd�� }|j|jd�d�WdQRXdS)Nrz__main__.pyz
source.pyz�rb�s#!)	rrrrrr�openZassertNotEqualr,)rrr�fr
r
r�test_default_no_shebang}s


z"ZipAppTest.test_default_no_shebangc
Cs�|jd}|j�|dj�|jd}tjt|�t|�dd�|jd��6}|j|jd�d�|jd	|j	��WdQRXdS)
Nrz__main__.pyz
source.pyz�interpreter�pythonr4r5s#!spython
)
rrrrrrr6r/r,�readline)rrrr7r
r
r�test_custom_interpreter�s


"z"ZipAppTest.test_custom_interpretercCsm|jd}|j�|dj�tj�}tjt|�|dd�|j|j	�j
d��dS)Nrz__main__.pyr9r:s	#!python
)rrrrrrrrr�getvalue�
startswith)rrrr
r
r�test_pack_to_fileobj�s

zZipAppTest.test_pack_to_fileobjcCsw|jd}|j�|dj�|jd}tjt|�t|�dd�|jtjt|��d�dS)Nrz__main__.pyz
source.pyzr9r:)rrrrrrr/�get_interpreter)rrrr
r
r�test_read_shebang�s


"zZipAppTest.test_read_shebangcCsq|jd}|j�|dj�|jd}tjt|�t|��|jtjt|��d�dS)Nrz__main__.pyz
source.pyz)rrrrrrr/r@)rrrr
r
r�test_read_missing_shebang�s


z$ZipAppTest.test_read_missing_shebangcCs�|jd}|j�|dj�|jd}tjt|�t|�dd�|jd}tjt|�t|�dd�|jtjt|��d�dS)Nrz__main__.pyz
source.pyzr9r:zchanged.pyzz	python2.7)rrrrrrr/r@)rrr�
new_targetr
r
r�test_modify_shebang�s


"
"zZipAppTest.test_modify_shebangcCs�|jd}|j�|dj�|jd}tjt|�t|�dd�tj�}tjt|�|dd�|j|j	�j
d��dS)Nrz__main__.pyz
source.pyzr9r:z	python2.7s#!python2.7
)rrrrrrrrrr=r>)rrrrCr
r
r�test_write_shebang_to_fileobj�s


"z(ZipAppTest.test_write_shebang_to_fileobjcCs�|jd}|j�|dj�|jd}|jd}tj||dd�tj||dd�|jtj|�d�dS)Nrz__main__.pyztarget1.pyzztarget2.pyzr9r:z	python2.7)rrrrrr/r@)rrZtarget1Ztarget2r
r
r�test_read_from_pathobj�s



z!ZipAppTest.test_read_from_pathobjcCs�|jd}|j�|dj�|jd}tj�}tjt|�|dd�tj�}|jd�tj||dd�|j	|j
�jd��dS)	Nrz__main__.pyz
source.pyzr9r:rz	python2.7s#!python2.7
)rrrrrrrrrrr=r>)rrrZtemp_archiverCr
r
r�test_read_from_fileobj�s



z!ZipAppTest.test_read_from_fileobjcCs�|jd}|j�|dj�|jd}tjt|�t|�dd�|jd}tjt|�t|�dd�|jtjt|��d�dS)Nrz__main__.pyz
source.pyzr9r:zchanged.pyz)rrrrrrr/r@)rrrrCr
r
r�test_remove_shebang�s


"
"zZipAppTest.test_remove_shebangc
Cs�|jd}|j�|dj�tj�}tjt|�|dd�tj�}|jd�tj||dd�|jd�t	j
|d��&}|jt|j
��dh�WdQRXdS)Nrz__main__.pyr9r:rr)rrrrrrrrrr r!r/�setr#)rrrrCr$r
r
r�test_content_of_copied_archive�s



z)ZipAppTest.test_content_of_copied_archive�win32z*Windows does not support an executable bitcCsu|jd}|j�|dj�|jd}tjt|�t|�dd�|j|j�jtj	@�dS)Nrz__main__.pyz
source.pyzr9r:)
rrrrrrr�stat�st_mode�S_IEXEC)rrrr
r
r�test_shebang_is_executable�s


"z%ZipAppTest.test_shebang_is_executablecCsu|jd}|j�|dj�|jd}tjt|�t|�dd�|j|j�jtj	@�dS)Nrz__main__.pyz
source.pyzr9)
rrrrrrZassertFalserLrMrN)rrrr
r
r�!test_no_shebang_is_not_executables


"z,ZipAppTest.test_no_shebang_is_not_executableN)�__name__�
__module__�__qualname__�__doc__rrrr%r&r)r+r-r1r3r8r<r?rArBrDrErFrGrHrJ�unittestZskipIf�sys�platformrOrPr
r
r
rrs4					
			

rc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
ddej�dd��Z
dd�ZdS)�ZipAppCmdlineTestz$Test zipapp module command line API.cCs5tj�}|j|j�tj|j�|_dS)N)rrrrrr	r
r)rrr
r
rrszZipAppCmdlineTest.setUpcCsF|jd}|j�|dj�|jd}tj||�|S)Nrz__main__.pyz
source.pyz)rrrrr)rrrr
r
r�make_archives


zZipAppCmdlineTest.make_archivecCsg|jd}|j�|dj�t|�g}tj|�|jd�}|j|j��dS)Nrz__main__.pyz.pyz)	rrrrrr*Zwith_suffixrr)rr�argsrr
r
r�test_cmdline_create!s


z%ZipAppCmdlineTest.test_cmdline_createcCsX|j�}|jd}t|�dt|�g}tj|�|j|j��dS)Nz
target.pyzz-o)rYrrrr*rr)r�originalrrZr
r
r�test_cmdline_copy+s


z#ZipAppCmdlineTest.test_cmdline_copyc	Csq|j�}|jd}t|�dt|�g}|jt��}tj|�WdQRX|j|jj	�dS)Nz
target.pyzz-o)
rYrrr'�
SystemExitrr*r�	exception�code)rr\rrZ�cmr
r
r�test_cmdline_copy_inplace3s
z+ZipAppCmdlineTest.test_cmdline_copy_inplacec	Csw|j�}|jd}t|�dt|�ddg}|jt��}tj|�WdQRX|j|jj	�dS)Nz
target.pyzz-oz-mzfoo:bar)
rYrrr'r^rr*rr_r`)rr\rrZrar
r
r�test_cmdline_copy_change_main=s
!z/ZipAppCmdlineTest.test_cmdline_copy_change_mainz
sys.stdoutZnew_callablec
Cst|j�}t|�dg}|jt��}tj|�WdQRX|j|jjd�|j|j	�d�dS)Nz--inforzInterpreter: <none>
)
rYrr'r^rr*r/r_r`r=)rZmock_stdoutrrZrar
r
r�test_info_commandGsz#ZipAppCmdlineTest.test_info_commandc	Cs\|jd}t|�dg}|jt��}tj|�WdQRX|j|jj�dS)Nz	dummy.pyzz--info)	rrr'r^rr*rr_r`)rrrZrar
r
r�test_info_errorRs

z!ZipAppCmdlineTest.test_info_errorN)rQrRrSrTrrYr[r]rbrcrr�StringIOrdrer
r
r
rrXs	


!rX�__main__)rTrrrLrVrrUrr Z
unittest.mockrZTestCaserrXrQr*r
r
r
r�<module>s�M