B
    2*™\Í4 ã            	   @   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   ú7C:\ALexclude\prg\programme\Python37\Lib\test\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ÚAttributeErrorZ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   Z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Zdd„ Zdd„ Zdd„ Zd	d
„ Ze	 
eoBej e¡d¡dd„ ƒZe	 
eobe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 ))ÚEnvironTestsz8check that os.environ object conform to mapping protocolNc             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 )z>Check that the repr() of os.environ looks like environ({...}).z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>N)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   )r/  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)rH  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)rH  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)rH  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}   Ú__doc__Z	type2testr%   r~   r  r  r   r   r   r   r    Úexistsr  r$  r'  r)  r.  r9  r  r=  r   Zrequires_mac_verr?  rF  rH  rI  rJ  rL  r   r   r   r   r  ¨  s,   )r  c               @   sR   e Zd 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 )Ú	WalkTestszTests for os.walk().c             K   s$   d|kr|  d¡|d< tj|f|ŽS )Nrí   Úfollowlinks)Úpopr   Úwalk)r$   ÚtopÚkwargsr   r   r   rR  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.   rU  rƒ   r0   éÿÿÿÿrW  rX  rV  rY  )	ÚlistrR  r\  r>   r¼   Úsortr]  r^  rb  )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 )NrU  r0   r   rW  rX  r.   rg  )r\  rR  ÚappendÚremover>   r¼   ri  rb  )r$   r\  rj  rÿ   Údirsr¶   r   r   r   Útest_walk_prune¼  s    zWalkTests.test_walk_prunec             C   s   |   t| jƒ¡ d S )N)rp  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   rU  r0   rg  rW  rX  rV  rY  )	rh  rR  r\  r>   r¼   ri  r^  r]  rb  )r$   rj  rk  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   ra  r3   rR  r\  r_  r>   rœ   )r$   Úwalk_itrÿ   ro  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)ÚonerrorrU  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>)rR  r\  rm  r!  r>   r   r    rÑ   r=   r)   r@  r™   )r$   Úerrorsrt  rÿ   ro  r¶   Údir1Zpath1Zpath1newÚrootsÚdir2r   r   r   Útest_walk_bad_dirõ  s"    

zWalkTests.test_walk_bad_dir)N)r{   r|   r}   rM  rR  r%   rl  rp  rq  rs  ru  r|  r   r   r   r   rO  \  s   E
rO  ÚfwalkzTest needs os.fwalk()c               @   sH   e Zd 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 )Ú
FwalkTestszTests for os.fwalk().c             k   s0   x*| j |f|ŽD ]\}}}}|||fV  qW d S )N)r}  )r$   rS  rT  rÿ   ro  r¶   Zroot_fdr   r   r   rR    s    zFwalkTests.walkc             O   s   t j||ŽS )N)r   r}  )r$   r[   rT  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 )z.
        compare with walk() results.
        )TFr0   )Úrepeat)rr  rP  )rr  rí   N)
ÚcopyÚ	itertoolsÚproductr  r   rR  Úsetr}  r™   r>   )
r$   Úwalk_kwargsÚfwalk_kwargsrr  rí   Úexpectedrÿ   ro  r¶   Úrootfdr   r   r   Ú_compare_to_walk  s    zFwalkTests._compare_to_walkc             C   s   dt ji}|  ||¡ d S )NrS  )r   r"   rˆ  )r$   rT  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Ú.rS  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ƒ  rd  )r$   rr  rí   r[   rÿ   ro  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}   rM  rR  r}  rˆ  r‰  r‹  r  r  r   r   r   r   r~    s   
r~  c               @   s   e Zd ZdZdd„ ZdS )ÚBytesWalkTestszTests for os.walk() with bytes.c       	      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í   rP  )rQ  r   rR  ÚfsencodeÚfsdecoderh  Úmap)	r$   rS  rT  ÚbrootÚbdirsÚbfilesrÿ   ro  r¶   r   r   r   rR  Q  s     
zBytesWalkTests.walkN)r{   r|   r}   rM  rR  r   r   r   r   r‘  O  s   r‘  c               @   s   e Zd ZdZddd„ZdS )ÚBytesFwalkTestszTests for os.walk() with bytes.rŠ  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“  rh  r”  )r$   rS  r[   rT  r•  r–  r—  Ztopfdrÿ   ro  r¶   r   r   r   r}  _  s    &
zBytesFwalkTests.fwalkN)rŠ  )r{   r|   r}   rM  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 )Nry  r{  Údir3Údir4Údir5Údir6)	r   r"   r   r    rÑ   r`  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   ry  r{  im  Úntiÿ  iý  )r   Z
temp_umaskr"   r   r    rÑ   r`  r)   rN  Ú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 )
Nry  iÿ  é   F)Úexist_okiþ  T)rp   r¦  ú/)
r   r    rÑ   r   r"   Úumaskr`  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 )Nry  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ž   rc  re  r   ÚSkipTestr`  )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 )Nry  rÈ   r1  F)r¦  T)r   r"   r   r    rÑ   r   r   r(   r5   r6   r`  rn  )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 )Nry  r{  rš  r›  rœ  r  )r   r    rÑ   r   r"   rN  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       €      ð¿rg  éþÿÿÿ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   re  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   r`  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±  ÚassertFalserN  )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Ì  rN  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)   rN  )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 )NZ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á  Z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 )zË
    Stubs out execv and execve functions when used as context manager.
    Records exec calls. The mock execv and execve functions always raise an
    exception as they would normally never return.
    c                s   ˆ   d| |f¡ tdƒ‚d S )NÚexecvzexecv called)rm  Ú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)rm  r6   rÆ   ZENOTDIR)r   r[   )rô  r   r   Úmock_execveß  s    z$_execvpe_mockup.<locals>.mock_execveN)r   rò  rö  r2  )r2  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ò  )r2  )r-  rö  s   PATHr/  )r   ÚseprH   r    rÑ   r’  r   rø  r5   ró  rÿ  r>   r¼   r6   r4  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)   Ú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$   rN  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   rn  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   rc  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ÚTestInvalidFDZfchdirr2   rb   Z	fdatasyncrŒ  ZfstatvfsÚfsyncZ	tcgetpgrpZ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 )Nrg  )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 )NZPC_NAME_MAX)r  r   Z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   r)  )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   r+  )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   r.  )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   r3  Ú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$  r'  r(  rL   r*  r,  rW   r/  r2  r5  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)r9  r:  r   r    rN  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   rZ  re  r3   r   r)   r    ÚsameopenfilerD   )r$   r9  r:  rÂ   r×   Úf2r   r   r   Ú
_test_linkì  s     zLinkTests._test_linkc             C   s   |   | j| j¡ d S )N)r>  r9  r:  )r$   r   r   r   Ú	test_linkö  s    zLinkTests.test_linkc             C   s(   |   t| jt ¡ ƒt| jt ¡ ƒ¡ d S )N)r>  rH   r9  r:   r©   r:  )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.r8  )r   r’  ÚUnicodeErrorr   r®  r9  r:  r>  )r$   r   r   r   Útest_unicode_nameý  s    zLinkTests.test_unicode_nameN)	r{   r|   r}   r%   r~   r>  r?  r@  rC  r   r   r   r   r7  â  s   
r7  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   rE  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   rF  ÚHAVE_WHEEL_GROUPr5   r6   rJ  r<   rG  Ú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   rF  r5   r6   rN  r<   ÚsetegidrG  rH  )r$   r   r   r   Útest_seteuid  s    zPosixUidGidTests.test_seteuidrO  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   rF  rK  r5   r6   rO  r<   rG  rL  )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   rF  r5   r6   rR  r<   rG  rH  )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   rF  rK  r5   r6   rU  r<   rG  rL  )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}   rH  rL  r   r   r   r   rI  rM  rP  rQ  rS  rT  rV  rW  r   r   r   r   rD    s   		rD  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ª   rm  )Ú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$   r[  rY  r   )rZ  r   r%   M  s6    








zPep383Tests.setUpc             C   s   t  | j¡ d S )N)r_  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)	r]  rƒ  r   rd  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   )r]  r   r   r    rÑ   r•   r(   )r$   rY  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)r]  r   r    rÑ   r•   rµ   )r$   rY  Úfullnamer   r   r   Útest_statvfs†  s    zPep383Tests.test_statvfsc             C   s*   x$| j D ]}t tj | j|¡¡ qW d S )N)r]  r   rl   r    rÑ   r•   )r$   rY  r   r   r   Ú	test_stat  s    zPep383Tests.test_statN)r{   r|   r}   r%   r~   rb  rc  r   r   r   r   re  rf  r   r   r   r   rX  K  s   %rX  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ü   rh  Úmsvcrtrý   rþ   ÚPeekNamedPipeÚBOOLÚrestypeÚHANDLEÚPOINTERZc_charÚDWORDÚargtypesrZ   ÚPopenr:   r^   r*  ÚPIPErO   rÞ  r(   rj  rk  ÚpollZcreate_string_bufferr¼   Zget_osfhandlerD   ZsizeofrÔ   r¾   r>   r<  rô   Úsleeprœ   r   ÚkillÚpidÚwait)r$   Zsigrü   rh  rl  rm  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_%srg  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   rt  r:   r^   r   r    rÑ   rÏ   rr   ZCREATE_NEW_PROCESS_GROUPrv  rô   rw  rx  ry  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   )rh  ÚCTRL_C_EVENT)rü   rh  rq  Zc_intrý   rþ   ÚSetConsoleCtrlHandlerrn  rs  ro  r†  r~  r‡  )r$   rh  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   rg  “  s   6rg  c               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚWin32ListdirTestszTest listdir on Windows.c          
   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"   r`  r   r   Úextendri  )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)r_  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 )z-Test when the path is not an "extended" path.c             S   s   g | ]}t  |¡‘qS r   )r   r’  )r   r    r   r   r   r   %  s    zCWin32ListdirTests.test_listdir_no_extended_path.<locals>.<listcomp>N)r>   Úsortedr   rd  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 )z&Test when the path starts with '\\?\'.z\\?\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>N)
r   r    rû   r   r"   r>   r‘  rd  rŽ  r’  )r$   r    r   r   r   Útest_listdir_extended_path'  s    z,Win32ListdirTests.test_listdir_extended_pathN)r{   r|   r}   rM  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    rN  Úfilelinkrn  Ú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    rN  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    rN  Ú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 )z2Create a "directory" link to a non-existent targetz"c:\\target does not exist.29r3c740TN)r—  r   r    r!   rn  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   rn  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$   rZ  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Úlevel3r9  rZ  )r   r    rû   r   r"   rÑ   rO   rØ   rÍ   r   r`  r  rt   Úrelpathr™   rd  r>   rl   )r$   Zlevel1r£  r¤  r9  Zorig_dirrZ  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   rn  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!   rN  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    rN  Ú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    rN  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    rN  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WinDLLrh  rp  ZGetCurrentProcessro  rn  ZGetProcessHandleCountZLPDWORDrs  rr  Zbyrefr>   r¾   rr   r¬   r¡  Ú_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 )zM
        Create this structure:

        base
         \___ some_dir
        zbase/some_dirN)r   r`  )r$   r   r   r   r%   1	  s    zNonLocalSymlinkTests.setUpc             C   s   t  d¡ d S )NrŸ  )r_  rØ   )r$   r   r   r   r~   :	  s    zNonLocalSymlinkTests.tearDownc             C   s   t j dd¡}t  d|¡ dS )a¹  
        The symlink target should resolve relative to the link, not relative
        to the current directory.

        Then, link base/some_link -> base/some_dir and ensure that some_link
        is resolved as a directory.

        In issue13772, it was discovered that directory detection failed if
        the symlink target was not specified relative to the current
        directory, which was a defect in the implementation.
        rŸ  Z	some_linkZsome_dirN)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$   rY  rZ  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   ÚwinZnl_langinfoZ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   rt  r:   r^   ru  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[   ry  Ú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ï  ZWEXITSTATUSrÝ  )r$   r[   ry  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Zdd„ ZdS )ÚProgramPriorityTestsz0Tests for os.getpriority() and os.setpriority().c             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ý  Z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}   rM  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  rm  )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   ri  |
  s    zSendfileTestServer.runningc             C   s$   t  ¡ | _t j | ¡ | j ¡  d S )N)r  ZEventÚ_SendfileTestServer__flagr  Ústartrz  )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ô   rw  r  )r$   r   r   r   rz  ‹
  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  Úpropertyri  r  r  rz  r   r!  r"  r  r#  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"   r;  )r$   r   r   r   r%   Á
  s    

zTestSendfile.setUpc             C   s0   | j  ¡  | j ¡  | jjr&| j ¡  d | _d S )N)r;  r(   r)  r(  ri  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 )zfA higher level wrapper representing how an application is
        supposed to use sendfile().
        N)r   r%  r6   rÆ   Z
ECONNRESETÚEAGAINÚEBUSY)r$   r[   rT  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¼   r'  r-  r*  rD   r)   r>   r)  Úshutdownr  Ú	SHUT_RDWRr(   r(  rz  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¼   r'  r-  r*  rD   r)   r)  r.  r  r/  r(   r(  rz  r  r  r>   )r$   r0  r1  Z	must_sendr2  r3  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¼   r'  r   r%  r*  rD   r6   rÆ   ÚEINVALr>   r)  r.  r  r/  r(   r(  rz  r  r  )r$   r1  r3  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 )Nrg  i   )
r5   r6   r   r%  r*  rD   r>   rÅ   rÆ   r6  )r$   rE  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Ý  r1  rÜ  Úinr   )r1  rÜ  ÚheadersÚtrailersro   )r   r%  r*  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   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyrg  i   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs   yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy)r:  i   )r'  r   r%  r*  rD   ZassertLessEqualr¼   Úminr-  r>   r)  r(   r(  rz  r  r  Úhash)r$   r0  Zexpected_datar3  r1  r2  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 )
Nr8  s   abcdefrN   r   rŠ   s   123456s   789)r;  s   abcde123456789)r   r"   rO   r#   r   r   r   r%  r*  rD   r)  r(   r(  rz  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 €  )r:  )r(  r  r  r5   r6   r   r%  r*  rD   r>   rÅ   rÆ   r6  )r$   rE  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   rB  i   i €  )r;  )r(  r  r  r5   r6   r   r%  r*  rD   r>   rÅ   rÆ   r6  )r$   rE  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   r%  r*  rD   rE  r6   rÆ   r,  r+  )r$   rî  r   r   r   Ú
test_flagsm  s    zTestSendfile.test_flagsN)r{   r|   r}   r'  r:   r€   rÉ  r<  r   r   Zrequires_headers_trailersÚmaxsizeZrequires_32brÇ  rµ  rÆ  r%   r~   r-  r4  r5  r7  r8  r=  r@  rA  rC  rD  r   r   rF  r   r   r   r   r&  «
  s6   
r&  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"   rH  rD   r6   r#   )r   r   r   r   Úsupports_extended_attributesy  s    
rI  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   rB  )r   r"   rO   r#   r   r5   r6   r>   rÅ   rÆ   ZENODATAr×  rh  rƒ  r^  r   ZXATTR_REPLACEZXATTR_CREATEZEEXISTrn  r‘  r¬   )r$   rK   ÚgetxattrrH  ÚremovexattrÚ	listxattrrT  rY  rE  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)rP  r%  r   r#   r"   r   r’  )r$   r[   rT  r   r   r   Ú_check_xattrs¿  s    z$ExtendedAttributeTests._check_xattrsc             C   s   |   tjtjtjtj¡ d S )N)rQ  r   rL  rH  rM  rN  )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í   )rQ  r   rL  rH  rM  rN  )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   rL  rD   )r    r[   r   r   r   r   rL  Ï  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   rH  rD   )r    r[   r   r   r   r   rH  Ò  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   rM  rD   )r    r[   r   r   r   r   rM  Õ  s    z4ExtendedAttributeTests.test_fds.<locals>.removexattrc          	   W   s*   t | dƒ}tj| ¡ f|žŽ S Q R X d S )NrN   )r   r   rN  rD   )r    r[   r   r   r   r   rN  Ø  s    z2ExtendedAttributeTests.test_fds.<locals>.listxattr)rQ  )r$   rL  rH  rM  rN  r   r   r   Útest_fdsÎ  s
    zExtendedAttributeTests.test_fdsN)r{   r|   r}   rP  rQ  rR  rS  rT  r   r   r   r   rK  ‰  s
   0rK  Ú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 )zÔCheck if get_terminal_size() returns a meaningful value.

        There's no easy portable way to actually check the size of the
        terminal, so let's check if it returns something sensible instead.
        r]   zfailed to query terminal sizeNr   )r   rU  r6   r:   r€   rÆ   r6  Ú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 )	zÕCheck if stty returns the same results

        stty actually tests stdin, so get_terminal_size is invoked on
        stdin explicitly. If stty succeeded, then get_terminal_size()
        should work too.
        ZsttyrM   zstty invocation failedr.   r   r]   zfailed to query terminal sizeN)rZ   Zcheck_outputr<  rš   rk   ZCalledProcessErrorre  r3   r„   r   rU  r:   Ú	__stdin__rD   r6   r€   rÆ   r6  rW  r>   )r$   rM   r†  ÚactualrÂ   r   r   r   Útest_stty_matchò  s    
zTermsizeTests.test_stty_matchN)r{   r|   r}   rZ  r]  r   r   r   r   rV  Þ  s   rV  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   r_  )r%  Úbytes_filenamesÚunicode_filenamesr   r\  r"   rm  ZTESTFN_UNDECODABLEr   r’  rT   rU   r¹  )r$   r_  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   Úlchownr&  ÚchflagsÚlchflagsÚchrootrZ  rN  z	user.tests   userÚlchmodr§  z	should bezNo exception thrown by {}),r¹  r   r  rc  r­  r   ra   rÎ   rl   r#   r:   r€   r  r`  r=   rj   ra  rd  r   rm  r²  rb  r&  rc  rd  re  rZ  rN  rL  rH  rM  rf  r§  rº   r%  rH   ZassertWarnsRegexÚDeprecationWarningr6   rB  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%   rj  r   r   r   r   r^    s   r^  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}   rn  r   r   r   r   rk  k  s   rk  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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>   r0  r1  )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>   r0  Ú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>   rq  rr  rs  r1  )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>   r0  )r$   rJ   r   r   r   rc  –  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>   r0  )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>   r0  )r$   Zfd1Úfd2r   r   r   Útest_dup£  s
    
zFDInheritanceTests.test_dupr  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)   r0  rÌ  )r$   rJ   rw  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   ry  rO   r(   r>   r0  )r$   Z	master_fdZslave_fdr   r   r   Útest_openpty¼  s
    zFDInheritanceTests.test_openpty)r{   r|   r}   rp  r   r  rq  rt  ru  rc  r   r   r   rv  rx  r  rz  r   r   r   r   ro  u  s   ro  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)rc  F)r   N)rd  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_fnrY  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{  r3  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>   r3  r4  )r$   rJ   r   r   r   r5  
  s    zBlockingTests.test_blockingN)r{   r|   r}   r5  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   rR  )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+  -  s   z*TestScandir.get_entries.<locals>.<genexpr>)r  r   Úscandirr    r>   r‘  Úkeys)r$   ÚnamesÚentriesr   r   r   Úget_entries,  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_equal2  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_entry?  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 )NrZ  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   ra  r    rÑ   rÍ   r   rZ  re  r3   rt   rm  r  r‘  r  )	r$   rZ  rt   rÏ   r   rÂ   r  r  rŒ  r   r   r   Útest_attributes[  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    rh  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   r`  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   rm  )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   rm  )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   ra  r3   r   r   rt   r    rÑ   r‘  r#   rm  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    rh  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    ÚassertWarnsrg  rh  r  r>   r¼   r   rÑ   rB  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.txtrZ  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   ra  rt   r    rÑ   rm  r   ra   rh  r>   r‘  rd  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    rh  r>   r¼   )r$   rG  r  Zentries2r   r   r   Útest_consume_iterator_twice)  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_type4  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$   rG  r   r   r   Ú
test_close8  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$   rG  r   r   r   Útest_context_managerC  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$   rG  r   r   r   Útest_context_manager_closeK  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$   rG  r   r   r   Útest_context_manager_exceptionR  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_collectrh  r´  )r$   rG  r   r   r   Útest_resource_warning\  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   rd  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_bytesq  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_stringu  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_fsdecodey  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¼  k  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dZeejƒZdS )ÚTestPEP519PurePythonz>Explicitly test the pure Python implementation of os.fspath().N)r{   r|   r}   rM  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­   r_  r~  r  rl   rZ   r:   Z	sysconfigr  rô   r   r‚  r6  rµ  r   rñ  r·  rq  r¯  ZgrpZgetgrallr¿  r   r	   Zprocess_gidrm  ZpwdZgetpwallrÁ  rŸ   Z	_testcapir   r   rG  Ztest.support.script_helperr   Ztest.supportr   r   rÈ  r   r   ÚversionrÉ  r  r€   rK  r   r   ZTestCaser   r   rÖ   r  ZBasicTestMappingProtocolr  rO  r   r~  r‘  r˜  r™  r³  rÉ  rÐ  rÓ  râ  Zget_config_varZOS_URANDOM_DONT_USE_FDr  rë  Úcontextmanagerrø  rù  r  r  r7  rD  rX  rg  r  Zskip_unless_symlinkr”  r­  r´  r»  r½  rÁ  rË  rÕ  rŒ  rû  rÿ  r  r  r  r&  rI  Zrequires_linux_versionrK  rV  r^  rk  ro  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
,`
PB
  P/
