B
    u9a[I  ã               @   sÔ   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mZm	Z	m
Z
mZmZmZ d dlZd dlmZmZmZmZmZmZmZmZmZmZmZ d dlZG dd„ de jƒZG dd„ de jƒZed	krÐe  ¡  dS )
é    N)Úcopy)Úimport_moduleÚTESTFNÚunlinkÚcheck_warningsÚcaptured_stdoutÚskip_unless_symlinkÚ
change_cwd)Ú	get_pathsÚget_platformÚget_config_varsÚget_pathÚget_path_namesÚ_INSTALL_SCHEMESÚ_get_default_schemeÚ_expand_varsÚget_scheme_namesÚget_config_varÚ_mainc                   st  e Zd Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdd„ Zdd„ Ze ejdkd ¡d!d"„ ƒZe ejd#kd$¡d%d&„ ƒZd'd(„ Zd)d*„ Ze e d+¡d,kd-¡d.d/„ ƒZe e d+¡d,kd-¡d0d1„ ƒZe e d+¡d,kd-¡d2d3„ ƒZ e ejd4koDe!ej"d5ƒd6¡d7d8„ ƒZ#e ejd#kd9¡d:d;„ ƒZ$‡  Z%S )<ÚTestSysConfigc                sð   t t| ƒ ¡  tjd d … | _ttdƒr<tj| _t ¡ | _	nd | _|  
d¡ | jt_tj| _tj| _tj| _tj| _tjj| _tjj| _tjj| _tjttjƒf| _g | _g | _x:dD ]2}|tjkrÜ| j |tj| f¡ q¶| j |¡ q¶W d S )NÚuname)Ú r   r   r   r   )ÚMACOSX_DEPLOYMENT_TARGETÚPATH)Úsuperr   ÚsetUpÚsysÚpathÚsys_pathÚhasattrÚosr   Ú_unameÚ
_set_unameÚ
_get_unameÚnameÚplatformÚversionÚsepÚjoinÚisabsÚ
splitdriveÚ	sysconfigÚ_CONFIG_VARSr   Ú_config_varsÚ_added_envvarsÚ_changed_envvarsÚenvironÚappend)ÚselfÚvar)Ú	__class__© ú$/usr/lib/python3.7/test_sysconfig.pyr      s,    






zTestSysConfig.setUpc                sä   | j tjd d …< |  ¡  | jd k	r,| jt_nt`| jt_| jt_| jt_| j	t_	| j
tj_
| jtj_| jtj_| jd t_tj ¡  tj | jd ¡ x| jD ]\}}|tj|< qžW x| jD ]}tj |d ¡ q¼W tt| ƒ ¡  d S )Nr   é   )r   r   r   Ú_cleanup_testfnr   r    r$   r%   r&   r'   r(   r)   r*   r-   r+   r,   ÚclearÚupdater/   r0   r.   Úpopr   r   ÚtearDown)r2   r3   Úvalue)r4   r5   r6   r<   0   s(    





zTestSysConfig.tearDownc             C   s   t  |¡| _d S )N)r    Úuname_resultr!   )r2   r   r5   r5   r6   r"   H   s    zTestSysConfig._set_unamec             C   s   | j S )N)r!   )r2   r5   r5   r6   r#   K   s    zTestSysConfig._get_unamec             C   s6   t }tj |¡rt |¡ ntj |¡r2t |¡ d S )N)r   r    r   ÚisfileÚremoveÚisdirÚshutilZrmtree)r2   r   r5   r5   r6   r8   N   s
    zTestSysConfig._cleanup_testfnc             C   s   |   tƒ tj¡ d S )N)ÚassertEqualr   r+   Z_SCHEME_KEYS)r2   r5   r5   r6   Útest_get_path_namesU   s    z!TestSysConfig.test_get_path_namesc             C   s>   t ƒ }tƒ }t|d ƒ}t| ¡ ƒ}t| ¡ ƒ}|  ||¡ d S )N)r
   r   r   ÚsortedÚitemsrC   )r2   ÚschemeZdefault_schemeÚwantedr5   r5   r6   Útest_get_pathsX   s    
zTestSysConfig.test_get_pathsc             C   s.   x(t D ] }xt | D ]}t||ƒ}qW qW d S )N)r   r   )r2   rG   r$   Zresr5   r5   r6   Útest_get_path`   s    
zTestSysConfig.test_get_pathc             C   s    t ƒ }|  |t¡ |  |¡ d S )N)r   ZassertIsInstanceÚdictÚ
assertTrue)r2   Zcvarsr5   r5   r6   Útest_get_config_varsf   s    z"TestSysConfig.test_get_config_varsc             C   sF  dt _dt_dt_|  tƒ d¡ dt _dt_dt_|  tƒ d¡ dt _dt_dt_|  d	¡ t 	t
ƒ ¡ d
t
ƒ d< dt
ƒ d< tj}z,dt_|  tƒ d¡ dt_|  tƒ d¡ W d |t_X |  d¡ t 	t
ƒ ¡ d
t
ƒ d< dt
ƒ d< tj}z,dt_|  tƒ d¡ dt_|  tƒ d¡ W d |t_X t 	t
ƒ ¡ dt
ƒ d< dt
ƒ d< |  tƒ d¡ t 	t
ƒ ¡ dt
ƒ d< |  tƒ d¡ t 	t
ƒ ¡ dt
ƒ d< |  tƒ d¡ t 	t
ƒ ¡ dt
ƒ d< |  tƒ d¡ t 	t
ƒ ¡ dt
ƒ d< |  tƒ d¡ x:d D ]2}t 	t
ƒ ¡ d!| t
ƒ d< |  tƒ d"| ¡ qâW dt _d#t_d$t_|  d%¡ |  tƒ d&¡ d S )'NÚntz>2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]Úwin32z>2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Amd64)]z	win-amd64ÚposixzU2.5 (r25:51918, Sep 19 2006, 08:49:13) 
[GCC 4.0.1 (Apple Computer, Inc. build 5341)]Údarwin)ÚDarwinÚmacziadez8.11.1z]Darwin Kernel Version 8.11.1: Wed Oct 10 18:23:28 PDT 2007; root:xnu-792.25.20~1/RELEASE_I386ZPowerPCz10.3r   zF-fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypesZCFLAGSiÿÿÿzmacosx-10.3-ppcl   ÿÿÿÿ zmacosx-10.3-ppc64)rR   rS   z8.11.1z]Darwin Kernel Version 8.11.1: Wed Oct 10 18:23:28 PDT 2007; root:xnu-792.25.20~1/RELEASE_I386Úi386zmacosx-10.3-i386zmacosx-10.3-x86_64z10.4zy-arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk  -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3zmacosx-10.4-fatz|-arch x86_64 -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk  -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3zmacosx-10.4-intelz†-arch x86_64 -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk  -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3zmacosx-10.4-fat3z’-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk  -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3zmacosx-10.4-universalz}-arch x86_64 -arch ppc64 -isysroot /Developer/SDKs/MacOSX10.4u.sdk  -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3zmacosx-10.4-fat64)ZppcrT   Zx86_64Zppc64zm-arch %s -isysroot /Developer/SDKs/MacOSX10.4u.sdk  -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3zmacosx-10.4-%szV2.3.5 (#1, Jul  4 2007, 17:28:59) 
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]Zlinux2)ZLinuxZaglaez2.6.21.1dedibox-r7z #1 Mon Apr 30 17:25:38 CEST 2007Zi686z
linux-i686)r    r$   r   r&   r%   rC   r   r"   Ú_osx_supportZ_remove_original_valuesr   Úmaxsize)r2   ZmaxintZarchr5   r5   r6   Útest_get_platformk   sv    













zTestSysConfig.test_get_platformc             C   s    t  ¡ }|  tj |¡|¡ d S )N)r+   Zget_config_h_filenamerL   r    r   r?   )r2   Zconfig_hr5   r5   r6   Útest_get_config_h_filenameá   s    z(TestSysConfig.test_get_config_h_filenamec             C   s   d}|   tƒ |¡ d S )N)rN   Znt_userZosx_framework_userZ
posix_homeÚposix_prefixÚ
posix_user)rC   r   )r2   rH   r5   r5   r6   Útest_get_scheme_nameså   s    z#TestSysConfig.test_get_scheme_namesc                sô   t jdkr,tj t j¡s,dd l}| d¡}ntj t j¡}tj 	t
¡}t ||¡ d }t jdkr¼dd„ tjD ƒ}d tj |¡| dd¡¡|d< tj |¡|d< t d	¡r¼tj tj¡|d
< d‡ fdd„	}zˆ  ||ƒ|||ƒ¡ W d t|ƒ X d S )NrO   r   c             S   s   i | ]}t j| | ¡ “qS r5   )r    r0   Úupper)Ú.0Úkr5   r5   r6   ú
<dictcomp>ú   s    z.TestSysConfig.test_symlink.<locals>.<dictcomp>z{};{}r   r   Z
PYTHONHOMETZ
PYTHONPATHc                sX   | ddg}t j|t jt j|d}| ¡ \}}|jrPt||fƒ ˆ  d |j¡¡ ||fS )Nz-cz1import sysconfig; print(sysconfig.get_platform()))ÚstdoutÚstderrÚenvz$Non-zero return code {0} (0x{0:08X}))Ú
subprocessÚPopenÚPIPEÚcommunicateÚ
returncodeÚprintZfailÚformat)Zpythonrb   ÚcmdÚpÚoutÚerr)r2   r5   r6   Úget  s    

z'TestSysConfig.test_symlink.<locals>.get)N)r   r%   r    r   ÚexistsÚ
executableÚ_winapiZGetModuleFileNameÚrealpathÚabspathr   Úsymlinkr0   ri   Údirnamern   r+   Zis_python_buildÚ__file__rC   r   )r2   rq   ÚrealÚlinkrb   rn   r5   )r2   r6   Útest_symlinkê   s$    

zTestSysConfig.test_symlinkc          	   C   sª   t dƒ}t dƒ}tjtjk}xˆdD ]€}t|dƒ}|rV| tjtj¡}| tjtj¡}n,tjtjkr‚| tjtj¡}| tjtj¡}t|dƒ}|  || ||d¡¡ q"W d S )NÚbaseÚuserbase)ZstdlibZ
platstdlibZpurelibZplatlibrY   rZ   r7   )	r   r   Úbase_prefixÚbase_exec_prefixr   ÚreplaceÚexec_prefixÚprefixrC   )r2   rz   ÚuserZadaptr$   Zglobal_pathZ	user_pathr5   r5   r6   Útest_user_similar  s    


zTestSysConfig.test_user_similarc          	   C   s8   t ƒ }tƒ  W d Q R X |  t| ¡  d¡ƒdk¡ d S )NÚ
r   )r   r   rL   ÚlenÚgetvalueÚsplit)r2   Úoutputr5   r5   r6   Ú	test_main*  s    zTestSysConfig.test_mainrO   zDoes not apply to Windowsc             C   s$   t  d¡}t  d¡}|  ||¡ d S )NZLDFLAGSZLDSHARED)r+   r   ZassertIn)r2   ZldflagsZldsharedr5   r5   r6   Útest_ldshared_value0  s    

z!TestSysConfig.test_ldshared_valuerQ   ztest only relevant on MacOSXc             C   sæ   t  ¡ }tj ¡ }d|kr |d= tjtjddgtj	tj
|d}| ¡ d  ¡ }| d¡}| ¡ }|  |d¡ |  ||¡ tj ¡ }d|d< tjtjddgtj	tj
|d}| ¡ d  ¡ }| d¡}| ¡ }|  |d¡ |  ||¡ d S )Nr   z-cz1import sysconfig; print(sysconfig.get_platform()))r`   ra   rb   r   zutf-8z10.1)r+   r   r    r0   r   rc   rd   r   rp   re   ZDEVNULLrf   ÚstripÚdecodeÚwaitrC   )r2   Zmy_platformrb   rk   Ztest_platformÚstatusr5   r5   r6   Útest_platform_in_subprocess7  s8    



z)TestSysConfig.test_platform_in_subprocessc             C   s¤   t  d¡}|  tj |¡|¡ |  tj |¡|¡ t jrntj |dd¡}|  tj 	|¡|¡ |  t  
|¡¡ n2tjdkr tj t  ¡ ¡}tj |¡}|  ||¡ d S )NÚsrcdirZIncludezPython.hrP   )r+   r   rL   r    r   r)   rA   Z_PYTHON_BUILDr(   ro   Z_is_python_source_dirr$   ru   Úget_makefile_filenamerr   rC   )r2   r   ZPython_hZmakefile_dirr5   r5   r6   Útest_srcdirb  s    

zTestSysConfig.test_srcdirc          	   C   s:   t  d¡}ttjƒ t  d¡}W d Q R X |  ||¡ d S )Nr   )r+   r   r	   r    ÚpardirrC   )r2   r   Zsrcdir2r5   r5   r6   Útest_srcdir_independent_of_cwdu  s    
z,TestSysConfig.test_srcdir_independent_of_cwdÚ
EXT_SUFFIXNz!EXT_SUFFIX required for this testc             C   s   |   ttjd¡ d S )NÚSO)ZassertWarnsÚDeprecationWarningr+   r   )r2   r5   r5   r6   Útest_SO_deprecation}  s    z!TestSysConfig.test_SO_deprecationc          	   C   s4   t dtfƒ |  t d¡t d¡¡ W d Q R X d S )Nr   r•   r”   )r   r–   rC   r+   r   )r2   r5   r5   r6   Útest_SO_valueƒ  s    zTestSysConfig.test_SO_valuec             C   s.   t  ¡ }|  |d ¡ |  |d |d ¡ d S )Nr•   r”   )r+   r   ZassertIsNotNonerC   )r2   Úvarsr5   r5   r6   Útest_SO_in_varsŠ  s    zTestSysConfig.test_SO_in_varsÚlinuxÚ
_multiarchzmultiarch-specific testc             C   s˜   t dƒ}dd l}dd l}| ¡ }t d¡}| d|¡rF|  d|k|¡ | d|¡r”| | 	¡ ¡dkr‚|  | 
d¡pz| 
d	¡|¡ n|  | 
d
¡|¡ d S )NÚctypesr   r”   z)(aarch64|arm|mips|ppc|powerpc|s390|sparc)r›   z(i[3-6]86|x86_64)$é   zi386-linux-gnu.sozx86_64-linux-gnux32.sozx86_64-linux-gnu.so)r   r%   ÚreÚmachiner+   r   ÚmatchrL   ZsizeofZc_char_pÚendswith)r2   r   r%   rŸ   r    Úsuffixr5   r5   r6   Útest_triplet_in_ext_suffix‘  s    
z(TestSysConfig.test_triplet_in_ext_suffixzOS X-specific testc             C   s    t  d¡}|  | d¡|¡ d S )Nr”   z
-darwin.so)r+   r   rL   r¢   )r2   r£   r5   r5   r6   Útest_osx_ext_suffix£  s    
z!TestSysConfig.test_osx_ext_suffix)&Ú__name__Ú
__module__Ú__qualname__r   r<   r"   r#   r8   rD   rI   rJ   rM   rW   rX   r[   r   ry   r‚   rˆ   ÚunittestÚskipIfr   r%   r‰   Z
skipUnlessrŽ   r‘   r“   r+   r   r—   r˜   rš   r   Úimplementationr¤   r¥   Ú__classcell__r5   r5   )r4   r6   r      s:   v*+
r   c               @   s0   e Zd Ze ej d¡d¡dd„ ƒZdd„ Z	dS )ÚMakefileTestsÚwinzTest is not Windows compatiblec             C   s    t  ¡ }|  tj |¡|¡ d S )N)r+   r   rL   r    r   r?   )r2   Úmakefiler5   r5   r6   Útest_get_makefile_filenameª  s    z(MakefileTests.test_get_makefile_filenamec          
   C   s’   |   tt¡ ttdƒN}td|d td|d td|d td|d td|d td|d W d Q R X t t¡}|  |d	d
dddddœ¡ d S )NÚwzvar1=a$(VAR2))ÚfilezVAR2=b$(var3)zvar3=42zvar4=$/invalidzvar5=dollar$$5zAvar6=${var3}/lib/python3.5/config-$(VAR2)$(var5)-x86_64-linux-gnuZab42Zb42é*   z	$/invalidzdollar$5z442/lib/python3.5/config-b42dollar$5-x86_64-linux-gnu)Zvar1ZVAR2Zvar3Zvar4Zvar5Zvar6)Z
addCleanupr   r   Úopenrh   r+   Z_parse_makefilerC   )r2   r¯   r™   r5   r5   r6   Útest_parse_makefile°  s"    
z!MakefileTests.test_parse_makefileN)
r¦   r§   r¨   r©   rª   r   r%   Ú
startswithr°   rµ   r5   r5   r5   r6   r­   ¨  s   r­   Ú__main__) r©   r   r    rc   rB   r   Ztest.supportr   r   r   r   r   r   r	   r+   r
   r   r   r   r   r   r   r   r   r   r   rU   ZTestCaser   r­   r¦   Úmainr5   r5   r5   r6   Ú<module>   s    $4   