o
    NZh                     @   sp   d 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ZddlZe
jG dd de
jZdS )	z%Tests for distutils.command.build_py.    N)build_py)Distribution)DistutilsFileError)supportc                   @   s\   e Zd Zdd Zdd Zejddd Zejddd	 Z	d
d Z
dd Zdd ZdS )TestBuildPyc           	      C   s:  |   }tjddd| |   }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ksPJ |  t| dks^J tj|d}t|}tj|d}d|v swJ d
|v s}J tjrtj|rJ d S t|}dtjj d|v sJ d S )Nz# Pretend this is a package.zInfo about this package)__init__.py
README.txtpkg)packagespackage_dirsetup.pyF)force	build_libbuildr   T   __pycache__r   z	__init__..pyc)mkdtempjaracopathr   r   osjoinscript_namer   ZDummyCommandZcommand_objr
   package_datar   r   compileZensure_finalizedrunlenZget_outputslistdirsysdont_write_bytecodeexistsimplementation	cache_tag)	selfsourcesdestinationdistcmdZpkgdestfilesZpycache_dirZ	pyc_files r)   X/var/www/auris/lib/python3.10/site-packages/setuptools/_distutils/tests/test_build_py.pytest_package_data   s>   


zTestBuildPy.test_package_datac                 C   s   |   }tjdddid| t| tdgddiddgid}tj|d|_dg|_	|
  z|  W d S  tyI   | d	 Y d S w )
N testfiler   docr	   doc/*)r
   r   r   r   r   z/failed package_data test when package_dir is ''r   r   r   r   r   chdirr   r   r   Zscript_argsZparse_command_lineZrun_commandsr   Zfailr#   r$   r&   r)   r)   r*   test_empty_package_dir<   s    
z"TestBuildPy.test_empty_package_dirzsys.dont_write_bytecodec                 C   s   | j dgd\}}t| | dd t|}d|_d|_|  |  t	|j}t
|ddgks6J t	tj|jd}|dtjj d	gksNJ d S )
N
boiledeggsZ
py_modulesboiledeggs.pyimport antigravityTherer   boiledeggs.r   )create_distr   r2   
write_filer   r   r   finalize_optionsr   r   sortedr   r   r   r!   r"   )r#   project_dirr&   r'   foundr)   r)   r*   test_byte_compileQ   s   
zTestBuildPy.test_byte_compilec                 C   s   | j dgd\}}t| | dd t|}d|_d|_d|_|  |	  t
|j}t|ddgks9J t
tj|jd}d	tjj d
}t||gksUJ d S )Nr5   r6   r7   r8   F   r9   r   r:   z
.opt-1.pyc)r;   r   r2   r<   r   r   optimizer   r=   r   r   r>   r   r   r   r!   r"   )r#   r?   r&   r'   r@   expectr)   r)   r*   test_byte_compile_optimizeda   s   
z'TestBuildPy.test_byte_compile_optimizedc                 C   s   |   }tjdddi ddi| t| tdgddgid}tj|d|_dg|_	|
  z|  W d
S  tyI   | d	 Y d
S w )zR
        A directory in package_data should not be added to the filelist.
        r	   r,   )r-   Zotherdirr.   r0   )r
   r   r   r   z0failed package_data when data dir includes a dirNr1   r3   r)   r)   r*   test_dir_in_package_datas   s*   

z$TestBuildPy.test_dir_in_package_datac                 C   sb   |   d }t|}d|_d|_tj}dt_z
|g  W |t_n|t_w d|jd jv s/J d S )NrB   Tzbyte-compiling is disabledr   )	r;   r   r   rC   r   r   byte_compilerecordsmessage)r#   caplogr&   r'   Zold_dont_write_bytecoder)   r)   r*   test_dont_write_bytecode   s   z$TestBuildPy.test_dont_write_bytecodec                 C   s   |   }tjddddiii| t| dddgdd}t|}|d}|  |	 }t
|d	ks7J |d
 d }|tjddksHJ |  tdd |jD rXJ dS )aU  
        Originally distutils implementation did not account for PEP 420
        and included warns for package directories that did not contain
        ``__init__.py`` files.
        After the acceptance of PEP 420, these warnings don't make more sense
        so we want to ensure there are not displayed to not confuse the users.
        nsr	   z	module.pyr,   zns.pkgr   )namer
   r   r   rB   r   /zns/pkg/module.pyc                 s   s     | ]}d |v od|v V  qdS )zpackage init filez	not foundNr)   ).0msgr)   r)   r*   	<genexpr>   s    
zCTestBuildPy.test_namespace_package_does_not_warn.<locals>.<genexpr>N)r   r   r   r   r   r2   r   Zget_command_objr=   Zfind_all_modulesr   replacesepr   anymessages)r#   rJ   tmpattrsr&   r'   modulesmodule_pathr)   r)   r*   $test_namespace_package_does_not_warn   s$   	

z0TestBuildPy.test_namespace_package_does_not_warnN)__name__
__module____qualname__r+   r4   pytestmarkZskipifrA   rE   rF   rK   r[   r)   r)   r)   r*   r      s    ,



 r   )__doc__r   r   Zdistutils.command.build_pyr   Zdistutils.corer   Zdistutils.errorsr   Zdistutils.testsr   Zjaraco.pathr   r_   Zcombine_markersZTempdirManagerr   r)   r)   r)   r*   <module>   s    