o
    Zh!                     @   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   _/var/www/html/lang_env/lib/python3.10/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s:J |j|ksAJ 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)Z
build_baseZ	build_libbuildc                 S   s(   t j| } t j|}| |ksJ d S N)ospathnormpath)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_baseZinstall_platbasesysimplementationr   replaceZinstall_libgetattrZinstall_platlibZinstall_purelibinstall_headersZinstall_scriptsZinstall_data)
selfZbuilddirZdestinationdistcmdr   Z	impl_name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
v sMJ qEtd	d
i}t|}dd |jD }d|v sfJ d|_tjtjrrJ tjtjr{J |  tjtjsJ tjtjsJ d|jv sJ d|jv sJ tj|jtj}	tjdkrt stjtj||}
tj|
d}ntdd}tj|d
}tj|	tj|ksJ 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   r/   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   Zshortlabelr   r   r   
<listcomp>d   s    z.TestInstall.test_user_site.<locals>.<listcomp>userTuserbaseZusersitentZIncluder    )r#   r;   siter6   r4   setattrr   r   r$   install_moduler   r   r   Zuser_optionsrE   existsr(   Zconfig_varsrelpathr.   r   r   dirnamer   Zget_python_incnormcase)r/   monkeypatchZ	orig_siteZ	orig_baser=   keyr0   r1   optionsZactual_headersZ	site_pathr!   Zexpect_headersr   r<   r   test_user_siteK   s<   
 zTestInstall.test_user_sitec                 C   s  t ddd}t|}|  |jddgksJ |jdksJ |jdks&J dg|_|  |jdgks6J |jdks=J |jdksDJ d  |_|_|  |jd u sUJ |jdks\J |jd u scJ d|_tt |  W d    d S 1 s{w   Y  d S )NrA   z	path,dirs)r   
extra_pathr   dirsrH   zpath,dirs,again)	r   r   Zhandle_extra_pathrT   Z
extra_dirsZ	path_filepytestraisesr   r/   r0   r1   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 d    n1 s$w   Y  d |_d|_tt |  W d    n1 sCw   Y  d |_d|_	tt |  W d    d S 1 scw   Y  d S )Nr   rA   prefixbaser'   rE   )
r   r   rZ   r)   rV   rW   r   finalize_optionsr'   rE   rX   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siJ d S )NZhelloZsayhi)Z
py_modulesscriptszhello.pyzdef main(): print('o hai')zfrom hello import main; main()r   filelistutf-8encodingc                 S      g | ]}t |jqS r   pathlibPathr   rB   liner   r   r   rD          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(   runre   rf   	read_text
splitlinesr*   r+   	cache_tagformatversion_info)r/   install_dirproject_dirr0   r1   contentfoundr   r   r   r   test_record   s&   

zTestInstall.test_recordc           	      C   s  t  }|d u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sJ d S )NzThe z command is not foundrA   z
xxmodule.c)Zext_modulesr   r   r_   r`   ra   c                 S   rc   r   rd   rg   r   r   r   rD      ri   z6TestInstall.test_record_extensions.<locals>.<listcomp>rj   rk   )r	   rV   skipr#   rl   r   r   rm   r
   Zcopy_xxmodule_cr   Zfixup_build_extr(   r   r&   ro   r   r$   rp   rq   re   rf   rr   rs   r   ru   r*   rv   )	r/   r1   rw   rx   r0   Zbuildextcmdry   rz   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J d S )NDEBUGTc                 s   s     | ]}|j tjkr|V  qd S r   )levelnologgingr~   )rB   Zrecr   r   r   	<genexpr>   s    z.TestInstall.test_debug_mode.<locals>.<genexpr>)rJ   rK   Z	set_levelr   r~   r{   anyrecords)r/   ZcaplogrP   r   r   r   test_debug_mode   s   zTestInstall.test_debug_modeN)__name__
__module____qualname__rV   markZxfailr3   rS   rY   r]   r{   r}   r   r   r   r   r   r      s    
)7 r   )!__doc__r   r   re   rI   r*   	distutilsr   Zdistutils.commandr   rK   Zdistutils.command.build_extr   distutils.command.installr   Zdistutils.corer   Zdistutils.errorsr   Zdistutils.extensionr   Zdistutils.testsr	   r
   Zdistutils.utilr   rV   r   Zcombine_markersr   ZusefixturesZTempdirManagerr   r   r   r   r   <module>   s,    

