B
    18™\& ã            	   @   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getuserÚgr_memÚgr_gid)Ú.0Úgr   r   úP/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/test/test_os.pyú
<listcomp>.   s    r
   Úgetgidc             C   s   g | ]
}|j ‘qS r   )Úpw_uid)r   Úur   r   r	   r
   7   s    )ÚINT_MAXÚPY_SSIZE_T_MAX)Úassert_python_ok)Ú
unix_shellÚFakePathFÚgeteuidÚthread_infoZlinuxthreadsÚ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)ÚfilenameÚ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Úgetrefcountr:   Ú	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ÚreadrC   ÚtypeÚbytes)r)   ÚfobjÚfdÚsr   r   r	   Ú	test_read†   s    
zFileTests.test_readzneeds INT_MAX < PY_SSIZE_T_MAXr4   r3   F)ÚsizeÚmemuseÚ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   rK   rI   rC   )r)   rR   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
rU   s   bacons   eggss   spam)r   r   r   r'   r+   ÚO_WRONLYr:   rA   r   Ú	bytearrayÚ
memoryviewr-   rC   rK   Ú
splitlines)r)   rO   rN   r   r   r	   Ú
test_write£   s    
zFileTests.test_writec             G   s"   t j|t jdd}|  |d¡ d S )NT)ÚcreationflagsÚshellr   )Ú
subprocessÚcallZCREATE_NEW_CONSOLErC   )r)   ÚargsÚ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)re   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)   rc   rO   r1   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-   rl   )r)   rO   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ó   2rm   Ú1)r   r'   rV   r(   r#   r   Úreplacer:   ÚFileNotFoundErrorÚstatr   rC   rK   )r)   ÚTESTFN2r1   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__rj   r-   )r)   r1   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_directoryrz   )r   Úget_attributer   r'   ÚNotImplementedErrorr;   )r)   r}   r   r   r	   Útest_symlink_keywordsá   s    zFileTests.test_symlink_keywordsN)Ú__name__Ú
__module__Ú__qualname__r*   ÚtearDownr2   r>   r   Úcpython_onlyrF   rQ   r   r   r   r   Ú
bigmemtestrX   r^   re   r?   Úplatformri   rl   ro   rw   r|   r„   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'   ÚfnamerV   r(   r#   )r)   r   r   r	   r*   ì   s    zStatAttributeTests.setUpru   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'  r5   )ÚdeltaéÈ   zNo exception raisedr3   )r4   )r   r3   r5   rŽ   rG   é   é   é   é   é	   r4   é   é   é   é   )r   ru   rC   ÚST_SIZEÚst_sizeÚdirÚlowerÚendswithÚgetattrÚassertInÚsplitr   ÚassertAlmostEqualÚfailÚ
IndexErrorÚst_modeÚAttributeErrorÚst_rdevrA   Ú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ÚUnicodeEncodeErrorr8   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 )Nr3   s   stat_resultrG   s   cos
stat_result
)
r   ru   r   ÚrangeÚpickleÚHIGHEST_PROTOCOLÚdumpsr¤   ÚloadsrC   )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_r4   r3   zNo exception raised)r4   )r   r3   r5   rŽ   rG   r•   r–   r—   r˜   r™   r4   rš   r›   rœ   r   )r   rÁ   r   rC   Úf_bfreeÚ	enumerater£   r.   Ú
isinstanceÚf_fsidr   Úlenr§   rª   r¬   Ústatvfs_resultrA   )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 )Nr3   s   statvfs_resultrG   s   cos
statvfs_result
)
r   rÁ   r   r¸   r¹   rº   r»   r¤   r¼   rC   )r)   r®   r½   r¾   r¿   r   r   r	   Útest_statvfs_result_pickles  s    
z-StatAttributeTests.test_statvfs_result_picklerf   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   ru   rt   r8   r;   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Ð   ru   r-   r:   r;   rC   Ú	exceptionÚerrnoÚEBADF)r)   rm   ÚwÚ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   ru   r   rØ   rC   r×   ÚFILE_ATTRIBUTE_DIRECTORYr   r'   ÚmkdirrV   Ú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 )	NÚTEMPs   ABCr˜   z
icacls.exez/denyz*S-1-5-32-545:(S))r_   r   )r   r%   ÚjoinÚenvironr   rV   r   r(   r#   ra   Ú
check_callru   Ú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   rV   Ú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   ru   Ú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   ru   r¦   rç   rè   rC   Ú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ó   rI   )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)rz   rò   )r   r%   r¥   r   rj   ró   r-   )r    rò   rÜ   r   Údirfdr   r   r	   rî   0  s
    z.UtimeTests.test_utime_dir_fd.<locals>.set_time)rñ   )r)   rî   r   r   r	   Útest_utime_dir_fd-  s    zUtimeTests.test_utime_dir_fdc             C   s   dd„ }| j || jd d S )Nc             S   s   t j| |d d S )N)rò   )r   ró   )r    rò   r   r   r	   rî   ;  s    z1UtimeTests.test_utime_directory.<locals>.set_time)r    )rñ   rÜ   )r)   rî   r   r   r	   Útest_utime_directory:  s    zUtimeTests.test_utime_directoryc             C   sb   t   ¡ }|| jƒ |  | j¡s$d}nd}t | j¡}d|j||j| f }| j|j|||d d S )Ng      ð?gš™™™™™©?zst_time=%r, current=%r, dt=%r)r“   Úmsg)Útimer   rë   r   ru   rè   r¦   )r)   rî   Ú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 )Nrf   r   ú\Ú rn   )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Ü   r8   r   ró   r   rC   ru   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   )rz   )r:   Ú
ValueErrorr   ró   r   rA   Úsupports_follow_symlinksrƒ   Úsupports_fdr   rI   Ú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   )rc   )Ú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é*   r3   )rò   r   )r3   r5   rŽ   )r:   rA   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   rK   ÚstriprC   )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   ÚiterrC   Únextr:   Ú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(  rC   rL   Ú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(  rC   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à   rC   Ú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)Úrecordrr   rq   )r?  s   PATHs   PATHs   abcÚabc)r   Údefpathr¥   Úpathseprß   rà   r"  ÚassertSequenceEqualÚget_exec_pathr$  ÚwarningsÚcatch_warningsÚBytesWarningr:   r  )r)   Zdefpath_listZ	test_pathZtest_envÚ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 %sÚunicodes   unicodeó   ÿs   bytesrM   )
r´   r?   rµ   r¶   r8   r   rà   rC   r%  Údecode)r)   rÊ   Zvalue_bytesr  Z	value_strr   r   r	   Útest_environb  s     



zEnvironTests.test_environbr4   r–   c             C   s@   t jdkr&dd }|  ttjj|¡ nd}|  ttjj|¡ d S )Nrf   r   iPÃ  zkey=)r?   r‹   r:   r  r   rà   Ú__delitem__r;   )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à   r:   ÚKeyErrorÚassertIsrÑ   rc   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)r0  r1  r   rà   rC   )r)   Z
collectionÚiteratorZnew_keyr   r   r	   Ú_test_environ_iterationC  s    
z$EnvironTests._test_environ_iterationc             C   s   |   tj¡ d S )N)rZ  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)rZ  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)rZ  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/  r4  r7  r9  r>  rJ  r$  rO  r   Úrequires_mac_verrQ  rX  rZ  r[  r\  r^  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	   re  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.
ÚbrokenTZtmp5r   r3   )r   r%   rß   rV   r   ræ   r'   Ú	walk_pathÚ	sub1_pathÚ
sub11_pathÚ	link_pathÚmakedirsr   r   Úcan_symlinkr}   r  Ú	sub2_treeÚchmodÚlistdirÚPermissionErrorru   Ú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%   r1   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 )NrG   r   r3   rh  rŽ   r5   éÿÿÿÿrj  rk  ri  rl  )	Úlistre  rp  rC   rÈ   Úsortrq  rr  rv  )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 )Nrh  r5   r   rj  rk  r3   r{  )rp  re  ÚappendÚremoverC   rÈ   r}  rv  )r)   rp  r~  r  ÚdirsrÂ   r   r   r	   Útest_walk_prune¼  s    zWalkTests.test_walk_prunec             C   s   |   t| jƒ¡ d S )N)r„  r   rp  )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)ÚtopdownrG   rŽ   r3   r   rh  r5   r{  rj  rk  ri  rl  )	r|  re  rp  rC   rÈ   r}  rr  rq  rv  )r)   r~  r  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û   rn  z+Didn't follow symlink with followlinks=True)r   ru  r8   re  rp  rs  rC   r§   )r)   Úwalk_itr  rƒ  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)Úonerrorrh  z.newc             S   s   g | ]\}}}|‘qS r   r   )r   rm   Údr1   r   r   r	   r
      s    z/WalkTests.test_walk_bad_dir.<locals>.<listcomp>)re  rp  r  r1  rC   r   r%   rß   rB   r.   rR  r¤   )r)   Úerrorsrˆ  r  rƒ  rÂ   Údir1Zpath1Zpath1newÚrootsÚdir2r   r   r	   Útest_walk_bad_dirõ  s"    

zWalkTests.test_walk_bad_dir)N)r…   r†   r‡   r_  re  r*   r€  r„  r…  r‡  r‰  r  r   r   r   r	   rb  \  s   E
rb  Ú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)   rf  rg  r  rƒ  rÂ   Zroot_fdr   r   r	   re    s    zFwalkTests.walkc             O   s   t j||ŽS )N)r   r‘  )r)   rc   rg  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.
        )TFr5   )Úrepeat)r†  rc  )r†  rû   N)
ÚcopyÚ	itertoolsÚproductr+  r   re  Úsetr‘  r¤   rC   )
r)   Úwalk_kwargsÚfwalk_kwargsr†  rû   Úexpectedr  rƒ  rÂ   Úrootfdr   r   r	   Ú_compare_to_walk  s    zFwalkTests._compare_to_walkc             C   s   dt ji}|  ||¡ d S )Nrf  )r   r'   rœ  )r)   rg  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Ú.rf  rz   )r   r   rj   r   r'   r”  rœ  r-   )r)   rO   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)TFr5   )r“  rû   )r•  r–  r   r'   r‘  r   Úfstatru   rC   r—  rx  )r)   r†  rû   rc   r  rƒ  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 )Nr3   é   )	r   r7   r-   r¸   r‘  r   r'   rV   rC   )r)   ZminfdÚir   Znewfdr   r   r	   Útest_fd_leakB  s    


zFwalkTests.test_fd_leakN)r…   r†   r‡   r_  re  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û   rc  )rd  r   re  ÚfsencodeÚfsdecoder|  Úmap)	r)   rf  rg  ÚbrootÚbdirsÚbfilesr  rƒ  rÂ   r   r   r	   re  Q  s     
zBytesWalkTests.walkN)r…   r†   r‡   r_  re  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§  r|  r¨  )r)   rf  rc   rg  r©  rª  r«  Útopfdr  rƒ  rÂ   r   r   r	   r‘  _  s    &
zBytesFwalkTests.fwalkN)rž  )r…   r†   r‡   r_  r‘  r   r   r   r	   r¬  \  s   r¬  c               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚMakedirTestsc             C   s   t  tj¡ d S )N)r   rÚ   r   r'   )r)   r   r   r	   r*   j  s    zMakedirTests.setUpc          
   C   s    t j}tj |ddd¡}t |¡ tj |dddd¡}t |¡ |  ttjtj¡ tj |dddddtj¡}t |¡ tj |dtjddddd¡}t |¡ d S )Nr  r  Údir3Údir4Údir5Údir6)	r   r'   r   r%   rß   rt  r:   r;   Ú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 )Nr5   r  r  im  Úntiÿ  iý  )r   Ú
temp_umaskr'   r   r%   rß   rt  r.   r`  Úisdirr   rC   ru   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 )
Nr  iÿ  é   F)Úexist_okiþ  T)ry   r¼  ú/)
r   r%   rß   r   r'   Úumaskrt  r:   r;   r  )r)   r%   ry   Ú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 )Nr  iÿ  r»  zCannot set S_ISGID for dir.z No support for S_ISGID dir mode.T)r¼  )r   r%   rß   r   r'   ru   ÚS_ISGIDr¾  ÚS_IMODEÚlstatr©   rw  ry  r   ÚSkipTestrt  )r)   r%   rÁ  ry   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 )Nr  rÔ   rA  F)r¼  T)r   r'   r   r%   rß   r   r   r-   r:   r;   rt  r‚  )r)   r´  r%   r1   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 )Nr  r  r¯  r°  r±  r²  )r   r%   rß   r   r'   r`  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       €      ð¿r{  éþÿÿÿr5   )r   ru   r   r'   Úst_uidÚst_gidÚdecimalZDecimalÚ	fractionsZFractionr:   rA   rÈ  ÚassertIsNone)r)   ru   ÚuidÚgidrÊ   r   r   r	   Ú*test_chown_uid_gid_arguments_must_be_indexÏ  s     z9ChownFileTests.test_chown_uid_gid_arguments_must_be_indexr3   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 )Nr5   )	Úgroupsr   ru   r   r'   rÍ  rÈ  rÎ  rC   )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 )Nr5   )	Ú	all_usersr   ru   r   r'   rÎ  rÈ  rÍ  rC   )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 )Nr5   )	r×  r   ru   r   r'   rÎ  r:   ry  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   rt  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Ç  ÚassertFalser`  )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â  r`  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#   r:   r;   rÇ  r.   r`  )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   hellorU   r’   )r   r   Údevnullr   r-   rC   rK   )r)   r1   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   r3   r4   rn   iè  )rC   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ê  ÚassertIsInstancerM   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-cr3   )rß   r   rC   rÈ   )r)   Úcountrh   Ú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 )Nr3   z%getrandom() syscall fails with ENOSYS)r   r÷  r;   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í  rM   rC   rÈ   )r)   rW   r   r   r	   Útest_getrandom_type]  s    
z"GetRandomTests.test_getrandom_typec             C   s   t  d¡}|  |d¡ d S )Nr   r’   )r   r÷  rC   )r)   Úemptyr   r   r	   Útest_getrandom0b  s    
zGetRandomTests.test_getrandom0c             C   s   |   ttdƒ¡ d S )NÚGRND_RANDOM)r.   r   r   )r)   r   r   r	   Útest_getrandom_randomf  s    z$GetRandomTests.test_getrandom_randomc             C   s,   yt  dt j¡ W n tk
r&   Y nX d S )Nr3   )r   r÷  ÚGRND_NONBLOCKÚBlockingIOError)r)   r   r   r	   Útest_getrandom_nonblockl  s    z&GetRandomTests.test_getrandom_nonblockc             C   s$   t  d¡}t  d¡}|  ||¡ d S )Nrì  )r   r÷  râ   )r)   rî  rï  r   r   r	   Útest_getrandom_valuet  s    

z#GetRandomTests.test_getrandom_valueN)
r…   r†   r‡   rÝ  rË  rú  rü  rþ  r  r  r   r   r   r	   rø  O  s   rø  ÚHAVE_GETENTROPYr3   ÚHAVE_GETRANDOMÚ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)   rh   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)   rh   Ú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   rG   )
rV   r   r(   r'   r#   r:  r   rC   rÈ   râ   )r)   rh   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)r  ÚRuntimeError)r   rc   )Úcallsr   r	   Ú
mock_execvÛ  s    z#_execvpe_mockup.<locals>.mock_execvc                s    ˆ   d| |f¡ ttjdƒ‚d S )NÚexecvezexecve called)r  r;   rÒ   ZENOTDIR)r   rc   )r  r   r	   Úmock_execveß  s    z$_execvpe_mockup.<locals>.mock_execveN)r   r  r  rB  )rB  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-)r:   r;   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	  )r:   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	  )r:   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arg2rg   Zprognamer¶  ZspamrY   r3   r   r  )rB  )r=  r  s   PATHr?  )r   ÚseprM   r%   rß   r¦  r   r  r:   r  r  rC   rÈ   r;   rD  r”  )
r)   Z	test_typeZprogram_pathÚprogramZfullpathZnative_fullpathÚ	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  r5  r   r   rM   )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?   rg   r   rà   r”  r:   r  r  )r)   rc   Únewenvr   r   r	   Útest_execve_invalid_env:  s    


z!ExecTests.test_execve_invalid_envrf   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  r;   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  rf   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   ru   r   r'   rt   r;   r§   )r)   r`  rù  r   r   r	   r*   \  s     zWin32ErrorTests.setUpc             C   s   |   ttjtjtjd ¡ d S )Nz.bak)r:   r;   r   rB   r   r'   )r)   r   r   r	   rF   h  s    zWin32ErrorTests.test_renamec             C   s   |   ttjtj¡ d S )N)r:   r;   r   r‚  r   r'   )r)   r   r   r	   Útest_removek  s    zWin32ErrorTests.test_removec             C   s   |   ttjtj¡ d S )N)r:   r;   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   )	rV   r   r(   r'   r   r:   r;   r   rÚ   )r)   r1   r   r   r	   Ú
test_mkdirq  s    zWin32ErrorTests.test_mkdirc             C   s   |   ttjtjd ¡ d S )N)r:   r;   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   )r:   r;   r   rw  r   r'   )r)   r   r   r	   Ú
test_chmodz  s    zWin32ErrorTests.test_chmodN)
r…   r†   r‡   r*   rF   r,  r.  r/  rô   r0  r   r   r   r	   r+  Z  s   r+  c            	   @   sÆ  e Zd Zddddddddd	g	Zd
d„ ZxeD ]Zeeƒeƒ de < q,W dd„ Ze 	e
edƒd¡dd„ ƒZe 	e
edƒd¡dd„ ƒZe 	e
edƒd¡dd„ ƒZe 	e
edƒd¡dd„ ƒZe 	e
edƒd ¡d!d"„ ƒZe 	e
ed#ƒd$¡d%d&„ ƒZe 	e
ed'ƒd(¡d)d*„ ƒZe 	e
ed+ƒd,¡d-d.„ ƒZe 	e
ed/ƒd0¡d1d2„ ƒZe 	e
ed3ƒd4¡d5d6„ ƒZe 	e
ed7ƒd8¡d9d:„ ƒZe 	e
ed;ƒd<¡d=d>„ ƒZe 	e
ed?ƒd@¡dAdB„ ƒZdCdD„ Ze 	e
edEƒdF¡dGdH„ ƒZdIS )JÚTestInvalidFDÚfchdirr7   rk   Ú	fdatasyncr   ÚfstatvfsÚfsyncÚ	tcgetpgrpÚttynamec                s   ‡ fdd„}|S )Nc                s   t tˆ ƒr|  ttˆ ƒ¡ d S )N)r   r   Úcheckr£   )r)   )r1   r   r	   Úhelper„  s    
z(TestInvalidFD.get_single.<locals>.helperr   )r1   r9  r   )r1   r	   Ú
get_singleƒ  s    zTestInvalidFD.get_singleÚ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_fdr;   rC   rÒ   rÓ   r§   )r)   r1   rc   rÎ   r   r   r	   r8  ‹  s    "zTestInvalidFD.checkÚisattyztest needs os.isatty()c             C   s   |   t t ¡ ¡d¡ d S )NF)rC   r   r=  r   r<  )r)   r   r   r	   Útest_isatty”  s    zTestInvalidFD.test_isattyr9   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 )Nr4   r5   z5Unable to acquire a range of invalid file descriptorsr3   )
r   r<  r¸   r   r   r;   r   rÄ  rC   r9   )r)   rO   r£  r   r   r	   r>   ˜  s     zTestInvalidFD.test_closerangeÚdup2ztest needs os.dup2()c             C   s   |   tjd¡ d S )Né   )r8  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   )r8  r   rB  )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 )Nr{  )r8  r   rD  )r)   r   r   r	   Útest_fchown°  s    zTestInvalidFD.test_fchownÚ	fpathconfztest needs os.fpathconf()c             C   s    |   tjd¡ |   tjd¡ d S )NÚPC_NAME_MAX)r8  r   ÚpathconfrF  )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   )r8  r   ÚtruncaterJ  )r)   r   r   r	   Útest_ftruncate¹  s    zTestInvalidFD.test_ftruncaterJ   ztest needs os.lseek()c             C   s   |   tjdd¡ d S )Nr   )r8  r   rJ   )r)   r   r   r	   Ú
test_lseek¾  s    zTestInvalidFD.test_lseekrK   ztest needs os.read()c             C   s   |   tjd¡ d S )Nr3   )r8  r   rK   )r)   r   r   r	   rQ   Â  s    zTestInvalidFD.test_readÚreadvztest needs os.readv()c             C   s   t dƒ}|  tj|g¡ d S )Nr4   )r[   r8  r   rN  )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   )r8  r   rP  )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ó    )r8  r   r   )r)   r   r   r	   r^   Ï  s    zTestInvalidFD.test_writeÚwritevztest needs os.writev()c             C   s   |   tjdg¡ d S )Ns   abc)r8  r   rS  )r)   r   r   r	   Útest_writevÓ  s    zTestInvalidFD.test_writevc             C   s   |   tj¡ |   tjd¡ d S )NT)r8  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)r8  r   rX  Úset_blocking)r)   r   r   r	   Útest_blockingÛ  s    zTestInvalidFD.test_blockingN)r…   r†   r‡   Zsinglesr:  r1   Úlocalsr8  r   r   r   r   r>  r>   rA  rC  rE  rI  rL  rM  rQ   rO  rQ  r^   rT  rW  rZ  r   r   r   r	   r1  ~  s,   

	r1  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)r^  r_  r   r%   r`  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(): %srm   )
r#   r   rm  ry  r8   r   r.   r%   ÚsameopenfilerI   )r)   r^  r_  rÎ   rå   Úf2r   r   r	   Ú
_test_linkì  s     zLinkTests._test_linkc             C   s   |   | j| j¡ d S )N)rc  r^  r_  )r)   r   r   r	   Ú	test_linkö  s    zLinkTests.test_linkc             C   s(   |   t| jt ¡ ƒt| jt ¡ ƒ¡ d S )N)rc  rM   r^  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.r]  )r   r¦  ÚUnicodeErrorr   rÄ  r^  r_  rc  )r)   r   r   r	   Útest_unicode_nameý  s    zLinkTests.test_unicode_nameN)	r…   r†   r‡   r*   rˆ   rc  rd  re  rh  r   r   r   r	   r\  â  s   
r\  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   Úgetuidr:   r;   rj  rA   Ú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   rk  ÚHAVE_WHEEL_GROUPr:   r;   ro  rA   rl  Ú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   rk  r:   r;   rs  rA   Úsetegidrl  rm  )r)   r   r   r	   Útest_seteuid  s    zPosixUidGidTests.test_seteuidrt  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   rk  rp  r:   r;   rt  rA   rl  rq  )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   rk  r:   r;   rw  rA   rl  rm  )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))ra   rá   r?   rg   )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   rk  rp  r:   r;   rz  rA   rl  rq  )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))ra   rá   r?   rg   )r)   r   r   r	   Útest_setregid_neg1C  s    z#PosixUidGidTests.test_setregid_neg1N)r…   r†   r‡   rm  rq  r   r   r   r   rn  rr  ru  rv  rx  ry  r{  r|  r   r   r   r	   ri    s   		ri  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¶   r  )Úfn)Úbytesfnr   r	   Úadd_filenameW  s
    z'Pep383Tests.setUp.<locals>.add_filenamez&couldn't create any non-ascii filenamezduplicate filename)r   ÚTESTFN_UNENCODABLEr    ÚTESTFN_NONASCIIr'   r   r¦  ZbdirÚTESTFN_UNICODEr8   r—  Ú	unicodefnrÚ   Úcreate_empty_filer%   rß   r§  r  ÚaddÚshutilræ   )r)   r€  r~  r   )r  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   rx  r    rC   Ú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 )NrU   )r„  r   r   r%   rß   r    r-   )r)   r~  r1   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)   r~  Ú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   ru   r%   rß   r    )r)   r~  r   r   r	   Ú	test_stat  s    zPep383Tests.test_statN)r…   r†   r‡   r*   rˆ   rŠ  r‹  r   r   r   r   r  rŽ  r   r   r   r	   r}  K  s   %r}  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   rn   zPeekNamedPipe failedgš™™™™™¹?r3   z1Did not receive communication from the subprocess))r  r  Úmsvcrtr  r  ÚPeekNamedPipeÚBOOLÚrestypeÚHANDLEÚPOINTERZc_charÚDWORDÚargtypesra   ÚPopenr?   rg   r:  ÚPIPErV   rô  r-   r’  r“  ÚpollZcreate_string_bufferrÈ   Zget_osfhandlerI   Úsizeofrâ   rÊ   rC   rN  r  Úsleepr§   r   ÚkillÚpidÚwait)r)   Úsigr  r  r”  r•  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 )Nrn   )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_%sr{  r3   r   zwin_console_handler.py)r_   )r   rn   gš™™™™™¹?z'Subprocess didn't finish initializationg      à?zsubprocess did not stop on {})ÚuuidZuuid1Úmmapra   rœ  r?   rg   r   r%   rß   rÜ   r{   ZCREATE_NEW_PROCESS_GROUPrž  r  r   r¡  r¢  r¨  ÚSIGINTr§   r:  )r)   Ú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   )r  ÚCTRL_C_EVENT)r  r  r™  Úc_intr  r  ÚSetConsoleCtrlHandlerr–  r›  r—  r±  r¨  r²  )r)   r  r  Ú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	   r  “  s   6r  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 )Nr5   zSUB%dzFILE%drÔ   z'I'm %s and proud of it. Blame test_os.
)Úcreated_pathsr¸   r   r%   rß   r   r'   rt  r   r   Úextendr}  )r)   r£  Zdir_nameZdir_pathÚ	file_nameZ	file_pathr1   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)rC   Úsortedr   rx  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'   rC   r¾  rx  r»  r¦  )r)   r%   r   r   r	   Útest_listdir_extended_path'  s    z,Win32ListdirTests.test_listdir_extended_pathN)r…   r†   r‡   r_  r*   rˆ   r¿  rÀ  r   r   r   r	   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^   t j | j¡st‚t j | j¡s$t‚t j | j¡r6t‚t j | j¡rHt‚t j | j¡rZt‚d S )N)	r   r%   r`  Údirlink_targetÚAssertionErrorÚfilelink_targetÚdirlinkÚfilelinkÚmissing_link)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%   r`  rÆ  r‚  rÅ  rÛ   r&   rÇ  )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   r}   rÂ  rÅ  r.   r%   r`  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   r}   rÄ  rÆ  r.   r%   r`  ÚisfilerÈ  rÉ  )r)   r   r   r	   Útest_file_linkV  s
    z Win32SymlinkTests.test_file_linkc             C   sF   | j }tj |¡rt |¡ d}tj |¡r0t‚d}t |||¡ dS )z2Create a "directory" link to a non-existent targetz"c:\\target does not exist.29r3c740TN)rÇ  r   r%   r&   r‚  r`  rÃ  r}   )r)   Zlinknamer~   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   r‚  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)rC   r   ru   râ   rÃ  r¦  )r)   rm  r~   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Úlevel3r^  rm  )r   r%   r  r   r'   rß   rV   ræ   rÚ   r#   rˆ  r-  r}   Úrelpathr¤   rx  rC   ru   )r)   Zlevel1rÑ  rÒ  r^  Zorig_dirrm  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)   r~   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XXXXXXXXXXXXXXXXXXXXXXXXXXXr4   r  é´   )r   r%   rß   r}   rt   r‚  r;   r¦  )r)   Zsegmentr%   Z
test_casesr   Údestr   r   r	   Útest_buffer_overflow´  s,    
z&Win32SymlinkTests.test_buffer_overflowN)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&   r`  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(   t j | j¡st‚t j | j¡r$t‚d S )N)r   r%   r`  Újunction_targetrÃ  Újunction)r)   r   r   r	   r*   Ü  s    zWin32JunctionTests.setUpc             C   s   t j | j¡rt  | j¡ d S )N)r   r%   r`  rÝ  rÛ   )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ÚCreateJunctionrÜ  rÝ  r.   r   r%   r`  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%   r`  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  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 )Ú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_errorr3   z\\?\C:z\\?\NULz	\\?\CONINr4   )r  Úctypes.wintypesÚImportErrorr   rÄ  ZWinDLLr  r˜  ÚGetCurrentProcessr—  r–  ZGetProcessHandleCountZLPDWORDr›  rš  ÚbyrefrC   rÊ   r{   r¸   r¶  Z_getfinalpathnamer   ru   )r)   r  ZkernelZhprocZhandle_countr  Zbefore_countÚ	filenamesr£  r   Ú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   rt  )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|¡ t j |¡s*t‚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ß   r}   r¸  rÃ  )r)   r   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Å)rC   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¶   rC   r§  )r)   r~  r  r   r   r	   Útest_identityS	  s    
zFSEncodingTests.test_identityN)r…   r†   r‡   rï  rñ  r   r   r   r	   rî  N	  s   rî  c               @   sN   e Zd Zdd„ Ze e d¡o<ej	 
d¡p<eedƒo<eedƒd¡dd	„ ƒZd
S )ÚDeviceEncodingTestsc             C   s   |   t d¡¡ d S )Ni@â )rÑ  r   Údevice_encoding)r)   r   r   r	   Útest_bad_fd`	  s    zDeviceEncodingTests.test_bad_fdr   ÚwinÚnl_langinfoÚCODESETz>test requires a tty and either Windows or nl_langinfo(CODESET)c             C   s(   t  d¡}|  |¡ |  t |¡¡ d S )Nr   )r   ró  Ú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ô  )
ra   rœ  r?   rg   r  ÚcommunicaterC   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?   rg   r   ÚspawnvÚP_NOWAITr   ÚwaitpidrC   )r)   rc   r¢  Ústatusr   r   r	   Útest_waitpidw	  s    zPidTests.test_waitpidN)	r…   r†   r‡   r   r   r   r   r  r	  r   r   r   r	   rÿ  m	  s   	rÿ  c               @   s$  e Zd Zdddœdd„Zedƒdd„ ƒZedƒd	d
„ ƒZedƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZ	edƒdd„ ƒZ
edƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZedƒdd „ ƒZedƒd!d"„ ƒZedƒd#d$„ ƒZedƒd%d&„ ƒZedƒd'd(„ ƒZd)d*„ Zedƒd+d,„ ƒZedƒd-d.„ ƒZd/S )0Ú
SpawnTestsF)Úwith_envÚ	use_bytesc         	   C   s¸   d| _ tj}|  tj|¡ |s*d| j  }n8ttjƒ| _t	t
 ¡ ƒ| _| j| j| j< d| j| j f }t|dƒ}| |¡ W d Q R X tj|g}|r´dd„ |D ƒ}dd„ | j ¡ D ƒ| _|S )	Né   zimport sys; sys.exit(%s)z4import sys, os; magic = os.environ[%r]; sys.exit(%s)rÔ   c             S   s   g | ]}t  |¡‘qS r   )r   r¦  )r   Úar   r   r	   r
   –	  s    z*SpawnTests.create_args.<locals>.<listcomp>c             S   s"   i | ]\}}t  |¡t  |¡“qS r   )r   r¦  )r   ÚkÚvr   r   r	   ú
<dictcomp>—	  s   z*SpawnTests.create_args.<locals>.<dictcomp>)Úexitcoder   r'   rV   r(   r"  r   rà   r=  r5  r¬  Zuuid4r)  r   r   r?   rg   r(  )r)   r  r  r    rh   r"   rc   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_WAITrC   r  )r)   rc   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=  rC   r  )r)   rc   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  rC   r  )r)   rc   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=  rC   r  )r)   rc   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  rC   r  )r)   rc   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=  rC   r  )r)   rc   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  rC   r  )r)   rc   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=  rC   r  )r)   rc   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   r3   Ú	WIFEXITEDr˜   )r  r   r  r  r  rC   r   r.   r$  ÚWEXITSTATUSr  )r)   rc   r¢  r®   r  r   r   r	   Útest_nowaitÌ	  s    
zSpawnTests.test_nowaitc             C   s8   | j ddd}t tj|d || j¡}|  || j¡ d S )NT)r  r  r   )r  r   r  r  r=  rC   r  )r)   rc   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  r:   r  r   r  r  )r)   rc   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  r:   r  r   r  r  )r)   rc   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  r:   r  r   r  r  )r)   rc   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  r:   r  r   r  r  )r)   rc   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?   rg   r   rà   r”  r  r  rC   r   r'   rV   r(   r   r   )r)   Úspawnrc   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/  r0  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   r1  râ   rÈ   )r)   Z	user_namer   r   r	   Útest_getlogin8
  s    zLoginTests.test_getloginN)r…   r†   r‡   r3  r   r   r   r	   r2  5
  s   r2  Ú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 )Nr3   é   z?unable to reliably test setpriority at current nice level of %s)r   r4  ÚPRIO_PROCESSr  r5  r   rÄ  rC   r;   rÒ   ZEACCES)r)   r´  Znew_prior	  r   r   r	   Útest_set_get_priorityB
  s    
z*ProgramPriorityTests.test_set_get_priorityN)r…   r†   r‡   r_  r9  r   r   r   r	   r6  =
  s   r6  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>  r  )r)   rW   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=  rD  rE  rF  rG  r   r   r   r	   ÚHandlerW
  s
   rH  c             C   sp   t j | ¡ tj | ¡ |  tjtj¡ |  	|¡ |  
d¡ | j ¡ d d… \| _| _d | _d| _t  ¡ | _d S )Nr•   r5   F)Ú	threadingÚThreadr=  ÚasyncoreÚ
dispatcherZcreate_socketÚsocketÚAF_INETÚSOCK_STREAMÚbindÚlistenÚgetsocknameÚhostÚportÚhandler_instanceÚ_activeÚLockÚ_active_lock)r)   Úaddressr   r   r	   r=  o
  s    

zSendfileTestServer.__init__c             C   s   | j S )N)rV  )r)   r   r   r	   r‘  |
  s    zSendfileTestServer.runningc             C   s.   | j r
t‚t ¡ | _tj | ¡ | j ¡  d S )N)r‘  rÃ  rI  ÚEventÚ_SendfileTestServer__flagrJ  Ústartr£  )r)   r   r   r	   r\  €
  s    

zSendfileTestServer.startc             C   s   | j s
t‚d| _|  ¡  d S )NF)r‘  rÃ  rV  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£   rU  r  r   r]  )r)   r   r   r	   r£  ‹
  s    zSendfileTestServer.waitc             C   sP   d| _ | j ¡  x2| j rBtjrB| j ¡  tjddd | j ¡  qW t 	¡  d S )NTgü©ñÒMbP?r3   )Útimeoutrò  )
rV  r[  r—  rK  Ú
socket_maprX  ÚacquireZloopÚreleaseÚ	close_all)r)   r   r   r	   Úrun“
  s    

zSendfileTestServer.runc             C   s   |   ¡ \}}|  |¡| _d S )N)ÚacceptrH  rU  )r)   rB  Ú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	   rG  §
  s    zSendfileTestServer.handle_errorN)r…   r†   r‡   r;  r<  rH  r=  Úpropertyr‘  r\  r]  r£  rc  rf  rg  rD  rh  rG  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   ÚlinuxÚsolarisÚ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   Ú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   Ú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   r3   i   rU   )r:  r   ÚHOSTÚserverr\  rM  ÚclientÚconnectrS  rT  Ú
settimeoutrC  rI   Ú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-   rt  rs  r‘  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   rj  r;   rÒ   Ú
ECONNRESETÚEAGAINÚEBUSY)r)   rc   rg  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È   rp  r{  rw  rI   r.   rC   rt  ÚshutdownrM  Ú	SHUT_RDWRr-   rs  r£  rU  rE  )r)   Ú
total_sentÚoffsetÚnbytesÚsentrW   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   r5   i   )rÈ   rp  r{  rw  rI   r.   rt  r|  rM  r}  r-   rs  r£  rU  rE  rC   )r)   r~  r  Z	must_sendr€  r  rW   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È   rp  r   rj  rw  rI   r;   rÒ   ÚEINVALrC   rt  r|  rM  r}  r-   rs  r£  rU  rE  )r)   r  r  rÎ   rW   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 )Nr{  i   )
r:   r;   r   rj  rw  rI   rC   rÑ   rÒ   r„  )r)   rW  r   r   r	   Útest_invalid_offset#  s    z TestSendfile.test_invalid_offsetc          	   C   sF   t jf | jdddœd| ji—Ž | jrBt j| j| jdddddd d S )Nr   i   )ró  r  rò  Úinr   )r  rò  ÚheadersÚtrailersrx   )r   rj  rw  rI   Ú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   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyr{  i   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs   yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy)rˆ  i   )rp  r   rj  rw  rI   ÚassertLessEqualrÈ   Úminr{  rC   rt  r-   rs  r£  rU  rE  Úhash)r)   r~  Zexpected_datar  r  r€  rW   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 )
Nr]  s   abcdefrU   r   r•   s   123456s   789)r‰  s   abcde123456789)r   r'   rV   r(   r#   r   r   rj  rw  rI   rt  r-   rs  r£  rU  rE  rC   )r)   rv   Z	file_datar1   rW   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ˆ  )rs  rU  r?  r:   r;   r   rj  rw  rI   rC   rÑ   rÒ   r„  )r)   rW  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   r‘  i   i €  )r‰  )rs  rU  r?  r:   r;   r   rj  rw  rI   rC   rÑ   rÒ   r„  )r)   rW  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   )rx   )	r   rj  rw  rI   r”  r;   rÒ   rz  ry  )r)   r	  r   r   r	   Ú
test_flagsm  s    zTestSendfile.test_flagsN)r…   r†   r‡   rp  r?   r‹   rý  rŠ  r   r   Zrequires_headers_trailersÚmaxsizeZrequires_32brÝ  rË  rÜ  r*   rˆ   r{  r‚  rƒ  r…  r†  r‹  r  r  r’  r“  r   r   r•  r   r   r   r	   rk  «
  s6   
rk  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'   r—  rI   r;   r(   )r"   r   r   r	   Úsupports_extended_attributesy  s    
r˜  z(no non-broken extended attribute supportr5   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>rn   r‘  )r   r'   rV   r(   r#   r:   r;   rC   rÑ   rÒ   ÚENODATArí  r|  r—  r†  r   ÚXATTR_REPLACEÚXATTR_CREATEÚEEXISTr‚  r¾  r¸   )r)   rP   Úgetxattrr—  ÚremovexattrÚ	listxattrrg  r~  rW  Z
init_xattrZxattrZmanyÚthingr   r   r	   Ú_check_xattrs_str  sL    
""


z(ExtendedAttributeTests._check_xattrs_strc             O   sB   | j tf|ž|Ž t tj¡ | j tjf|ž|Ž t tj¡ d S )N)r£  r5  r   r(   r'   r   r¦  )r)   rc   rg  r   r   r	   Ú_check_xattrs¿  s    z$ExtendedAttributeTests._check_xattrsc             C   s   |   tjtjtjtj¡ d S )N)r¤  r   rŸ  r—  r   r¡  )r)   r   r   r	   Útest_simpleÆ  s    z"ExtendedAttributeTests.test_simplec             C   s    | j tjtjtjtjdd d S )NF)rû   )r¤  r   rŸ  r—  r   r¡  )r)   r   r   r	   Ú
test_lpathÊ  s    z!ExtendedAttributeTests.test_lpathc             C   s4   dd„ }dd„ }dd„ }dd„ }|   ||||¡ d S )	Nc          	   W   s*   t | dƒ}tj| ¡ f|žŽ S Q R X d S )NrU   )r   r   rŸ  rI   )r%   rc   r"   r   r   r	   rŸ  Ï  s    z1ExtendedAttributeTests.test_fds.<locals>.getxattrc          	   W   s0   t | ddƒ}tj| ¡ f|žŽ  W d Q R X d S )Nrý   r   )r   r   r—  rI   )r%   rc   r"   r   r   r	   r—  Ò  s    z1ExtendedAttributeTests.test_fds.<locals>.setxattrc          	   W   s0   t | ddƒ}tj| ¡ f|žŽ  W d Q R X d S )Nrý   r   )r   r   r   rI   )r%   rc   r"   r   r   r	   r   Õ  s    z4ExtendedAttributeTests.test_fds.<locals>.removexattrc          	   W   s*   t | dƒ}tj| ¡ f|žŽ S Q R X d S )NrU   )r   r   r¡  rI   )r%   rc   r"   r   r   r	   r¡  Ø  s    z2ExtendedAttributeTests.test_fds.<locals>.listxattr)r¤  )r)   rŸ  r—  r   r¡  r   r   r	   Útest_fdsÎ  s
    zExtendedAttributeTests.test_fdsN)r…   r†   r‡   r£  r¤  r¥  r¦  r§  r   r   r   r	   rš  ‰  s
   0rš  Ú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.
        rf   zfailed to query terminal sizeNr   )r   r¨  r;   r?   r‹   rÒ   r„  ÚENOTTYr8   ÚassertGreaterEqualÚcolumnsÚlines)r)   rR   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sttyrR   zstty invocation failedr3   r   rf   zfailed to query terminal sizeN)ra   Úcheck_outputrN  r¥   rt   ÚCalledProcessErrorry  r8   r   r   r¨  r?   Ú	__stdin__rI   r;   r‹   rÒ   r„  rª  rC   )r)   rR   rš  ÚactualrÎ   r   r   r	   Útest_stty_matchò  s    
zTermsizeTests.test_stty_matchN)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 )Ú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µ  )r5  Úbytes_filenamesÚunicode_filenamesr   r  r'   r  ÚTESTFN_UNDECODABLEr   r¦  r[   r\   ré  )r)   rµ  ÚdecodedÚ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ÿ  rf   s   dstr€   rÈ  r   ÚlchownrK  ÚchflagsÚlchflagsÚchrootrm  r¡  z	user.tests   userÚlchmodrÕ  z	should bezNo exception thrown by {}),ré  r   r-  rw  rÃ  r   rj   rÛ   ru   r(   r?   r‹   r¼  r¶  rB   rs   r·  rx  r   r  rÈ  r»  rK  r¼  r½  r¾  rm  r¡  rŸ  r—  r   r¿  rÕ  rÆ   r5  rM   ÚassertWarnsRegexÚDeprecationWarningr;   rT  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*   rÄ  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   ÚassertGreaterr8   )r)   Zcpusr   r   r	   Útest_cpu_countl  s
    zCPUCountTests.test_cpu_countN)r…   r†   r‡   rÈ  r   r   r   r	   rÅ  k  s   rÅ  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   r{   rj   rV   r-   rC   rU  rV  )r)   rO   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   r{   rj   rV   r-   rC   rU  ÚfcntlÚF_GETFDÚ
FD_CLOEXECZF_SETFD)r)   rO   rx   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   r{   rj   rV   r-   rC   rË  rÌ  rÍ  rV  )r)   rO   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   r{   rj   rV   r-   rC   rU  )r)   rO   r   r   r	   r‹  –  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Ð   rV   r-   rC   rU  )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   r{   rj   rV   r-   r7   rC   rU  )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)Úinheritable)r   r   r{   rj   rV   r-   rC   r?  r.   rU  râ  )r)   rO   rÑ  Zfd3r   r   r	   rA  «  s    zFDInheritanceTests.test_dup2Úopenptyzneed os.openpty()c             C   sP   t  ¡ \}}|  t j|¡ |  t j|¡ |  t  |¡d¡ |  t  |¡d¡ d S )NF)r   rÔ  rV   r-   rC   rU  )r)   Z	master_fdZslave_fdr   r   r	   Útest_openpty¼  s
    zFDInheritanceTests.test_openpty)r…   r†   r‡   rÊ  r   r)  rË  rÎ  rÏ  r‹  r   r   r   rÐ  rÒ  rA  rÕ  r   r   r   r	   rÉ  u  s   rÉ  c               @   sH   e Zd Zddddejfdfddddd	eed
dƒfgZdd„ Zdd„ ZdS )ÚPathTConverterTests)ru   Tr   N)rÃ  Fr   Nr/   FN)r¼  F)r   N)r½  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   rZ   r+   rV   r(   r-   Ú	functionsÚsubTestr£   rª   ÚassertRaisesRegexrA   )r)   Zstr_filenameZbytes_fspathÚbytes_filenamerO   Z
int_fspathZ
str_fspathr   Zallow_fdÚ
extra_argsZ
cleanup_fnr~  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   r5   Úfloatg¸…ëQ¸@Úobject)rÙ  rA   r   ru   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Ö  rX  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   r{   rj   rV   r-   rC   rX  rY  )r)   rO   r   r   r	   rZ  
  s    zBlockingTests.test_blockingN)r…   r†   r‡   rZ  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   re  )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_pathrV   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Æ   rM   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%   rC   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ý  rC   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   ÚDirEntryrC   r   r%   rß   Úinoderu   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 )Nrm  r    zfile.txtzlink_file.txtzos.link(): %sÚsymlink_dirT)r   zsymlink_file.txt)rû  zsymlink_file.txtF)r   r   r   ru  r%   rß   rÚ   r#   rm  ry  r8   r}   r  r¼  rî  rú  )	r)   rm  r}   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 )Nr3   r   )
rÆ   rM   rç  r%   r|  r   rê  rC   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ê  rC   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ÿ  rC   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ÿ  rC   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í  rM   rC   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ù  r:   rt   rô  ru   rÇ  )r)   r%   ré  r   r   r	   Útest_removed_dir¯  s    




zTestScandir.test_removed_dirc             C   sª   |   ¡ }t |j¡ |  | ¡ ¡ tjdkr:|  | ¡ ¡ |  | 	¡ ¡ tjdkrv|  
t|j¡ | ¡  |jdd n0|  | ¡ d¡ |  
t|j¡ | j
t|jdd d S )Nr¶  F)rû   r   )rÿ  r   r(   r%   râ  rõ  r   r.   r÷  rù  r:   rt   rô  ru   rÇ  )r)   ré  r   r   r	   Útest_removed_fileÅ  s    

zTestScandir.test_removed_filec             C   sÐ   t  ¡ s|  d¡S |  d¡}t |tj | jd¡¡ |  ddg¡}|d }t 	|¡ |  
| ¡ d¡ |  | ¡ ¡ |  | ¡ ¡ |  |jdd¡ |  |jdd¡ |  | ¡ ¡ |  t|j¡ |jdd d S )Nzcannot create symbolic linkzfile.txtzsymlink.txtr   F)rû   )r   ru  r8   r#   r   r}   r%   rß   rî  r(   rÇ  rô  râ  rõ  r÷  r.   rù  r:   rt   ru   )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.txtr3   r   s   file.txt)
r#   r   r¦  r%   r|  rê  rC   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.txtr3   r   s   file.txt)r#   r[   r\   r   r¦  r%   ÚassertWarnsrÁ  r|  rê  rC   rÈ   r   rß   rT  rL   rM   )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.txtrm  c             S   s   g | ]
}|j ‘qS r   )r   )r   ré  r   r   r	   r
     s    z'TestScandir.test_fd.<locals>.<listcomp>)rz   F)rz   rû   )rû   )r¤   r   rê  r  r#   r   ru  r}   r%   rß   r  r   rj   r|  rC   r¾  rx  r   r  rù  ru   r  r-   )r)   Zexpected_namesrO   r3  rí  rì  ré  rê   r   r   r	   Útest_fd	  s.    


zTestScandir.test_fdc             C   s   |   ttjd¡ d S )Nr	  )r:   rt   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.txtr3   r   )r#   r   rê  r%   r|  rC   rÈ   )r)   rY  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¾ó?)r:   rA   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%   r1  r-   Úcheck_no_resource_warning)r)   rY  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%   r1  r  )r)   rY  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%   r1  r-   )r)   rY  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.txtr3   r   )r#   r:   ÚZeroDivisionErrorr   rê  r%   r1  r  )r)   rY  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%   r1  r
  ÚResourceWarningr   Ú
gc_collectr|  r  )r)   rY  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   rx  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)rC   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)rC   r  )r)   rP   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   rC   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   )rC   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   )rL   r   r   r:   rA   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)r:   rA   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   r3   )r:   rA   r  r   rL   Ú
__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   rC   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‡   r_  r  r   r0  r  r   r   r   r	   r1  ­  s   r1  Ú__main__)r   )N)}r;  rK  rù  Ú
contextlibrÏ  rÒ   rÐ  r   r•  rþ  r­  r   r¹   r‡  r¨  rM  ru   ra   r?   Ú	sysconfigrI  r  r   r¬  rF  rã  r   r  ræ  rË  rÞ  ÚgrpÚgetgrallrÕ  r   r   Zprocess_gidr  ÚpwdÚgetpwallr×  rª   Ú	_testcapir   r   r–  Ztest.support.script_helperr   Ztest.supportr   r   rÞ  r   r   Úversionrý  r*  r‹   rp  r   r#   ÚTestCaser$   rŒ   rä   r   ZBasicTestMappingProtocolr!  rb  r   r’  r¥  r¬  r®  rÉ  rß  ræ  ré  rø  Úget_config_varZOS_URANDOM_DONT_USE_FDr)  r  Úcontextmanagerr  r  r+  r1  r\  ri  r}  r  rº  Úskip_unless_symlinkrÁ  rÛ  râ  rì  rî  rò  rÿ  r
  r¹  r2  r6  rL  rJ  r:  rk  r˜  Úrequires_linux_versionrš  r©  r´  rÅ  rÉ  rÖ  rá  râ  rå  r  r(  r1  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/
