U
    aÊ¹jª!  ã                   @   sØ   d Z ddlZddl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m	Z	 ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlZdd„ Zejej d¡G dd„ dejƒƒƒZ dS )z$Tests for distutils.command.install.é    N)Ú	sysconfig)Úinstall)Ú	build_ext)ÚINSTALL_SCHEMESr   )ÚDistribution)ÚDistutilsOptionError)Ú	Extension)Úmissing_compiler_executableÚsupport)Úis_mingwc                 C   s   | t  d¡ S )NÚ
EXT_SUFFIX)r   Úget_config_var)Úmodname© r   úg/var/www/html/bwave/python/venv/lib/python3.8/site-packages/setuptools/_distutils/tests/test_install.pyÚ_make_ext_name   s    r   Zsave_envc                   @   sT   e Zd Zejjddd�dd„ ƒZdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚTestInstallz=platform.system() == "Windows" and sys.version_info > (3, 11)zpypa/distutils#148)Úreasonc           
      C   s*  |   ¡ }tj |d¡}tddiƒ}tj |d¡|_tj|tj |d¡d�|jd< t	|ƒ}||_
| ¡  |j|kstt‚|j|ks‚t‚dd	„ }tjj d
d¡}tj |d|¡}||j|ƒ ttddƒ}tj |||¡}	||j|	ƒ ||j|ƒ ||jtj |d|d¡ƒ ||jtj |d¡ƒ ||j|ƒ d S )NZinstallationÚnameZfoopkgzsetup.pyÚlib)Ú
build_baseÚ	build_libÚbuildc                 S   s(   t j | ¡} t j |¡}| |ks$t‚d S ©N)ÚosÚpathÚnormpathÚAssertionError)ÚgotÚexpectedr   r   r   Ú
check_path8   s    z=TestInstall.test_home_installation_scheme.<locals>.check_pathÚcpythonÚpythonÚ
platlibdirÚincludeÚbin)Úmkdtempr   r   Újoinr   Úscript_namer
   ZDummyCommandÚcommand_objr   ÚhomeÚensure_finalizedÚinstall_baser   Úinstall_platbaseÚsysÚimplementationr   ÚreplaceÚinstall_libÚgetattrÚinstall_platlibÚinstall_purelibÚinstall_headersÚinstall_scriptsÚinstall_data)
ÚselfZbuilddirZdestinationÚdistÚcmdr    Z	impl_nameZlibdirZ_platlibdirr#   r   r   r   Útest_home_installation_scheme   s6    þþz)TestInstall.test_home_installation_schemec                    sÎ  ˆ   ¡ ˆ _tj}tj}| tdtj ˆ jd¡¡ | tdtj ˆ jd¡¡ | t	dtj¡ | t	dtj¡ ‡ fdd„}| tjd|¡ dD ]}|t
ksŠt‚qŠtd	d
iƒ}t|ƒ}dd„ |jD ƒ}d|ksÌt‚d|_tj tj¡rät‚tj tj¡röt‚| ¡  tj tj¡�st‚tj tj¡�s&t‚d|jk�s6t‚d|jk�sFt‚tj |jtj¡}	tjdk�r’tƒ �s’tj tj |¡|¡}
tj |
d¡}nt dd¡}tj |d
¡}tj |	¡tj |¡k�sÊt‚d S )NÚ	USER_BASEÚBÚ	USER_SITEÚSc                    s(   |   d¡r$tj ˆ j| dd …  ¡S | S )Nú~é   )Ú
startswithr   r   r   Útmpdir)r   ©r8   r   r   Ú_expanduserV   s    
z/TestInstall.test_user_site.<locals>._expanduserÚ
expanduser)Únt_userÚ
posix_userr   Úxxc                 S   s   g | ]\}}}|‘qS r   r   )Ú.0r   ÚshortÚlabelr   r   r   Ú
<listcomp>d   s     z.TestInstall.test_user_site.<locals>.<listcomp>ÚuserTÚuserbaseÚusersiteÚntÚIncluder   Ú )r&   rC   Úsiter>   r<   Úsetattrr   r   r'   Úinstall_moduler   r   r   r   Úuser_optionsrN   Úexistsr+   Úconfig_varsÚrelpathr5   r   r   Údirnamer   Úget_python_incÚnormcase)r8   ÚmonkeypatchZ	orig_siteZ	orig_baserE   Úkeyr9   r:   ÚoptionsZactual_headersZ	site_pathr$   Zexpect_headersr   rD   r   Útest_user_siteK   s<    
zTestInstall.test_user_sitec              	   C   sî   t dddœƒ}t|ƒ}| ¡  |jddgks0t‚|jdks>t‚|jdksLt‚dg|_| ¡  |jdgkslt‚|jdkszt‚|jdksˆt‚d  |_|_| ¡  |jd ksªt‚|jdks¸t‚|jd ksÆt‚d|_t t	¡� | ¡  W 5 Q R X d S )NrI   z	path,dirs)r   Ú
extra_pathr   ÚdirsrS   zpath,dirs,again)
r   r   Úhandle_extra_pathrb   r   Ú
extra_dirsÚ	path_fileÚpytestÚraisesr   ©r8   r9   r:   r   r   r   Útest_handle_extra_path‚   s&    z"TestInstall.test_handle_extra_pathc              	   C   s–   t ddiƒ}t|ƒ}d|_d|_t t¡� | ¡  W 5 Q R X d |_d|_t t¡� | ¡  W 5 Q R X d |_d|_	t t¡� | ¡  W 5 Q R X d S )Nr   rI   ÚprefixÚbaser*   rN   )
r   r   rk   r,   rg   rh   r   Úfinalize_optionsr*   rN   ri   r   r   r   Útest_finalize_optionsŸ   s    z!TestInstall.test_finalize_optionsc                 C   sÖ   |   ¡ }| jdgdgd�\}}t |¡ |  dd¡ |  dd¡ t|ƒ}||jd< ||_tj 	|d¡|_
| ¡  | ¡  t |j
¡jd	d
�}dd„ | ¡ D ƒ}ddtjj› d�ddjtjd d… Ž g}||ksÒt‚d S )NZhelloZsayhi)Ú
py_modulesÚscriptszhello.pyzdef main(): print('o hai')zfrom hello import main; main()r   Úfilelistúutf-8©Úencodingc                 S   s   g | ]}t  |¡j‘qS r   ©ÚpathlibÚPathr   ©rJ   Úliner   r   r   rM   Ç   s     z+TestInstall.test_record.<locals>.<listcomp>zhello.z.pycúUNKNOWN-0.0.0-py{}.{}.egg-infoé   )r&   Úcreate_distr   ÚchdirÚ
write_filer   r)   Úrootr   r'   Úrecordr+   Úrunrv   rw   Ú	read_textÚ
splitlinesr.   r/   Ú	cache_tagÚformatÚversion_infor   )r8   Úinstall_dirÚproject_dirr9   r:   ÚcontentÚfoundr   r   r   r   Útest_record·   s&    

üzTestInstall.test_recordc           	      C   s  t ƒ }|d k	r t d|›d�¡ |  ¡ }| jtddgƒgd�\}}t |¡ t 	|¡ t
|ƒ}t |¡ | ¡  t|ƒ}||jd< ||jd< ||_tj |d¡|_| ¡  | ¡  t |j¡jd	d
�}dd„ | ¡ D ƒ}tdƒdjtjd d… Ž g}||k�st‚d S )NzThe z command is not foundrI   z
xxmodule.c)Úext_modulesr   r   rq   rr   rs   c                 S   s   g | ]}t  |¡j‘qS r   ru   rx   r   r   r   rM   é   s     z6TestInstall.test_record_extensions.<locals>.<listcomp>rz   r{   )r	   rg   Úskipr&   r|   r   r   r}   r
   Zcopy_xxmodule_cr   Zfixup_build_extr+   r   r)   r   r   r'   r€   r�   rv   rw   r‚   rƒ   r   r…   r.   r†   r   )	r8   r:   r‡   rˆ   r9   Zbuildextcmdr‰   rŠ   r   r   r   r   Útest_record_extensionsÐ   s2    ÿ





þz"TestInstall.test_record_extensionsc                 C   s>   |  tdd¡ | tj¡ |  ¡  tdd„ |jD ƒƒs:t‚d S )NÚDEBUGTc                 s   s   | ]}|j tjkr|V  qd S r   )ÚlevelnoÚloggingr�   )rJ   Zrecr   r   r   Ú	<genexpr>õ   s      z.TestInstall.test_debug_mode.<locals>.<genexpr>)	rU   rV   Z	set_levelr‘   r�   r‹   ÚanyÚrecordsr   )r8   Zcaplogr^   r   r   r   Útest_debug_modeð   s    zTestInstall.test_debug_modeN)Ú__name__Ú
__module__Ú__qualname__rg   ÚmarkZxfailr;   ra   rj   rn   r‹   rŽ   r•   r   r   r   r   r      s   þ
)7 r   )!Ú__doc__r‘   r   rv   rT   r.   Ú	distutilsr   Údistutils.commandr   rV   Zdistutils.command.build_extr   Údistutils.command.installr   Údistutils.corer   Údistutils.errorsr   Údistutils.extensionr   Zdistutils.testsr	   r
   Údistutils.utilr   rg   r   Zcombine_markersr™   ZusefixturesZTempdirManagerr   r   r   r   r   Ú<module>   s*   

ÿ