B
    u9a‚D  ã               @   s   d dl m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 d dlZd dl	m
Z
 G dd„ de jƒZG dd„ de jƒZedkrŒe  ¡  dS )	é    )ÚmockN)Úsupportc               @   s  e Zd Zdd„ Zej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e ej d¡d¡dd „ ƒZd!d"„ Zd#d$„ Zd%d&„ Ze ejd'kd(¡d)d*„ ƒZd+d,„ Zd-d.„ Zejd/d0„ ƒZ d1d2„ Z!d3d4„ Z"d5d6„ Z#d7S )8ÚPlatformTestc             C   s   t  ¡ }d S )N)ÚplatformZarchitecture)ÚselfÚres© r   ú#/usr/lib/python3.7/test_platform.pyÚtest_architecture   s    zPlatformTest.test_architecturec          	      sü   t jdkr,tj t j¡s,dd l}| d¡}ntj t j¡}tj 	t
j¡}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ˆ  |t jƒ|||d¡ W d t |¡ X d S )NÚwin32r   c             S   s   i | ]}t j| | ¡ “qS r   )ÚosÚenvironÚupper)Ú.0Úkr   r   r	   ú
<dictcomp>!   s    z>PlatformTest.test_architecture_via_symlink.<locals>.<dictcomp>z{};{}ÚPATHÚ Z
PYTHONHOMETZ
PYTHONPATHc                sj   | ddg}t j|t jt j|d}| ¡ }|jrftt|d ƒƒ tt|d ƒtjd ˆ  	d 
|j¡¡ |S )Nz-cz/import platform; print(platform.architecture()))ÚstdoutÚstderrÚenvr   é   )Úfilez'unexpected return code: {0} (0x{0:08X}))Ú
subprocessÚPopenÚPIPEZcommunicateÚ
returncodeÚprintÚreprÚsysr   ZfailÚformat)Zpythonr   ÚcmdÚpÚr)r   r   r	   Úget(   s    

z7PlatformTest.test_architecture_via_symlink.<locals>.get)r   )N)r   r   r   ÚpathÚexistsÚ
executableÚ_winapiÚGetModuleFileNameÚrealpathÚabspathr   ÚTESTFNÚsymlinkr   r    Údirnamer$   Ú	sysconfigZis_python_buildÚ__file__ÚassertEqualÚremove)r   r(   ÚrealÚlinkr   r$   r   )r   r	   Útest_architecture_via_symlink   s$    

z*PlatformTest.test_architecture_via_symlinkc             C   s,   x&dD ]}xdD ]}t   ||¡}qW qW d S )N)FT)r   )r   ZaliasedZterser   r   r   r	   Útest_platform:   s    

zPlatformTest.test_platformc             C   s   t  ¡ }d S )N)r   Úsystem)r   r   r   r   r	   Útest_system?   s    zPlatformTest.test_systemc             C   s   t  ¡ }d S )N)r   Únode)r   r   r   r   r	   Ú	test_nodeB   s    zPlatformTest.test_nodec             C   s   t  ¡ }d S )N)r   Úrelease)r   r   r   r   r	   Útest_releaseE   s    zPlatformTest.test_releasec             C   s   t  ¡ }d S )N)r   Úversion)r   r   r   r   r	   Útest_versionH   s    zPlatformTest.test_versionc             C   s   t  ¡ }d S )N)r   Úmachine)r   r   r   r   r	   Útest_machineK   s    zPlatformTest.test_machinec             C   s   t  ¡ }d S )N)r   Ú	processor)r   r   r   r   r	   Útest_processorN   s    zPlatformTest.test_processorc             C   s   t j| _t j| _t j| _d S )N)r   r=   Úsave_versionÚ_gitÚsave_gitr   Úsave_platform)r   r   r   r	   ÚsetUpQ   s    zPlatformTest.setUpc             C   s   | j t_| jt_| jt_d S )N)rC   r   r=   rE   rD   rF   r   )r   r   r   r	   ÚtearDownV   s    zPlatformTest.tearDownc             C   s:  xBdD ]:\}}t  |¡\}}}}}}}	|  ||dd|||	f|¡ qW dd| jfddddd	d
ddddd| jfdi}
xÄ|
 ¡ D ]¸\\}}}}|t_|d kr¦ttdƒr¬t`n|t_|d k	rº|t_ |  t  	¡ |d ¡ |  t  
¡ |d ¡ |  t  ¡ |d ¡ |  t  ¡ |d ¡ |  t  ¡ |d ¡ |  t  ¡ |d ¡ qzW d S )N))zC2.4.3 (#1, Jun 21 2006, 13:54:21) 
[GCC 3.3.4 (pre 3.3.5 20040809)])ÚCPythonz2.4.3r   r   Ú1zJun 21 2006 13:54:21zGCC 3.3.4 (pre 3.3.5 20040809))z)IronPython 1.0.60816 on .NET 2.0.50727.42)Ú
IronPythonz	1.0.60816r   r   r   r   z.NET 2.0.50727.42)z4IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42)rK   z1.0.0r   r   r   r   z.NET 2.0.50727.42)z"2.4.3 (truncation, date, t) 
[GCC])rI   z2.4.3r   r   Ú
truncationzdate tÚGCC)z!2.4.3 (truncation, date, ) 
[GCC])rI   z2.4.3r   r   rL   ÚdaterM   )z 2.4.3 (truncation, date,) 
[GCC])rI   z2.4.3r   r   rL   rN   rM   )z2.4.3 (truncation, date) 
[GCC])rI   z2.4.3r   r   rL   rN   rM   )z2.4.3 (truncation, d) 
[GCC])rI   z2.4.3r   r   rL   ÚdrM   )z2.4.3 (truncation, ) 
[GCC])rI   z2.4.3r   r   rL   r   rM   )z2.4.3 (truncation,) 
[GCC])rI   z2.4.3r   r   rL   r   rM   )z2.4.3 (truncation) 
[GCC])rI   z2.4.3r   r   rL   r   rM   r   zX2.6.1 (r261:67515, Dec  6 2008, 15:26:00) 
[GCC 4.0.1 (Apple Computer, Inc. build 5370)])rI   z	tags/r261Ú67515)rI   z2.6.1z	tags/r261rP   )z
r261:67515zDec  6 2008 15:26:00z+GCC 4.0.1 (Apple Computer, Inc. build 5370))z/IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053NÚcli)rK   z2.0.0r   r   )r   r   z.NET 2.0.50727.3053)z=2.6.1 (IronPython 2.6.1 (2.6.10920.0) on .NET 2.0.50727.1433)NrQ   )rK   z2.6.1r   r   )r   r   z.NET 2.0.50727.1433)z@2.7.4 (IronPython 2.7.4 (2.7.0.40) on Mono 4.0.30319.1 (32-bit))NrQ   )rK   z2.7.4r   r   )r   r   zMono 4.0.30319.1 (32-bit))z^2.5 (trunk:6107, Mar 26 2009, 13:02:18) 
[Java HotSpot(TM) Client VM ("Apple Computer, Inc.")])ÚJythonÚtrunkÚ6107zjava1.5.0_16)rR   z2.5.0rS   rT   )z
trunk:6107zMar 26 2009zjava1.5.0_16z12.5.2 (63378, Mar 26 2009, 18:03:29)
[PyPy 1.0.0])ÚPyPyrS   Ú63378)rU   z2.5.2rS   rV   )rV   zMar 26 2009r   rD   r   r   é   é   é   é   )r   Z_sys_versionr1   rF   Úitemsr   r=   ÚhasattrrD   Zpython_implementationZpython_versionZpython_branchZpython_revisionZpython_buildZpython_compiler)r   ÚinputÚoutputÚnamer=   ÚbranchZrevisionZbuildnoZ	builddateZcompilerZsys_versionsZversion_tagZscmZsys_platformÚinfor   r   r	   Útest_sys_version[   sD    
zPlatformTest.test_sys_versionc             C   s   t  t  ¡ t  ¡ t  ¡ ¡}d S )N)r   Zsystem_aliasr7   r;   r=   )r   r   r   r   r	   Útest_system_alias²   s    zPlatformTest.test_system_aliasc             C   s†   t  ¡ }|  t|ƒ¡ |  |d |j¡ |  |d |j¡ |  |d |j¡ |  |d |j¡ |  |d |j	¡ |  |d |j
¡ d S )Nr   r   rW   rX   rY   rZ   )r   ÚunameÚ
assertTrueÚanyr1   r7   r9   r;   r=   r?   rA   )r   r   r   r   r	   Ú
test_uname¹   s    zPlatformTest.test_unameÚwinzwindows only testc          	   C   s   z‚t  ¡ p}d|kr|d= d|d< d t_t ¡ \}}}}}}|  |d¡ d|d< d t_t ¡ \}}}}}}|  |d¡ W d Q R X W d d t_X d S )NZPROCESSOR_ARCHITEW6432ZfooZPROCESSOR_ARCHITECTUREZbar)r   ZEnvironmentVarGuardr   Z_uname_cacherd   r1   )r   r   r7   r9   r;   r=   r?   rA   r   r   r	   Útest_uname_win32_ARCHITEW6432Ã   s    
z*PlatformTest.test_uname_win32_ARCHITEW6432c             C   s$   t  ¡ }tj dkr |  t|ƒ¡ d S )NÚjava)r   Zjava_verr   re   Úall)r   r   r   r   r	   Útest_java_verØ   s    
zPlatformTest.test_java_verc             C   s   t  ¡ }d S )N)r   Z	win32_ver)r   r   r   r   r	   Útest_win32_verÝ   s    zPlatformTest.test_win32_verc             C   sò   t  ¡ }t  ¡ jdkrît dd¡}d }x(|D ] }| d¡r,| ¡  ¡ d }P q,W | 	¡  |  
|d k¡ |d  d¡}| d¡}t|ƒt|ƒ }|dkr¦| dg| ¡ |  ||¡ |  |d	 d
¡ tjdkrÞ|  |d d¡ n|  |d d¡ d S )NZDarwinZsw_versr#   zProductVersion:éÿÿÿÿr   Ú.Ú0r   )r   r   r   ÚlittlerW   )Zi386Zx86_64ZPowerPC)r   Úmac_verrd   r7   r   ÚpopenÚ
startswithÚstripÚsplitÚcloseZassertFalseÚlenÚextendr1   r   Ú	byteorderZassertIn)r   r   ÚfdZreal_verZlnZresult_listZexpect_listZlen_diffr   r   r	   Útest_mac_verà   s(    



zPlatformTest.test_mac_verÚdarwinzOSX only testc             C   sP   t  ¡ }|dkr$t ¡ }t  d¡ n(t  |d¡\}}|  ||¡ |  |d¡ d S )Nr   )r   Úforkr   rr   Ú_exitÚwaitpidr1   )r   Úpidra   ZcpidÚstsr   r   r	   Útest_mac_ver_with_fork  s    z#PlatformTest.test_mac_ver_with_forkc          	   C   s.   t  ¡  t  ddt¡ t ¡ }W d Q R X d S )NÚignorez?dist\(\) and linux_distribution\(\) functions are deprecated .*)ÚwarningsÚcatch_warningsÚfilterwarningsÚDeprecationWarningr   Údist)r   r   r   r   r	   Ú	test_dist  s    
zPlatformTest.test_distc          	   C   sÀ   t j tj¡r,t j tjd ¡r,tjd }n2tjdkrXt j tj¡sXdd l}| d¡}ntj}t 	|¡}|  
tjtj¡ ttjdƒ}| dd ¡ | d¡ W d Q R X |  t 	tj¡d¡ d S )	Nz.exer   r   Úwbó   xiö?  s"   GLIBC_1.23.4 GLIBC_1.9 GLIBC_1.21 )Zglibcz1.23.4)r   r%   Úisdirr   r'   r&   r   r(   r)   Zlibc_verZ
addCleanupr   Úunlinkr,   ÚopenÚwriter1   )r   r'   r(   r   Úfr   r   r	   Útest_libc_ver  s    
zPlatformTest.test_libc_verc             C   s|  ddl m} |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|d	ƒ¡ |  |dƒ|d
ƒ¡ |  |d	ƒ|dƒ¡ |  |d
ƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ |  |d ƒ|d!ƒ¡ |  |d"ƒ|d#ƒ¡ |  |d"ƒ|d ƒ¡ |  |d!ƒ|d#ƒ¡ |  |d ƒ|d#ƒ¡ |  |d$ƒ|d%ƒ¡ |  |d&ƒ|d'ƒ¡ |  |d(ƒ|d)ƒ¡ d S )*Nr   )Ú_comparable_versionz1.2.3z1.2.10z1.2.3.4z1_2-3+4z1.2spamz1.2devz1.2alphaz1.2az1.2betaz1.2bz1.2cz1.2RCz1.2rcz1.2.0z1.2plz1.2pz1.5.1z1.5.2b2z3.10aZ161z8.02z3.4jz
1996.07.12z3.1.1.6z3.2.pl0Z2g6Z11gz0.9z2.2z1.2z1.2.1z1.1z1.2.2z0.4z0.4.0z1.13++z5.5.kwz0.960923z	2.2beta29)r   r“   r1   Z
assertLess)r   ÚVr   r   r	   Útest__comparable_version2  s@    z%PlatformTest.test__comparable_versionc             C   s(   x"dD ]\}}|   t |¡|¡ qW d S )N)
)zSuSE Linux 9.3 (x86-64))zSuSE Linux z9.3zx86-64)zSUSE LINUX 10.1 (X86-64))zSUSE LINUX z10.1zX86-64)zSUSE LINUX 10.1 (i586))zSUSE LINUX z10.1Zi586)z Fedora Core release 5 (Bordeaux))zFedora CoreÚ5ZBordeaux)z"Red Hat Linux release 8.0 (Psyche))zRed Hat Linuxz8.0ZPsyche)z Red Hat Linux release 9 (Shrike))zRed Hat LinuxÚ9ZShrike)z+Red Hat Enterprise Linux release 4 (Nahant))zRed Hat Enterprise LinuxÚ4ZNahant)zCentOS release 4)ZCentOSr˜   N)zRocks release 4.2.1 (Cydonia))ZRocksz4.2.1ZCydonia)r   )r   r   r   )r1   r   Z_parse_release_file)r   r]   r^   r   r   r	   Útest_parse_release_fileV  s    z$PlatformTest.test_parse_release_filec       	   
   C   s  t jdk}|rd t j¡}nd t j¡}t ¡ H t dt¡ t |¡&}| 	¡  
¡ }| ¡  |  |d¡ W d Q R X W d Q R X d}|rŒd}nd}| t j¡}t ¡ n t dt¡ t |d	¡J}| |¡}| ¡ }|  |¡ tjd
krì|}n|d? }|  |t|ƒ¡ W d Q R X W d Q R X d S )Nr   z"{}" -c "print('Hello')"z'{}' -c 'print("Hello")'r„   ZHelloZplopz<"{}" -c "import sys; data=sys.stdin.read(); exit(len(data))"z<'{}' -c 'import sys; data=sys.stdin.read(); exit(len(data))'ÚwÚnté   )r   r   r    r'   r…   r†   Úsimplefilterrˆ   rs   Úreadru   rw   r1   r   ZassertIsNotNoner   r_   rx   )	r   Z	mswindowsZcommandr   ZhelloÚdataÚstdinÚretr   r   r   r	   Ú
test_popeng  s2    

 



zPlatformTest.test_popenc             C   s¶   t  ¡ ¤}tj |d¡}t|ddd}| d¡ W d Q R X t d|¡B t	 
¡ " t	 ddt¡ t ¡ \}}}W d Q R X |  |d	¡ W d Q R X |  |d
¡ |  |d¡ W d Q R X d S )Nzfedora-releaserš   zutf-8)Úencodingu)   Fedora release 19 (SchrÃ¶dingerâ€™s Cat)
zplatform._UNIXCONFDIRr„   z?dist\(\) and linux_distribution\(\) functions are deprecated .*ZFedoraZ19u   SchrÃ¶dingerâ€™s Cat)ÚtempfileZTemporaryDirectoryr   r%   Újoinr   r   r   Zpatchr…   r†   r‡   rˆ   r   Úlinux_distributionr1   )r   ZtempdirÚfilenamer‘   Zdistnamer=   Zdistidr   r   r	   Ú test_linux_distribution_encoding‡  s    

z-PlatformTest.test_linux_distribution_encodingN)$Ú__name__Ú
__module__Ú__qualname__r
   r   Zskip_unless_symlinkr5   r6   r8   r:   r<   r>   r@   rB   rG   rH   rb   rc   rg   ÚunittestZ
skipUnlessr   r   rt   ri   rl   rm   r|   rƒ   rŠ   r’   Zcpython_onlyr•   r™   r¢   r¨   r   r   r   r	   r      s2   )W
!
$ r   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚDeprecationTestc          	   C   s4   |   t¡}t ¡  W d Q R X |  t|jƒd¡ d S )NzFdist() and linux_distribution() functions are deprecated in Python 3.5)ÚassertWarnsrˆ   r   r‰   r1   ÚstrÚwarning)r   Úcmr   r   r	   Útest_dist_deprecationŸ  s    z%DeprecationTest.test_dist_deprecationc          	   C   s4   |   t¡}t ¡  W d Q R X |  t|jƒd¡ d S )NzFdist() and linux_distribution() functions are deprecated in Python 3.5)r®   rˆ   r   r¦   r1   r¯   r°   )r   r±   r   r   r	   Ú#test_linux_distribution_deprecation¦  s    z3DeprecationTest.test_linux_distribution_deprecationN)r©   rª   r«   r²   r³   r   r   r   r	   r­     s   r­   Ú__main__)r¬   r   r   r   r   r   r/   r¤   r…   Ztestr   ZTestCaser   r­   r©   Úmainr   r   r   r	   Ú<module>   s       