B
    u9a‡' ã            	   @   sè  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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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 yd dlZW n ek
rø   dZY nX yd dlZW n ek
r    dZY nX yd dlZW n ek
rH   dZY nX yFd dlZdd„ e  ¡ D ƒZ!e"edƒrŽe #¡ Z$e$e!krŽe! %e$¡ W n ek
rª   g Z!Y nX yd dl&Z&dd„ e& '¡ D ƒZ(W n ee)fk
rè   g Z(Y nX yd dl*m+Z+m,Z, W n  ek
r   ej- Z+Z,Y nX d dl.m/Z/ d d	l0m1Z1m2Z2 d
Z3e"edƒrXe 4¡ d kZ3e"edƒr~ej5j6r~ej5j6 7d¡Z8nd
Z8ej9 7d¡oše #¡ d kZ:dd„ Z;d—dd„Z<G dd„ dej=ƒZ>G dd„ dej=ƒZ?G dd„ dej=ƒZ@d dlmAZA G dd„ deAjBƒZCG dd„ dej=ƒZDe Ee"edƒd ¡G d!d"„ d"eDƒƒZFG d#d$„ d$eDƒZGe Ee"edƒd ¡G d%d&„ d&eFƒƒZHG d'd(„ d(ej=ƒZIe Ee"ed)ƒd*¡G d+d,„ d,ej=ƒƒZJG d-d.„ d.ej=ƒZKG d/d0„ d0ej=ƒZLG d1d2„ d2ej=ƒZMe Ee"ed3ƒd4¡G d5d6„ d6ej=ƒƒZNe Od7¡d8kp$e Od9¡d8kp$e Od:¡d8kZPe QePd;¡G d<d=„ d=ej=ƒƒZRejSd˜d>d?„ƒZTG d@dA„ dAej=ƒZUe Eej9dBkdC¡G dDdE„ dEej=ƒƒZVG dFdG„ dGej=ƒZWG dHdI„ dIej=ƒZXe Qej9dBkdJ¡G dKdL„ dLej=ƒƒZYe Qej9dBkdJ¡G dMdN„ dNej=ƒƒZZe Eej9dBkdC¡G dOdP„ dPej=ƒƒZ[e Eej9dBkdC¡G dQdR„ dRej=ƒƒZ\e Eej9dBkdC¡ej]G dSdT„ dTej=ƒƒƒZ^e Eej9dBkdC¡G dUdV„ dVej=ƒƒZ_e Eej9dBkdC¡G dWdX„ dXej=ƒƒZ`ej]G dYdZ„ dZej=ƒƒZaG d[d\„ d\ej=ƒZbG d]d^„ d^ej=ƒZcG d_d`„ d`ej=ƒZdG dadb„ dbej=ƒZee fdc¡e Ee"eddƒde¡G dfdg„ dgej=ƒƒƒZge Ee"edhƒoVe"ediƒdj¡G dkdl„ dlej=ƒƒZhG dmdn„ dnejiejjƒZke Ee"edoƒdp¡G dqdr„ drej=ƒƒZldsdt„ Zme Eemƒ du¡e ndvdwdx¡G dydz„ dzej=ƒƒƒZoe Ee"ed{ƒd|¡G d}d~„ d~ej=ƒƒZpG dd€„ d€ej=ƒZqG dd‚„ d‚ej=ƒZrG dƒd„„ d„ej=ƒZsG d…d†„ d†ej=ƒZte Ee"ed‡ƒdˆ¡G d‰dŠ„ dŠej=ƒƒZuG d‹dŒ„ dŒej=ƒZvG ddŽ„ dŽej=ƒZwG dd„ dej=ƒZxG d‘d’„ d’ej=ƒZye"ed“ƒrÒG d”d•„ d•exƒZze{d–kräe |¡  dS )™é    N)Úsupportc             C   s    g | ]}t  ¡ |jkr|j‘qS © )ÚgetpassZgetuserZgr_memZgr_gid)Ú.0Úgr   r   ú/usr/lib/python3.7/test_os.pyú
<listcomp>.   s    r   Úgetgidc             C   s   g | ]
}|j ‘qS r   )Zpw_uid)r   Úur   r   r   r   7   s    )ÚINT_MAXÚPY_SSIZE_T_MAX)Úassert_python_ok)Ú
unix_shellÚFakePathFÚgeteuidÚthread_infoZlinuxthreadsZfreebsdc             C   s   t  tt| ƒd|  ¡S )Nzrequires os.%s)ÚunittestÚ
skipUnlessÚhasattrÚos)Únamer   r   r   Úrequires_os_funcT   s    r   ó   contentc          	   C   s&   t | ddƒ}| |¡ W d Q R X d S )NÚxbr   )ÚopenÚwrite)ÚfilenameZcontentÚfpr   r   r   Úcreate_fileX   s    r   c               @   sÂ   e Zd Zdd„ ZeZdd„ Zdd„ Zejdd„ ƒZ	d	d
„ Z
eje eek d¡ejed ddddd„ ƒƒƒZdd„ Zdd„ Ze ejdkd¡dd„ ƒZdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$S )%Ú	FileTestsc             C   s   t j tj¡rt  tj¡ d S )N)r   ÚpathÚlexistsr   ÚTESTFNÚunlink)Úselfr   r   r   ÚsetUp_   s    zFileTests.setUpc             C   s:   t  tjt jt jB ¡}t  |¡ |  t  tjt j	¡¡ d S )N)
r   r   r   r"   ÚO_CREATÚO_RDWRÚcloseÚ
assertTrueÚaccessÚW_OK)r$   Úfr   r   r   Útest_accessd   s    
zFileTests.test_accessc          	   C   s¢   t  tjt jt jB ¡}t  |¡}zNd}xD||d krjt  |¡ |d7 }|dkrX|  d¡ |t  |¡ }}q(W W d t  |¡ X t  	||d ¡ |  
tt j|d¡ d S )Nr   é   é
   z%couldn't allocate two consecutive fdsé   ó   a)r   r   r   r"   r&   r'   Údupr(   ÚskipTestÚ
closerangeÚassertRaisesÚOSErrorr   )r$   ÚfirstÚsecondZretriesr   r   r   Útest_closerangei   s    


zFileTests.test_closerangec             C   s<   t j}t |¡}|  ttj|d¡ t |¡}|  ||¡ d S )Nr   )	r   r"   ÚsysÚgetrefcountr5   Ú	TypeErrorr   ÚrenameÚassertEqual)r$   r    ÚoldÚnewr   r   r   Útest_rename~   s
    

zFileTests.test_renamec          	   C   sl   t tjdƒV}| d¡ | ¡  | ¡ }t |dd¡ t |d¡}|  	t
|ƒt¡ |  	|d¡ W d Q R X d S )Nzw+bs   spamr   é   )r   r   r"   r   ÚflushÚfilenor   ÚlseekÚreadr>   ÚtypeÚbytes)r$   ÚfobjÚfdÚsr   r   r   Ú	test_read†   s    
zFileTests.test_readzneeds INT_MAX < PY_SSIZE_T_MAXr/   r.   F)ÚsizeZmemuseZdry_runc          	   C   sT   |   tjtj¡ ttjdƒ ttjdƒ}t | ¡ |¡}W d Q R X |  	|d¡ d S )Ns   testÚrb)
Ú
addCleanupr   r#   r"   r   r   r   rF   rD   r>   )r$   rM   r   Údatar   r   r   Útest_large_read   s
    zFileTests.test_large_readc          	   C   s”   t  tjt jt jB ¡}|  tt j|d¡ t  |d¡ t  |t	dƒ¡ t  |t
dƒ¡ t  |¡ ttjdƒ }|  | ¡  ¡ dddg¡ W d Q R X d S )	NÚbeanss   bacon
s   eggs
s   spam
rN   s   bacons   eggss   spam)r   r   r   r"   r&   ÚO_WRONLYr5   r<   r   Ú	bytearrayÚ
memoryviewr(   r>   rF   Ú
splitlines)r$   rJ   rI   r   r   r   Ú
test_write£   s    
zFileTests.test_writec             G   s"   t j|t jdd}|  |d¡ d S )NT)ÚcreationflagsÚshellr   )Ú
subprocessZcallZCREATE_NEW_CONSOLEr>   )r$   ÚargsZretcoder   r   r   Úwrite_windows_console¯   s    zFileTests.write_windows_consoleÚwin32z$test specific to the Windows consolec             C   s*   d}|   tjd|¡ |   tjdd|¡ d S )Nzprint('x' * 100000)z-cz-u)r\   r:   Ú
executable)r$   Úcoder   r   r   Útest_write_windows_console·   s    z$FileTests.test_write_windows_consolec             G   s,   t  tjt j¡}t j|f|žŽ }| ¡  d S )N)r   r   r   r"   ÚO_RDONLYÚfdopenr(   )r$   r[   rJ   r,   r   r   r   Úfdopen_helperÂ   s    zFileTests.fdopen_helperc             C   sB   t  tjt jt jB ¡}t  |¡ |  ¡  |  d¡ |  dd¡ d S )NÚréd   )r   r   r   r"   r&   r'   r(   rc   )r$   rJ   r   r   r   Útest_fdopenÇ   s
    

zFileTests.test_fdopenc          	   C   sˆ   t jd }|  t jt j¡ |  t j|¡ tt jdƒ t|dƒ t t j|¡ |  ttj	t j¡ t
|dƒ}|  | ¡ d¡ W d Q R X d S )Nz.2ó   1ó   2rd   Ú1)r   r"   rO   r#   r   r   Úreplacer5   ÚFileNotFoundErrorÚstatr   r>   rF   )r$   ÚTESTFN2r,   r   r   r   Útest_replaceÏ   s    

zFileTests.test_replacec             C   s"   t jtt jdd d}t  |¡ d S )Niÿ  )r    ÚflagsÚmodeÚdir_fd)r   r   Ú__file__ra   r(   )r$   r,   r   r   r   Útest_open_keywordsÜ   s    zFileTests.test_open_keywordsc          	   C   s@   t  td¡}y|dt jdd d W n ttfk
r:   Y nX d S )NÚsymlinkÚtargetF)ÚsrcÚdstÚtarget_is_directoryrq   )r   Zget_attributer   r"   ÚNotImplementedErrorr6   )r$   rt   r   r   r   Útest_symlink_keywordsá   s    zFileTests.test_symlink_keywordsN)Ú__name__Ú
__module__Ú__qualname__r%   ÚtearDownr-   r9   r   Úcpython_onlyrA   rL   r   r   r   r   Z
bigmemtestrQ   rW   r\   r:   Úplatformr`   rc   rf   rn   rs   rz   r   r   r   r   r   ^   s&   

 
r   c               @   sü   e Zd Zdd„ Ze eedƒd¡dd„ ƒZdd„ Z	d	d
„ Z
dd„ Ze eedƒd¡dd„ ƒZe eedƒd¡dd„ ƒZe ejdkd¡dd„ ƒZe ejdkd¡e eedƒd¡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#S )$ÚStatAttributeTestsc             C   s(   t j| _|  t j| j¡ t| jdƒ d S )Ns   ABC)r   r"   ÚfnamerO   r#   r   )r$   r   r   r   r%   ì   s    zStatAttributeTests.setUprl   ztest needs os.stat()c       
   	   C   sú  t  |¡}|  |tj d¡ |  |jd¡ t|ƒ}xpttƒD ]d}|d d… dkr<| ¡ }| d¡rldd„ }ndd„ }|  |t||ƒƒ|tt|ƒ ¡ |  	||¡ q<W xDd 
¡ D ]8}tt||ƒd ƒ}t||d	 ƒd
 }| j||dd q®W y|d  |  d¡ W n tk
r   Y nX yd|_|  d¡ W n tk
rB   Y nX yd|_|  d¡ W n ttfk
rr   Y nX yd|_|  d¡ W n tk
rž   Y nX yt  d¡}	|  d¡ W n tk
rÎ   Y nX yt  d¡}	W n tk
rô   Y nX d S )Né   ZST_ZTIMEc             S   s   t | ƒS )N)Úint)Úxr   r   r   Útruncÿ   ó    z7StatAttributeTests.check_stat_attributes.<locals>.truncc             S   s   | S )Nr   )r…   r   r   r   r†     r‡   zst_atime st_mtime st_ctimei † Z_nsi'  r0   )ÚdeltaéÈ   zNo exception raisedr.   )r/   )r   r.   r0   rƒ   rB   é   é   é   é   é	   r/   é   é   é   é   )r   rl   r>   ÚST_SIZEÚst_sizeÚdirÚlowerÚendswithÚgetattrÚassertInÚsplitr„   ÚassertAlmostEqualÚfailÚ
IndexErrorÚst_modeÚAttributeErrorÚst_rdevr<   ÚparrotÚstat_result)
r$   r‚   ÚresultÚmembersr   Úattrr†   ZfloatyZnanosecondyÚresult2r   r   r   Úcheck_stat_attributesñ   s\    



z(StatAttributeTests.check_stat_attributesc             C   s   |   | j¡ d S )N)r§   r‚   )r$   r   r   r   Útest_stat_attributes3  s    z'StatAttributeTests.test_stat_attributesc             C   sH   y| j  t ¡ ¡}W n$ tk
r8   |  d| j  ¡ Y nX |  |¡ d S )Nz#cannot encode %a for the filesystem)r‚   Úencoder:   ÚgetfilesystemencodingÚUnicodeEncodeErrorr3   r§   )r$   r‚   r   r   r   Útest_stat_attributes_bytes6  s
    z-StatAttributeTests.test_stat_attributes_bytesc             C   sj   t  | j¡}xXttjd ƒD ]F}t ||¡}|  d|¡ |dk rL|  d|¡ t |¡}|  	||¡ qW d S )Nr.   s   stat_resultrB   s   cos
stat_result
)
r   rl   r‚   ÚrangeÚpickleÚHIGHEST_PROTOCOLÚdumpsr™   Úloadsr>   )r$   r£   ÚprotoÚpÚ	unpickledr   r   r   Útest_stat_result_pickle=  s    
z*StatAttributeTests.test_stat_result_pickleÚstatvfsztest needs os.statvfs()c             C   s   t  | j¡}|  |j|d ¡ d}x.t|ƒD ]"\}}|  t|d| ƒ|| ¡ q,W |  t|j	t
ƒ¡ |  t|ƒd¡ yd|_|  d¡ W n tk
rœ   Y nX yd|_|  d¡ W n tk
rÆ   Y nX yt  d¡}|  d¡ W n tk
rô   Y nX yt  d¡}W n tk
r   Y nX d S )	Nrƒ   )
ZbsizeZfrsizeZblocksZbfreeZbavailÚfilesZffreeZfavailÚflagZnamemaxZf_r/   r.   zNo exception raised)r/   )r   r.   r0   rƒ   rB   rŠ   r‹   rŒ   r   rŽ   r/   r   r   r‘   r’   )r   r¶   r‚   r>   Úf_bfreeÚ	enumerater˜   r)   Ú
isinstanceÚf_fsidr„   Úlenrœ   rŸ   r¡   Ústatvfs_resultr<   )r$   r£   r¤   ÚvalueÚmemberr¦   r   r   r   Útest_statvfs_attributesG  s4    
z*StatAttributeTests.test_statvfs_attributeszneed os.statvfs()c             C   sj   t  | j¡}xXttjd ƒD ]F}t ||¡}|  d|¡ |dk rL|  d|¡ t |¡}|  	||¡ qW d S )Nr.   s   statvfs_resultrB   s   cos
statvfs_result
)
r   r¶   r‚   r­   r®   r¯   r°   r™   r±   r>   )r$   r£   r²   r³   r´   r   r   r   Útest_statvfs_result_pickles  s    
z-StatAttributeTests.test_statvfs_result_pickler]   zWin32 specific testsc          
   C   s\   yt  d¡ W nH tk
r,   |  d¡ Y n, tk
rV } z|  d¡ W d d }~X Y nX d S )Nzc:\pagefile.syszc:\pagefile.sys does not existzCould not stat pagefile.sys)r   rl   rk   r3   r6   rœ   )r$   Úer   r   r   Útest_1686475€  s    zStatAttributeTests.test_1686475Úpipezrequires os.pipe()c          	   C   sh   t  ¡ \}}zt  |¡ W d t  |¡ t  |¡ X |  t¡}t  |¡ W d Q R X |  |jjtj	¡ d S )N)
r   rÅ   rl   r(   r5   r6   r>   Ú	exceptionÚerrnoÚEBADF)r$   rd   ÚwZctxr   r   r   Ú
test_15261Š  s    
zStatAttributeTests.test_15261c             C   sF   |   t|dƒ¡ |   t|jtƒ¡ |   d|j  ko:dkn  ¡ d S )NÚst_file_attributesr   l   ÿÿ )r)   r   r»   rË   r„   )r$   r£   r   r   r   Úcheck_file_attributes˜  s    z(StatAttributeTests.check_file_attributesz$st_file_attributes is Win32 specificc             C   sz   t  | j¡}|  |¡ |  |jtj@ d¡ tjd }t  	|¡ |  
t j|¡ t  |¡}|  |¡ |  |jtj@ tj¡ d S )Nr   r•   )r   rl   r‚   rÌ   r>   rË   ÚFILE_ATTRIBUTE_DIRECTORYr   r"   ÚmkdirrO   Úrmdir)r$   r£   Údirnamer   r   r   Útest_file_attributes  s    






z'StatAttributeTests.test_file_attributesc             C   sd   t j t jd | j¡}|  tj|¡ t|dƒ d}t	j
d|ddg|d t  |¡}|  |jd¡ d S )	NZTEMPs   ABCr   z
icacls.exez/denyz*S-1-5-32-545:(S))rX   r   )r   r    ÚjoinÚenvironr‚   rO   r   r#   r   rZ   Ú
check_callrl   ÚassertNotEqualr”   )r$   r‚   ZDETACHED_PROCESSr£   r   r   r   Útest_access_denied²  s    


z%StatAttributeTests.test_access_deniedN)r{   r|   r}   r%   r   r   r   r   r§   r¨   r¬   rµ   rÁ   rÂ   r:   r€   rÄ   rÊ   rÌ   rÑ   rÖ   r   r   r   r   r   ë   s   B
,
r   c               @   sä   e Zd Zdd„ Zdd„ Zd)dd„Zdd	„ Zed
d„ ƒZdd„ Z	dd„ Z
e ejejkd¡dd„ ƒZe ejejkd¡dd„ ƒZe ejejkd¡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jd'd(„ ƒZdS )*Ú
UtimeTestsc             C   sD   t j| _tj | jd¡| _|  t j| j¡ t 	| j¡ t
| jƒ d S )NÚf1)r   r"   rÐ   r   r    rÒ   r‚   rO   ÚrmtreerÎ   r   )r$   r   r   r   r%   É  s
    zUtimeTests.setUpc             C   s4   t  |¡}|j|d kp2|j|d kp2|j|d kS )NrŒ   r   rŽ   )r   rl   Úst_atimeÚst_mtimeÚst_ctime)r$   r   Ústr   r   r   Úsupport_subsecondÑ  s    
zUtimeTests.support_subsecondNc             C   s¸   |s
| j }|  |¡}|r"d}d}nd}d}||||fƒ t |¡}|rt| j|j|d dd | j|j|d dd n$|  |j|d ¡ |  |j|d ¡ |  |j|¡ |  |j	|¡ d S )Ni8Z¹;l   °
o] l    rT l    P¬9 g•Ö&è.>gíµ ÷Æ°>)rˆ   )
r‚   rÞ   r   rl   r›   rÚ   rÛ   r>   Úst_atime_nsÚst_mtime_ns)r$   Úset_timer   rÞ   Úatime_nsÚmtime_nsrÝ   r   r   r   Ú_test_utimeÙ  s"    

zUtimeTests._test_utimec             C   s   dd„ }|   |¡ d S )Nc             S   s   t j| |d d S )N)Úns)r   Úutime)r   rå   r   r   r   rá   ù  s    z'UtimeTests.test_utime.<locals>.set_time)rä   )r$   rá   r   r   r   Ú
test_utimeø  s    zUtimeTests.test_utimec             C   s   | d d S )Ng•Ö&è.>g•Ö&è.>r   )rå   r   r   r   Ú	ns_to_secþ  s    zUtimeTests.ns_to_secc                s   ‡ fdd„}ˆ   |¡ d S )Nc                s0   |\}}ˆ   |¡}ˆ   |¡}t | ||f¡ d S )N)rè   r   ræ   )r   rå   râ   rã   ÚatimeÚmtime)r$   r   r   rá     s    

z2UtimeTests.test_utime_by_indexed.<locals>.set_time)rä   )r$   rá   r   )r$   r   Útest_utime_by_indexed  s    z UtimeTests.test_utime_by_indexedc                s   ‡ fdd„}ˆ   |¡ d S )Nc                s2   |\}}ˆ   |¡}ˆ   |¡}tj| ||fd d S )N)Útimes)rè   r   ræ   )r   rå   râ   rã   ré   rê   )r$   r   r   rá     s    

z0UtimeTests.test_utime_by_times.<locals>.set_time)rä   )r$   rá   r   )r$   r   Útest_utime_by_times  s    zUtimeTests.test_utime_by_timesz9follow_symlinks support for utime required for this test.c             C   s   dd„ }|   |¡ d S )Nc             S   s   t j| |dd d S )NF)rå   Úfollow_symlinks)r   ræ   )r   rå   r   r   r   rá     s    z9UtimeTests.test_utime_nofollow_symlinks.<locals>.set_time)rä   )r$   rá   r   r   r   Útest_utime_nofollow_symlinks  s    z'UtimeTests.test_utime_nofollow_symlinksz,fd support for utime required for this test.c             C   s   dd„ }|   |¡ d S )Nc          	   S   s.   t | ddƒ}tj| ¡ |d W d Q R X d S )NÚwbr   )rå   )r   r   ræ   rD   )r   rå   r   r   r   r   rá   &  s    z*UtimeTests.test_utime_fd.<locals>.set_time)rä   )r$   rá   r   r   r   Útest_utime_fd#  s    zUtimeTests.test_utime_fdz0dir_fd support for utime required for this test.c             C   s   dd„ }|   |¡ d S )Nc          	   S   sD   t j | ¡\}}t  |t j¡}zt j|||d W d t  |¡ X d S )N)rq   rå   )r   r    rš   r   ra   ræ   r(   )r   rå   rÐ   r   Údirfdr   r   r   rá   0  s
    z.UtimeTests.test_utime_dir_fd.<locals>.set_time)rä   )r$   rá   r   r   r   Útest_utime_dir_fd-  s    zUtimeTests.test_utime_dir_fdc             C   s   dd„ }| j || jd d S )Nc             S   s   t j| |d d S )N)rå   )r   ræ   )r   rå   r   r   r   rá   ;  s    z1UtimeTests.test_utime_directory.<locals>.set_time)r   )rä   rÐ   )r$   rá   r   r   r   Útest_utime_directory:  s    zUtimeTests.test_utime_directoryc             C   sb   t   ¡ }|| jƒ |  | j¡s$d}nd}t | j¡}d|j||j| f }| j|j|||d d S )Ng      ð?gš™™™™™©?zst_time=%r, current=%r, dt=%r)rˆ   Úmsg)Útimer‚   rÞ   r   rl   rÛ   r›   )r$   rá   Zcurrentrˆ   rÝ   rõ   r   r   r   Ú_test_utime_current@  s    

zUtimeTests._test_utime_currentc                s   ‡ fdd„}ˆ   |¡ d S )Nc                s   t  ˆ j¡ d S )N)r   ræ   r‚   )r   )r$   r   r   rá   W  s    z/UtimeTests.test_utime_current.<locals>.set_time)r÷   )r$   rá   r   )r$   r   Útest_utime_currentV  s    zUtimeTests.test_utime_currentc                s   ‡ fdd„}ˆ   |¡ d S )Nc                s   t  ˆ jd ¡ d S )N)r   ræ   r‚   )r   )r$   r   r   rá   ]  s    z3UtimeTests.test_utime_current_old.<locals>.set_time)r÷   )r$   rá   r   )r$   r   Útest_utime_current_old\  s    z!UtimeTests.test_utime_current_oldc             C   sl   t jdkrhtj tj |¡¡d d }dd l}|jj}| 	dd¡}| 
|d dd d d |t|ƒ¡}|rh|jS d S )Nr]   r   ú\Ú re   )r:   r€   r   r    Ú
splitdriveÚabspathÚctypesÚwindllÚkernel32Zcreate_unicode_bufferZGetVolumeInformationWr½   r¿   )r$   r    Úrootrþ   r   ÚbufÚokr   r   r   Úget_file_systemb  s    

zUtimeTests.get_file_systemc             C   sJ   |   | j¡dkr|  d¡ d}t | j||f¡ |  t | j¡j|¡ d S )NZNTFSzrequires NTFSl    rT )	r  rÐ   r3   r   ræ   r‚   r>   rl   rÛ   )r$   Zlarger   r   r   Útest_large_timeo  s
    
zUtimeTests.test_large_timec          
   C   sÌ  |   t¡ tj| jddd W d Q R X |   t¡ t | jddg¡ W d Q R X |   t¡ t | jd¡ W d Q R X |   t¡ t | jd¡ W d Q R X |   t¡ tj| jddgd W d Q R X |   t¡ tj| jdd W d Q R X |   t¡ tj| jdd W d Q R X tjtjkrD|   t¡ tj| jddd W d Q R X tjtjkr’t	| jdd	ƒ,}|   t¡ t | 
¡ d¡ W d Q R X W d Q R X tjtjkrÈ|   t¡ tj| jdd	d
 W d Q R X d S )N)rŠ   rŠ   )rå   rŠ   )rŠ   )rŠ   rŠ   rŠ   F)rî   rð   r   )rq   )r5   Ú
ValueErrorr   ræ   r‚   r<   Úsupports_follow_symlinksry   Úsupports_fdr   rD   Úsupports_dir_fd)r$   r   r   r   r   Útest_utime_invalid_argumentsy  s0    $z'UtimeTests.test_utime_invalid_argumentsc          	   C   s–   dd„ }|   t¡ tj| j|dƒdfd W d Q R X |   t¡ tj| j|dƒdfd W d Q R X |   t¡ tj| j|dƒdfd W d Q R X d S )Nc                s   G ‡ fdd„dƒ}|ƒ S )Nc                   s   e Zd Z‡ fdd„ZdS )z?UtimeTests.test_issue31577.<locals>.get_bad_int.<locals>.BadIntc                 s   ˆ S )Nr   )r[   )Údivmod_ret_valr   r   Ú
__divmod__›  s    zJUtimeTests.test_issue31577.<locals>.get_bad_int.<locals>.BadInt.__divmod__N)r{   r|   r}   r  r   )r  r   r   ÚBadIntš  s   r  r   )r  r  r   )r  r   Úget_bad_int™  s    z/UtimeTests.test_issue31577.<locals>.get_bad_inté*   r.   )rå   r   )r.   r0   rƒ   )r5   r<   r   ræ   r‚   )r$   r  r   r   r   Útest_issue31577•  s    ""zUtimeTests.test_issue31577)N)r{   r|   r}   r%   rÞ   rä   rç   Ústaticmethodrè   rë   rí   r   r   r   ræ   r  rï   r  rñ   r	  ró   rô   r÷   rø   rù   r  r  r
  r   r   r  r   r   r   r   r×   È  s*   
			
r×   )Úmapping_testsc               @   sâ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Ze 	e
o>ej e
¡d
¡dd„ ƒZe 	e
o^ej e
¡d
¡dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Ze 	ejd¡dd„ ƒZe dd¡dd„ ƒZdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ ZdS )(ÚEnvironTestsNc             C   sF   t tjƒ| _tjrt tjƒ| _x"|  ¡  ¡ D ]\}}|tj|< q,W d S )N)	Údictr   rÓ   Ú_EnvironTests__saveÚsupports_bytes_environÚenvironbÚ_EnvironTests__savebÚ
_referenceÚitems)r$   Úkeyr¿   r   r   r   r%   ¬  s
    zEnvironTests.setUpc             C   s:   t j ¡  t j | j¡ t jr6t j ¡  t j | j¡ d S )N)r   rÓ   ÚclearÚupdater  r  r  r  )r$   r   r   r   r~   ³  s
    

zEnvironTests.tearDownc             C   s   ddddœS )NZVALUE1ZVALUE2ZVALUE3)ZKEY1ZKEY2ZKEY3r   )r$   r   r   r   r  º  s    zEnvironTests._referencec             C   s   t j ¡  t jS )N)r   rÓ   r  )r$   r   r   r   Ú_empty_mapping½  s    
zEnvironTests._empty_mappingzrequires a shellc          	   C   sN   t j ¡  t jjdd t  dt ¡}| ¡  ¡ }|  |d¡ W d Q R X d S )NZWorld)ZHELLOz%s -c 'echo $HELLO')	r   rÓ   r  r  Úpopenr   rF   Ústripr>   )r$   r  r¿   r   r   r   Útest_update2Â  s
    
zEnvironTests.test_update2c          	   C   sd   t  dt ¡L}t|ƒ}|  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  tt|¡ W d Q R X d S )Nz %s -c 'echo "line1
line2
line3"'zline1
zline2
zline3
)r   r  r   Úiterr>   Únextr5   ÚStopIteration)r$   r  Úitr   r   r   Útest_os_popen_iterË  s    
zEnvironTests.test_os_popen_iterc             C   s<   x6t j ¡ D ](\}}|  t|ƒt¡ |  t|ƒt¡ qW d S )N)r   rÓ   r  r>   rG   Ústr)r$   r  Úvalr   r   r   Útest_keyvalue_typesØ  s    z EnvironTests.test_keyvalue_typesc             C   s2   x,|   ¡  ¡ D ]\}}|  tj |¡|¡ qW d S )N)r  r  r>   r   rÓ   Úget)r$   r  r¿   r   r   r   Ú
test_itemsÝ  s    zEnvironTests.test_itemsc          
   C   s4   t j}|  t|ƒd d dd„ | ¡ D ƒ¡¡¡ d S )Nzenviron({{{}}})z, c             s   s   | ]\}}d   ||¡V  qdS )z
{!r}: {!r}N)Úformat)r   r  r¿   r   r   r   ú	<genexpr>æ  s   z-EnvironTests.test___repr__.<locals>.<genexpr>)r   rÓ   r>   Úreprr,  rÒ   r  )r$   Úenvr   r   r   Útest___repr__â  s    zEnvironTests.test___repr__c          	   C   sF  t j t j¡}ddddg}dt j |¡i}t j}z2t|ƒt _|  |t  ¡ ¡ |  |t jd d¡ W d |t _X |  |t  i ¡¡ |  dt  ddi¡¡ |  |t  |¡¡ t j	rBy&t
jdd	 d
ddœ}W d Q R X W n tk
rè   Y nX |  tt j|¡ |  t  ddi¡dg¡ |  t  ddi¡dg¡ |  t  ddi¡dg¡ d S )Nz/montyz/pythonrû   z/flying/circusÚPATH)r/  )rû   T)Úrecordri   rh   )r1  s   PATHs   PATHs   abcÚabc)r   Údefpathrš   ÚpathseprÒ   rÓ   r  ÚassertSequenceEqualÚget_exec_pathr  ÚwarningsÚcatch_warningsÚBytesWarningr5   r  )r$   Zdefpath_listZ	test_pathZtest_envZsaved_environZ	mixed_envr   r   r   Útest_get_exec_pathé  s2    
zEnvironTests.test_get_exec_pathz#os.environb required for this test.c             C   sº   d}y|  t ¡ d¡}W n, tk
rD   dt ¡ f }|  |¡ Y nX |tjd< |  tjd |¡ |  tjd |¡ d}|tjd< |  tjd |¡ | 	t ¡ d¡}|  tjd |¡ d S )	Nu   euroâ‚¬Úsurrogateescapez'U+20AC character is not encodable to %sZunicodes   unicodeó   ÿs   bytesrH   )
r©   r:   rª   r«   r3   r   rÓ   r>   r  Údecode)r$   r¿   Zvalue_bytesrõ   Z	value_strr   r   r   Útest_environb  s     



zEnvironTests.test_environbr/   r‹   c             C   s@   t jdkr&dd }|  ttjj|¡ nd}|  ttjj|¡ d S )Nr]   r…   iPÃ  zkey=)r:   r€   r5   r  r   rÓ   Ú__delitem__r6   )r$   r  r   r   r   Útest_unset_error*  s
    
zEnvironTests.test_unset_errorc          	   C   s˜   d}|   |tj¡ |  t¡}tj|  W d Q R X |  |jjd |¡ |  |jj	¡ |  t¡}tj|= W d Q R X |  |jjd |¡ |  |jj	¡ d S )NZ
missingkeyr   )
ÚassertNotInr   rÓ   r5   ÚKeyErrorÚassertIsrÆ   r[   r)   Ú__suppress_context__)r$   ÚmissingÚcmr   r   r   Útest_key_type5  s    zEnvironTests.test_key_typec             C   sL   t |ƒ}d}t|ƒ dtj|< zt|ƒ |  tj| d¡ W d tj|= X d S )NZ__new_key__Ztest_environ_iteration)r"  r#  r   rÓ   r>   )r$   Z
collectionÚiteratorZnew_keyr   r   r   Ú_test_environ_iterationC  s    
z$EnvironTests._test_environ_iterationc             C   s   |   tj¡ d S )N)rJ  r   rÓ   )r$   r   r   r   Ú(test_iter_error_when_changing_os_environR  s    z5EnvironTests.test_iter_error_when_changing_os_environc             C   s   |   tj ¡ ¡ d S )N)rJ  r   rÓ   r  )r$   r   r   r   Ú.test_iter_error_when_changing_os_environ_itemsU  s    z;EnvironTests.test_iter_error_when_changing_os_environ_itemsc             C   s   |   tj ¡ ¡ d S )N)rJ  r   rÓ   Úvalues)r$   r   r   r   Ú/test_iter_error_when_changing_os_environ_valuesX  s    z<EnvironTests.test_iter_error_when_changing_os_environ_values)r{   r|   r}   Z	type2testr%   r~   r  r  r   r   r   r   r    Úexistsr!  r&  r)  r+  r0  r;  r  r?  r   Zrequires_mac_verrA  rH  rJ  rK  rL  rN  r   r   r   r   r  ¨  s*   )r  c               @   sN   e Zd Zdd„ Zdd„ Zdd„ Zddd	„Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dS )Ú	WalkTestsc             K   s$   d|kr|  d¡|d< tj|f|ŽS )Nrî   Úfollowlinks)Úpopr   Úwalk)r$   ÚtopÚkwargsr   r   r   rS  a  s    zWalkTests.walkc          
   C   s.  t jj}|  tjtj¡ |tjdƒ| _|| jdƒ| _|| jdƒ| _	|| jdƒ}||dƒ}|| jdƒ}|| jdƒ}||dƒ}||dƒ}||d	ƒ| _
|tjd
ƒ}|tjd
dƒ}	||dƒ}
||dƒ}||dƒ}t  | j	¡ t  |¡ t  |¡ t  |¡ x@||||	|fD ].}t|dƒ}| d| d ¡ W d Q R X qW t ¡ r¤t  t j |¡| j
¡ t  d|
d¡ t  |ddƒ|d¡ t  |ddƒ|d¡ |dd	gddddgf| _n|dgdgf| _t  |d¡ yt  |¡ W n( tk
rö   |  t j|tj¡ Y n4X t  |tj¡ t  |¡ t  |¡ | jd d d…= d S )NZTEST1ÚSUB1ÚSUB11ÚSUB2ZSUB21Útmp1Útmp2Ztmp3ÚlinkZTEST2Útmp4Zbroken_linkZbroken_link2Zbroken_link3r…   zI'm z" and proud of it.  Blame test_os.
ZbrokenTZtmp5r   r.   )r   r    rÒ   rO   r   rÙ   r"   Ú	walk_pathÚ	sub1_pathÚ
sub11_pathÚ	link_pathÚmakedirsr   r   Úcan_symlinkrt   rý   Ú	sub2_treeÚchmodÚlistdirÚPermissionErrorrl   ÚS_IRWXUr#   rÏ   )r$   rÒ   Z	sub2_pathZ
sub21_pathZ	tmp1_pathZ	tmp2_pathZ	tmp3_pathZ	tmp5_pathZt2_pathZ	tmp4_pathZbroken_link_pathZbroken_link2_pathZbroken_link3_pathr    r,   r   r   r   r%   f  sT    








"


zWalkTests.setUpc             C   sì   t |  | j¡ƒ}|  t|ƒd¡ |d d d dk}|d d  ¡  |dd|   d  ¡  |dd|   d  ¡  |  |d | jddgd	gf¡ |  |d|  | jd
gdgf¡ |  |d|  | jg g f¡ |  |dd|   | j¡ d S )NrB   r   r.   rV  rƒ   r0   éÿÿÿÿrX  rY  rW  rZ  )	ÚlistrS  r]  r>   r½   Úsortr^  r_  rc  )r$   ÚallÚflippedr   r   r   Útest_walk_topdown«  s     zWalkTests.test_walk_topdownNc             C   s°   |d kr| j }g }x:|  |¡D ],\}}}| |||f¡ d|kr| d¡ qW |  t|ƒd¡ |  |d | j dgdgf¡ |d d  ¡  |d d  ¡  |  |d | j¡ d S )NrV  r0   r   rX  rY  r.   rh  )r]  rS  ÚappendÚremover>   r½   rj  rc  )r$   r]  rk  r  Údirsr·   r   r   r   Útest_walk_prune¼  s    zWalkTests.test_walk_prunec             C   s   |   t| jƒ¡ d S )N)rq  r   r]  )r$   r   r   r   Útest_file_like_pathÏ  s    zWalkTests.test_file_like_pathc             C   sî   t | j| jddƒ}|  t|ƒd|¡ |d d d dk}|d d  ¡  |dd|   d	  ¡  |dd|   d  ¡  |  |d | jdd
gdgf¡ |  || | jg g f¡ |  ||d  | jdgdgf¡ |  |dd|   | j¡ d S )NF)ÚtopdownrB   rƒ   r.   r   rV  r0   rh  rX  rY  rW  rZ  )	ri  rS  r]  r>   r½   rj  r_  r^  rc  )r$   rk  rl  r   r   r   Útest_walk_bottom_upÒ  s    

zWalkTests.test_walk_bottom_upc             C   sj   t  ¡ s|  d¡ | j| jdd}xB|D ]0\}}}|| jkr(|  |g ¡ |  |dg¡ P q(W |  d¡ d S )Nzneed symlink supportT)rî   r\  z+Didn't follow symlink with followlinks=True)r   rb  r3   rS  r]  r`  r>   rœ   )r$   Úwalk_itr  rp  r·   r   r   r   Útest_walk_symlinkç  s    

zWalkTests.test_walk_symlinkc          
   C   sÔ   g }| j | j|jd}t|ƒ\}}}|  |g ¡ d}tj ||¡}tj ||d ¡}t ||¡ z`dd„ |D ƒ}	|  	|¡ |  
||	¡ |  
||	¡ x*|D ]"}
|
|kr˜|  tj ||
¡|	¡ q˜W W d t ||¡ X d S )N)ÚonerrorrV  z.newc             S   s   g | ]\}}}|‘qS r   r   )r   rd   Údr,   r   r   r   r      s    z/WalkTests.test_walk_bad_dir.<locals>.<listcomp>)rS  r]  rn  r#  r>   r   r    rÒ   r=   r)   rB  r™   )r$   Úerrorsru  r  rp  r·   Údir1Zpath1Zpath1newÚrootsÚdir2r   r   r   Útest_walk_bad_dirõ  s"    

zWalkTests.test_walk_bad_dir)N)r{   r|   r}   rS  r%   rm  rq  rr  rt  rv  r}  r   r   r   r   rP  \  s   E
rP  ÚfwalkzTest needs os.fwalk()c               @   sD   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S )Ú
FwalkTestsc             k   s0   x*| j |f|ŽD ]\}}}}|||fV  qW d S )N)r~  )r$   rT  rU  r  rp  r·   Zroot_fdr   r   r   rS    s    zFwalkTests.walkc             O   s   t j||ŽS )N)r   r~  )r$   r[   rU  r   r   r   r~    s    zFwalkTests.fwalkc       
      C   sÆ   |  ¡ }|  ¡ }x°tjdddD ]ž\}}|j||d |j||d i }x.tjf |ŽD ]\}}}t|ƒt|ƒf||< qVW xD| jf |ŽD ]4\}}}}	|  ||¡ |  	|| t|ƒt|ƒf¡ q†W q W d S )N)TFr0   )Úrepeat)rs  rQ  )rs  rî   )
ÚcopyÚ	itertoolsÚproductr  r   rS  Úsetr~  r™   r>   )
r$   Úwalk_kwargsÚfwalk_kwargsrs  rî   Úexpectedr  rp  r·   Úrootfdr   r   r   Ú_compare_to_walk  s    zFwalkTests._compare_to_walkc             C   s   dt ji}|  ||¡ d S )NrT  )r   r"   r‰  )r$   rU  r   r   r   Útest_compare_to_walk(  s    
zFwalkTests.test_compare_to_walkc          	   C   sJ   z8t  dt j¡}dtji}| ¡ }||d< |  ||¡ W d t  |¡ X d S )NÚ.rT  rq   )r   r   ra   r   r"   r  r‰  r(   )r$   rJ   r…  r†  r   r   r   Útest_dir_fd,  s    
zFwalkTests.test_dir_fdc             C   s„   x~t jdddD ]l\}}tj|d f}xV| j|d|iŽD ]B\}}}}t |¡ t |¡ |  t	t 
|¡ƒt	|ƒt	|ƒB ¡ q6W qW d S )N)TFr0   )r€  rî   )r‚  rƒ  r   r"   r~  r   Úfstatrl   r>   r„  re  )r$   rs  rî   r[   r  rp  r·   rˆ  r   r   r   Útest_yields_correct_dir_fd6  s    

z%FwalkTests.test_yields_correct_dir_fdc             C   sd   t  d¡}t  |¡ x&tdƒD ]}x|  tj¡D ]}q0W qW t  d¡}|  t j|¡ |  ||¡ d S )Nr.   é   )	r   r2   r(   r­   r~  r   r"   rO   r>   )r$   ZminfdÚir…   Znewfdr   r   r   Útest_fd_leakB  s    


zFwalkTests.test_fd_leakN)
r{   r|   r}   rS  r~  r‰  rŠ  rŒ  rŽ  r‘  r   r   r   r   r    s   
r  c               @   s   e Zd Zdd„ ZdS )ÚBytesWalkTestsc       	      k   s¤   d|kr|  d¡|d< xˆtjt |¡f|ŽD ]p\}}}t |¡}tttj|ƒƒ}tttj|ƒƒ}|||fV  tttj|ƒƒ|d d …< tttj|ƒƒ|d d …< q,W d S )Nrî   rQ  )rR  r   rS  ÚfsencodeÚfsdecoderi  Úmap)	r$   rT  rU  ÚbrootÚbdirsÚbfilesr  rp  r·   r   r   r   rS  Q  s     
zBytesWalkTests.walkN)r{   r|   r}   rS  r   r   r   r   r’  O  s   r’  c               @   s   e Zd Zddd„ZdS )ÚBytesFwalkTestsr‹  c             o   s–   xt jt  |¡f|ž|ŽD ]t\}}}}t  |¡}ttt j|ƒƒ}	ttt j|ƒƒ}
||	|
|fV  ttt j|	ƒƒ|d d …< ttt j|
ƒƒ|d d …< qW d S )N)r   r~  r“  r”  ri  r•  )r$   rT  r[   rU  r–  r—  r˜  Útopfdr  rp  r·   r   r   r   r~  _  s    &
zBytesFwalkTests.fwalkN)r‹  )r{   r|   r}   r~  r   r   r   r   r™  \  s   r™  c               @   sD   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S )ÚMakedirTestsc             C   s   t  tj¡ d S )N)r   rÎ   r   r"   )r$   r   r   r   r%   j  s    zMakedirTests.setUpc          
   C   s    t j}tj |ddd¡}t |¡ tj |dddd¡}t |¡ |  ttjtj¡ tj |dddddtj¡}t |¡ tj |dtjddddd¡}t |¡ d S )Nrz  r|  Údir3Údir4Údir5Údir6)	r   r"   r   r    rÒ   ra  r5   r6   Úcurdir)r$   Úbaser    r   r   r   Útest_makedirm  s    


zMakedirTests.test_makedirc          	   C   s¦   t  d¡’ t j}tj |d¡}tj |d¡}t |d¡ |  tj |¡¡ |  tj 	|¡¡ tj
dkr˜|  t |¡jd@ d¡ |  t |¡jd@ d¡ W d Q R X d S )Nr0   rz  r|  im  Úntiÿ  iý  )r   Z
temp_umaskr"   r   r    rÒ   ra  r)   rO  Úisdirr   r>   rl   rž   )r$   r¡  Úparentr    r   r   r   Ú	test_mode|  s    
zMakedirTests.test_modec             C   s–   t j tjd¡}d}t  d¡}t  ||¡ |  tt j||¡ | jtt j||dd t j|ddd t j||dd t  |¡ t jt j 	d	¡dd d S )
Nrz  iÿ  é   F)Úexist_okiþ  T)rp   r¨  ú/)
r   r    rÒ   r   r"   Úumaskra  r5   r6   rý   )r$   r    rp   Úold_maskr   r   r   Ú test_exist_ok_existing_directoryˆ  s    

z-MakedirTests.test_exist_ok_existing_directoryc          	   C   sø   t j tjd¡}tj}d}t  d¡}zÂt t  	tj¡j
¡}yt  tj||B ¡ W n tk
rn   t d¡‚Y nX t  	tj¡j
|@ |krt d¡‚t  |||B ¡ t j||dd t  |t t  	|¡j
¡| @ ¡ t j|||B dd W d t  |¡ X d S )Nrz  iÿ  r§  zCannot set S_ISGID for dir.z No support for S_ISGID dir mode.T)r¨  )r   r    rÒ   r   r"   rl   ÚS_ISGIDrª  ÚS_IMODEÚlstatrž   rd  rf  r   ÚSkipTestra  )r$   r    r­  rp   r«  Zexisting_testfn_moder   r   r   Útest_exist_ok_s_isgid_directory–  s$    

 z,MakedirTests.test_exist_ok_s_isgid_directoryc             C   sx   t j}tj t jd¡}t|dƒ}| d¡ | ¡  |  t	tj
|¡ | jt	tj
|dd | jt	tj
|dd t |¡ d S )Nrz  rÉ   r3  F)r¨  T)r   r"   r   r    rÒ   r   r   r(   r5   r6   ra  ro  )r$   r¡  r    r,   r   r   r   Ú#test_exist_ok_existing_regular_file±  s    

z0MakedirTests.test_exist_ok_existing_regular_filec          	   C   sP   t j tjdddddd¡}x&t j |¡s@|tjkr@t j |¡}qW t  |¡ d S )Nrz  r|  rœ  r  rž  rŸ  )r   r    rÒ   r   r"   rO  rÐ   Ú
removedirs)r$   r    r   r   r   r~   ¼  s
    
zMakedirTests.tearDownN)
r{   r|   r}   r%   r¢  r¦  r¬  r±  r²  r~   r   r   r   r   r›  i  s   r›  ÚchownzTest needs chownc               @   sŠ   e Zd Zedd„ ƒZdd„ Ze ee	ƒdkd¡dd„ ƒZ
e eoJeeƒdkd	¡d
d„ ƒZe e oleeƒdkd¡dd„ ƒZedd„ ƒZdS )ÚChownFileTestsc             C   s   t  tj¡ d S )N)r   rÎ   r   r"   )Úclsr   r   r   Ú
setUpClassË  s    zChownFileTests.setUpClassc             C   s˜   t  tj¡}|j}|j}xNddt d¡t 	dd¡fD ]0}|  
tt jtj||¡ |  
tt jtj||¡ q4W |  t  tj||¡¡ |  t  tjdd¡¡ d S )Ng      ð¿y       €      ð¿rh  éþÿÿÿr0   )r   rl   r   r"   Úst_uidÚst_gidÚdecimalZDecimalÚ	fractionsZFractionr5   r<   r´  ÚassertIsNone)r$   rl   ÚuidÚgidr¿   r   r   r   Ú*test_chown_uid_gid_arguments_must_be_indexÏ  s     z9ChownFileTests.test_chown_uid_gid_arguments_must_be_indexr.   ztest needs more than one groupc             C   sv   t d d… \}}t tj¡j}t tj||¡ t tj¡j}|  ||¡ t tj||¡ t tj¡j}|  ||¡ d S )Nr0   )	Úgroupsr   rl   r   r"   r¹  r´  rº  r>   )r$   Zgid_1Zgid_2r¾  r¿  r   r   r   Ú
test_chownÙ  s    zChownFileTests.test_chownz0test needs root privilege and more than one userc             C   sv   t d d… \}}t tj¡j}t tj||¡ t tj¡j}|  ||¡ t tj||¡ t tj¡j}|  ||¡ d S )Nr0   )	Ú	all_usersr   rl   r   r"   rº  r´  r¹  r>   )r$   Úuid_1Úuid_2r¿  r¾  r   r   r   Útest_chown_with_rootä  s    z#ChownFileTests.test_chown_with_rootz2test needs non-root account and more than one userc          	   C   sX   t d d… \}}t tj¡j}|  t¡& t tj||¡ t tj||¡ W d Q R X d S )Nr0   )	rÃ  r   rl   r   r"   rº  r5   rf  r´  )r$   rÄ  rÅ  r¿  r   r   r   Útest_chown_without_permissionð  s
    z,ChownFileTests.test_chown_without_permissionc             C   s   t  tj¡ d S )N)r   rÏ   r   r"   )r¶  r   r   r   ÚtearDownClassù  s    zChownFileTests.tearDownClassN)r{   r|   r}   Úclassmethodr·  rÀ  r   r   r½   rÁ  rÂ  Úroot_in_posixrÃ  rÆ  rÇ  rÈ  r   r   r   r   rµ  È  s   
rµ  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚRemoveDirsTestsc             C   s   t  tj¡ d S )N)r   ra  r   r"   )r$   r   r   r   r%   ÿ  s    zRemoveDirsTests.setUpc             C   s   t  t j¡ d S )N)r   rÙ   r"   )r$   r   r   r   r~     s    zRemoveDirsTests.tearDownc             C   sx   t j tjd¡}t  |¡ t j |d¡}t  |¡ t  |¡ |  t j |¡¡ |  t j |¡¡ |  t j tj¡¡ d S )NÚdiraÚdirb)	r   r    rÒ   r   r"   rÎ   r³  ÚassertFalserO  )r$   rÌ  rÍ  r   r   r   Útest_remove_all  s    


zRemoveDirsTests.test_remove_allc             C   sŠ   t j tjd¡}t  |¡ t j |d¡}t  |¡ tt j |d¡ƒ t  |¡ |  t j 	|¡¡ |  
t j 	|¡¡ |  
t j 	tj¡¡ d S )NrÌ  rÍ  zfile.txt)r   r    rÒ   r   r"   rÎ   r   r³  rÎ  rO  r)   )r$   rÌ  rÍ  r   r   r   Útest_remove_partial  s    


z#RemoveDirsTests.test_remove_partialc          	   C   s    t j tjd¡}t  |¡ t j |d¡}t  |¡ tt j |d¡ƒ |  t¡ t  	|¡ W d Q R X |  
t j |¡¡ |  
t j |¡¡ |  
t j tj¡¡ d S )NrÌ  rÍ  zfile.txt)r   r    rÒ   r   r"   rÎ   r   r5   r6   r³  r)   rO  )r$   rÌ  rÍ  r   r   r   Útest_remove_nothing  s    

z#RemoveDirsTests.test_remove_nothingN)r{   r|   r}   r%   r~   rÏ  rÐ  rÑ  r   r   r   r   rË  þ  s
   
rË  c               @   s   e Zd Zdd„ ZdS )ÚDevNullTestsc          	   C   sX   t tjddƒ}| d¡ | ¡  W d Q R X t tjdƒ}|  | ¡ d¡ W d Q R X d S )Nrð   r   s   hellorN   r‡   )r   r   Údevnullr   r(   r>   rF   )r$   r,   r   r   r   Útest_devnull(  s
    
zDevNullTests.test_devnullN)r{   r|   r}   rÔ  r   r   r   r   rÒ  '  s   rÒ  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚURandomTestsc             C   sr   |   tt d¡ƒd¡ |   tt d¡ƒd¡ |   tt d¡ƒd¡ |   tt d¡ƒd¡ |   tt d¡ƒd¡ d S )Nr   r.   r/   re   iè  )r>   r½   r   Úurandom)r$   r   r   r   Útest_urandom_length1  s
    z URandomTests.test_urandom_lengthc             C   s0   t  d¡}|  |t¡ t  d¡}|  ||¡ d S )Né   )r   rÖ  ÚassertIsInstancerH   rÕ   )r$   Údata1Údata2r   r   r   Útest_urandom_value8  s    

zURandomTests.test_urandom_valuec             C   s<   d  dd| ddf¡}td|ƒ}|d }|  t|ƒ|¡ |S )NÚ
zimport os, syszdata = os.urandom(%s)zsys.stdout.buffer.write(data)zsys.stdout.buffer.flush()z-cr.   )rÒ   r   r>   r½   )r$   Úcountr_   ÚoutÚstdoutr   r   r   Úget_urandom_subprocess>  s    
z#URandomTests.get_urandom_subprocessc             C   s$   |   d¡}|   d¡}|  ||¡ d S )NrØ  )rá  rÕ   )r$   rÚ  rÛ  r   r   r   Útest_urandom_subprocessI  s    

z$URandomTests.test_urandom_subprocessN)r{   r|   r}   r×  rÜ  rá  râ  r   r   r   r   rÕ  0  s   rÕ  Ú	getrandomzneed os.getrandom()c               @   s@   e Zd Zedd„ ƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚGetRandomTestsc          
   C   sP   yt  d¡ W n< tk
rJ } z|jtjkr8t d¡‚n‚ W d d }~X Y nX d S )Nr.   z%getrandom() syscall fails with ENOSYS)r   rã  r6   rÇ   ZENOSYSr   r°  )r¶  Úexcr   r   r   r·  Q  s    zGetRandomTests.setUpClassc             C   s*   t  d¡}|  |t¡ |  t|ƒd¡ d S )NrØ  )r   rã  rÙ  rH   r>   r½   )r$   rP   r   r   r   Útest_getrandom_type]  s    
z"GetRandomTests.test_getrandom_typec             C   s   t  d¡}|  |d¡ d S )Nr   r‡   )r   rã  r>   )r$   Úemptyr   r   r   Útest_getrandom0b  s    
zGetRandomTests.test_getrandom0c             C   s   |   ttdƒ¡ d S )NÚGRND_RANDOM)r)   r   r   )r$   r   r   r   Útest_getrandom_randomf  s    z$GetRandomTests.test_getrandom_randomc             C   s,   yt  dt j¡ W n tk
r&   Y nX d S )Nr.   )r   rã  ÚGRND_NONBLOCKÚBlockingIOError)r$   r   r   r   Útest_getrandom_nonblockl  s    z&GetRandomTests.test_getrandom_nonblockc             C   s$   t  d¡}t  d¡}|  ||¡ d S )NrØ  )r   rã  rÕ   )r$   rÚ  rÛ  r   r   r   Útest_getrandom_valuet  s    

z#GetRandomTests.test_getrandom_valueN)
r{   r|   r}   rÉ  r·  ræ  rè  rê  rí  rî  r   r   r   r   rä  O  s   rä  ZHAVE_GETENTROPYr.   ZHAVE_GETRANDOMZHAVE_GETRANDOM_SYSCALLz*os.random() does not use a file descriptorc               @   s0   e Zd Ze ed¡dd„ ƒZdd„ Zdd„ ZdS )	ÚURandomFDTestsz!test requires the resource modulec             C   s   d}t d|ƒ d S )NaÌ  if 1:
            import errno
            import os
            import resource

            soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
            resource.setrlimit(resource.RLIMIT_NOFILE, (1, hard_limit))
            try:
                os.urandom(16)
            except OSError as e:
                assert e.errno == errno.EMFILE, e.errno
            else:
                raise AssertionError("OSError not raised")
            z-c)r   )r$   r_   r   r   r   Útest_urandom_failure„  s    z#URandomFDTests.test_urandom_failurec             C   s   d}t d|ƒ\}}}d S )Na  if 1:
            import os
            import sys
            import test.support
            os.urandom(4)
            with test.support.SuppressCrashReport():
                os.closerange(3, 256)
            sys.stdout.buffer.write(os.urandom(4))
            z-Sc)r   )r$   r_   Úrcrß  Úerrr   r   r   Útest_urandom_fd_closed›  s    z%URandomFDTests.test_urandom_fd_closedc             C   s–   |   tjtj¡ ttjdƒ djtjd}td|ƒ\}}}|  t|ƒd¡ |  	|dd… |dd… ¡ td|ƒ\}}}|  t|ƒd¡ |  	||¡ d S )Ns   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxa­  if 1:
            import os
            import sys
            import test.support
            os.urandom(4)
            with test.support.SuppressCrashReport():
                for fd in range(3, 256):
                    try:
                        os.close(fd)
                    except OSError:
                        pass
                    else:
                        # Found the urandom fd (XXX hopefully)
                        break
                os.closerange(3, 256)
            with open({TESTFN!r}, 'rb') as f:
                new_fd = f.fileno()
                # Issue #26935: posix allows new_fd and fd to be equal but
                # some libc implementations have dup2 return an error in this
                # case.
                if new_fd != fd:
                    os.dup2(new_fd, fd)
                sys.stdout.buffer.write(os.urandom(4))
                sys.stdout.buffer.write(os.urandom(4))
            )r"   z-Scr   r   rB   )
rO   r   r#   r"   r   r,  r   r>   r½   rÕ   )r$   r_   rñ  rß  rò  Zout2Zerr2r   r   r   Útest_urandom_fd_reopened©  s    z'URandomFDTests.test_urandom_fd_reopenedN)	r{   r|   r}   r   r   Úresourcerð  ró  rô  r   r   r   r   rï    s   rï  c             #   sl   g ‰ ‡ fdd„}‡ fdd„}z6t j}t j}t j}|t _|t _| d k	rJ| t _ˆ V  W d |t _|t _|t _X d S )Nc                s   ˆ   d| |f¡ tdƒ‚d S )NÚexecvzexecv called)rn  ÚRuntimeError)r   r[   )Úcallsr   r   Ú
mock_execvÛ  s    z#_execvpe_mockup.<locals>.mock_execvc                s    ˆ   d| |f¡ ttjdƒ‚d S )NÚexecvezexecve called)rn  r6   rÇ   ZENOTDIR)r   r[   )rø  r   r   Úmock_execveß  s    z$_execvpe_mockup.<locals>.mock_execve)r   rö  rú  r4  )r4  rù  rû  Z
orig_execvZorig_execveZorig_defpathr   )rø  r   Ú_execvpe_mockupÐ  s    	
rü  c               @   st   e Zd Ze ed¡dd„ ƒZdd„ Zdd„ Ze 	e
edƒd	¡d
d„ ƒZdd„ Zdd„ Ze 	ejdkd¡dd„ ƒZdS )Ú	ExecTestsz4avoid triggering a linuxthreads bug: see issue #4970c             C   s   |   ttjddgd ¡ d S )Nzno such app-)r5   r6   r   Úexecvpe)r$   r   r   r   Útest_execvpe_with_bad_programó  s    z'ExecTests.test_execvpe_with_bad_programc             C   sN   |   ttjdd¡ |   ttjdg ¡ |   ttjdd¡ |   ttjddg¡ d S )NÚnotepadr   )rû   rû   )r5   r  r   rö  )r$   r   r   r   Útest_execv_with_bad_arglistù  s    z%ExecTests.test_execv_with_bad_arglistc             C   sB   |   ttjdg d ¡ |   ttjdg i ¡ |   ttjddgi ¡ d S )Nr   rû   )r5   r  r   rþ  )r$   r   r   r   Útest_execvpe_with_bad_arglistÿ  s    z'ExecTests.test_execvpe_with_bad_arglistÚ_execvpez)No internal os._execvpe function to test.c       
   	   C   s”  t jd }|tkr:d}t j t  |¡|¡}|}dddg}n6d}dddg}t j ||¡}t jdkrlt  |¡}n|}d	d
i}tƒ @}|  t	t j
||¡ |  t|ƒd¡ |  |d d||ff¡ W d Q R X t|dF}| jtt j
|||d |  t|ƒd¡ |  |d d|||ff¡ W d Q R X tƒ j}| ¡ }	|tkr>||	d< n||	d< | jtt j
|||	d |  t|ƒd¡ |  |d d|||	ff¡ W d Q R X d S )NZabsolutepaths
   executables   prognameZarg1Zarg2r^   Zprognamer£  ZspamrR   r.   r   rö  )r4  )r/  rú  s   PATHr1  )r   ÚseprH   r    rÒ   r“  r   rü  r5   r÷  r  r>   r½   r6   r6  r  )
r$   Z	test_typeZprogram_pathZprogramZfullpathZnative_fullpathZ	argumentsr/  rø  Zenv_pathr   r   r   Ú_test_internal_execvpe  sD    


"



z ExecTests._test_internal_execvpec             C   s"   |   t¡ tjdkr|   t¡ d S )Nr£  )r  r'  r   r   rH   )r$   r   r   r   Útest_internal_execvpe_str5  s    

z#ExecTests.test_internal_execvpe_strc          	   C   s¾   t jddg}tj ¡ }d|d< |  t¡ t |d ||¡ W d Q R X tj ¡ }d|d< |  t¡ t |d ||¡ W d Q R X tj ¡ }d|d	< |  t¡ t |d ||¡ W d Q R X d S )
Nz-cÚpassÚcabbagezFRUIT VEGETABLEr   zorange VEGETABLE=cabbageÚFRUITÚlemonzFRUIT=ORANGE)r:   r^   r   rÓ   r  r5   r  rú  )r$   r[   Únewenvr   r   r   Útest_execve_invalid_env:  s    


z!ExecTests.test_execve_invalid_envr]   zWin32-specific testc          
   C   s`   yt  ddgi ¡ W n< tk
rP } z|  |jd kp<|jdk¡ W d d }~X Y nX |  d¡ d S )Nrû   Úargr   zNo OSError raised)r   rú  r6   r)   Zwinerrorrœ   )r$   rÃ   r   r   r   Útest_execve_with_empty_pathO  s
    ,z%ExecTests.test_execve_with_empty_pathN)r{   r|   r}   r   ÚskipIfÚUSING_LINUXTHREADSrÿ  r  r  r   r   r   r  r  r  r:   r€   r  r   r   r   r   rý  ò  s   0rý  r]   zWin32 specific testsc               @   sD   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S )ÚWin32ErrorTestsc          
   C   sv   yt  tj¡ W nP tk
r(   d}Y nJ tk
r` } zd}|  dtj|f ¡ W d d }~X Y nX |  dtj ¡ d S )NFTz.file %s must not exist; os.stat failed with %szfile %s must not exist)r   rl   r   r"   rk   r6   rœ   )r$   rO  rå  r   r   r   r%   \  s     zWin32ErrorTests.setUpc             C   s   |   ttjtjtjd ¡ d S )Nz.bak)r5   r6   r   r=   r   r"   )r$   r   r   r   rA   h  s    zWin32ErrorTests.test_renamec             C   s   |   ttjtj¡ d S )N)r5   r6   r   ro  r   r"   )r$   r   r   r   Útest_removek  s    zWin32ErrorTests.test_removec             C   s   |   ttjtj¡ d S )N)r5   r6   r   Úchdirr   r"   )r$   r   r   r   Ú
test_chdirn  s    zWin32ErrorTests.test_chdirc          	   C   s>   |   tjtj¡ ttjdƒ}|  ttjtj¡ W d Q R X d S )Nr…   )	rO   r   r#   r"   r   r5   r6   r   rÎ   )r$   r,   r   r   r   Ú
test_mkdirq  s    zWin32ErrorTests.test_mkdirc             C   s   |   ttjtjd ¡ d S )N)r5   r6   r   ræ   r   r"   )r$   r   r   r   rç   w  s    zWin32ErrorTests.test_utimec             C   s   |   ttjtjd¡ d S )Nr   )r5   r6   r   rd  r   r"   )r$   r   r   r   Ú
test_chmodz  s    zWin32ErrorTests.test_chmodN)
r{   r|   r}   r%   rA   r  r  r  rç   r  r   r   r   r   r  Z  s   r  c            	   @   sÆ  e Zd Zddddddddd	g	Zd
d„ ZxeD ]Zeeƒeƒ de < q,W dd„ Ze 	e
edƒd¡dd„ ƒZe 	e
edƒd¡dd„ ƒZe 	e
edƒd¡dd„ ƒZe 	e
edƒd¡dd„ ƒZe 	e
edƒd ¡d!d"„ ƒZe 	e
ed#ƒd$¡d%d&„ ƒZe 	e
ed'ƒd(¡d)d*„ ƒZe 	e
ed+ƒd,¡d-d.„ ƒZe 	e
ed/ƒd0¡d1d2„ ƒZe 	e
ed3ƒd4¡d5d6„ ƒZe 	e
ed7ƒd8¡d9d:„ ƒZe 	e
ed;ƒd<¡d=d>„ ƒZe 	e
ed?ƒd@¡dAdB„ ƒZdCdD„ Ze 	e
edEƒdF¡dGdH„ ƒZdIS )JÚTestInvalidFDÚfchdirr2   rb   Ú	fdatasyncr  ÚfstatvfsÚfsyncÚ	tcgetpgrpÚttynamec                s   ‡ fdd„}|S )Nc                s   t tˆ ƒr|  ttˆ ƒ¡ d S )N)r   r   Úcheckr˜   )r$   )r,   r   r   Úhelper„  s    
z(TestInvalidFD.get_single.<locals>.helperr   )r,   r  r   )r,   r   Ú
get_singleƒ  s    zTestInvalidFD.get_singleZtest_c          
   G   s\   y|t  ¡ f|žŽ  W n2 tk
rH } z|  |jtj¡ W d d }~X Y nX |  d| ¡ d S )Nz5%r didn't raise an OSError with a bad file descriptor)r   Úmake_bad_fdr6   r>   rÇ   rÈ   rœ   )r$   r,   r[   rÃ   r   r   r   r  ‹  s    "zTestInvalidFD.checkÚisattyztest needs os.isatty()c             C   s   |   t t ¡ ¡d¡ d S )NF)r>   r   r"  r   r!  )r$   r   r   r   Útest_isatty”  s    zTestInvalidFD.test_isattyr4   ztest needs os.closerange()c          	   C   sv   t  ¡ }x:tdƒD ].}yt || ¡ W n tk
r<   Y qX P qW |dk rVt d¡‚|  t 	||| d ¡d ¡ d S )Nr/   r0   z5Unable to acquire a range of invalid file descriptorsr.   )
r   r!  r­   r   r  r6   r   r°  r>   r4   )r$   rJ   r  r   r   r   r9   ˜  s     zTestInvalidFD.test_closerangeÚdup2ztest needs os.dup2()c             C   s   |   tjd¡ d S )Né   )r  r   r$  )r$   r   r   r   Ú	test_dup2¨  s    zTestInvalidFD.test_dup2Úfchmodztest needs os.fchmod()c             C   s   |   tjd¡ d S )Nr   )r  r   r'  )r$   r   r   r   Útest_fchmod¬  s    zTestInvalidFD.test_fchmodÚfchownztest needs os.fchown()c             C   s   |   tjdd¡ d S )Nrh  )r  r   r)  )r$   r   r   r   Útest_fchown°  s    zTestInvalidFD.test_fchownÚ	fpathconfztest needs os.fpathconf()c             C   s    |   tjd¡ |   tjd¡ d S )NÚPC_NAME_MAX)r  r   Úpathconfr+  )r$   r   r   r   Útest_fpathconf´  s    zTestInvalidFD.test_fpathconfÚ	ftruncateztest needs os.ftruncate()c             C   s    |   tjd¡ |   tjd¡ d S )Nr   )r  r   Útruncater/  )r$   r   r   r   Útest_ftruncate¹  s    zTestInvalidFD.test_ftruncaterE   ztest needs os.lseek()c             C   s   |   tjdd¡ d S )Nr   )r  r   rE   )r$   r   r   r   Ú
test_lseek¾  s    zTestInvalidFD.test_lseekrF   ztest needs os.read()c             C   s   |   tjd¡ d S )Nr.   )r  r   rF   )r$   r   r   r   rL   Â  s    zTestInvalidFD.test_readÚreadvztest needs os.readv()c             C   s   t dƒ}|  tj|g¡ d S )Nr/   )rT   r  r   r3  )r$   r  r   r   r   Ú
test_readvÆ  s    zTestInvalidFD.test_readvÚ	tcsetpgrpztest needs os.tcsetpgrp()c             C   s   |   tjd¡ d S )Nr   )r  r   r5  )r$   r   r   r   Útest_tcsetpgrptË  s    zTestInvalidFD.test_tcsetpgrptr   ztest needs os.write()c             C   s   |   tjd¡ d S )Nó    )r  r   r   )r$   r   r   r   rW   Ï  s    zTestInvalidFD.test_writeÚwritevztest needs os.writev()c             C   s   |   tjdg¡ d S )Ns   abc)r  r   r8  )r$   r   r   r   Útest_writevÓ  s    zTestInvalidFD.test_writevc             C   s   |   tj¡ |   tjd¡ d S )NT)r  r   Úget_inheritableÚset_inheritable)r$   r   r   r   Útest_inheritable×  s    zTestInvalidFD.test_inheritableÚget_blockingz-needs os.get_blocking() and os.set_blocking()c             C   s   |   tj¡ |   tjd¡ d S )NT)r  r   r=  Úset_blocking)r$   r   r   r   Útest_blockingÛ  s    zTestInvalidFD.test_blockingN)r{   r|   r}   Zsinglesr   r,   Úlocalsr  r   r   r   r   r#  r9   r&  r(  r*  r.  r1  r2  rL   r4  r6  rW   r9  r<  r?  r   r   r   r   r  ~  s,   

	r  c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )Ú	LinkTestsc             C   s    t j| _tj t jd ¡| _d S )NÚ2)r   r"   Úfile1r   r    rÒ   Úfile2)r$   r   r   r   r%   ã  s    zLinkTests.setUpc             C   s0   x*| j | jfD ]}tj |¡rt |¡ qW d S )N)rC  rD  r   r    rO  r#   )r$   Úfiler   r   r   r~   ç  s    zLinkTests.tearDownc          
   C   s–   t |ƒ yt ||¡ W n0 tk
rH } z|  d| ¡ W d d }~X Y nX t|dƒ8}t|dƒ"}|  tj | 	¡ | 	¡ ¡¡ W d Q R X W d Q R X d S )Nzos.link(): %srd   )
r   r   r[  rf  r3   r   r)   r    ÚsameopenfilerD   )r$   rC  rD  rÃ   rØ   Úf2r   r   r   Ú
_test_linkì  s     zLinkTests._test_linkc             C   s   |   | j| j¡ d S )N)rH  rC  rD  )r$   r   r   r   Ú	test_linkö  s    zLinkTests.test_linkc             C   s(   |   t| jt ¡ ƒt| jt ¡ ƒ¡ d S )N)rH  rH   rC  r:   rª   rD  )r$   r   r   r   Útest_link_bytesù  s    zLinkTests.test_link_bytesc             C   s\   yt  d¡ W n tk
r,   t d¡‚Y nX |  jd7  _| jd | _|  | j| j¡ d S )Nõ   Ã±z#Unable to encode for this platform.rB  )r   r“  ÚUnicodeErrorr   r°  rC  rD  rH  )r$   r   r   r   Útest_unicode_nameý  s    zLinkTests.test_unicode_nameN)	r{   r|   r}   r%   r~   rH  rI  rJ  rM  r   r   r   r   rA  â  s   
rA  zPosix specific testsc               @   sä   e Zd ZdZdZe eedƒd¡dd„ ƒZ	e eedƒd¡dd	„ ƒZ
e eed
ƒd¡dd„ ƒZe eedƒd¡dd„ ƒZe eedƒd¡dd„ ƒZe eedƒd¡dd„ ƒZe eedƒd¡dd„ ƒZe eedƒd¡dd„ ƒZdS )ÚPosixUidGidTestsl        Úsetuidztest needs os.setuid()c             C   sB   t  ¡ dkr|  tt jd¡ |  tt jd¡ |  tt j| j¡ d S )Nr   z
not an int)r   Úgetuidr5   r6   rO  r<   ÚOverflowErrorÚUID_OVERFLOW)r$   r   r   r   Útest_setuid  s    zPosixUidGidTests.test_setuidÚsetgidztest needs os.setgid()c             C   sF   t  ¡ dkr ts |  tt jd¡ |  tt jd¡ |  tt j| j¡ d S )Nr   z
not an int)	r   rP  ÚHAVE_WHEEL_GROUPr5   r6   rT  r<   rQ  ÚGID_OVERFLOW)r$   r   r   r   Útest_setgid  s    zPosixUidGidTests.test_setgidÚseteuidztest needs os.seteuid()c             C   sB   t  ¡ dkr|  tt jd¡ |  tt jd¡ |  tt j| j¡ d S )Nr   z
not an int)	r   rP  r5   r6   rX  r<   ÚsetegidrQ  rR  )r$   r   r   r   Útest_seteuid  s    zPosixUidGidTests.test_seteuidrY  ztest needs os.setegid()c             C   sF   t  ¡ dkr ts |  tt jd¡ |  tt jd¡ |  tt j| j¡ d S )Nr   z
not an int)	r   rP  rU  r5   r6   rY  r<   rQ  rV  )r$   r   r   r   Útest_setegid"  s    zPosixUidGidTests.test_setegidÚsetreuidztest needs os.setreuid()c             C   sn   t  ¡ dkr|  tt jdd¡ |  tt jdd¡ |  tt jdd¡ |  tt j| jd¡ |  tt jd| j¡ d S )Nr   z
not an int)r   rP  r5   r6   r\  r<   rQ  rR  )r$   r   r   r   Útest_setreuid)  s    zPosixUidGidTests.test_setreuidc             C   s   t  tjddg¡ d S )Nz-cz,import os,sys;os.setreuid(-1,-1);sys.exit(0))rZ   rÔ   r:   r^   )r$   r   r   r   Útest_setreuid_neg12  s    z#PosixUidGidTests.test_setreuid_neg1Úsetregidztest needs os.setregid()c             C   sr   t  ¡ dkr"ts"|  tt jdd¡ |  tt jdd¡ |  tt jdd¡ |  tt j| jd¡ |  tt jd| j¡ d S )Nr   z
not an int)	r   rP  rU  r5   r6   r_  r<   rQ  rV  )r$   r   r   r   Útest_setregid:  s    zPosixUidGidTests.test_setregidc             C   s   t  tjddg¡ d S )Nz-cz,import os,sys;os.setregid(-1,-1);sys.exit(0))rZ   rÔ   r:   r^   )r$   r   r   r   Útest_setregid_neg1C  s    z#PosixUidGidTests.test_setregid_neg1N)r{   r|   r}   rR  rV  r   r   r   r   rS  rW  rZ  r[  r]  r^  r`  ra  r   r   r   r   rN    s   		rN  c               @   sN   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Ze e	e
d	ƒd
¡dd„ ƒZdd„ ZdS )ÚPep383Testsc                s  t jrt j| _nt jr t j| _nt j| _t | j¡| _g ‰ ‡ fdd„}|t jƒ t jr`|t jƒ t jrp|t jƒ ˆ s~|  	d¡ t
ƒ | _t | j¡ yPxJˆ D ]B}t  tj | j|¡¡ t |¡}|| jkrÐtdƒ‚| j |¡ qšW W n   t | j¡ ‚ Y nX d S )Nc                s2   yt  | ¡} W n tk
r"   d S X ˆ  | ¡ d S )N)r   r“  r«   rn  )Úfn)Úbytesfnr   r   Úadd_filenameW  s
    z'Pep383Tests.setUp.<locals>.add_filenamez&couldn't create any non-ascii filenamezduplicate filename)r   ÚTESTFN_UNENCODABLEr•   ZTESTFN_NONASCIIr"   r   r“  ZbdirZTESTFN_UNICODEr3   r„  Ú	unicodefnrÎ   Zcreate_empty_filer    rÒ   r”  r  ÚaddÚshutilrÙ   )r$   re  rc  r   )rd  r   r%   M  s6    








zPep383Tests.setUpc             C   s   t  | j¡ d S )N)ri  rÙ   r•   )r$   r   r   r   r~   r  s    zPep383Tests.tearDownc          	   C   sl   | j }tt | j¡ƒ}|  ||¡ t ¡ }z0t tj¡ |  tt ¡ ƒtt tj¡ƒ¡ W d t |¡ X d S )N)	rg  r„  r   re  r•   r>   Úgetcwdr  r  )r$   r‡  ÚfoundZcurrent_directoryr   r   r   Útest_listdiru  s    $zPep383Tests.test_listdirc             C   s2   x,| j D ]"}ttj | j|¡dƒ}| ¡  qW d S )NrN   )rg  r   r   r    rÒ   r•   r(   )r$   rc  r,   r   r   r   Ú	test_open  s    zPep383Tests.test_openr¶   zneed os.statvfs()c             C   s.   x(| j D ]}tj | j|¡}t |¡ qW d S )N)rg  r   r    rÒ   r•   r¶   )r$   rc  Úfullnamer   r   r   Útest_statvfs†  s    zPep383Tests.test_statvfsc             C   s*   x$| j D ]}t tj | j|¡¡ qW d S )N)rg  r   rl   r    rÒ   r•   )r$   rc  r   r   r   Ú	test_stat  s    zPep383Tests.test_statN)r{   r|   r}   r%   r~   rl  rm  r   r   r   r   ro  rp  r   r   r   r   rb  K  s   %rb  c               @   sF   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Ze d	¡d
d„ ƒZ	dd„ Z
dS )ÚWin32KillTestsc             C   sx  dd l }ddl m} dd l}|jjj}|j|_|j| 	|j
¡|j| 	|j¡| 	|j¡| 	|j¡f|_d}tjtjdd |¡gtjtjtjd}|  |jj¡ |  |jj¡ |  |jj¡ d\}}	x”||	k rJ| ¡ d krJ| t|ƒ¡}
|| |j ¡ ¡|
| |
¡d d d ƒ}|  |dd¡ |
jr6|   ||
j !¡ ¡ P t" #d	¡ |d
7 }qÂW |  $d¡ t% &|j'|¡ |   | (¡ |¡ d S )Nr   )ÚwintypesÚrunningz-cz<import sys;sys.stdout.write('{}');sys.stdout.flush();input())rà  ÚstderrÚstdin)r   re   zPeekNamedPipe failedgš™™™™™¹?r.   z1Did not receive communication from the subprocess))rþ   rr  Úmsvcrtrÿ   r   ÚPeekNamedPipeÚBOOLÚrestypeÚHANDLEÚPOINTERZc_charÚDWORDÚargtypesrZ   ÚPopenr:   r^   r,  ÚPIPErO   rà  r(   rt  ru  ÚpollZcreate_string_bufferr½   Zget_osfhandlerD   ZsizeofrÕ   r¿   r>   r>  rö   Úsleeprœ   r   ÚkillÚpidÚwait)r$   Zsigrþ   rr  rv  rw  rõ   ÚprocrÞ  Úmaxr  Zrsltr   r   r   Ú_kill•  sF    







zWin32KillTests._killc             C   s   |   tj¡ d S )N)r‡  ÚsignalÚSIGTERM)r$   r   r   r   Útest_kill_sigtermË  s    z Win32KillTests.test_kill_sigtermc             C   s   |   d¡ d S )Nre   )r‡  )r$   r   r   r   Útest_kill_intÏ  s    zWin32KillTests.test_kill_intc             C   sì   dt  ¡  }t dd|¡}d|d< tjtjtj 	tj 
t¡d¡|gtjd}d\}}xR||k rŒ| ¡ d krŒ|d dkrxP t d¡ |d7 }qVW t |jtj¡ |  d	¡ t |j|¡ t d
¡ | ¡ sèt |jtj¡ |  d |¡¡ d S )Nz
test_os_%srh  r.   r   zwin_console_handler.py)rX   )r   re   gš™™™™™¹?z'Subprocess didn't finish initializationg      à?zsubprocess did not stop on {})ÚuuidZuuid1ÚmmaprZ   r~  r:   r^   r   r    rÒ   rÐ   rr   ZCREATE_NEW_PROCESS_GROUPr€  rö   r  r‚  rƒ  rˆ  ÚSIGINTrœ   r,  )r$   Zeventr   ZtagnameÚmr…  rÞ  r†  r   r   r   Ú_kill_with_eventÓ  s(    



zWin32KillTests._kill_with_eventz.subprocesses aren't inheriting Ctrl+C propertyc             C   sd   ddl m} dd l }| |j¡ƒ }|jjj}| |j¡|jf|_|j|_	||dƒ |  
tjd¡ d S )Nr   )rr  ÚCTRL_C_EVENT)rþ   rr  r{  Zc_intrÿ   r   ÚSetConsoleCtrlHandlerrx  r}  ry  r  rˆ  r‘  )r$   rr  rþ   ZNULLr’  r   r   r   Útest_CTRL_C_EVENTð  s    



z Win32KillTests.test_CTRL_C_EVENTc             C   s   |   tjd¡ d S )NÚCTRL_BREAK_EVENT)r  rˆ  r”  )r$   r   r   r   Útest_CTRL_BREAK_EVENT  s    z$Win32KillTests.test_CTRL_BREAK_EVENTN)r{   r|   r}   r‡  rŠ  r‹  r  r   Úskipr“  r•  r   r   r   r   rq  “  s   6rq  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚWin32ListdirTestsc          
   C   s”   g | _ x~tdƒD ]r}d| }tj tj|¡}d| }tj tj|¡}t |¡ t|dƒ}| 	d| ¡ W d Q R X | j  
||g¡ qW | j  ¡  d S )Nr0   zSUB%dzFILE%drÉ   z'I'm %s and proud of it. Blame test_os.
)Úcreated_pathsr­   r   r    rÒ   r   r"   ra  r   r   Úextendrj  )r$   r  Zdir_nameZdir_pathÚ	file_nameZ	file_pathr,   r   r   r   r%     s    
zWin32ListdirTests.setUpc             C   s   t  tj¡ d S )N)ri  rÙ   r   r"   )r$   r   r   r   r~     s    zWin32ListdirTests.tearDownc             C   sH   |   tt tj¡ƒ| j¡ |   tt t tj¡¡ƒdd„ | jD ƒ¡ d S )Nc             S   s   g | ]}t  |¡‘qS r   )r   r“  )r   r    r   r   r   r   %  s    zCWin32ListdirTests.test_listdir_no_extended_path.<locals>.<listcomp>)r>   Úsortedr   re  r   r"   r˜  r“  )r$   r   r   r   Útest_listdir_no_extended_path  s    z/Win32ListdirTests.test_listdir_no_extended_pathc             C   sh   dt j tj¡ }|  tt  |¡ƒ| j¡ dt  	t j tj¡¡ }|  tt  |¡ƒdd„ | jD ƒ¡ d S )Nz\\?\s   \\?\c             S   s   g | ]}t  |¡‘qS r   )r   r“  )r   r    r   r   r   r   4  s    z@Win32ListdirTests.test_listdir_extended_path.<locals>.<listcomp>)
r   r    rý   r   r"   r>   r›  re  r˜  r“  )r$   r    r   r   r   Útest_listdir_extended_path'  s    z,Win32ListdirTests.test_listdir_extended_pathN)r{   r|   r}   r%   r~   rœ  r  r   r   r   r   r—    s   r—  c               @   sÄ   e Zd ZdZej e¡ZdZ	ej 
e¡ZdZdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Ze d¡dd„ ƒZe d¡dd„ ƒZdd„ Zdd„ Ze ej d¡oªej d¡d¡dd„ ƒZdd„ Zd S )!ÚWin32SymlinkTestsZfilelinktestZdirlinktestzmissing linkc             C   s   d S )Nr   )r$   r   r   r   r%   @  s    zWin32SymlinkTests.setUpc             C   sR   t j | j¡rt  | j¡ t j | j¡r4t  | j¡ t j | j¡rNt  | j¡ d S )N)	r   r    rO  Úfilelinkro  ÚdirlinkrÏ   r!   Úmissing_link)r$   r   r   r   r~   G  s    zWin32SymlinkTests.tearDownc             C   s`   t  | j| j¡ |  t j | j¡¡ |  t j | j¡¡ |  t j | j¡¡ |  	| j| j¡ d S )N)
r   rt   Údirlink_targetr   r)   r    rO  r¤  ÚislinkÚ
check_stat)r$   r   r   r   Útest_directory_linkO  s
    z%Win32SymlinkTests.test_directory_linkc             C   s`   t  | j| j¡ |  t j | j¡¡ |  t j | j¡¡ |  t j | j¡¡ |  	| j| j¡ d S )N)
r   rt   Úfilelink_targetrŸ  r)   r    rO  Úisfiler£  r¤  )r$   r   r   r   Útest_file_linkV  s
    z Win32SymlinkTests.test_file_linkc             C   s6   | j }tj |¡rt |¡ d}d}t |||¡ d S )Nz"c:\\target does not exist.29r3c740T)r¡  r   r    r!   ro  rt   )r$   Zlinknameru   Ztarget_is_dirr   r   r   Ú_create_missing_dir_link]  s    
z*Win32SymlinkTests._create_missing_dir_linkc             C   s   |   ¡  t | j¡ d S )N)r©  r   ro  r¡  )r$   r   r   r   Ú,test_remove_directory_link_to_missing_targetg  s    z>Win32SymlinkTests.test_remove_directory_link_to_missing_targetz)currently fails; consider for improvementc             C   s    |   ¡  |  tj | j¡¡ d S )N)r©  r)   r   r    r¤  r¡  )r$   r   r   r   Ú.test_isdir_on_directory_link_to_missing_targetn  s    z@Win32SymlinkTests.test_isdir_on_directory_link_to_missing_targetc             C   s   |   ¡  t | j¡ d S )N)r©  r   rÏ   r¡  )r$   r   r   r   Ú.test_rmdir_on_directory_link_to_missing_targett  s    z@Win32SymlinkTests.test_rmdir_on_directory_link_to_missing_targetc             C   sn   |   t |¡t |¡¡ |  t |¡t |¡¡ t |¡}|   t |¡t |¡¡ |  t |¡t |¡¡ d S )N)r>   r   rl   rÕ   r¯  r“  )r$   r[  ru   Z
bytes_linkr   r   r   r¤  z  s
    
zWin32SymlinkTests.check_statc          	   C   s@  t j tj¡}t j |d¡}t j |d¡}|  tj|¡ t  |¡ t  |¡ t  |¡ t j t j |d¡¡}t	|ƒ t  
¡ }z²t  |¡ t j |d¡}t  t j |¡d¡ |  dt  t  
¡ ¡¡ |  t  |¡t  d¡¡ t  |¡ |  t  |¡t  t j |¡¡¡ t  |¡ |  t  |¡t  t j |¡¡¡ W d t  |¡ X d S )NÚlevel2Úlevel3rC  r[  )r   r    rý   r   r"   rÒ   rO   rÙ   rÎ   r   rj  r  rt   Úrelpathr™   re  r>   rl   )r$   Zlevel1r­  r®  rC  Zorig_dirr[  r   r   r   Ú
test_12084‚  s.    





zWin32SymlinkTests.test_12084zC:\Users\All UserszC:\ProgramDatazTest directories not foundc             C   s"   t  d¡}|  t j |d¡¡ d S )NzC:\Users\All UserszC:\ProgramData)r   Úreadlinkr)   r    Úsamefile)r$   ru   r   r   r   Ú
test_29248¥  s    
zWin32SymlinkTests.test_29248c          	   C   sö   d}t jj|gd Ž }d| |f||f|d d… |d d… fg}x°|D ]¨\}}yt  ||¡ W n tk
rr   Y n&X yt  |¡ W n tk
r–   Y nX yt  t  |¡t  |¡¡ W n tk
rÈ   Y qFX yt  |¡ W qF tk
rì   Y qFX qFW d S )NZXXXXXXXXXXXXXXXXXXXXXXXXXXXr/   rú   é´   )r   r    rÒ   rt   rk   ro  r6   r“  )r$   Zsegmentr    Z
test_casesrv   Údestr   r   r   Útest_buffer_overflow´  s,    
z&Win32SymlinkTests.test_buffer_overflowN)r{   r|   r}   rŸ  r   r    rý   rr   r¦  r   rÐ   r¢  r¡  r%   r~   r¥  r¨  r©  rª  r   r–  r«  r¬  r¤  r°  r   r!   rO  r³  r¶  r   r   r   r   rž  7  s&   
#
rž  c               @   sD   e Zd ZdZej ej e¡¡Z	dd„ Z
dd„ Zdd„ Zdd	„ Zd
S )ÚWin32JunctionTestsZjunctiontestc             C   s   d S )Nr   )r$   r   r   r   r%   Ü  s    zWin32JunctionTests.setUpc             C   s   t j | j¡rt  | j¡ d S )N)r   r    rO  ÚjunctionrÏ   )r$   r   r   r   r~   à  s    zWin32JunctionTests.tearDownc             C   sP   t  | j| j¡ |  tj | j¡¡ |  tj | j¡¡ |  	tj 
| j¡¡ d S )N)Ú_winapiÚCreateJunctionÚjunction_targetr¸  r)   r   r    rO  r¤  rÎ  r£  )r$   r   r   r   Útest_create_junctionæ  s    z'Win32JunctionTests.test_create_junctionc             C   sH   t  | j| j¡ |  tj | j¡¡ t | j¡ |  	tj | j¡¡ d S )N)
r¹  rº  r»  r¸  r)   r   r    rO  r#   rÎ  )r$   r   r   r   Útest_unlink_removes_junctionî  s    z/Win32JunctionTests.test_unlink_removes_junctionN)r{   r|   r}   r¸  r   r    rÐ   rý   rr   r»  r%   r~   r¼  r½  r   r   r   r   r·  ×  s   r·  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚWin32NtTestsc             C   s   ddl m} | d¡| _d S )Nr   )r   r£  )Útestr   Úimport_moduler£  )r$   r   r   r   r   r%   ÷  s    zWin32NtTests.setUpc             C   s   d S )Nr   )r$   r   r   r   r~   ü  s    zWin32NtTests.tearDownc             C   sB  ydd l }dd l}W n tk
r2   t d¡‚Y nX |jddd}|jj|j_	|jj
|j_	|jj|jjf|j_| ¡ }|j ¡ }| || |¡¡}|  d|¡ |j}ddd	tg}xXtd
ƒD ]L}xF|D ]>}	y| j |	¡}
W n   Y nX yt |	¡}
W qÄ   Y qÄX qÄW qºW | || |¡¡}|  d|¡ |j| }|  d|¡ d S )Nr   z'ctypes module is required for this testzKernel32.dllT)Zuse_last_errorr.   z\\?\C:z\\?\NULz	\\?\CONINr/   )rþ   Zctypes.wintypesÚImportErrorr   r°  ZWinDLLrr  rz  ZGetCurrentProcessry  rx  ZGetProcessHandleCountZLPDWORDr}  r|  Zbyrefr>   r¿   rr   r­   r£  Z_getfinalpathnamer   rl   )r$   rþ   ZkernelZhprocZhandle_countr  Zbefore_countÚ	filenamesr  r   ZtmpZhandle_deltar   r   r   Útest_getfinalpathname_handlesÿ  s@    


z*Win32NtTests.test_getfinalpathname_handlesN)r{   r|   r}   r%   r~   rÃ  r   r   r   r   r¾  õ  s   r¾  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚNonLocalSymlinkTestsc             C   s   t  d¡ d S )Nzbase/some_dir)r   ra  )r$   r   r   r   r%   1	  s    zNonLocalSymlinkTests.setUpc             C   s   t  d¡ d S )Nr¡  )ri  rÙ   )r$   r   r   r   r~   :	  s    zNonLocalSymlinkTests.tearDownc             C   s   t j dd¡}t  d|¡ d S )Nr¡  Z	some_linkZsome_dir)r   r    rÒ   rt   )r$   rv   r   r   r   Útest_directory_link_nonlocal=	  s    z1NonLocalSymlinkTests.test_directory_link_nonlocalN)r{   r|   r}   r%   r~   rÅ  r   r   r   r   rÄ  .	  s   	rÄ  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚFSEncodingTestsc             C   s(   |   t d¡d¡ |   t d¡d¡ d S )Ns   abcÿu   abcÅ)r>   r   r“  r”  )r$   r   r   r   Útest_nopO	  s    zFSEncodingTests.test_nopc          	   C   sJ   xDdD ]<}yt  |¡}W n tk
r.   wY nX |  t  |¡|¡ qW d S )N)u	   unicodeÅu   latinÃ©Úascii)r   r“  r«   r>   r”  )r$   rc  rd  r   r   r   Útest_identityS	  s    
zFSEncodingTests.test_identityN)r{   r|   r}   rÇ  rÉ  r   r   r   r   rÆ  N	  s   rÆ  c               @   sN   e Zd Zdd„ Ze e d¡o<ej	 
d¡p<eedƒo<eedƒd¡dd	„ ƒZd
S )ÚDeviceEncodingTestsc             C   s   |   t d¡¡ d S )Ni@â )r½  r   Údevice_encoding)r$   r   r   r   Útest_bad_fd`	  s    zDeviceEncodingTests.test_bad_fdr   ÚwinÚnl_langinfoÚCODESETz>test requires a tty and either Windows or nl_langinfo(CODESET)c             C   s(   t  d¡}|  |¡ |  t |¡¡ d S )Nr   )r   rË  ZassertIsNotNoner)   ÚcodecsÚlookup)r$   Úencodingr   r   r   Útest_device_encodingd	  s    

z(DeviceEncodingTests.test_device_encodingN)r{   r|   r}   rÌ  r   r   r   r"  r:   r€   Ú
startswithr   ÚlocalerÓ  r   r   r   r   rÊ  ^	  s   rÊ  c               @   s.   e Zd Ze eedƒd¡dd„ ƒZdd„ ZdS )ÚPidTestsÚgetppidztest needs os.getppidc             C   s<   t jtjddgt jd}| ¡ \}}|  t|ƒt 	¡ ¡ d S )Nz-czimport os; print(os.getppid()))rà  )
rZ   r~  r:   r^   r  Zcommunicater>   r„   r   Úgetpid)r$   r³   rà  Ú_r   r   r   Útest_getppidn	  s
    

zPidTests.test_getppidc             C   sD   t jddg}t tjt|d ƒ|¡}t |d¡}|  ||df¡ d S )Nz-cr  r   )r:   r^   r   ÚspawnvÚP_NOWAITr   Úwaitpidr>   )r$   r[   rƒ  Ústatusr   r   r   Útest_waitpidw	  s    zPidTests.test_waitpidN)	r{   r|   r}   r   r   r   r   rÚ  rß  r   r   r   r   rÖ  m	  s   	rÖ  c               @   s$  e Zd Zdddœdd„Zedƒdd„ ƒZedƒd	d
„ ƒZedƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZ	edƒdd„ ƒZ
edƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZedƒdd „ ƒZedƒd!d"„ ƒZedƒd#d$„ ƒZedƒd%d&„ ƒZedƒd'd(„ ƒZd)d*„ Zedƒd+d,„ ƒZedƒd-d.„ ƒZd/S )0Ú
SpawnTestsF)Úwith_envÚ	use_bytesc         	   C   s¸   d| _ tj}|  tj|¡ |s*d| j  }n8ttjƒ| _t	t
 ¡ ƒ| _| j| j| j< d| j| j f }t|dƒ}| |¡ W d Q R X tj|g}|r´dd„ |D ƒ}dd„ | j ¡ D ƒ| _|S )	Né   zimport sys; sys.exit(%s)z4import sys, os; magic = os.environ[%r]; sys.exit(%s)rÉ   c             S   s   g | ]}t  |¡‘qS r   )r   r“  )r   Úar   r   r   r   –	  s    z*SpawnTests.create_args.<locals>.<listcomp>c             S   s"   i | ]\}}t  |¡t  |¡“qS r   )r   r“  )r   ÚkÚvr   r   r   ú
<dictcomp>—	  s   z*SpawnTests.create_args.<locals>.<dictcomp>)Úexitcoder   r"   rO   r#   r  r   rÓ   r/  r'  rŒ  Zuuid4r  r   r   r:   r^   r  )r$   rá  râ  r   r_   r   r[   r   r   r   Úcreate_args€	  s$    
zSpawnTests.create_argsÚspawnlc             C   s2   |   ¡ }tjtj|d f|žŽ }|  || j¡ d S )Nr   )ré  r   rê  ÚP_WAITr>   rè  )r$   r[   rè  r   r   r   Útest_spawnlœ	  s    zSpawnTests.test_spawnlÚspawnlec             C   s<   | j dd}tjtj|d f|| jfžŽ }|  || j¡ d S )NT)rá  r   )ré  r   rí  rë  r/  r>   rè  )r$   r[   rè  r   r   r   Útest_spawnle¢	  s    zSpawnTests.test_spawnleÚspawnlpc             C   s2   |   ¡ }tjtj|d f|žŽ }|  || j¡ d S )Nr   )ré  r   rï  rë  r>   rè  )r$   r[   rè  r   r   r   Útest_spawnlp¨	  s    zSpawnTests.test_spawnlpÚspawnlpec             C   s<   | j dd}tjtj|d f|| jfžŽ }|  || j¡ d S )NT)rá  r   )ré  r   rñ  rë  r/  r>   rè  )r$   r[   rè  r   r   r   Útest_spawnlpe®	  s    zSpawnTests.test_spawnlperÛ  c             C   s.   |   ¡ }t tj|d |¡}|  || j¡ d S )Nr   )ré  r   rÛ  rë  r>   rè  )r$   r[   rè  r   r   r   Útest_spawnv´	  s    zSpawnTests.test_spawnvÚspawnvec             C   s6   | j dd}t tj|d || j¡}|  || j¡ d S )NT)rá  r   )ré  r   rô  rë  r/  r>   rè  )r$   r[   rè  r   r   r   Útest_spawnveº	  s    zSpawnTests.test_spawnveÚspawnvpc             C   s.   |   ¡ }t tj|d |¡}|  || j¡ d S )Nr   )ré  r   rö  rë  r>   rè  )r$   r[   rè  r   r   r   Útest_spawnvpÀ	  s    zSpawnTests.test_spawnvpÚspawnvpec             C   s6   | j dd}t tj|d || j¡}|  || j¡ d S )NT)rá  r   )ré  r   rø  rë  r/  r>   rè  )r$   r[   rè  r   r   r   Útest_spawnvpeÆ	  s    zSpawnTests.test_spawnvpec             C   s†   |   ¡ }t tj|d |¡}t |d¡}|  |d |¡ |d }ttdƒrp|  t |¡¡ |  t 	|¡| j
¡ n|  || j
d> ¡ d S )Nr   r.   Ú	WIFEXITEDr   )ré  r   rÛ  rÜ  rÝ  r>   r   r)   rú  ÚWEXITSTATUSrè  )r$   r[   rƒ  r£   rÞ  r   r   r   Útest_nowaitÌ	  s    
zSpawnTests.test_nowaitc             C   s8   | j ddd}t tj|d || j¡}|  || j¡ d S )NT)rá  râ  r   )ré  r   rô  rë  r/  r>   rè  )r$   r[   rè  r   r   r   Útest_spawnve_bytesÙ	  s    zSpawnTests.test_spawnve_bytesc             C   s>   |   ¡ }|  ttjtj|d ¡ |  ttjtj|d d¡ d S )Nr   rû   )ré  r5   r  r   rê  rÜ  )r$   r[   r   r   r   Útest_spawnl_noargsà	  s    zSpawnTests.test_spawnl_noargsc             C   sB   |   ¡ }|  ttjtj|d i ¡ |  ttjtj|d di ¡ d S )Nr   rû   )ré  r5   r  r   rí  rÜ  )r$   r[   r   r   r   Útest_spawnle_noargsæ	  s    zSpawnTests.test_spawnle_noargsc             C   sv   |   ¡ }|  ttjtj|d d¡ |  ttjtj|d g ¡ |  ttjtj|d d¡ |  ttjtj|d dg¡ d S )Nr   r   )rû   rû   )ré  r5   r  r   rÛ  rÜ  )r$   r[   r   r   r   Útest_spawnv_noargsì	  s
    zSpawnTests.test_spawnv_noargsc             C   s~   |   ¡ }|  ttjtj|d di ¡ |  ttjtj|d g i ¡ |  ttjtj|d di ¡ |  ttjtj|d dgi ¡ d S )Nr   r   )rû   rû   )ré  r5   r  r   rô  rÜ  )r$   r[   r   r   r   Útest_spawnve_noargsô	  s
    zSpawnTests.test_spawnve_noargsc          	   C   sd  t jddg}tj ¡ }d|d< y|tj|d ||ƒ}W n tk
rJ   Y nX |  |d¡ tj ¡ }d|d< y|tj|d ||ƒ}W n tk
r–   Y nX |  |d¡ tj ¡ }d	|d
< y|tj|d ||ƒ}W n tk
râ   Y nX |  |d¡ tj	}|  
tj|¡ t|dƒ}| d¡ W d Q R X t j|g}tj ¡ }d|d< |tj|d ||ƒ}|  |d¡ d S )Nz-cr  r  zFRUIT VEGETABLEr   é   zorange VEGETABLE=cabbager	  r
  zFRUIT=ORANGErÉ   zPimport sys, os
if os.getenv("FRUIT") != "orange=lemon":
    raise AssertionErrorzorange=lemon)r:   r^   r   rÓ   r  rë  r  r>   r   r"   rO   r#   r   r   )r$   Zspawnr[   r  rè  r   r   r   r   r   Ú_test_invalid_envü	  s>    




zSpawnTests._test_invalid_envc             C   s   |   tj¡ d S )N)r  r   rô  )r$   r   r   r   Útest_spawnve_invalid_env*
  s    z#SpawnTests.test_spawnve_invalid_envc             C   s   |   tj¡ d S )N)r  r   rø  )r$   r   r   r   Útest_spawnvpe_invalid_env.
  s    z$SpawnTests.test_spawnvpe_invalid_envN)r{   r|   r}   ré  r   rì  rî  rð  rò  ró  rõ  r÷  rù  rü  rý  rþ  rÿ  r   r  r  r  r  r   r   r   r   rà  	  s$   .rà  z>Skip due to platform/environment differences on *NIX buildbotsÚgetloginztest needs os.getloginc               @   s   e Zd Zdd„ ZdS )Ú
LoginTestsc             C   s   t  ¡ }|  t|ƒd¡ d S )Nr   )r   r  rÕ   r½   )r$   Z	user_namer   r   r   Útest_getlogin8
  s    zLoginTests.test_getloginN)r{   r|   r}   r  r   r   r   r   r  5
  s   r  ÚgetpriorityÚsetpriorityz'needs os.getpriority and os.setpriorityc               @   s   e Zd Zdd„ ZdS )ÚProgramPriorityTestsc             C   sÂ   t  t jt  ¡ ¡}t  t jt  ¡ |d ¡ zFt  t jt  ¡ ¡}|dkr^|dkr^t d| ¡‚n|  ||d ¡ W d yt  t jt  ¡ |¡ W n0 tk
rº } z|j	t	j
krª‚ W d d }~X Y nX X d S )Nr.   é   z?unable to reliably test setpriority at current nice level of %s)r   r	  ÚPRIO_PROCESSrØ  r
  r   r°  r>   r6   rÇ   ZEACCES)r$   r¡  Znew_priorò  r   r   r   Útest_set_get_priorityB
  s    
z*ProgramPriorityTests.test_set_get_priorityN)r{   r|   r}   r  r   r   r   r   r  =
  s   r  c               @   sv   e Zd ZG dd„ dejƒZdd„ Zedd„ ƒZdd„ Z	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ ZeZdd„ Zdd„ ZdS )ÚSendfileTestServerc               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )zSendfileTestServer.Handlerc             C   s.   t j | |¡ g | _d| _d| _|  d¡ d S )NTFs   220 ready
)ÚasynchatÚ
async_chatÚ__init__Ú	in_bufferÚ
accumulateÚclosedÚpush)r$   Úconnr   r   r   r  Y
  s
    z#SendfileTestServer.Handler.__init__c             C   s    |   d¡}| jr| j |¡ d S )Ni   )Úrecvr  r  rn  )r$   rP   r   r   r   Úhandle_read`
  s    
z&SendfileTestServer.Handler.handle_readc             C   s   d  | j¡S )Nr‡   )rÒ   r  )r$   r   r   r   Úget_datae
  s    z#SendfileTestServer.Handler.get_datac             C   s   |   ¡  d| _d S )NT)r(   r  )r$   r   r   r   Úhandle_closeh
  s    z'SendfileTestServer.Handler.handle_closec              C   s   ‚ d S )Nr   )r$   r   r   r   Úhandle_errorl
  s    z'SendfileTestServer.Handler.handle_errorN)r{   r|   r}   r  r  r  r  r  r   r   r   r   ÚHandlerW
  s
   r  c             C   sp   t j | ¡ tj | ¡ |  tjtj¡ |  	|¡ |  
d¡ | j ¡ d d… \| _| _d | _d| _t  ¡ | _d S )NrŠ   r0   F)Ú	threadingÚThreadr  ÚasyncoreÚ
dispatcherZcreate_socketÚsocketZAF_INETZSOCK_STREAMZbindZlistenZgetsocknameÚhostÚportÚhandler_instanceÚ_activeZLockÚ_active_lock)r$   Zaddressr   r   r   r  o
  s    

zSendfileTestServer.__init__c             C   s   | j S )N)r&  )r$   r   r   r   rs  |
  s    zSendfileTestServer.runningc             C   s$   t  ¡ | _t j | ¡ | j ¡  d S )N)r  ZEventÚ_SendfileTestServer__flagr  Ústartr„  )r$   r   r   r   r)  €
  s    
zSendfileTestServer.startc             C   s   d| _ |  ¡  d S )NF)r&  rÒ   )r$   r   r   r   Ústop†
  s    zSendfileTestServer.stopc             C   s*   xt | jddƒst d¡ qW |  ¡  d S )Nr  Fgü©ñÒMbP?)r˜   r%  rö   r  r*  )r$   r   r   r   r„  ‹
  s    zSendfileTestServer.waitc             C   sP   d| _ | j ¡  x2| j rBtjrB| j ¡  tjddd | j ¡  qW t 	¡  d S )NTgü©ñÒMbP?r.   )ZtimeoutrÞ  )
r&  r(  r„  r   Z
socket_mapr'  ÚacquireZloopÚreleaseZ	close_all)r$   r   r   r   Úrun“
  s    

zSendfileTestServer.runc             C   s   |   ¡ \}}|  |¡| _d S )N)Zacceptr  r%  )r$   r  Zaddrr   r   r   Úhandle_acceptœ
  s    z SendfileTestServer.handle_acceptc             C   s   |   ¡  d S )N)r(   )r$   r   r   r   Úhandle_connect 
  s    z!SendfileTestServer.handle_connectc             C   s   dS )Nr   r   )r$   r   r   r   Úwritable¤
  s    zSendfileTestServer.writablec              C   s   ‚ d S )Nr   )r$   r   r   r   r  §
  s    zSendfileTestServer.handle_errorN)r{   r|   r}   r  r  r  r  Úpropertyrs  r)  r*  r„  r-  r.  r/  r  r0  r  r   r   r   r   r  U
  s   	r  Úsendfileztest needs os.sendfile()c               @   s
  e Zd Zdd Zej d¡ o8ej d¡ o8ej d¡ Ze 	ed¡Z
e 	ejdk d¡Zed	d
„ ƒZe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e
dd „ ƒZe
ed!d"„ ƒƒZe
ed#d$„ ƒƒZe
e 	eed%ƒd&¡d'd(„ ƒƒZd)S )*ÚTestSendfiles    12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcdei   ZlinuxZsolarisZsunosz%requires headers and trailers supportl        z(test is only meaningful on 32-bit buildsc             C   s   t  ¡ | _tt j| jƒ d S )N)r   Zthreading_setupr  r   r"   ÚDATA)r¶  r   r   r   r·  ·
  s    
zTestSendfile.setUpClassc             C   s   t j| jŽ  t  t j¡ d S )N)r   Zthreading_cleanupr  r#   r"   )r¶  r   r   r   rÈ  ¼
  s    zTestSendfile.tearDownClassc             C   s~   t tjdfƒ| _| j ¡  t ¡ | _| j | jj| jj	f¡ | j 
d¡ | j d¡ | j ¡ | _ttjdƒ| _| j ¡ | _d S )Nr   r.   i   rN   )r  r   ZHOSTÚserverr)  r"  ÚclientZconnectr#  r$  Z
settimeoutr  rD   Úsocknor   r"   rE  )r$   r   r   r   r%   Á
  s    

zTestSendfile.setUpc             C   s0   | j  ¡  | j ¡  | jjr&| j ¡  d | _d S )N)rE  r(   r6  r5  rs  r*  )r$   r   r   r   r~   Í
  s
    


zTestSendfile.tearDownc          
   O   sb   x\yt j||ŽS  tk
rX } z,|jtjkr0‚ n|jtjtjfkrFwn‚ W d d }~X Y qX qW d S )N)r   r2  r6   rÇ   Z
ECONNRESETÚEAGAINÚEBUSY)r$   r[   rU  rò  r   r   r   Úsendfile_wrapperÔ
  s    zTestSendfile.sendfile_wrapperc             C   sÐ   d}d}d}xZ|t | jƒk rf|  | j| j||¡}|dkr:P ||7 }||7 }|  ||k¡ |  ||¡ qW |  |t | jƒ¡ | j t	j
¡ | j ¡  | j ¡  | jj ¡ }|  t |ƒt | jƒ¡ |  || j¡ d S )Nr   i   )r½   r4  r:  r7  rD   r)   r>   r6  Úshutdownr"  Ú	SHUT_RDWRr(   r5  r„  r%  r  )r$   Ú
total_sentÚoffsetÚnbytesÚsentrP   r   r   r   Útest_send_whole_fileå
  s$    

z!TestSendfile.test_send_whole_filec             C   sè   d}t | jƒd }t | jƒ| }d}xH||k rl|  | j| j||¡}|dkrLP ||7 }||7 }|  ||k¡ q&W | j tj	¡ | j 
¡  | j ¡  | jj ¡ }| jt | jƒd d … }|  |t |ƒ¡ |  t |ƒt |ƒ¡ |  ||¡ d S )Nr   r0   i   )r½   r4  r:  r7  rD   r)   r6  r;  r"  r<  r(   r5  r„  r%  r  r>   )r$   r=  r>  Z	must_sendr?  r@  rP   r‡  r   r   r   Útest_send_at_certain_offsetû
  s&    


z(TestSendfile.test_send_at_certain_offsetc          
   C   s¢   t | jƒd }yt | j| j|d¡}W n0 tk
rV } z|jtjkrF‚ W d d }~X Y nX |  	|d¡ | j
 tj¡ | j
 ¡  | j ¡  | jj ¡ }|  	|d¡ d S )Ni   r   r‡   )r½   r4  r   r2  r7  rD   r6   rÇ   ÚEINVALr>   r6  r;  r"  r<  r(   r5  r„  r%  r  )r$   r>  r@  rÃ   rP   r   r   r   Útest_offset_overflow  s    

z!TestSendfile.test_offset_overflowc          	   C   s@   |   t¡}t | j| jdd¡ W d Q R X |  |jjtj	¡ d S )Nrh  i   )
r5   r6   r   r2  r7  rD   r>   rÆ   rÇ   rC  )r$   rG  r   r   r   Útest_invalid_offset#  s    z TestSendfile.test_invalid_offsetc          	   C   sF   t jf | jdddœd| ji—Ž | jrBt j| j| jdddddd d S )Nr   i   )rß  r>  rÞ  Úinr   )r>  rÞ  ÚheadersÚtrailersro   )r   r2  r7  rD   ÚSUPPORT_HEADERS_TRAILERS)r$   r   r   r   Útest_keywords(  s
    zTestSendfile.test_keywordsc             C   sð   d}d| j d d…  }tj| j| jddddgd}|  |d¡ ||7 }d}x\|t|ƒk r¦tt|ƒ| dƒ}|  | j| j||¡}|dkrˆP |  ||¡ ||7 }||7 }qLW |  	|t|ƒ¡ | j
 ¡  | j ¡  | jj ¡ }|  	t|ƒt|ƒ¡ d S )	Nr   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyrh  i   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs   yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy)rG  i   )r4  r   r2  r7  rD   ZassertLessEqualr½   Úminr:  r>   r6  r(   r5  r„  r%  r  Úhash)r$   r=  Zexpected_datar@  r>  r?  rP   r   r   r   Útest_headers2  s*    

zTestSendfile.test_headersc          	   C   sŠ   t jd }d}|  t j|¡ t||ƒ t|dƒP}tj| j| 	¡ ddddgd | j
 ¡  | j ¡  | jj ¡ }|  |d	¡ W d Q R X d S )
NrB  s   abcdefrN   r   rŠ   s   123456s   789)rH  s   abcde123456789)r   r"   rO   r#   r   r   r   r2  r7  rD   r6  r(   r5  r„  r%  r  r>   )r$   rm   Z	file_datar,   rP   r   r   r   Útest_trailersK  s    



zTestSendfile.test_trailersc          	   C   sX   d| j j_|  t¡(}tj| j| jdddd gd d W d Q R X |  	|j
jtj¡ d S )NFr   ó   xi   i €  )rG  )r5  r%  r  r5   r6   r   r2  r7  rD   r>   rÆ   rÇ   rC  )r$   rG  r   r   r   Útest_headers_overflow_32bits[  s
    
z)TestSendfile.test_headers_overflow_32bitsc          	   C   sX   d| j j_|  t¡(}tj| j| jdddd gd d W d Q R X |  	|j
jtj¡ d S )NFr   rO  i   i €  )rH  )r5  r%  r  r5   r6   r   r2  r7  rD   r>   rÆ   rÇ   rC  )r$   rG  r   r   r   Útest_trailers_overflow_32bitsd  s
    
z*TestSendfile.test_trailers_overflow_32bitsÚSF_NODISKIOztest needs os.SF_NODISKIOc          
   C   sZ   yt j| j| jddt jd W n6 tk
rT } z|jtjtjfkrD‚ W d d }~X Y nX d S )Nr   i   )ro   )	r   r2  r7  rD   rR  r6   rÇ   r9  r8  )r$   rò  r   r   r   Ú
test_flagsm  s    zTestSendfile.test_flagsN)r{   r|   r}   r4  r:   r€   rÔ  rI  r   r   Zrequires_headers_trailersÚmaxsizeZrequires_32brÉ  r·  rÈ  r%   r~   r:  rA  rB  rD  rE  rJ  rM  rN  rP  rQ  r   r   rS  r   r   r   r   r3  «
  s6   
r3  c           	   C   sl   t tdƒsdS zJttjddƒ2} yt |  ¡ dd¡ W n tk
rJ   dS X W d Q R X W d t tj¡ X dS )NÚsetxattrFr   r   s	   user.testr‡   T)	r   r   r   r   r"   rU  rD   r6   r#   )r   r   r   r   Úsupports_extended_attributesy  s    
rV  z(no non-broken extended attribute supportr0   r‹   é'   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚExtendedAttributeTestsc          	   K   s¼  t j}|  t j|¡ t|ƒ |  t¡}|||dƒf|Ž W d Q R X |  |jj	t	j
¡ ||ƒ}	|  |	t¡ |||dƒdf|Ž t|	ƒ}
|
 d¡ |  t||ƒƒ|
¡ |  ||df|Žd¡ |||dƒdtjf|Ž |  ||df|Žd¡ |  t¡}|||dƒdtjf|Ž W d Q R X |  |jj	t	j¡ |  t¡}|||dƒdtjf|Ž W d Q R X |  |jj	t	j
¡ |||dƒdtjf|Ž |
 d¡ |  t||ƒƒ|
¡ |||dƒf|Ž |  t¡}|||dƒf|Ž W d Q R X |  |jj	t	j
¡ |
 d¡ |  t||ƒƒ|
¡ |  |||dƒf|Žd¡ |||dƒdf|Ž |  |||dƒf|Žd¡ |||dƒf|Ž td	d
„ tdƒD ƒƒ}x|D ]}|||df|Ž q~W |  t||ƒƒt|	ƒt|ƒB ¡ d S )Nz	user.testr‡   s	   user.tests   hellos   byez
user.test2s   foos   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac             s   s   | ]}d   |¡V  qdS )zuser.test{}N)r,  )r   r  r   r   r   r-  º  s    z;ExtendedAttributeTests._check_xattrs_str.<locals>.<genexpr>re   rO  )r   r"   rO   r#   r   r5   r6   r>   rÆ   rÇ   ZENODATArÙ  ri  r„  rh  r   ÚXATTR_REPLACEÚXATTR_CREATEZEEXISTro  r›  r­   )r$   rK   ÚgetxattrrU  ÚremovexattrÚ	listxattrrU  rc  rG  Z
init_xattrZxattrZmanyÚthingr   r   r   Ú_check_xattrs_str  sL    
""


z(ExtendedAttributeTests._check_xattrs_strc             O   sB   | j tf|ž|Ž t tj¡ | j tjf|ž|Ž t tj¡ d S )N)r_  r'  r   r#   r"   r   r“  )r$   r[   rU  r   r   r   Ú_check_xattrs¿  s    z$ExtendedAttributeTests._check_xattrsc             C   s   |   tjtjtjtj¡ d S )N)r`  r   r[  rU  r\  r]  )r$   r   r   r   Útest_simpleÆ  s    z"ExtendedAttributeTests.test_simplec             C   s    | j tjtjtjtjdd d S )NF)rî   )r`  r   r[  rU  r\  r]  )r$   r   r   r   Ú
test_lpathÊ  s    z!ExtendedAttributeTests.test_lpathc             C   s4   dd„ }dd„ }dd„ }dd„ }|   ||||¡ d S )	Nc          	   W   s*   t | dƒ}tj| ¡ f|žŽ S Q R X d S )NrN   )r   r   r[  rD   )r    r[   r   r   r   r   r[  Ï  s    z1ExtendedAttributeTests.test_fds.<locals>.getxattrc          	   W   s0   t | ddƒ}tj| ¡ f|žŽ  W d Q R X d S )Nrð   r   )r   r   rU  rD   )r    r[   r   r   r   r   rU  Ò  s    z1ExtendedAttributeTests.test_fds.<locals>.setxattrc          	   W   s0   t | ddƒ}tj| ¡ f|žŽ  W d Q R X d S )Nrð   r   )r   r   r\  rD   )r    r[   r   r   r   r   r\  Õ  s    z4ExtendedAttributeTests.test_fds.<locals>.removexattrc          	   W   s*   t | dƒ}tj| ¡ f|žŽ S Q R X d S )NrN   )r   r   r]  rD   )r    r[   r   r   r   r   r]  Ø  s    z2ExtendedAttributeTests.test_fds.<locals>.listxattr)r`  )r$   r[  rU  r\  r]  r   r   r   Útest_fdsÎ  s
    zExtendedAttributeTests.test_fdsN)r{   r|   r}   r_  r`  ra  rb  rc  r   r   r   r   rX  ‰  s
   0rX  Úget_terminal_sizezrequires os.get_terminal_sizec               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTermsizeTestsc          
   C   sx   yt  ¡ }W nJ tk
rV } z,tjdks:|jtjtjfkrD|  d¡ ‚ W d d }~X Y nX |  	|j
d¡ |  	|jd¡ d S )Nr]   zfailed to query terminal sizer   )r   rd  r6   r:   r€   rÇ   rC  ÚENOTTYr3   ZassertGreaterEqualÚcolumnsÚlines)r$   rM   rÃ   r   r   r   Útest_does_not_crashà  s    
z!TermsizeTests.test_does_not_crashc          
   C   sÊ   yt  ddg¡ ¡  ¡ }W n& tt jtfk
r@   |  d¡ Y nX t|d ƒt|d ƒf}yt	 
tj ¡ ¡}W nJ tk
r¸ } z,tjdksœ|jtjtjfkr¦|  d¡ ‚ W d d }~X Y nX |  ||¡ d S )NZsttyrM   zstty invocation failedr.   r   r]   zfailed to query terminal size)rZ   Zcheck_outputr>  rš   rk   ZCalledProcessErrorrf  r3   r„   r   rd  r:   Ú	__stdin__rD   r6   r€   rÇ   rC  rf  r>   )r$   rM   r‡  ÚactualrÃ   r   r   r   Útest_stty_matchò  s    
zTermsizeTests.test_stty_matchN)r{   r|   r}   ri  rl  r   r   r   r   re  Þ  s   re  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚOSErrorTestsc             C   s¬   G dd„ dt ƒ}g | _g | _tjd k	r.tj}ntj}| j |¡ | j ||ƒ¡ tjd k	rbtj}nt 	tj¡}| j |¡ | j t
|ƒ¡ | j t|ƒ¡ | j| j | _d S )Nc               @   s   e Zd ZdS )zOSErrorTests.setUp.<locals>.StrN)r{   r|   r}   r   r   r   r   ÚStr  s   rn  )r'  Úbytes_filenamesÚunicode_filenamesr   rf  r"   rn  ZTESTFN_UNDECODABLEr   r“  rT   rU   rÂ  )r$   rn  ZdecodedZencodedr   r   r   r%     s    

zOSErrorTests.setUpc             C   sX  | j tjf| j tjdf| j tjf| j tjtjf| j tjf| j tjf| j tj	fg}t
jdkr | | jtjdf| jtjdf| jtjdf| jtjdf| jtjff¡ n,| | j tjf| j tjdf| j tjdff¡ ttdƒrì| | j tjddf¡ ttdƒr| | j tjddf¡ ttdƒr.| | j tjdf¡ ttd	ƒrN| | j tjdf¡ ttd
ƒrn| | j tjdf¡ ttdƒrŒ| | j tjf¡ ttdƒrât
jdkrÎ| | jtjdf¡ | | jtjdf¡ n| | j tjdf¡ ttdƒr(| | j tjf| j tjdf| j tjddf| j tjdff¡ ttdƒrH| | j tjdf¡ ttdƒr†t
jdkrt| | jtj f¡ n| | j tj f¡ xÌ|D ]Ä^}}}x¶|D ]®}yJt!|t"t#fƒrÂ||f|žŽ  n&|  $t%d¡ ||f|žŽ  W d Q R X W nL t&k
r" } z|  '|j(|t"|ƒ¡ W d d }~X Y n& t)k
r6   Y nX |  *d +|¡¡ qœW qŒW d S )Niÿ  r]   s   dstrw   r´  r   Úlchownr0  ÚchflagsÚlchflagsÚchrootr[  r]  z	user.tests   userÚlchmodr±  z	should bezNo exception thrown by {}),rÂ  r   r  rd  r¯  r   ra   rÏ   rl   r#   r:   r€   r™  ro  r=   rj   rp  re  r   rn  r´  rq  r0  rr  rs  rt  r[  r]  r[  rU  r\  ru  r±  r»   r'  rH   ZassertWarnsRegexÚDeprecationWarningr6   rD  r   ÚUnicodeDecodeErrorrœ   r,  )r$   ZfuncsrÂ  ÚfuncZ	func_argsr   rò  r   r   r   Útest_oserror_filename"  sv    








$z"OSErrorTests.test_oserror_filenameN)r{   r|   r}   r%   ry  r   r   r   r   rm    s   rm  c               @   s   e Zd Zdd„ ZdS )ÚCPUCountTestsc             C   s8   t  ¡ }|d k	r*|  |t¡ |  |d¡ n
|  d¡ d S )Nr   z&Could not determine the number of CPUs)r   Ú	cpu_countrÙ  r„   ÚassertGreaterr3   )r$   Zcpusr   r   r   Útest_cpu_countl  s
    zCPUCountTests.test_cpu_countN)r{   r|   r}   r}  r   r   r   r   rz  k  s   rz  c               @   s¼   e Zd Zdd„ Ze edkd¡dd„ ƒZe edkd¡dd„ ƒZd	d
„ Z	e 
eedƒd¡dd„ ƒZdd„ Ze 
ejdkd¡dd„ ƒZe 
eedƒd¡dd„ ƒZe 
eedƒd¡dd„ ƒZdS )ÚFDInheritanceTestsc             C   sP   t  tt j¡}|  t j|¡ |  t  |¡d¡ t  |d¡ |  t  |¡d¡ d S )NFT)	r   r   rr   ra   rO   r(   r>   r:  r;  )r$   rJ   r   r   r   Útest_get_set_inheritablev  s
    z+FDInheritanceTests.test_get_set_inheritableNz
need fcntlc             C   sn   t  tt j¡}|  t j|¡ |  t  |¡d¡ t |tj	¡}|tj
 M }t |tj|¡ |  t  |¡d¡ d S )NFT)r   r   rr   ra   rO   r(   r>   r:  ÚfcntlÚF_GETFDÚ
FD_CLOEXECZF_SETFD)r$   rJ   ro   r   r   r   Útest_get_inheritable_cloexec~  s    z/FDInheritanceTests.test_get_inheritable_cloexecc             C   sf   t  tt j¡}|  t j|¡ |  t |tj¡tj	@ tj	¡ t  
|d¡ |  t |tj¡tj	@ d¡ d S )NTr   )r   r   rr   ra   rO   r(   r>   r€  r  r‚  r;  )r$   rJ   r   r   r   Útest_set_inheritable_cloexec‹  s    z/FDInheritanceTests.test_set_inheritable_cloexecc             C   s2   t  tt j¡}|  t j|¡ |  t  |¡d¡ d S )NF)r   r   rr   ra   rO   r(   r>   r:  )r$   rJ   r   r   r   rm  –  s    zFDInheritanceTests.test_openrÅ   zneed os.pipe()c             C   sP   t  ¡ \}}|  t j|¡ |  t j|¡ |  t  |¡d¡ |  t  |¡d¡ d S )NF)r   rÅ   rO   r(   r>   r:  )r$   ZrfdZwfdr   r   r   Ú	test_pipe›  s
    zFDInheritanceTests.test_pipec             C   sJ   t  tt j¡}|  t j|¡ t  |¡}|  t j|¡ |  t  |¡d¡ d S )NF)	r   r   rr   ra   rO   r(   r2   r>   r:  )r$   Úfd1Úfd2r   r   r   Útest_dup£  s
    
zFDInheritanceTests.test_dupr]   zwin32-specific testc             C   sH   t  dt j¡}|  t j|¡ t  |¡}|  t j|¡ |  t  |¡¡ d S )NZNUL)r   r   ra   rO   r(   r2   rÎ  r:  )r$   r†  r‡  r   r   r   Útest_dup_nul«  s
    
zFDInheritanceTests.test_dup_nulr$  zneed os.dup2()c             C   s¤   t  tt j¡}|  t j|¡ t  tt j¡}|  t j|¡ |  t  ||¡|¡ |  t  	|¡¡ t  tt j¡}|  t j|¡ |  t j||dd|¡ |  
t  	|¡¡ d S )NF)Zinheritable)r   r   rr   ra   rO   r(   r>   r$  r)   r:  rÎ  )r$   rJ   r‡  Zfd3r   r   r   r&  ´  s    zFDInheritanceTests.test_dup2Úopenptyzneed os.openpty()c             C   sP   t  ¡ \}}|  t j|¡ |  t j|¡ |  t  |¡d¡ |  t  |¡d¡ d S )NF)r   rŠ  rO   r(   r>   r:  )r$   Z	master_fdZslave_fdr   r   r   Útest_openptyÅ  s
    zFDInheritanceTests.test_openpty)r{   r|   r}   r  r   r  r€  rƒ  r„  rm  r   r   r   r…  rˆ  r:   r€   r‰  r&  r‹  r   r   r   r   r~  u  s   	r~  c               @   sH   e Zd Zddddejfdfddddd	eed
dƒfgZdd„ Zdd„ ZdS )ÚPathTConverterTests)rl   Tr   N)r¯  Fr   Nr*   FN)rr  F)r   N)rs  F)r   Nr   )r   r(   c             C   s   t j}tjdkrd  }}nt j d¡}t|ƒ}t t|ƒtjtjB ¡}|  	t j
t j¡ |  	tj|¡ t|ƒ}t|ƒ}x$| jD ]\}}}	}
| j|dú ytt|ƒ}W n tk
r¾   w~Y nX xX||||fD ]H}|d krÜqÎ| j||d& ||f|	žŽ }|
d k	r|
|ƒ W d Q R X qÎW |  td¡ ||f|	žŽ  W d Q R X |rh||f|	žŽ }|
d k	rŽ|
|ƒ n&|  td¡ ||f|	žŽ  W d Q R X W d Q R X q~W d S )Nr£  rÈ  )r   )r   r    zto return str or byteszos.PathLike)r   r"   r   r   r©   r   r   rS   r&   rO   r#   r(   Ú	functionsZsubTestr˜   rŸ   ÚassertRaisesRegexr<   )r$   Zstr_filenameZbytes_fspathÚbytes_filenamerJ   Z
int_fspathZ
str_fspathr   Zallow_fdZ
extra_argsZ
cleanup_fnrc  r    r£   r   r   r   Útest_path_t_converterÚ  sF    






z)PathTConverterTests.test_path_t_converterc          	   C   sˆ   d}|   t|d ¡ t tdƒ¡ W d Q R X |   t|d ¡ t tdƒ¡ W d Q R X |   t|d ¡ t ttƒ ƒ¡ W d Q R X d S )Nz-__fspath__\(\) to return str or bytes, not %sr„   r0   Úfloatg¸…ëQ¸@Úobject)rŽ  r<   r   rl   r   r’  )r$   rõ   r   r   r   Ú&test_path_t_converter_and_custom_class  s    z:PathTConverterTests.test_path_t_converter_and_custom_class)	r{   r|   r}   r   ÚF_OKr˜   r  r  r“  r   r   r   r   rŒ  Î  s   ,rŒ  r=  z-needs os.get_blocking() and os.set_blocking()c               @   s   e Zd Zdd„ ZdS )ÚBlockingTestsc             C   sn   t  tt j¡}|  t j|¡ |  t  |¡d¡ t  |d¡ |  t  |¡d¡ t  |d¡ |  t  |¡d¡ d S )NTF)	r   r   rr   ra   rO   r(   r>   r=  r>  )r$   rJ   r   r   r   r?    s    zBlockingTests.test_blockingN)r{   r|   r}   r?  r   r   r   r   r•    s   r•  c               @   s   e Zd Zdd„ ZdS )ÚExportsTestsc             C   s    |   dtj¡ |   dtj¡ d S )Nr   rS  )r™   r   Ú__all__)r$   r   r   r   Útest_os_all!  s    zExportsTests.test_os_allN)r{   r|   r}   r˜  r   r   r   r   r–     s   r–  c               @   sú   e Zd ZejZdd„ Zd8dd„Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zd9d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ejkd$¡d%d&„ ƒZd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Z d1d2„ Z!d3d4„ Z"d5d6„ Z#d7S ):ÚTestScandirc             C   s>   t j tj¡| _t  | j¡| _|  tj| j¡ t  	| j¡ d S )N)
r   r    Úrealpathr   r"   r“  Ú
bytes_pathrO   rÙ   rÎ   )r$   r   r   r   r%   )  s    zTestScandir.setUpúfile.txtc             C   s2   t |tƒr| jn| j}tj ||¡}t|dƒ |S )Ns   python)r»   rH   r›  r    r   rÒ   r   )r$   r   r    r   r   r   r   r   /  s    
zTestScandir.create_filec             C   s2   t dd„ t | j¡D ƒƒ}|  t| ¡ ƒ|¡ |S )Nc             s   s   | ]}|j |fV  qd S )N)r   )r   Úentryr   r   r   r-  6  s   z*TestScandir.get_entries.<locals>.<genexpr>)r  r   Úscandirr    r>   r›  Úkeys)r$   ÚnamesÚentriesr   r   r   Úget_entries5  s    zTestScandir.get_entriesc             C   s^   |rNxTt |ƒD ]:}| d¡sq|dkr(q|  t||ƒt||ƒ|||f¡ qW n|  ||¡ d S )NZst_)Úst_devÚst_inoÚst_nlink)r•   rÔ  r>   r˜   )r$   Zstat1Zstat2Zskip_fieldsr¥   r   r   r   Úassert_stat_equal;  s    
zTestScandir.assert_stat_equalc             C   s2  |   |tj¡ |  |j|¡ |  |jtj | j|¡¡ |  | ¡ tj|jddj	¡ t |j¡}|  | 
¡ t |j¡¡ |  | ¡ t |j¡¡ |  | ¡ tj |j¡¡ tj|jdd}|  |j
ddt |j¡¡ |  |jddt |j¡¡ |  | ¡ |tjdko| ¡ |  |jdd|tjdk¡ d S )NF)rî   r£  )rÙ  r   ÚDirEntryr>   r   r    rÒ   Úinoderl   r¤  Úis_dirÚS_ISDIRrž   Úis_fileÚS_ISREGÚ
is_symlinkr£  r¦  )r$   r  r   r©  r«  r­  Z
entry_statZentry_lstatr   r   r   Úcheck_entryH  s.    




zTestScandir.check_entryc       	   
   C   s€  t tdƒ}t ¡ }tj | jd¡}t |¡ |  d¡}|rˆyt |tj | jd¡¡ W n0 t	k
r† } z|  
d| ¡ W d d }~X Y nX |rÀtj|tj | jd¡dd t |tj | jd	¡¡ ddg}|rÖ| d¡ |rä| d
¡ |  |¡}|d }|  |dddd¡ |d }|  |dddd¡ |rB|d }|  |dddd¡ |r||d }|  |dddd¡ |d	 }|  |d	ddd¡ d S )Nr[  r•   zfile.txtzlink_file.txtzos.link(): %sÚsymlink_dirT)rx   zsymlink_file.txt)r¯  zsymlink_file.txtF)r   r   r   rb  r    rÒ   rÎ   r   r[  rf  r3   rt   rn  r™  r¢  r®  )	r$   r[  rt   rÐ   r   rÃ   r   r¡  r  r   r   r   Útest_attributesd  s@    


 


zTestScandir.test_attributesc             C   sN   t |tƒr| jn| j}tt |¡ƒ}|  t|ƒd¡ |d }|  |j	|¡ |S )Nr.   r   )
r»   rH   r›  r    ri  r   rž  r>   r½   r   )r$   r   r    r¡  r  r   r   r   Ú	get_entry  s    zTestScandir.get_entryc             C   s   | j |d}|  tj |¡¡S )N)r   )r   r±  r   r    Úbasename)r$   r   r   r   r   r   Úcreate_file_entry–  s    zTestScandir.create_file_entryc          	   C   sf   |   ¡ }t ¡ }zDt | j¡ tdd„ t ¡ D ƒƒ}|  t| 	¡ ƒtj 
|¡g¡ W d t |¡ X d S )Nc             s   s   | ]}|j |fV  qd S )N)r   )r   r  r   r   r   r-  ¢  s    z5TestScandir.test_current_directory.<locals>.<genexpr>)r   r   rj  r  r    r  rž  r>   r›  rŸ  r²  )r$   r   Zold_dirr¡  r   r   r   Útest_current_directoryš  s    z"TestScandir.test_current_directoryc             C   s   |   ¡ }|  t|ƒd¡ d S )Nz<DirEntry 'file.txt'>)r³  r>   r.  )r$   r  r   r   r   Ú	test_repr¨  s    zTestScandir.test_reprc             C   s*   |   ¡ }|  t |¡tj | jd¡¡ d S )Nzfile.txt)r³  r>   r   Úfspathr    rÒ   )r$   r  r   r   r   Útest_fspath_protocol¬  s    z TestScandir.test_fspath_protocolc             C   sN   t  d¡}| j|d}t  |¡}|  |t¡ |  |t j t  | j¡|¡¡ d S )Nzbytesfile.txt)r   )	r   r“  r³  r¶  rÙ  rH   r>   r    rÒ   )r$   r  Zbytes_entryr¶  r   r   r   Útest_fspath_protocol_bytes°  s    

z&TestScandir.test_fspath_protocol_bytesc             C   sÄ   t j | jd¡}t  |¡ |  d¡}t  |¡ t jdkrF|  | ¡ ¡ |  	| 
¡ ¡ |  	| ¡ ¡ t jdkr|  t|j¡ | ¡  |jdd n0|  | ¡ d¡ |  t|j¡ | jt|jdd d S )Nr•   r£  F)rî   r   )r   r    rÒ   rÎ   r±  rÏ   r   r)   r©  rÎ  r«  r­  r5   rk   r¨  rl   r|  )r$   r    r  r   r   r   Útest_removed_dir¸  s    




zTestScandir.test_removed_dirc             C   sª   |   ¡ }t |j¡ |  | ¡ ¡ tjdkr:|  | ¡ ¡ |  | 	¡ ¡ tjdkrv|  
t|j¡ | ¡  |jdd n0|  | ¡ d¡ |  
t|j¡ | j
t|jdd d S )Nr£  F)rî   r   )r³  r   r#   r    rÎ  r©  r   r)   r«  r­  r5   rk   r¨  rl   r|  )r$   r  r   r   r   Útest_removed_fileÎ  s    

zTestScandir.test_removed_filec             C   sÐ   t  ¡ s|  d¡S |  d¡}t |tj | jd¡¡ |  ddg¡}|d }t 	|¡ |  
| ¡ d¡ |  | ¡ ¡ |  | ¡ ¡ |  |jdd¡ |  |jdd¡ |  | ¡ ¡ |  t|j¡ |jdd d S )Nzcannot create symbolic linkzfile.txtzsymlink.txtr   F)rî   )r   rb  r3   r   r   rt   r    rÒ   r¢  r#   r|  r¨  rÎ  r©  r«  r)   r­  r5   rk   rl   )r$   r   r¡  r  r   r   r   Útest_broken_symlinká  s     


zTestScandir.test_broken_symlinkc          	   C   sp   |   d¡ t | j¡}tt |¡ƒ}|  t|ƒd|¡ |d }|  |jd¡ |  |jt tj 	| jd¡¡¡ d S )Nzfile.txtr.   r   s   file.txt)
r   r   r“  r    ri  rž  r>   r½   r   rÒ   )r$   Ú
path_bytesr¡  r  r   r   r   Ú
test_bytesö  s    
zTestScandir.test_bytesc          
   C   sÀ   |   d¡ x°ttfD ]¤}|t | j¡ƒ}|  t¡ tt 	|¡ƒ}W d Q R X |  
t|ƒd|¡ |d }|  
|jd¡ |  
|jt tj | jd¡¡¡ |  t|jƒt¡ |  t|jƒt¡ qW d S )Nzfile.txtr.   r   s   file.txt)r   rT   rU   r   r“  r    ÚassertWarnsrv  ri  rž  r>   r½   r   rÒ   rD  rG   rH   )r$   r¶  r¼  r¡  r  r   r   r   Útest_bytes_like  s    
zTestScandir.test_bytes_likez.fd support for listdir required for this test.c          	   C   sX  |   tjtj¡ |  d¡ dg}t ¡ rJt dtj 	| jd¡¡ | 
d¡ t | jtj¡}zìt |¡}t|ƒ}W d Q R X dd„ |D ƒ}|  t|ƒ|¡ |  |t |¡¡ x˜|D ]}|  |j|j¡ |  t |¡|j¡ |  | ¡ |jdk¡ tjtjkr°tj|j|d}|  | ¡ |¡ tj|j|dd}|  |jdd|¡ q°W W d t |¡ X d S )	Nzfile.txtr[  c             S   s   g | ]
}|j ‘qS r   )r   )r   r  r   r   r   r      s    z'TestScandir.test_fd.<locals>.<listcomp>)rq   F)rq   rî   )rî   )r™   r   rž  r  r   r   rb  rt   r    rÒ   rn  r   ra   ri  r>   r›  re  r   r¶  r­  rl   r	  r(   )r$   Zexpected_namesrJ   r%  r¡  r   r  rÝ   r   r   r   Útest_fd  s.    


zTestScandir.test_fdc             C   s   |   ttjd¡ d S )Nrû   )r5   rk   r   rž  )r$   r   r   r   Útest_empty_path/  s    zTestScandir.test_empty_pathc             C   sN   |   d¡ t | j¡}t|ƒ}|  t|ƒd|¡ t|ƒ}|  t|ƒd|¡ d S )Nzfile.txtr.   r   )r   r   rž  r    ri  r>   r½   )r$   rI  r¡  Zentries2r   r   r   Útest_consume_iterator_twice2  s    
z'TestScandir.test_consume_iterator_twicec             C   s(   x"di g gD ]}|   ttj|¡ qW d S )NgX9´Èv¾ó?)r5   r<   r   rž  )r$   Úobjr   r   r   Útest_bad_path_type=  s    zTestScandir.test_bad_path_typec          	   C   sR   |   d¡ |   d¡ t | j¡}t|ƒ | ¡  | ¡  |  ¡  ~W d Q R X d S )Nzfile.txtz	file2.txt)r   r   rž  r    r#  r(   Úcheck_no_resource_warning)r$   rI  r   r   r   Ú
test_closeA  s    


zTestScandir.test_closec          	   C   sN   |   d¡ |   d¡ t | j¡}t|ƒ W d Q R X |  ¡  ~W d Q R X d S )Nzfile.txtz	file2.txt)r   r   rž  r    r#  rÅ  )r$   rI  r   r   r   Útest_context_managerL  s    


z TestScandir.test_context_managerc          	   C   s@   |   d¡ |   d¡ t | j¡}t|ƒ | ¡  W d Q R X d S )Nzfile.txtz	file2.txt)r   r   rž  r    r#  r(   )r$   rI  r   r   r   Útest_context_manager_closeT  s
    

z&TestScandir.test_context_manager_closec          
   C   sl   |   d¡ |   d¡ |  t¡. t | j¡}t|ƒ dd  W d Q R X W d Q R X |  ¡  ~W d Q R X d S )Nzfile.txtz	file2.txtr.   r   )r   r5   ÚZeroDivisionErrorr   rž  r    r#  rÅ  )r$   rI  r   r   r   Útest_context_manager_exception[  s    


z*TestScandir.test_context_manager_exceptionc          	   C   sv   |   d¡ |   d¡ t | j¡}t|ƒ |  t¡ ~t ¡  W d Q R X t | j¡}t	|ƒ |  
¡  ~W d Q R X d S )Nzfile.txtz	file2.txt)r   r   rž  r    r#  r¾  ÚResourceWarningr   Z
gc_collectri  rÅ  )r$   rI  r   r   r   Útest_resource_warninge  s    


z!TestScandir.test_resource_warningN)rœ  )rœ  )$r{   r|   r}   r   rÅ  r%   r   r¢  r¦  r®  r°  r±  r³  r´  rµ  r·  r¸  r¹  rº  r»  r½  r¿  r   r   r   re  r  rÀ  rÁ  rÂ  rÄ  rÆ  rÇ  rÈ  rÊ  rÌ  r   r   r   r   r™  &  s8   
)	

r™  c               @   sN   e Zd ZeejƒZdd„ Zdd„ Zdd„ Zdd„ Z	d	d
„ Z
dd„ Zdd„ ZdS )Ú
TestPEP519c             C   s$   xdD ]}|   ||  |¡¡ qW d S )N)s   hellos   goodbyes   some/path/and/file)r>   r¶  )r$   Úbr   r   r   Útest_return_bytesz  s    
zTestPEP519.test_return_bytesc             C   s$   xdD ]}|   ||  |¡¡ qW d S )N)ZhelloZgoodbyezsome/path/and/file)r>   r¶  )r$   rK   r   r   r   Útest_return_string~  s    
zTestPEP519.test_return_stringc             C   sP   xJdD ]B}t |ƒ}|  ||  |¡¡ |  dt |¡¡ |  dt |¡¡ qW d S )N)zpath/like/objects   path/like/objects   path/like/objectzpath/like/object)r   r>   r¶  r   r“  r”  )r$   r³   Zpathliker   r   r   Útest_fsencode_fsdecode‚  s
    
z!TestPEP519.test_fsencode_fsdecodec             C   sB   |   d|  tdƒ¡¡ |  tttjƒ¡ |  ttdƒtjƒ¡ d S )Nz#feelthegilr…   )r>   r¶  r   r)   Ú
issubclassr   ÚPathLiker»   )r$   r   r   r   Útest_pathlikeŠ  s    zTestPEP519.test_pathlikec             C   s8   t ddi ƒ}x&tt t|ƒ fD ]}|  t| j|¡ qW d S )NZblahr   )rG   r„   r   r5   r<   r¶  )r$   ZvaporÚor   r   r   Útest_garbage_in_exception_out  s    z(TestPEP519.test_garbage_in_exception_outc             C   s   |   t| j¡ d S )N)r5   r<   r¶  )r$   r   r   r   Útest_argument_required”  s    z!TestPEP519.test_argument_requiredc             C   sR   |   t| jtdƒ¡ tddi ƒ}d|_|   t| j|ƒ ¡ |   t| jttƒ ƒ¡ d S )Nr  Zfoor   r.   )r5   r<   r¶  r   rG   Ú
__fspath__rÉ  )r$   Úcr   r   r   Útest_bad_pathlike—  s    
zTestPEP519.test_bad_pathlikeN)r{   r|   r}   r  r   r¶  rÏ  rÐ  rÑ  rÔ  rÖ  r×  rÚ  r   r   r   r   rÍ  t  s   
rÍ  c               @   s   e Zd Zdd„ ZdS )Ú
TimesTestsc             C   sr   t  ¡ }|  |t j¡ x"dD ]}t||ƒ}|  |t¡ qW t jdkrn|  |jd¡ |  |j	d¡ |  |j
d¡ d S )N)ÚuserÚsystemÚchildren_userÚchildren_systemÚelapsedr£  r   )r   rì   rÙ  Útimes_resultr˜   r‘  r   r>   rÞ  rß  rà  )r$   rì   Zfieldr¿   r   r   r   Ú
test_times¤  s    


zTimesTests.test_timesN)r{   r|   r}   râ  r   r   r   r   rÛ  £  s   rÛ  Ú_fspathc               @   s   e Zd ZeejƒZdS )ÚTestPEP519PurePythonN)r{   r|   r}   r  r   rã  r¶  r   r   r   r   rä  ¶  s   rä  Ú__main__)r   )N)}r  r   rÐ  Ú
contextlibr»  rÇ   r¼  r   r‚  rÕ  r  r   r®   ri  rˆ  r"  rl   rZ   r:   Z	sysconfigr  rö   r   rŒ  r8  r¿  r   rõ  rÁ  r€  r¹  ZgrpZgetgrallrÁ  r   r	   Zprocess_gidrn  ÚpwdZgetpwallrÃ  rŸ   Z	_testcapir   r   rT  Ztest.support.script_helperr   Ztest.supportr   r   rÊ  r   r   ÚversionrÔ  r  r€   rU  r   r   ZTestCaser   r   r×   r  ZBasicTestMappingProtocolr  rP  r   r  r’  r™  r›  rµ  rË  rÒ  rÕ  rä  Zget_config_varZOS_URANDOM_DONT_USE_FDr  rï  Úcontextmanagerrü  rý  r  r  rA  rN  rb  rq  r—  Zskip_unless_symlinkrž  r·  r¾  rÄ  rÆ  rÊ  rÖ  rà  r–  r  r  r!  r  r  r3  rV  Zrequires_linux_versionrX  re  rm  rz  r~  rŒ  r•  r–  r™  rÍ  rÛ  rä  r{   Úmainr   r   r   r   Ú<module>   s@  






  ^ _ 5 0C_
5)	
-
M!h
#d%
C
G
s
/ 

8
 7
V
 NQ
,`
YB
  P/
