B
    18™\£-  ã               @   sv   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ZddlZe 	ej 
d¡d¡G dd„ dejƒƒZedkrre ¡  dS )z=
Test suite for _osx_support: shared OS X support functions.
é    NÚdarwinzrequires OS Xc               @   sŒ   e Z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dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!S )"ÚTest_OSXSupportc             C   s`   d | _ d| _tj t ¡ ¡| _tj 	¡ | _
|  | j
j¡ x"dD ]}|| j
kr>| j
 |¡ q>W d S )NZbogus_program_xxxx)ÚCFLAGSÚLDFLAGSÚCPPFLAGSÚ
BASECFLAGSÚ	BLDSHAREDÚLDSHAREDÚCCÚCXXÚ	PY_CFLAGSÚ
PY_LDFLAGSÚPY_CPPFLAGSÚPY_CORE_CFLAGSÚPY_CORE_LDFLAGS)ÚmaxDiffÚ	prog_nameÚosÚpathÚabspathÚgetcwdÚtemp_path_dirÚtestÚsupportÚEnvironmentVarGuardÚenvÚ
addCleanupÚ__exit__Úunset)ÚselfÚcv© r!   úZ/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/test/test__osx_support.pyÚsetUp   s    

zTest_OSXSupport.setUpc                s   ˆ  ‡ ‡fdd„ˆ D ƒ¡ d S )Nc             3   s.   | ]&}ˆ | ˆ| krd | ˆ | fV  qdS )Z_OSX_SUPPORT_INITIAL_Nr!   )Ú.0Úk)Úconfig_varsÚexpected_varsr!   r"   ú	<genexpr>"   s   zDTest_OSXSupport.add_expected_saved_initial_values.<locals>.<genexpr>)Úupdate)r   r&   r'   r!   )r&   r'   r"   Ú!add_expected_saved_initial_values   s    z1Test_OSXSupport.add_expected_saved_initial_valuesc          	   C   sº   | j d r| j d d | j d< | j d tj | j¡ | j d< tj | j¡ |  	t
 | j¡¡ |  tjj| j¡ t| jdƒ}| d¡ W d Q R X t | jtj¡ |  | jt
 | j¡¡ d S )NÚPATHú:Úwz#!/bin/sh
/bin/echo OK
)r   r   r   r   r   r   r   Úunlinkr   ÚassertIsNoneÚ_osx_supportZ_find_executabler   ÚopenÚwriteÚchmodÚstatÚS_IRWXUÚassertEqual)r   Úfr!   r!   r"   Útest__find_executable&   s    
z%Test_OSXSupport.test__find_executablec          	   C   s¦   | j d r| j d d | j d< | j d tj | j¡ | j d< tj | j¡ |  	tjj| j¡ t
| jdƒ}| d¡ W d Q R X t | jtj¡ |  dt | j¡¡ d S )Nr+   r,   r-   z##!/bin/sh
/bin/echo ExpectedOutput
ZExpectedOutput)r   r   r   r   r   r   r   r.   r   r   r1   r2   r3   r4   r5   r6   r0   Z_read_output)r   r7   r!   r!   r"   Útest__read_output3   s    
z!Test_OSXSupport.test__read_outputc             C   s"   t  d¡}|  tj |¡d¡ d S )NZccz!cc not found - check xcode-select)r0   Z_find_build_toolÚ
assertTruer   r   Úisfile)r   Úoutr!   r!   r"   Útest__find_build_tool?   s    
z%Test_OSXSupport.test__find_build_toolc             C   s    |   t ¡ d  t ¡ ¡¡ d S )Nr   )r:   ÚplatformÚmac_verÚ
startswithr0   Z_get_system_version)r   r!   r!   r"   Útest__get_system_versionD   s    z(Test_OSXSupport.test__get_system_versionc             C   sL   ddi}ddi}d}d}t  |||¡ |  ||¡ t  |¡ |  ||¡ d S )Nr
   zgcc-test -pthreadszclang -pthreads)r0   Ú_save_modified_valueÚassertNotEqualZ_remove_original_valuesr6   )r   r&   r'   r    Únewvaluer!   r!   r"   Útest__remove_original_valuesH   s    
z,Test_OSXSupport.test__remove_original_valuesc             C   sB   ddi}ddi}|   ||¡ d}d}t |||¡ |  ||¡ d S )Nr
   zgcc-test -pthreadszclang -pthreads)r*   r0   rB   r6   )r   r&   r'   r    rD   r!   r!   r"   Útest__save_modified_valueV   s    z)Test_OSXSupport.test__save_modified_valuec             C   s6   ddi}|  ¡ }d}d}t |||¡ |  ||¡ d S )Nr
   zgcc-test -pthreads)Úcopyr0   rB   r6   )r   r&   r'   r    rD   r!   r!   r"   Ú#test__save_modified_value_unchangedc   s    z3Test_OSXSupport.test__save_modified_value_unchangedc             C   sH   dd l }tdd„ | ¡ d  d¡dd… D ƒƒ}|  |dkt ¡ ¡ d S )Nr   c             s   s   | ]}t |ƒV  qd S )N)Úint)r$   Úir!   r!   r"   r(   o   s    zBTest_OSXSupport.test__supports_universal_builds.<locals>.<genexpr>Ú.é   )é
   é   )r>   Útupler?   Úsplitr6   r0   Z_supports_universal_builds)r   r>   Zmac_ver_tupler!   r!   r"   Útest__supports_universal_buildsm   s
     
z/Test_OSXSupport.test__supports_universal_buildsc          
   C   sâ   d}dddddddd	œ}d
ddddddd	œ}|   ||¡ | jd rPd| jd  nd}tj | j¡| | jd< x^|D ]V\}}tj |¡ |  	tjj|¡ t
|dƒ}| d| ¡ W d Q R X t |tj¡ qrW |  |t |¡¡ d S )N))zgcc-testz i686-apple-darwin11-llvm-gcc-4.2)Úclangzclang version 3.1zgcc-test -pthreadsz	cc++-testz3-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  z-arch ppc -arch i386   -gz--I. -isysroot /Developer/SDKs/MacOSX10.4u.sdkz(gcc-test -bundle -arch ppc -arch i386 -gzRgcc-test -bundle -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g)r
   r   r   r   r   r   r	   zclang -pthreadszclang++z%clang -bundle -arch ppc -arch i386 -gzOclang -bundle -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -gr+   r,   Ú r-   z#!/bin/sh
/bin/echo )r*   r   r   r   r   r   r   r   r.   r   r1   r2   r3   r4   r5   r6   r0   Z_find_appropriate_compiler)r   Z	compilersr&   r'   ÚsuffixÚc_nameZc_outputr7   r!   r!   r"   Útest__find_appropriate_compilert   s6    z/Test_OSXSupport.test__find_appropriate_compilerc             C   sB   ddddddœ}ddd	d
ddœ}|   ||¡ |  |t |¡¡ d S )Nz3-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  z-arch ppc -arch i386   -gz--I. -isysroot /Developer/SDKs/MacOSX10.4u.sdkz(gcc-4.0 -bundle  -arch ppc -arch i386 -gzRgcc-4.0 -bundle  -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g)r   r   r   r   r	   z -fno-strict-aliasing  -g -O3    z    -gz-I.  zgcc-4.0 -bundle    -gzgcc-4.0 -bundle      -g)r*   r6   r0   Z_remove_universal_flags)r   r&   r'   r!   r!   r"   Útest__remove_universal_flags›   s    z,Test_OSXSupport.test__remove_universal_flagsc          	   C   sÈ   dddddddœ}ddd	dd
ddœ}|   ||¡ | jd rHd| jd  nd}tj | j¡| | jd< d}tj |¡ |  	tjj|¡ t
|dƒ}| d¡ W d Q R X t |tj¡ |  |t |¡¡ d S )NrR   z3-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  z-arch ppc -arch i386   -gz--I. -isysroot /Developer/SDKs/MacOSX10.4u.sdkz(gcc-4.0 -bundle  -arch ppc -arch i386 -gzRgcc-4.0 -bundle  -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g)r
   r   r   r   r   r	   z*-fno-strict-aliasing  -g -O3  -arch i386  z -arch i386   -gzgcc-4.0 -bundle   -arch i386 -gzIgcc-4.0 -bundle   -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -gr+   r,   rS   r-   z#!/bin/sh
exit 255)r*   r   r   r   r   r   r   r   r.   r   r1   r2   r3   r4   r5   r6   r0   Z_remove_unsupported_archs)r   r&   r'   rT   rU   r7   r!   r!   r"   Útest__remove_unsupported_archs±   s0    z.Test_OSXSupport.test__remove_unsupported_archsc             C   sP   d| j d< ddddddd	œ}dd
ddddd	œ}|  ||¡ |  |t |¡¡ d S )Nz-arch x86_64Z	ARCHFLAGSrR   z3-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  z-arch ppc -arch i386   -gz--I. -isysroot /Developer/SDKs/MacOSX10.4u.sdkz(gcc-4.0 -bundle  -arch ppc -arch i386 -gzQgcc-4.0 -bundle -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g)r
   r   r   r   r   r	   z--fno-strict-aliasing  -g -O3     -arch x86_64z    -g -arch x86_64z"gcc-4.0 -bundle    -g -arch x86_64zKgcc-4.0 -bundle   -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g -arch x86_64)r   r*   r6   r0   Z_override_all_archs)r   r&   r'   r!   r!   r"   Útest__override_all_archsÓ   s"    
z(Test_OSXSupport.test__override_all_archsc             C   sF   dddddddœ}dddd	dd
dœ}|   ||¡ |  |t |¡¡ d S )NrR   z[-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  -isysroot /Developer/SDKs/MacOSX10.1.sdkz-arch ppc -arch i386   -gz,-I. -isysroot /Developer/SDKs/MacOSX10.1.sdkz(gcc-4.0 -bundle  -arch ppc -arch i386 -gzQgcc-4.0 -bundle  -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.1.sdk -g)r
   r   r   r   r   r	   z4-fno-strict-aliasing  -g -O3 -arch ppc -arch i386   z-I.  z)gcc-4.0 -bundle  -arch ppc -arch i386  -g)r*   r6   r0   Z_check_for_unavailable_sdk)r   r&   r'   r!   r!   r"   Útest__check_for_unavailable_sdkí   s     z/Test_OSXSupport.test__check_for_unavailable_sdkc             C   s*   dddœ}t  |ddd¡}|  d|¡ d S )Nz[-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  -isysroot /Developer/SDKs/MacOSX10.1.sdkz10.6)r   ÚMACOSX_DEPLOYMENT_TARGETú )Zmacosxz10.6Zfat)r0   Úget_platform_osxr6   )r   r&   Úresultr!   r!   r"   Útest_get_platform_osx  s    z%Test_OSXSupport.test_get_platform_osxN)Ú__name__Ú
__module__Ú__qualname__r#   r*   r8   r9   r=   rA   rE   rF   rH   rQ   rV   rW   rX   rY   rZ   r_   r!   r!   r!   r"   r      s    
'"r   Ú__main__)Ú__doc__r   r>   r4   ÚsysÚunittestZtest.supportr   r0   Ú
skipUnlessr@   ÚTestCaser   r`   Úmainr!   r!   r!   r"   Ú<module>   s   
  