o
    NZh!                     @   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   W/var/www/auris/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builddir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<   siter7   r5   setattrr   r   r$   install_moduler   r   r   Zuser_optionsrF   existsr(   Zconfig_varsrelpathr.   r   r   dirnamer   Zget_python_incnormcase)r/   monkeypatchZ	orig_siteZ	orig_baser>   keyr1   r2   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 )NrB   z	path,dirs)r   
extra_pathr   dirsrI   zpath,dirs,again)	r   r   Zhandle_extra_pathrU   Z
extra_dirsZ	path_filepytestraisesr   r/   r1   r2   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   rB   prefixbaser'   rF   )
r   r   r[   r)   rW   rX   r   finalize_optionsr'   rF   rY   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   rC   liner   r   r   rE          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(   runrf   rg   	read_text
splitlinesr*   r+   	cache_tagformatversion_info)r/   install_dirproject_dirr1   r2   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 foundrB   z
xxmodule.c)Zext_modulesr   r   r`   ra   rb   c                 S   rd   r   re   rh   r   r   r   rE      rj   z6TestInstall.test_record_extensions.<locals>.<listcomp>rk   rl   )r	   rW   skipr#   rm   r   r   rn   r
   Zcopy_xxmodule_cr   Zfixup_build_extr(   r   r&   rp   r   r$   rq   rr   rf   rg   rs   rt   r   rv   r*   rw   )	r/   r2   rx   ry   r1   Zbuildextcmdrz   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J d S )NDEBUGTc                 s   s     | ]}|j tjkr|V  qd S r   )levelnologgingr   )rC   Zrecr   r   r   	<genexpr>   s    z.TestInstall.test_debug_mode.<locals>.<genexpr>)rK   rL   Z	set_levelr   r   r|   anyrecords)r/   ZcaplogrQ   r   r   r   test_debug_mode   s   zTestInstall.test_debug_modeN)__name__
__module____qualname__rW   markZxfailr4   rT   rZ   r^   r|   r~   r   r   r   r   r   r      s    
)7 r   )!__doc__r   r   rf   rJ   r*   	distutilsr   Zdistutils.commandr   rL   Zdistutils.command.build_extr   distutils.command.installr   Zdistutils.corer   Zdistutils.errorsr   Zdistutils.extensionr   Zdistutils.testsr	   r
   Zdistutils.utilr   rW   r   Zcombine_markersr   ZusefixturesZTempdirManagerr   r   r   r   r   <module>   s,    

