B
    18™\¿  ã               @   s   d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ G dd	„ d	ejejejƒZd
d„ ZedkrŒeeƒ ƒ dS )z%Tests for distutils.command.build_py.é    N)Úbuild_py)ÚDistribution)ÚDistutilsFileError)Úsupport)Úrun_unittestc               @   sX   e Zd Zdd„ Zdd„ Ze ejd¡dd„ ƒZ	e ejd¡dd	„ ƒZ
d
d„ Zdd„ ZdS )ÚBuildPyTestCasec       
      C   s€  |   ¡ }ttj |d¡dƒ}z| d¡ W d | ¡  X ttj |d¡dƒ}z| d¡ W d | ¡  X |   ¡ }tdgd|idœƒ}tj |d¡|_t	j
d	|d
|jd< dg|_ddgi|_d|i|_t|ƒ}d|_| ¡  |  |j|j¡ | ¡  |  t| ¡ ƒd¡ tj |d¡}t |¡}tj |d¡}|  d|¡ |  d|¡ tjr^|  tj |¡¡ nt |¡}	|  dtjj |	¡ d S )Nz__init__.pyÚwz# Pretend this is a package.z
README.txtzInfo about this packageÚpkg)ÚpackagesÚpackage_dirzsetup.pyr   )ÚforceÚ	build_libÚbuildé   é   Ú__pycache__z__init__.%s.pyc)ÚmkdtempÚopenÚosÚpathÚjoinÚwriteÚcloser   Úscript_namer   ÚDummyCommandÚcommand_objr
   Úpackage_datar   r   ÚcompileÚensure_finalizedÚassertEqualÚrunÚlenÚget_outputsÚlistdirÚassertInÚsysÚdont_write_bytecodeÚassertFalseÚexistsÚimplementationÚ	cache_tag)
ÚselfÚsourcesÚfZdestinationÚdistÚcmdZpkgdestÚfilesZpycache_dirZ	pyc_files© r1   úa/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/distutils/tests/test_build_py.pyÚtest_package_data   sF    




z!BuildPyTestCase.test_package_datac             C   sÆ   |   ¡ }ttj |d¡dƒ ¡  tj |d¡}t |¡ ttj |d¡dƒ ¡  t |¡ tdgddiddgidœƒ}tj |d	¡|_	d
g|_
| ¡  y| ¡  W n tk
rÀ   |  d¡ Y nX d S )Nz__init__.pyr   ÚdocÚtestfiler	   Ú zdoc/*)r
   r   r   zsetup.pyr   z/failed package_data test when package_dir is '')r   r   r   r   r   r   ÚmkdirÚchdirr   r   Úscript_argsÚparse_command_lineÚrun_commandsr   Úfail)r+   r,   Útestdirr.   r1   r1   r2   Útest_empty_package_dirD   s     

z&BuildPyTestCase.test_empty_package_dirzbyte-compile disabledc             C   sœ   | j dgd\}}t |¡ |  dd¡ t|ƒ}d|_d|_| ¡  | ¡  t 	|j¡}|  
t|ƒddg¡ t 	tj |jd¡¡}|  
|dtjj g¡ d S )	NÚ
boiledeggs)Ú
py_moduleszboiledeggs.pyzimport antigravityr   Úherer   zboiledeggs.%s.pyc)Úcreate_distr   r8   Ú
write_filer   r   r   Úfinalize_optionsr    r#   r   Úsortedr   r   r%   r)   r*   )r+   Úproject_dirr.   r/   Úfoundr1   r1   r2   Útest_byte_compile[   s    
z!BuildPyTestCase.test_byte_compilec             C   s¬   | j dgd\}}t |¡ |  dd¡ t|ƒ}d|_d|_d|_| ¡  | 	¡  t 
|j¡}|  t|ƒddg¡ t 
tj |jd¡¡}d	 tjj¡}|  t|ƒ|g¡ d S )
Nr?   )r@   zboiledeggs.pyzimport antigravityr   r   rA   r   zboiledeggs.{}.opt-1.pyc)rB   r   r8   rC   r   r   Úoptimizer   rD   r    r#   r   rE   r   r   Úformatr%   r)   r*   )r+   rF   r.   r/   rG   Zexpectr1   r1   r2   Útest_byte_compile_optimizedl   s    
z+BuildPyTestCase.test_byte_compile_optimizedc             C   sì   |   ¡ }tj |d¡}t |¡ ttj |d¡dƒ ¡  tj |d¡}t |¡ ttj |d¡dƒ ¡  t tj |d¡¡ t |¡ tdgddgidœƒ}tj |d	¡|_	d
g|_
| ¡  y| ¡  W n tk
ræ   |  d¡ Y nX dS )zR
        A directory in package_data should not be added to the filelist.
        r	   z__init__.pyr   r4   r5   Zotherdirzdoc/*)r
   r   zsetup.pyr   z0failed package_data when data dir includes a dirN)r   r   r   r   r7   r   r   r8   r   r   r9   r:   r;   r   r<   )r+   r,   Úpkg_dirZdocdirr.   r1   r1   r2   Útest_dir_in_package_data~   s$    


z(BuildPyTestCase.test_dir_in_package_datac             C   sl   |   ¡ d }t|ƒ}d|_d|_tj}dt_z| g ¡ W d |t_X |  d| jd d | jd d  ¡ d S )Nr   Tzbyte-compiling is disabledr   é   )	rB   r   r   rI   r%   r&   Úbyte_compiler$   Úlogs)r+   r.   r/   Úold_dont_write_bytecoder1   r1   r2   Útest_dont_write_bytecode   s    z(BuildPyTestCase.test_dont_write_bytecodeN)Ú__name__Ú
__module__Ú__qualname__r3   r>   ÚunittestÚskipIfr%   r&   rH   rK   rM   rR   r1   r1   r1   r2   r      s   1r   c               C   s
   t  t¡S )N)rV   Ú	makeSuiter   r1   r1   r1   r2   Ú
test_suite¯   s    rY   Ú__main__)Ú__doc__r   r%   rV   Zdistutils.command.build_pyr   Údistutils.corer   Zdistutils.errorsr   Údistutils.testsr   Ztest.supportr   ÚTempdirManagerÚLoggingSilencerÚTestCaser   rY   rS   r1   r1   r1   r2   Ú<module>   s    