asda?‰PNG  IHDR ? f ??C1 sRGB ??é gAMA ±? üa pHYs ? ??o¨d GIDATx^íüL”÷e÷Y?a?("Bh?_ò???¢§?q5k?*:t0A-o??¥]VkJ¢M??f?±8\k2íll£1]q?ù???T a bYh| @sdddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddl m!Z!z ddl"Z"Wne#y(dZ"Yn0z ddl$Z$Wne#yNdZ$Yn0z ddl%Z%Wne#ytdZ%Yn0zddl&Z&dde&'DZ(Wne#e)fygZ(Yn0zddl*m+Z+m,Z,Wne#yej-Z+Z,Yn0ddl.m/Z/dd lm0Z0m1Z1d Z2e3e d re 4dkZ2e3ed rDej5j6rDej5j67d Z8nd Z8ej 7do`e 9dkZ:ddZ;dddZGdddej=Z?Gdddej=Z@Gdddej=ZAddlmBZBGdddeBjCZDGdd d ej=ZEeFe3e d!d"Gd#d$d$eEZGGd%d&d&eEZHeFe3e d!d"Gd'd(d(eGZIGd)d*d*ej=ZJeFe3e d+d,Gd-d.d.ej=ZKGd/d0d0ej=ZLGd1d2d2ej=ZMGd3d4d4ej=ZNeFe3e d5d6Gd7d8d8ej=ZOePd9d:kpePd;d:kpePd<d:kZQeReQd=eRej d>kd?Gd@dAdAej=ZSejTddBdCZUeFe3e dDdEGdFdGdGej=ZVeFej dHkdIGdJdKdKej=ZWGdLdMdMej=ZXGdNdOdOej=ZYeRej dHkdPGdQdRdRej=ZZeRej dHkdPGdSdTdTej=Z[eFej dHkdIGdUdVdVej=Z\eFej dHkdIGdWdXdXej=Z]eFe3e dYdZGd[d\d\ej=Z^eFej dHkdIej_Gd]d^d^ej=Z`eFej dHkdIGd_d`d`ej=ZaeFej dHkdIGdadbdbej=Zbej_Gdcddddej=ZcGdedfdfej=ZdGdgdhdhej=ZeGdidjdjej=ZfGdkdldlej=ZgehdmeFe3e dndoGdpdqdqej=ZieFe3e drove3e dsdtGdudvdvej=ZjGdwdxdxejkejlZmeFe3e dydzGd{d|d|ej=Znd}d~ZoeFeodepdddGdddej=ZqeFe3e ddGdddej=ZreFe3e ddepddGdddej=ZsGdddej=ZtGdddej=ZuGdddej=ZvGdddej=ZweFe3e ddGdddej=ZxGdddej=ZyGdddej=ZzGdddej=Z{Gdddej=Z|Gdddej=Z}e;dGdddej=Z~e3e drNGddde|Zedkr`edS)N)support) socket_helper) win32_is_iotcCsg|] }|jqS)pw_uid).0urr(/usr/local/lib/python3.9/test/test_os.py 3r )INT_MAXPY_SSIZE_T_MAXassert_python_ok) unix_shellFakePathFgeteuid thread_infoZ linuxthreadsZfreebsdcCsttt|d|S)Nzrequires os.%s)unittest skipUnlesshasattrosnamerrr requires_os_funcPsrcontentcCs:t|dd}||Wdn1s,0YdS)Nxbr)openwrite)filenameZcontentfprrr create_fileTsr!c@s$eZdZddZddZddZdS) MiscTestscCst}||tdSN)rgetcwdassertIsInstancestrselfcwdrrr test_getcwdZszMiscTests.test_getcwdc Cs~d}d}d}|d|t|}t>}t|}|}t}||||t|ttjj }|dkrvq t||kr|dkr|d|}tj ||}zt |t |Wn\t yYq YnFty} z,| jtjkrWYd} ~ q nWYd} ~ n d} ~ 00|}q>tjr:tdt|Wdn1sP0YWdn1sp0YdS)NiZpython_test_dir_arz!Tested current directory length: )lentempfileTemporaryDirectoryrZ change_cwdrr$ assertEqualpathsepjoinmkdirchdirFileNotFoundErrorOSErrorerrnoZ ENAMETOOLONGverboseprint) r(Zmin_lenZdirlendirnameZtmpdirr1expectedr)Zneedexcrrr test_getcwd_long_path^s6       zMiscTests.test_getcwd_long_pathcCs.t}||t|t|tdSr#)rgetcwdbr%bytesr0fsdecoder$r'rrr test_getcwdbs zMiscTests.test_getcwdbN)__name__ __module__ __qualname__r*r>rBrrrr r"Ys5r"c@seZdZddZeZddZddZejddZ d d Z eje e ekd eje d d ddddZddZddZe ejdkdddZddZddZddZd d!Zd"d#Ze eed$d%d&d'Ze eed$d%d(d)Ze eed$d%d*d+Zd,S)- FileTestscCstjtjrttjdSr#)rr1lexistsrTESTFNunlinkr(rrr setUpszFileTests.setUpcCs:ttjtjtjB}t||ttjtj dSr#) rrrrHO_CREATO_RDWRclose assertTrueaccessW_OKr(frrr test_accesss zFileTests.test_accessc CsttjtjtjB}t|}zTd}||dkrht||d7}|dkrV|d|t|}}q&Wt|n t|0t ||d| t tj |ddS)Nr z%couldn't allocate two consecutive fdsa) rrrrHrLrMduprNskipTest closerange assertRaisesr7r)r(firstsecondZretriesrrr test_closeranges    zFileTests.test_closerangecCs<tj}t|}|ttj|dt|}|||dSNr) rrHsys getrefcountr\ TypeErrorrrenamer0)r(r1oldnewrrr test_renames   zFileTests.test_renamecCsttjd`}|d||}t|ddt|d}| t |t | |dWdn1sr0YdS)Nw+bspamr) rrrHrflushfilenorlseekreadr0typer@)r(fobjfdsrrr test_reads  zFileTests.test_readzneeds INT_MAX < PY_SSIZE_T_MAXrVrUF)sizeZmemusedry_runcCsh|tjtjttjdttjd }t||}Wdn1sN0Y| |ddS)Nstestrb) addCleanuprrIrHr!rrrnrlr0)r(rtr datarrr test_large_reads  .zFileTests.test_large_readcCsttjtjtjB}|ttj|dt|dt|t dt|t dt |ttjd(}| | gdWdn1s0YdS)Nbeanssbacon seggs sspam rv)sbaconseggsri)rrrrHrLO_WRONLYr\rcr bytearray memoryviewrNr0rn splitlines)r(rqrprrr test_writes  zFileTests.test_writecGs"tj|tjdd}||ddS)NT) creationflagsshellr) subprocesscallZCREATE_NEW_CONSOLEr0)r(argsretcoderrr write_windows_consoles zFileTests.write_windows_consolewin32z$test specific to the Windows consolecCs*d}|tjd||tjdd|dS)Nzprint('x' * 100000)-cz-u)rra executabler(coderrr test_write_windows_consolesz$FileTests.test_write_windows_consolecGs.ttjtj}tj|g|R}|dSr#)rrrrHO_RDONLYfdopenrN)r(rrqrSrrr fdopen_helperszFileTests.fdopen_helpercCsBttjtjtjB}t|||d|dddS)Nrd)rrrrHrLrMrNrr(rqrrr test_fdopens   zFileTests.test_fdopencCstjd}|tjtj|tj|ttjdt|dttj||ttj tjt |d }| | dWdn1s0YdS)Nz.212r1) rrHrwrIr!rreplacer\r6statrr0rn)r(TESTFN2rSrrr test_replace s    zFileTests.test_replacecCs"tjttjddd}t|dS)N)r1flagsmodedir_fd)rr__file__rrNrRrrr test_open_keywordss zFileTests.test_open_keywordsc Cs>ttd}z|dtjdddWnttfy8Yn0dS)NsymlinktargetF)srcdsttarget_is_directoryr)rZ get_attributerrHNotImplementedErrorr7)r(rrrr test_symlink_keywordss  zFileTests.test_symlink_keywordscopy_file_rangeztest needs os.copy_file_range()cCs<|ttdddWdn1s.0YdS)NrrUi)r\ ValueErrorrrrJrrr #test_copy_file_range_invalid_values%s z-FileTests.test_copy_file_range_invalid_valuesc Cs tjd}d}ttj||tjtjttjd}||j|}t|d}|tj|||j|}zt ||d}Wn<t y}z$|j t j kr| |WYd}~n`d}~00||tddt|d(}|||d|Wdn1s0YdS)Nz.3 0123456789rvrhr)rrHr!rwrIrrNrlrrr7r8ENOSYSrZassertInranger0rn) r(rrxin_filein_fdout_fileout_fdierrr test_copy_file_range*s(         zFileTests.test_copy_file_rangec Cs^tjd}d}d}d}d}ttj||tjtjttjd}||j|}t|d}|tj|||j|} ztj || |||d} Wn<t y} z$| j t j kr| | WYd} ~ nd} ~ 00|| td |d t|d}|} Wdn1s0Y|| d|d ||| |d|||| dS) Nz.4rrrrvrh)Z offset_srcZ offset_dstrrU)rrHr!rwrIrrNrlrrr7r8rrZrrrnr0) r(ZTESTFN4rxZ bytes_to_copyZin_skipZout_seekrrrrrrrnrrr test_copy_file_range_offsetLs<           (z%FileTests.test_copy_file_range_offsetN) rCrDrErKtearDownrTr_r cpython_onlyrgrsrrr r Z bigmemtestryrrraplatformrrrrrrrrrrrrrrr rFs<          !rFc@seZdZddZddZddZddZd d Ze e e d d d dZ e e e d dddZ e ejdkdddZe ejdkde e e ddddZddZe ejdkdddZe ejdkddd Ze ejdkdd!d"Zd#S)$StatAttributeTestscCs(tj|_|tj|jt|jddS)NABC)rrHfnamerwrIr!rJrrr rK{szStatAttributeTests.setUpc Cst|}||tjd||jdt|}ttD]d}|dddkr:|}|drjdd}ndd}||t|||tt|| ||q:d D]8}t t||d}t||d d }|j ||d d qz|d | dWnty Yn0zd|_| dWnty6Yn0zd|_| dWnttfydYn0zd|_| dWntyYn0ztd} | dWntyYn0ztd} WntyYn0dS)NrZST_ZTIMEcSst|Sr#)intxrrr truncr z7StatAttributeTests.check_stat_attributes..trunccSs|Sr#rrrrr rr zst_atime st_mtime st_ctimeiZ_nsi'rWdeltar+No exception raisedrUrVrrUrWrrjrr rV )rrr0ST_SIZEst_sizedirlowerendswithgetattrrsplitrassertAlmostEqualfail IndexErrorst_modeAttributeErrorst_rdevrcparrot stat_result) r(rresultmembersrattrrZfloatyZ nanosecondyresult2rrr check_stat_attributess^       z(StatAttributeTests.check_stat_attributescCs||jdSr#)rrrJrrr test_stat_attributessz'StatAttributeTests.test_stat_attributescCsFz|jt}Wn"ty6|d|jYn0||dS)Nz#cannot encode %a for the filesystem)rencoderagetfilesystemencodingUnicodeEncodeErrorrZr)r(rrrr test_stat_attributes_bytess  z-StatAttributeTests.test_stat_attributes_bytescCsft|j}ttjdD]F}t||}|d||dkrJ|d|t|}| ||qdS)NrUs stat_resultrjscos stat_result ) rrrrpickleHIGHEST_PROTOCOLdumpsrloadsr0r(rprotopZ unpickledrrr test_stat_result_pickles     z*StatAttributeTests.test_stat_result_picklestatvfsztest needs os.statvfs()cCst|j}||j|dd}t|D]"\}}|t|d|||q*|t|j t |t |dzd|_| dWnt yYn0zd|_| dWnt yYn0ztd}| dWntyYn0ztd}WntyYn0dS) Nr) ZbsizeZfrsizeZblocksZbfreeZbavailfilesZffreeZfavailflagZnamemaxZf_rVrUrrr)rrrr0f_bfree enumeraterrO isinstancef_fsidrr-rrrstatvfs_resultrc)r(rrvaluememberrrrr test_statvfs_attributess4     z*StatAttributeTests.test_statvfs_attributesneed os.statvfs()cCsft|j}ttjdD]F}t||}|d||dkrJ|d|t|}| ||qdS)NrUsstatvfs_resultrjscos statvfs_result ) rrrrrrrrrr0rrrr test_statvfs_result_pickles     z-StatAttributeTests.test_statvfs_result_picklerWin32 specific testsc Cs\ztdWnHty*|dYn.tyV}z|dWYd}~n d}~00dS)Nzc:\pagefile.syszc:\pagefile.sys does not existzCould not stat pagefile.sys)rrr6rZr7rr(rrrr test_1686475s  zStatAttributeTests.test_1686475pipezrequires os.pipe()c Cst\}}z"t|Wt|t|nt|t|0|t}t|Wdn1sp0Y||jjtj dSr#) rrrrNr\r7r0 exceptionr8EBADF)r(rwctxrrr test_15261s      (zStatAttributeTests.test_15261cCsF|t|d|t|jt|d|jko:dkndS)Nst_file_attributesr)rOrrrr)r(rrrr check_file_attributes&sz(StatAttributeTests.check_file_attributesz$st_file_attributes is Win32 specificcCszt|j}||||jtj@dtjd}t || tj |t|}||||jtj@tjdS)Nrr) rrrr r0rFILE_ATTRIBUTE_DIRECTORYrrHr4rwrmdir)r(rr;rrr test_file_attributes+s        z'StatAttributeTests.test_file_attributescCsdtjtjd|j}|tj|t|dd}t j d|ddg|dt |}| |j ddS) NTEMPrrz icacls.exez/denyz*S-1-5-32-545:(S)rr)rr1r3environrrwrrIr!r check_callrassertNotEqualr)r(rZDETACHED_PROCESSrrrr test_access_denied@s   z%StatAttributeTests.test_access_deniedcCs6dtjtd}t|}||jtjdS)Nz//./r)rr1 splitdriver$rr0rS_IFBLK)r(rrrrr test_stat_block_deviceUs z)StatAttributeTests.test_stat_block_deviceN)rCrDrErKrrrrrrrrrrrarrrr r rrrrrr rzs2A  +       rc@seZdZddZddZd)ddZdd Zed d Zd d Z ddZ e e je jvdddZe e je jvdddZe e je jvdddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zejd'd(ZdS)* UtimeTestscCsDtj|_tj|jd|_|tj|jt |jt |jdS)Nf1) rrHr;rr1r3rrwrmtreer4r!rJrrr rK_s  zUtimeTests.setUpcCs4t|}|j|dkp2|j|dkp2|j|dkS)Nrrr)rrst_atimest_mtimest_ctime)r(rstrrr support_subsecondgs    zUtimeTests.support_subsecondNcCs|s |j}||}|r"d}d}nd}d}||||ft|}|rt|j|j|ddd|j|j|dddn$||j|d||j|d||j|||j |dS)Ni8Z;l o]r TlP9& .>gư>r) rrrrrrrr0 st_atime_ns st_mtime_ns)r(set_timerratime_nsmtime_nsrrrr _test_utimeos"  zUtimeTests._test_utimecCsdd}||dS)NcSstj||ddSNnsrutimerr)rrr r#sz'UtimeTests.test_utime..set_timer&r(r#rrr test_utimeszUtimeTests.test_utimecCs |ddS)Nr g& .>rr(rrr ns_to_secszUtimeTests.ns_to_seccsfdd}|dS)Ncs0|\}}|}|}t|||fdSr#r0rr+rr)r$r%ZatimemtimerJrr r#s  z2UtimeTests.test_utime_by_indexed..set_timer-r.rrJr test_utime_by_indexeds z UtimeTests.test_utime_by_indexedcsfdd}|dS)Ncs2|\}}|}|}tj|||fddS)N)timesr1r2rJrr r#s  z0UtimeTests.test_utime_by_times..set_timer-r.rrJr test_utime_by_timess zUtimeTests.test_utime_by_timesz9follow_symlinks support for utime required for this test.cCsdd}||dS)NcSstj||dddS)NF)r)follow_symlinksr*r,rrr r#sz9UtimeTests.test_utime_nofollow_symlinks..set_timer-r.rrr test_utime_nofollow_symlinkssz'UtimeTests.test_utime_nofollow_symlinksz,fd support for utime required for this test.cCsdd}||dS)NcSsBt|dd"}tj||dWdn1s40YdS)Nwbrr()rrr+rl)rr)r rrr r#sz*UtimeTests.test_utime_fd..set_timer-r.rrr test_utime_fdszUtimeTests.test_utime_fdz0dir_fd support for utime required for this test.cCsdd}||dS)NcSsNtj|\}}t| }tj|||dWdn1s@0YdS)N)rr))rr1rr open_dir_fdr+)rr)r;rdirfdrrr r#s z.UtimeTests.test_utime_dir_fd..set_timer-r.rrr test_utime_dir_fdszUtimeTests.test_utime_dir_fdcCsdd}|j||jddS)NcSstj||ddSr'r*r,rrr r#sz1UtimeTests.test_utime_directory..set_timer)r&r;r.rrr test_utime_directoryszUtimeTests.test_utime_directorycCsbt}||j||js$d}nd}t|j}d|j||j|f}|j|j|||ddS)Ng?g?zst_time=%r, current=%r, dt=%r)rmsg)timerrrrrr)r(r#currentrrr@rrr _test_utime_currents    zUtimeTests._test_utime_currentcsfdd}|dS)NcstjdSr#rr+rr>rJrr r#sz/UtimeTests.test_utime_current..set_timerCr.rrJr test_utime_currents zUtimeTests.test_utime_currentcsfdd}|dS)NcstjddSr#rDr>rJrr r#sz3UtimeTests.test_utime_current_old..set_timerEr.rrJr test_utime_current_olds z!UtimeTests.test_utime_current_oldc Csltjdkrhtjtj|dd}ddl}|jj}| dd}| |ddddd|t |}|rh|j SdS)Nrr\r) rarrr1rabspathctypeswindllkernel32Zcreate_unicode_bufferZGetVolumeInformationWr-r)r(r1rootrKrMbufokrrr get_file_systems   zUtimeTests.get_file_systemcCsJ||jdkr|dd}t|j||f|t|jj|dS)NZNTFSz requires NTFSr) rQr;rZrr+rr0rr)r(Zlargerrr test_large_times  zUtimeTests.test_large_timec Cs|t"tj|jdddWdn1s20Y|t"t|jddgWdn1sn0Y|tt|jdWdn1s0Y|tt|jdWdn1s0Y|t$tj|jddgdWdn1s0Y|t tj|jddWdn1sZ0Y|t tj|jddWdn1s0Ytjtjvr|t"tj|jdddWdn1s0Ytjtjvrft |jdd L}|t t| dWdn1s<0YWdn1s\0Ytjtj vr|t"tj|jdd d Wdn1s0YdS) N)rrr(r)r)rrrFr7r9rr) r\rrr+rrcsupports_follow_symlinksr supports_fdrrlsupports_dir_fd)r(r rrr test_utime_invalid_arguments s0 0 0 , , 4 0 0 2 P z'UtimeTests.test_utime_invalid_argumentscCsdd}|t(tj|j|ddfdWdn1s@0Y|t(tj|j|ddfdWdn1s0Y|t(tj|j|ddfdWdn1s0YdS)NcsGfddd}|S)NcseZdZfddZdS)z?UtimeTests.test_issue31577..get_bad_int..BadIntcsSr#r)rdivmod_ret_valrr __divmod__.szJUtimeTests.test_issue31577..get_bad_int..BadInt.__divmod__N)rCrDrEr[rrYrr BadInt-sr\r)rZr\rrYr get_bad_int,sz/UtimeTests.test_issue31577..get_bad_int*rUr(r)rUrWr)r\rcrr+r)r(r]rrr test_issue31577(s 6 6 zUtimeTests.test_issue31577)N)rCrDrErKrr&r/ staticmethodr0r4r6rrrr+rUr8rVr:rWr=r?rCrFrGrQrRrXrrr_rrrr r^s:         r) mapping_testsc@seZdZdZdZddZddZddZd d Ze e oBe j e d d d Ze e obe j e d ddZddZddZddZddZe e jdddZddZedddd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Z d-d.Z!d/d0Z"d1d2Z#d3d4Z$d5d6Z%dS)7 EnvironTestsz8check that os.environ object conform to mapping protocolNcCsBttj|_tjrttj|_|D]\}}|tj|<q*dSr#) dictrr_EnvironTests__savesupports_bytes_environenvironb_EnvironTests__saveb _referenceitemsr(keyrrrr rK?s   zEnvironTests.setUpcCs:tjtj|jtjr6tjtj|jdSr#)rrclearupdaterdrerfrgrJrrr rFs   zEnvironTests.tearDowncCs ddddS)NZVALUE1ZVALUE2ZVALUE3)ZKEY1ZKEY2ZKEY3rrJrrr rhMszEnvironTests._referencecCstjtjSr#)rrrlrJrrr _empty_mappingPs zEnvironTests._empty_mappingzrequires a shellcCsbtjtjjddtdt(}|}||dWdn1sT0YdS)NZWorld)ZHELLOz%s -c 'echo $HELLO') rrrlrmpopenrrnstripr0)r(rorrrr test_update2Us   zEnvironTests.test_update2cCsxtdtV}t|}|t|d|t|d|t|d|tt|Wdn1sj0YdS)Nz %s -c 'echo "line1 line2 line3"'zline1 zline2 zline3 )rroriterr0nextr\ StopIteration)r(roitrrr test_os_popen_iter^szEnvironTests.test_os_popen_itercCs8tjD](\}}|t|t|t|tq dSr#)rrrir0ror&)r(rkvalrrr test_keyvalue_typesksz EnvironTests.test_keyvalue_typescCs.|D]\}}|tj||q dSr#)rhrir0rrgetrjrrr test_itemspszEnvironTests.test_itemsc Cs4tj}|t|dddd|DdS)z>Check that the repr() of os.environ looks like environ({...}).zenviron({{{}}})z, css|]\}}d||VqdS)z {!r}: {!r}Nformat)rrkrrrr xsz-EnvironTests.test___repr__..N)rrr0reprr|r3ri)r(envrrr test___repr__uszEnvironTests.test___repr__cCsZtjtj}gd}dtj|i}tj}z8t|t_||t||tjddW|t_n|t_0||ti|dtddi||t|tj rVz:t j dddd d }Wdn1s0YWnt yYn0| ttj||td d id g|td d id g|tdd id gdS)N)z/montyz/pythonrIz/flying/circusPATHrrIrIT)recordrr)rPATHrabcabc)rdefpathrpathsepr3rrcassertSequenceEqual get_exec_pathrewarningscatch_warnings BytesWarningr\r)r(Z defpath_listZ test_pathZtest_envZ saved_environZ mixed_envrrr test_get_exec_path|s8 , zEnvironTests.test_get_exec_pathz#os.environb required for this test.cCsd}z|td}Wn*tyBdtf}||Yn0|tjd<|tjd||tjd|d}|tjd<|tjd|| td}|tjd|dS) Nueuro€surrogateescapez'U+20AC character is not encodable to %sunicodesunicodesbytesr@) rrarrrZrrr0rfdecode)r(rZ value_bytesr@Z value_strrrr test_environbs$    zEnvironTests.test_environbcCsd}d}d|d}t}||dt||tjtjd|gdtj dd}| |j t |t|tjtjd|gdtj dd}| |j t dWdn1s0YdS)NZ PYTHONTESTVARZ testvaluez%import os; print(repr(os.environ.get(z)))rT)checkstdouttext)rZEnvironmentVarGuardpoprputenvrrunrarPIPEr0rrstripr~unsetenv)r(rrrrprocrrr test_putenv_unsetenvs     z!EnvironTests.test_putenv_unsetenvrVrcCs~dD].}|ttftj|d|ttftj|qtjdkrzdd}|ttj|d|ttjd||ttj|dS)N)rIz=namezna=mezname=znameznamerrrrX)r\r7rrrrrar)r(rZlongstrrrr test_putenv_unsetenv_errors z'EnvironTests.test_putenv_unsetenv_errorcCsd}||tj|t}tj|Wdn1s<0Y||jjd|||jj |t}tj|=Wdn1s0Y||jjd|||jj dS)NZ missingkeyr) assertNotInrrr\KeyErrorassertIsrrrO__suppress_context__)r(missingcmrrr test_key_types ( &zEnvironTests.test_key_typecCsTt|}d}t|dtj|<z&t||tj|dWtj|=n tj|=0dS)NZ __new_key__Ztest_environ_iteration)rrrsrrr0)r(Z collectioniteratorZnew_keyrrr _test_environ_iterations z$EnvironTests._test_environ_iterationcCs|tjdSr#)rrrrJrrr (test_iter_error_when_changing_os_environsz5EnvironTests.test_iter_error_when_changing_os_environcCs|tjdSr#)rrrrirJrrr .test_iter_error_when_changing_os_environ_itemssz;EnvironTests.test_iter_error_when_changing_os_environ_itemscCs|tjdSr#)rrrvaluesrJrrr /test_iter_error_when_changing_os_environ_valuessztjj}|tjtj|tjd|_||jd|_||jd|_ ||jd}||d}||jd}||jd}||d}||d}||d |_ |tjd }|tjd d } ||d } ||d } ||d} t |j t |t |t ||||| |fD]H} t | ddd"}| d| dWdn1s<0Yqtrttj||j td| dt|dd| dt|dd| d|dd ggdf|_n|dgdgf|_t|dzt|Wn&ty|tj|tjYn40t|tjt|t||jddd=dS)NZTEST1SUB1SUB11SUB2ZSUB21tmp1tmp2tmp3linkZTEST2tmp4 broken_link broken_link2 broken_link3rutf-8encodingzI'm z" and proud of it. Blame test_os. brokenTZtmp5)rrrrrrU)rr1r3rwrrrH walk_path sub1_path sub11_path link_pathmakedirsrr can_symlinkrrJ sub2_treechmodlistdirPermissionErrorrS_IRWXUrIr )r(r3Z sub2_pathZ sub21_pathZ tmp1_pathZ tmp2_pathZ tmp3_pathZ tmp5_pathZt2_pathZ tmp4_pathZbroken_link_pathZbroken_link2_pathZbroken_link3_pathr1rSrrr rKjsT               6    zWalkTests.setUpcCst||j}|t|d|ddddk}|dd|dd|d|dd|d||d|jddgd gf||d||jd gd gf||d||jggf||dd||jdS) NrjrrUrrrWrrrr) listrrr0r-sortrrrr(allZflippedrrr test_walk_topdowns zWalkTests.test_walk_topdownNcCs|dur|j}g}||D],\}}}||||fd|vr|dq|t|d||d|jdgdgf|dd|dd||d|jdS)NrrWrrrrUr)rrappendremover0r-rr)r(rrrNdirsrrrr test_walk_prunes zWalkTests.test_walk_prunecCs|t|jdSr#)rrrrJrrr test_file_like_pathszWalkTests.test_file_like_pathcCst|j|jdd}|t|d||ddddk}|dd|dd|d |dd|d||d|jdd gd gf||||jggf|||d|jd gd gf||dd||jdS)NFtopdownrjrrUrrrWrrrrr) rrrr0r-rrrrrrrr test_walk_bottom_ups$   zWalkTests.test_walk_bottom_upcCshts|d|j|jdd}|D]2\}}}||jkr&||g||dgqdq&|ddS)Nzneed symlink supportTrSrz+Didn't follow symlink with followlinks=True)rrrZrrrr0r)r(walk_itrNrrrrr test_walk_symlinks   zWalkTests.test_walk_symlinkc Csg}|j|j|jd}t|\}}}||gd}tj||}tj||d}t||zhdd|D} | || || | || |D]"} | |kr| tj|| | qWt||nt||0dS)N)onerrorrz.newcSsg|]\}}}|qSrr)rrdrSrrr r r z/WalkTests.test_walk_bad_dir..) rrrrsr0rr1r3rdrOrr) r(errorsrrNrrdir1Zpath1Zpath1newrootsdir2rrr test_walk_bad_dirs"     zWalkTests.test_walk_bad_dircsd}tjtjdtjjgdg|R}t|fddtdD}t|dD]>}||rldgnggf}|D]}t||qxtj |}q\fddtdD}}t|dD]D}|||krdgnggf}|D]}t||qtj|d}qdS) NZdeeprcsg|]}jddqS)Frrrjbaser(rr r r z7WalkTests.test_walk_many_open_files..rrUcsg|]}jddqS)Trrrrrr r r ) rr1r3rrHrrr0rsr;)r(depthrZitersrr<rurrr test_walk_many_open_filess" z#WalkTests.test_walk_many_open_files)N) rCrDrErrrKrrrrrrr rrrr r`sE rfwalkzTest needs os.fwalk()c@sLeZdZdZddZddZddZdd Zd d Zd d Z ddZ dZ dS) FwalkTestszTests for os.fwalk().cks0|j|fi|D]\}}}}|||fVqdSr#)r )r(rrrNrrZroot_fdrrr r(szFwalkTests.walkcOstj|i|Sr#)rr r(rrrrr r ,szFwalkTests.fwalkc Cs|}|}tjdddD]\}}|j||d|j||di}tjfi|D]\}}}t|t|f||<qV|jfi|D]4\}}}} |||| ||t|t|fqqdS)z. compare with walk() results. TFrWrepeat)rr)rr7N) r itertoolsproductrmrrsetr rr0) r( walk_kwargs fwalk_kwargsrr7r<rNrrrootfdrrr _compare_to_walk/s zFwalkTests._compare_to_walkcCsdtji}|||dS)Nr)rrHr)r(rrrr test_compare_to_walkAs zFwalkTests.test_compare_to_walkc CsTzBtdtj}dtji}|}||d<|||Wt|n t|0dS)N.rr)rrrrrHrrrN)r(rqrrrrr test_dir_fdEs zFwalkTests.test_dir_fdcCs|tjdddD]h\}}tj|df}|j|d|iD]B\}}}}t|t||t t |t |t |Bq2qdS)NrrWrr7) rrrrHr rfstatrr0rr)r(rr7rrNrrrrrr test_yields_correct_dir_fdOs    z%FwalkTests.test_yields_correct_dir_fdcCs\td}t|tdD]}|tjD]}q,qtd}|tj||||dS)NrU) rrYrNrr rrHrwr0)r(ZminfdrrZnewfdrrr test_fd_leak[s    zFwalkTests.test_fd_leakN) rCrDrErrr rrrrrr rrrr r $s  r c@seZdZdZddZdS)BytesWalkTestsTests for os.walk() with bytes.c ksd|vr|d|d<tjt|fi|D]p\}}}t|}tttj|}tttj|}|||fVtttj||dd<tttj||dd<q.dSr)rrrfsencoderArmap) r(rrbrootbdirsbfilesrNrrrrr rns"  zBytesWalkTests.walkN)rCrDrErrrrrr rlsrc@seZdZdZdddZdS)BytesFwalkTestsr rc ostjt|g|Ri|D]t\}}}}t|}tttj|} tttj|} || | |fVtttj| |dd<tttj| |dd<qdSr#)rr r!rArr") r(rrrr#r$r%topfdrNrrrrr r |s* zBytesFwalkTests.fwalkN)r)rCrDrErr rrrr r&ysr&c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS) MakedirTestscCsttjdSr#rr4rrHrJrrr rKszMakedirTests.setUpc Cstj}tj|ddd}t|tj|dddd}t||ttjtjtj|dddddtj}t|tj|dtjddddd}t|dSNrrZdir3Zdir4Zdir5Zdir6) rrHrr1r3rr\r7curdir)r(rr1rrr test_makedirs   zMakedirTests.test_makedircCstdtj}tj|d}tj|d}t|d|tj||tj |tj dkr| t |j d@d| t |j d@dWdn1s0YdS)NrWrrimntri)rZ temp_umaskrHrr1r3rrOrisdirrr0rr)r(rparentr1rrr test_modes   zMakedirTests.test_modecCstjtjd}d}td}t|||ttj|||jttj||ddtj|dddtj||ddt|tjtj d dddS) NrrFexist_okiT)rr3/) rr1r3rrHumaskrr\r7rJ)r(r1rold_maskrrr test_exist_ok_existing_directorys   z-MakedirTests.test_exist_ok_existing_directoryc Cstjtjd}tj}d}td}ztt tjj }zt tj||BWnt ylt dYn0t tjj |@|krt dt|||Btj||ddt |tt |j |@tj|||BddWt|n t|0dS)Nrrr1zCannot set S_ISGID for dir.z No support for S_ISGID dir mode.Tr2)rr1r3rrHrS_ISGIDr5S_IMODElstatrrrrSkipTestr)r(r1r8rr6Zexisting_testfn_moderrr test_exist_ok_s_isgid_directorys&     z,MakedirTests.test_exist_ok_s_isgid_directorycCstj}tjtjd}t|d}|dWdn1s@0Y|ttj ||jttj |dd|jttj |ddt |dS)NrrrFr2T) rrHrr1r3rrr\r7rr)r(rr1rSrrr #test_exist_ok_existing_regular_files (z0MakedirTests.test_exist_ok_existing_regular_filec CsLtjtjdddddd}tj|s>|tjkr>tj|}qt|dSr*)rr1r3rrHrr; removedirsr(r1rrr rs zMakedirTests.tearDownN) rCrDrErKr,r0r7r<r=rrrrr r(s  r(chownzTest needs chownc@seZdZeddZddZeee ddddZ ee oHe e d kd d d Zee oje e d kd ddZeddZdS)ChownFileTestscCsttjdSr#r)clsrrr setUpClassszChownFileTests.setUpClasscCsttj}|j}|j}ddtdt ddfD]0}| t tj tj||| t tj tj||q2| t tj||| t tjdddS)NgyrrW)rrrrHst_uidst_giddecimalZDecimal fractionsZFractionr\rcr@ assertIsNone)r(ruidgidrrrr *test_chown_uid_gid_arguments_must_be_indexs z9ChownFileTests.test_chown_uid_gid_arguments_must_be_index getgroupszneed os.getgroupscCst}t|dkr|d|dd\}}ttjj}ttj||ttjj }| ||ttj||ttjj }| ||dS)NrWztest needs at least 2 groups) rrNr-rZrrrHrFr@rGr0)r(groupsZgid_1Zgid_2rKrLrrr test_chown_gids   zChownFileTests.test_chown_gidrUz0test needs root privilege and more than one usercCsvtdd\}}ttjj}ttj||ttjj}|||ttj||ttjj}|||dSNrW) all_usersrrrrHrGr@rFr0)r(uid_1uid_2rLrKrrr test_chown_with_roots z#ChownFileTests.test_chown_with_rootz2test needs non-root account and more than one usercCsltdd\}}ttjj}|t0ttj||ttj||Wdn1s^0YdSrQ) rRrrrrHrGr\rr@)r(rSrTrLrrr test_chown_without_permissions  z,ChownFileTests.test_chown_without_permissioncCsttjdSr#)rr rrHrBrrr tearDownClassszChownFileTests.tearDownClassN)rCrDrE classmethodrDrMrrrrrP root_in_posixr-rRrUrVrWrrrr rAs     rAc@s4eZdZddZddZddZddZd d Zd S) RemoveDirsTestscCsttjdSr#)rrrrHrJrrr rK!szRemoveDirsTests.setUpcCsttjdSr#)rrrHrJrrr r$szRemoveDirsTests.tearDowncCsxtjtjd}t|tj|d}t|t||tj||tj||tjtjdS)Ndiradirb) rr1r3rrHr4r> assertFalserr(r[r\rrr test_remove_all's   zRemoveDirsTests.test_remove_allcCstjtjd}t|tj|d}t|ttj|dt||tj || tj || tj tjdSNr[r\file.txt) rr1r3rrHr4r!r>r]rrOr^rrr test_remove_partial1s   z#RemoveDirsTests.test_remove_partialcCstjtjd}t|tj|d}t|ttj|d|tt |Wdn1sn0Y| tj || tj || tj tjdSr`) rr1r3rrHr4r!r\r7r>rOrr^rrr test_remove_nothing<s   (z#RemoveDirsTests.test_remove_nothingN)rCrDrErKrr_rbrcrrrr rZ s   rZc@seZdZddZdS) DevNullTestscCsttjdd"}|d|Wdn1s60Yttjd }||dWdn1sr0YdS)Nr9rhellorvr )rrdevnullrrNr0rnrRrrr test_devnullJs  &zDevNullTests.test_devnullN)rCrDrErgrrrr rdIsrdc@s,eZdZddZddZddZddZd S) URandomTestscCsr|ttdd|ttdd|ttdd|ttdd|ttdddS)NrrUrVri)r0r-rurandomrJrrr test_urandom_lengthSs z URandomTests.test_urandom_lengthcCs0td}||ttd}|||dSN)rrir%r@rr(Zdata1Zdata2rrr test_urandom_valueZs   zURandomTests.test_urandom_valuecCs<ddd|ddf}td|}|d}|t|||S)N zimport os, syszdata = os.urandom(%s)zsys.stdout.buffer.write(data)zsys.stdout.buffer.flush()rrU)r3rr0r-)r(countroutrrrr get_urandom_subprocess`s z#URandomTests.get_urandom_subprocesscCs$|d}|d}|||dSrk)rrrrmrrr test_urandom_subprocessks  z$URandomTests.test_urandom_subprocessN)rCrDrErjrnrrrsrrrr rhRs rh getrandomzneed os.getrandom()c@s@eZdZeddZddZddZddZd d Zd d Z d S)GetRandomTestsc CsRztdWn>tyL}z&|jtjkr6tdnWYd}~n d}~00dS)NrUz%getrandom() syscall fails with ENOSYS)rrtr7r8rrr;)rCr=rrr rDss   zGetRandomTests.setUpClasscCs*td}||t|t|ddSrk)rrtr%r@r0r-r(rxrrr test_getrandom_types  z"GetRandomTests.test_getrandom_typecCstd}||ddS)Nrr )rrtr0)r(emptyrrr test_getrandom0s zGetRandomTests.test_getrandom0cCs|ttddS)N GRND_RANDOM)rOrrrJrrr test_getrandom_randomsz$GetRandomTests.test_getrandom_randomcCs*ztdtjWnty$Yn0dSNrU)rrt GRND_NONBLOCKBlockingIOErrorrJrrr test_getrandom_nonblocks z&GetRandomTests.test_getrandom_nonblockcCs$td}td}|||dSrk)rrtrrmrrr test_getrandom_values  z#GetRandomTests.test_getrandom_valueN) rCrDrErXrDrwryr{rrrrrr ruqs ruZHAVE_GETENTROPYrUZHAVE_GETRANDOMZHAVE_GETRANDOM_SYSCALLz*os.random() does not use a file descriptorZvxworksz$VxWorks can't set RLIMIT_NOFILE to 1c@s0eZdZeedddZddZddZdS) URandomFDTestsz!test requires the resource modulecCsd}td|dS)Naif 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") rrrrrr test_urandom_failuresz#URandomFDTests.test_urandom_failurecCsd}td|\}}}dS)Naif 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)) -Scr)r(rrcrqerrrrr test_urandom_fd_closeds z%URandomFDTests.test_urandom_fd_closedcCs|tjtjttjddjtjd}td|\}}}|t|d| |dd|ddtd|\}}}|t|d| ||dS)Nsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxaif 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)) )rHrrrrj) rwrrIrHr!r|rr0r-r)r(rrrqrZout2Zerr2rrr test_urandom_fd_reopeneds z'URandomFDTests.test_urandom_fd_reopenedN) rCrDrErrresourcerrrrrrr rs  rc#s~gfdd}fdd}zHtj}tj}tj}|t_|t_|durJ|t_VW|t_|t_|t_n|t_|t_|t_0dS)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. csd||ftddS)Nexecvz execv called)r RuntimeErrorrrcallsrr mock_execvsz#_execvpe_mockup..mock_execvcs d||fttjddS)Nexecvez execve called)rr7r8ENOTDIRrrrr mock_execvesz$_execvpe_mockup..mock_execveN)rrrr)rrrZ orig_execvZ orig_execveZ orig_defpathrrr _execvpe_mockups$   rrzneed os.execv()c@steZdZeedddZddZddZe e e dd d d Z d d Z ddZe ejdkdddZdS) ExecTestsz4avoid triggering a linuxthreads bug: see issue #4970cCs|ttjddgddS)Nz no such app-)r\r7rexecvperJrrr test_execvpe_with_bad_programs z'ExecTests.test_execvpe_with_bad_programcCsN|ttjdd|ttjdg|ttjdd|ttjddgdS)NnotepadrrrI)r\rrrrJrrr test_execv_with_bad_arglistsz%ExecTests.test_execv_with_bad_arglistcCsB|ttjdgd|ttjdgi|ttjddgidS)NrrI)r\rrrrJrrr test_execvpe_with_bad_arglist$sz'ExecTests.test_execvpe_with_bad_arglist_execvpez)No internal os._execvpe function to test.c Cstjd}|tur8d}tjt||}|}gd}n4d}gd}tj||}tjdkrht|}n|}ddi}tJ}|t tj ||| t |d | |d d ||ffWdn1s0Yt|d P}|jt tj |||d | t |d ||d d|||ffWdn1s60Ytt}|} |turd|| d<n|| d<|jt tj ||| d | t |d ||d d||| ffWdn1s0YdS)NZ absolutepaths executable)sprognamearg1arg2r)Zprognamerrr-ZspamrzrUrr)rrrrr)rr2r@r1r3r!rrr\rrr0r-r7rr) r(Z test_typeZ program_pathZprogramfullpathZnative_fullpathZ argumentsrrZenv_pathrrr _test_internal_execvpe)sN    6    $     z ExecTests._test_internal_execvpecCs"|ttjdkr|tdS)Nr-)rr&rrr@rJrrr test_internal_execvpe_strZs  z#ExecTests.test_internal_execvpe_strcCstjddg}tj}d|d<|t"t|d||Wdn1sP0Ytj}d|d<|t"t|d||Wdn1s0Ytj}d|d <|t"t|d||Wdn1s0YdS) NrpasscabbageFRUITVEGETABLErorangeVEGETABLE=cabbageFRUITlemon FRUIT=ORANGE)rarrrrr\rr)r(rnewenvrrr test_execve_invalid_env_s   0  0  z!ExecTests.test_execve_invalid_envrzWin32-specific testc CsbztddgiWn>tyR}z&||jdup:|jdkWYd}~nd}~00|ddS)NrIargrzNo OSError raised)rrr7rOwinerrorrrrrr test_execve_with_empty_pathts 0z%ExecTests.test_execve_with_empty_pathN)rCrDrErskipIfUSING_LINUXTHREADSrrrrrrrrrrarrrrrr rs   /rrrc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)Win32ErrorTestsc CsvzttjWnPty&d}YnLty`}z$d}|dtj|fWYd}~nd}~00|dtjdS)NFTz.file %s must not exist; os.stat failed with %szfile %s must not exist)rrrrHr6r7r)r(rr=rrr rKs zWin32ErrorTests.setUpcCs|ttjtjtjddS)Nz.bak)r\r7rrdrrHrJrrr rgszWin32ErrorTests.test_renamecCs|ttjtjdSr#)r\r7rrrrHrJrrr test_removeszWin32ErrorTests.test_removecCs|ttjtjdSr#)r\r7rr5rrHrJrrr test_chdirszWin32ErrorTests.test_chdircCsR|tjtjttjd"}|ttjtjWdn1sD0YdS)Nr) rwrrIrHrr\r7rr4rRrrr test_mkdirszWin32ErrorTests.test_mkdircCs|ttjtjddSr#)r\r7rr+rrHrJrrr r/szWin32ErrorTests.test_utimecCs|ttjtjddSr`)r\r7rrrrHrJrrr test_chmodszWin32ErrorTests.test_chmodN) rCrDrErKrgrrrr/rrrrr rs rc@seZdZgdZddZeD]Zeeede<qddZe e e ddd d Z e e e d d d dZ e e e ddddZe e e ddddZe e e ddddZe e e ddddZe e e dd d!d"Ze e e d#d$d%d&Ze e e d'd(d)d*Ze e e d+d,d-d.Ze e e d/d0d1d2Ze e e d3d4d5d6Ze e e d7d8d9d:Zd;d<Ze e e d=d>d?d@ZdAS)B TestInvalidFD) fchdirrYr fdatasyncrfstatvfsfsync tcgetpgrpttynamecsfdd}|S)Ncsttr|ttdSr#)rrrrrJrSrr helpers z(TestInvalidFD.get_single..helperr)rSrrrr get_singles zTestInvalidFD.get_singleZtest_c Gs`z|tg|RWn4tyL}z||jtjWYd}~nd}~00|d|dS)Nz5%r didn't raise an OSError with a bad file descriptor)r make_bad_fdr7r0r8rr)r(rSrrrrr rs&zTestInvalidFD.checkisattyztest needs os.isatty()cCs|ttddSNF)r0rrrrrJrrr test_isattyszTestInvalidFD.test_isattyr[ztest needs os.closerange()c Csrt}tdD].}zt||Wnty8Yq0q@q|dkrRtd|t |||dddS)NrVrWz5Unable to acquire a range of invalid file descriptorsrU) rrrrrr7rr;r0r[)r(rqrrrr r_s  zTestInvalidFD.test_closerangedup2ztest needs os.dup2()cCs|tjddS)N)rrrrJrrr test_dup2szTestInvalidFD.test_dup2fchmodztest needs os.fchmod()cCs|tjddSr`)rrrrJrrr test_fchmodszTestInvalidFD.test_fchmodfchownztest needs os.fchown()cCs|tjdddS)Nr)rrrrJrrr test_fchownszTestInvalidFD.test_fchown fpathconfztest needs os.fpathconf()cCs |tjd|tjddS)N PC_NAME_MAX)rrpathconfrrJrrr test_fpathconfszTestInvalidFD.test_fpathconf ftruncateztest needs os.ftruncate()cCs |tjd|tjddSr`)rrtruncaterrJrrr test_ftruncateszTestInvalidFD.test_ftruncatermztest needs os.lseek()cCs|tjdddSr`)rrrmrJrrr test_lseekszTestInvalidFD.test_lseekrnztest needs os.read()cCs|tjddSr|)rrrnrJrrr rsszTestInvalidFD.test_readreadvztest needs os.readv()cCstd}|tj|gdS)NrV)r|rrr)r(rOrrr test_readvszTestInvalidFD.test_readv tcsetpgrpztest needs os.tcsetpgrp()cCs|tjddSr`)rrrrJrrr test_tcsetpgrptszTestInvalidFD.test_tcsetpgrptrztest needs os.write()cCs|tjddS)N )rrrrJrrr rszTestInvalidFD.test_writewritevztest needs os.writev()cCs|tjdgdS)Nr)rrrrJrrr test_writevszTestInvalidFD.test_writevcCs|tj|tjddSNT)rrget_inheritableset_inheritablerJrrr test_inheritables zTestInvalidFD.test_inheritable get_blocking-needs os.get_blocking() and os.set_blocking()cCs|tj|tjddSr)rrr set_blockingrJrrr test_blockings zTestInvalidFD.test_blockingN)rCrDrEZsinglesrrSlocalsrrrrrrr_rrrrrrrsrrrrrrrrrr rsH               rc@s<eZdZddZddZddZddZd d Zd d Zd S) LinkTestscCs tj|_tjtjd|_dS)Nr)rrHfile1rr1r3file2rJrrr rKszLinkTests.setUpcCs,|j|jfD]}tj|r t|q dSr#)rrrr1rrI)r(filerrr r s zLinkTests.tearDownc Cst|zt||Wn2tyJ}z|d|WYd}~n d}~00t|dV}t|d,}|tj| | Wdn1s0YWdn1s0YdS)N os.link(): %sr) r!rrrrZrrOr1 sameopenfilerl)r(rrrrf2rrr _test_links$zLinkTests._test_linkcCs||j|jdSr#)rrrrJrrr test_linkszLinkTests.test_linkcCs(|t|jtt|jtdSr#)rr@rrarrrJrrr test_link_bytesszLinkTests.test_link_bytescCsZztdWnty*tdYn0|jd7_|jd|_||j|jdS)Nñz#Unable to encode for this platform.r)rr! UnicodeErrorrr;rrrrJrrr test_unicode_name"s  zLinkTests.test_unicode_nameN) rCrDrErKrrrrrrrrr rs  rzPosix specific testsc@seZdZdZdZeeeddddZ eeedddd Z eeed d d d Z eeeddddZ eeeddddZ eeeddddZeeeddddZeeeddddZdS)PosixUidGidTestssetuidztest needs os.setuid()cCsBtdkr|ttjd|ttjd|ttj|jdSNrz not an int)rgetuidr\r7rrc OverflowError UID_OVERFLOWrJrrr test_setuid2s zPosixUidGidTests.test_setuidsetgidztest needs os.setgid()cCsFtdkr ts |ttjd|ttjd|ttj|jdSr) rrHAVE_WHEEL_GROUPr\r7rrcr GID_OVERFLOWrJrrr test_setgid9szPosixUidGidTests.test_setgidseteuidztest needs os.seteuid()cCsBtdkr|ttjd|ttjd|ttj|jdSr) rrr\r7rrcsetegidrrrJrrr test_seteuid@s zPosixUidGidTests.test_seteuidrztest needs os.setegid()cCsFtdkr ts |ttjd|ttjd|ttj|jdSr) rrrr\r7rrcrrrJrrr test_setegidGszPosixUidGidTests.test_setegidsetreuidztest needs os.setreuid()cCsntdkr|ttjdd|ttjdd|ttjdd|ttj|jd|ttjd|jdSr)rrr\r7rrcrrrJrrr test_setreuidNs  zPosixUidGidTests.test_setreuidcCsttjddgdS)Nrz,import os,sys;os.setreuid(-1,-1);sys.exit(0)rrrarrJrrr test_setreuid_neg1Wsz#PosixUidGidTests.test_setreuid_neg1setregidztest needs os.setregid()cCsrtdkr"ts"|ttjdd|ttjdd|ttjdd|ttj|jd|ttjd|jdSr) rrrr\r7rrcrrrJrrr test_setregid_s zPosixUidGidTests.test_setregidcCsttjddgdS)Nrz,import os,sys;os.setregid(-1,-1);sys.exit(0)rrJrrr test_setregid_neg1hsz#PosixUidGidTests.test_setregid_neg1N)rCrDrErrrrrrrrrrrrrrrrrr r,s$       rc@sNeZdZddZddZddZddZee e d d d d Z d dZ dS) Pep383Testscstjrtj|_ntjr tj|_ntj|_t|j|_gfdd}|tjtjr`|tjtjrp|tjs~| dt |_ t |jzLD]B}t tj|j|t|}||j vrtd|j |qWnt|jYn0dS)Ncs2zt|}Wnty"YdS0|dSr#)rr!rr)fnbytesfnrr add_filename|s  z'Pep383Tests.setUp..add_filenamez&couldn't create any non-ascii filenamezduplicate filename)rTESTFN_UNENCODABLErZTESTFN_NONASCIIrHrr!ZbdirZTESTFN_UNICODErZr unicodefnr4Zcreate_empty_filer1r3rAraddshutilr)r(rrrrr rKrs6           zPep383Tests.setUpcCst|jdSr#)r rrrJrrr rszPep383Tests.tearDownc Csv|j}tt|j}|||t}z:ttj|tttttjWt|n t|0dSr#) r rrrrr0r$r5r2)r(r<foundZcurrent_directoryrrr test_listdirs  "zPep383Tests.test_listdircCs.|jD]"}ttj|j|d}|qdSNrv)r rrr1r3rrN)r(rrSrrr test_opens zPep383Tests.test_openrrcCs*|jD]}tj|j|}t|qdSr#)r rr1r3rr)r(rfullnamerrr test_statvfss zPep383Tests.test_statvfscCs&|jD]}ttj|j|qdSr#)r rrr1r3r)r(rrrr test_stats zPep383Tests.test_statN) rCrDrErKrr rrrrrrrrrrr rps%   rc@sFeZdZddZddZddZddZed d d Z d d Z dS)Win32KillTestsc Csvddl}ddlm}ddl}|jjj}|j|_|j| |j |j | |j | |j | |j f|_ d}t jtjdd|gt jt jt jd}||jj||jj||jjd\}} || krJ|durJ|t|} |||j| || ddd} || dd| jr6| || j!qTt"#d |d 7}q|$d t%&|j'|| |(|dS) Nrwintypesrunningrz.N)r0sortedrrrrHr=r!rJrrr test_listdir_no_extended_path@ sz/Win32ListdirTests.test_listdir_no_extended_pathcCshdtjtj}|tt||jdt tjtj}|tt|dd|jDdS)z&Test when the path starts with '\\?\'.\\?\\\?\cSsg|]}t|qSrr@rArrr r Y r z@Win32ListdirTests.test_listdir_extended_path..N) rr1rJrrHr0rBrr=r!r?rrr test_listdir_extended_pathL s  z,Win32ListdirTests.test_listdir_extended_pathN)rCrDrErrKrrCrFrrrr r<, s   r<readlinkzneeds os.readlink()c@szeZdZdZejeZe eZ e eZ ddZ ddZ ddZdd Zejd d Zejd d ZejddZdS) ReadlinkTestsZ readlinktestcCsbtj|}tj|}tjdkrRdd}||r>|dd}||rR|dd}|||dS)NrcSs|t|trdndS)NrErD) startswithrr@)rrrr i sz/ReadlinkTests.assertPathEqual..rj)rr1normcaserarr0)r(leftrightZ has_prefixrrr assertPathEqualc s     zReadlinkTests.assertPathEqualcCsT|tj|j|tj|j|tj|j|tj|jdSr#) rOrr1rfilelink_targetfilelinkb_targetr]filelink filelinkbrJrrr rKq szReadlinkTests.setUpcCs0t|j}|ttj|j|ttj|dSr#)rrOr\r7rrG)r(rOrrr test_not_symlinkw s zReadlinkTests.test_not_symlinkcCs(|ttjd|ttjtddS)Nz missing-link)r\r6rrGrrJrrr test_missing_link| s zReadlinkTests.test_missing_linkcCsBt|j|j|tj|jt|j}|t ||jdSr#) rrrOrQrwrrIrrNrG)r(rQrrr test_pathlike s zReadlinkTests.test_pathlikecCsNt|j|j|tj|jtt|j}| ||j| |t dSr#) rrrPrRrwrrIrGrrNr%r@r?rrr test_pathlike_bytes s z!ReadlinkTests.test_pathlike_bytescCsJt|j|j|tj|jt|j}|||j| |t dSr#) rrrPrRrwrrIrGrNr%r@r?rrr test_bytes s  zReadlinkTests.test_bytesN)rCrDrErQrr1rJrrOr!rRrPrNrKrSrTrskip_unless_symlinkrUrVrWrrrr rH\ s     rHc@seZdZdZejeZdZ ej eZ dZ ddZ ddZdd Zd d Zd d ZddZddZddZddZddZeejdoejddddZddZdd Zd!S)"Win32SymlinkTestsZ filelinktestZ dirlinktestz missing linkcCs^tj|jsJtj|js$Jtj|jr6Jtj|jrHJtj|jrZJdSr#)rr1rdirlink_targetrOdirlinkrQ missing_linkrJrrr rK s zWin32SymlinkTests.setUpcCsRtj|jrt|jtj|jr4t|jtj|jrNt|jdSr#) rr1rrQrr[r rGr\rJrrr r s   zWin32SymlinkTests.tearDowncCs`t|j|j|tj|j|tj|j|tj|j| |j|jdSr#) rrrZr[rOr1rr.islink check_statrJrrr test_directory_link s z%Win32SymlinkTests.test_directory_linkcCs`t|j|j|tj|j|tj|j|tj|j| |j|jdSr#) rrrOrQrOr1risfiler]r^rJrrr test_file_link s z Win32SymlinkTests.test_file_linkcCsF|j}tj|rt|d}tj|r0Jd}t|||dS)z2Create a "directory" link to a non-existent targetz"c:\\target does not exist.29r3c740TN)r\rr1rGrrr)r(ZlinknamerZ target_is_dirrrr _create_missing_dir_link s  z*Win32SymlinkTests._create_missing_dir_linkcCs|t|jdSr#)rbrrr\rJrrr ,test_remove_directory_link_to_missing_target sz>Win32SymlinkTests.test_remove_directory_link_to_missing_targetcCs ||tj|jdSr#)rbr]rr1r.r\rJrrr .test_isdir_on_directory_link_to_missing_target sz@Win32SymlinkTests.test_isdir_on_directory_link_to_missing_targetcCs|t|jdSr#)rbrr r\rJrrr .test_rmdir_on_directory_link_to_missing_target sz@Win32SymlinkTests.test_rmdir_on_directory_link_to_missing_targetcCsn|t|t||t|t|t|}|t|t||t|t|dSr#)r0rrrr:r!)r(rrZ bytes_linkrrr r^ s  zWin32SymlinkTests.check_statc CsJtjtj}tj|d}tj|d}|tj|t|t|t|tjtj|d}t |t }zt |tj|d}t tj |d|dtt |t|tdt ||t|ttj |t ||t|ttj |Wt |n t |0dS)Nlevel2level3rr)rr1rJrrHr3rwrr4r!r$r5rrelpathrrr0r)r(Zlevel1rfrgrZorig_dirrrrr test_12084 s2        zWin32SymlinkTests.test_12084C:\Users\All UsersC:\ProgramDatazTest directories not foundcCs"td}|tj|ddS)Nrjrk)rrGrOr1samefile)r(rrrr test_29248 s zWin32SymlinkTests.test_29248c Csd}tjj|gd}d||f||f|dd|ddfg}|D]\}}zt||WntynYn$0zt|WntyYn0ztt|t|WntyYqD0zt|WqDtyYqD0qDdS)NZXXXXXXXXXXXXXXXXXXXXXXXXXXXrVrH)rr1r3rr6rr7r!)r(Zsegmentr1Z test_casesrdestrrr test_buffer_overflow s.      z&Win32SymlinkTests.test_buffer_overflowcstjdtjs"|dfddttdD}|D]\}tj r`t t d|t |}| |t ||t |j| |jt jqqF|ddS)Nz$%LOCALAPPDATA%\Microsoft\WindowsAppsz%test requires a WindowsApps directorycsg|]}tj|qSr)rr1r3rr,rNrr r : sz6Win32SymlinkTests.test_appexeclink..z*.exez Testing withz$test requires an app execution alias)rr1 expandvarsr.rZfnmatchfilterrrr9r:r:r0rr]S_ISLNKrst_reparse_tagZIO_REPARSE_TAG_APPEXECLINK)r(aliasesaliasrrrrr test_appexeclink5 s       z"Win32SymlinkTests.test_appexeclinkN)rCrDrErQrr1rJrrOr[r;rZr\rKrr_rarbrcrdrer^rirrrGrrmrprzrrrr rY s,   #  #rYc@sDeZdZdZejejeZ ddZ ddZ ddZ dd Z d S) Win32JunctionTestsZ junctiontestcCs(tj|jsJtj|jr$JdSr#)rr1rjunction_targetrGjunctionrJrrr rKO szWin32JunctionTests.setUpcCstj|jrt|jdSr#)rr1rGr}rIrJrrr rS szWin32JunctionTests.tearDowncCst|j|j|tj|j|tj|j|tj |j| t |jt |j| t |jt |j|tj|j| tjd|jtjt|jdS)NrD)_winapiCreateJunctionr|r}rOrr1rGrr.rrr:r0r]r]rKrGrJrrr test_create_junctionW sz'Win32JunctionTests.test_create_junctioncCs\t|j|j|tj|j|tj|jt |j| tj|jdSr#) r~rr|r}rOrr1rrGrIr]rJrrr test_unlink_removes_junctiond s  z/Win32JunctionTests.test_unlink_removes_junctionN)rCrDrEr}rr1r;rJrr|rKrrrrrrr r{J s  r{c@seZdZddZddZdS) Win32NtTestsc Cs,td}td}ddl}|jddd}|jj|j_|jj|j _|jj|jj f|j _ |}|j }| || |}|d||j}dd d tg}td D]R} |D]H} z|| WntyYn0zt| WqtyYq0qq| || |}|d||j|} |d| dS) Nr-rKrz Kernel32.dllT)Zuse_last_errorrUz\\?\C:z\\?\NULz \\?\CONINrV)r import_moduleZctypes.wintypesZWinDLLrrZGetCurrentProcessrrZGetProcessHandleCountZLPDWORDr"r!Zbyrefr0rrr_getfinalpathname Exceptionrr) r(r-rKZkernelZhprocZ handle_countrPZ before_count filenames_rZ handle_deltarrr test_getfinalpathname_handlesn sB            z*Win32NtTests.test_getfinalpathname_handlesc Cstj}|tj|td}td}tt j d||t |g}t|krzt |WqFty}z|jdks~JWYd}~qFd}~00qFz|dWntjy|Yn0Wdn1s0YdS)Nra import os import sys import time filename = sys.argv[1] deadline = float(sys.argv[2]) while time.time() < deadline: try: with open(filename, "w") as f: pass except OSError: pass try: os.remove(filename) except OSError: pass rrWrU)rrHrwrIrAtextwrapdedentrr#rarr&rrr6rr(TimeoutExpired terminate)r(rdeadlineZcommandrrrrr test_stat_unlink_race s   &z"Win32NtTests.test_stat_unlink_raceN)rCrDrErrrrrr rl s0rc@s$eZdZddZddZddZdS)NonLocalSymlinkTestscCstddS)zM Create this structure: base \___ some_dir z base/some_dirN)rrrJrrr rK szNonLocalSymlinkTests.setUpcCstddS)Nr)r rrJrrr r szNonLocalSymlinkTests.tearDowncCs.tjdd}td|tj|s*JdS)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. rZ some_linkZsome_dirN)rr1r3rr.)r(rrrr test_directory_link_nonlocal s  z1NonLocalSymlinkTests.test_directory_link_nonlocalN)rCrDrErKrrrrrr r s rc@seZdZddZddZdS)FSEncodingTestscCs(|tdd|tdddS)NsabcuabcŁ)r0rr!rArJrrr test_nop szFSEncodingTests.test_nopc CsFdD]<}zt|}Wnty,YqYn0|t||qdS)N)u unicodeŁulatinéascii)rr!rr0rA)r(rrrrr test_identity s   zFSEncodingTests.test_identityN)rCrDrErrrrrr r src@sVeZdZddZeedoDe oDe j dpDe e doDe e dddd Zd S) DeviceEncodingTestscCs|tddS)Ni@)rJrdevice_encodingrJrrr test_bad_fd szDeviceEncodingTests.test_bad_fdrwin nl_langinfoCODESETz>test requires a tty and either Windows or nl_langinfo(CODESET)cCs(td}|||t|dSr`)rrZassertIsNotNonerOcodecslookup)r(rrrr test_device_encoding s  z(DeviceEncodingTests.test_device_encodingN)rCrDrErrrrrrrarrIrlocalerrrrr r s "rc@seZdZeeeddddZdddZdd Z d d Z ee j d kd ddZ ee j d kd ddZeeeddddZdS)PidTestsgetppidztest needs os.getppidcCs<tjtjddgtjd}|\}}|t|t dS)Nrzimport os; print(os.getppid()))r) rr#rarr communicater0rrgetpid)r(rrrrrr test_getppid s  zPidTests.test_getppidNcCstjdkr(dtjddd|dg}n tjd|g}ttjtj|}|durV||t|d\}}|t|||||dS)Nr"rr) rarrrspawnvP_NOWAITwaitpidr0waitstatus_to_exitcode)r(rexitcodecallbackrr'Zpid2statusrrr check_waitpid s  zPidTests.check_waitpidcCs|jddddS)Nrr)rrrrJrrr test_waitpid# szPidTests.test_waitpidcCsVd}d|d}|j||d|ttdWdn1sH0YdS)Nzimport sys; sys.exit()rg)rr\rcrr)r(rrrrr test_waitstatus_to_exitcode& s   z$PidTests.test_waitstatus_to_exitcoderwin32-specific testcCs"d}d|d}|j||ddS)Nl:z$import _winapi; _winapi.ExitProcess(rrr)r(ZSTATUS_CONTROL_C_EXITrrrr test_waitpid_windows. s zPidTests.test_waitpid_windowscCsd}ddd|fD]}|t|d>|q|t"t|dd>Wdn1s^0Y|ttdWdn1s0YdS)Nr rrUrrr)r0rrr\rr)r(Z max_exitcoderrrr #test_waitstatus_to_exitcode_windows6 s 0 z,PidTests.test_waitstatus_to_exitcode_windowsSIGKILLzneed signal.SIGKILLcs6dtjd}tjfdd}|j| |ddS)Nzimport time; time.sleep(rcst|dSr#)rr&)r'signumrr kill_processI sz?PidTests.test_waitstatus_to_exitcode_kill..kill_process)rr)rZ LONG_TIMEOUTr,rr)r(rrrrr test_waitstatus_to_exitcode_killD s z)PidTests.test_waitstatus_to_exitcode_kill)N)rCrDrErrrrrrrrrarrrr,rrrrr r s    rc@s$eZdZdddddZedddZedd d Zed d d ZedddZedddZ edddZ edddZ edddZ edddZ eddd Zedd!d"Zedd#d$Zedd%d&Zedd'd(Zd)d*Zedd+d,Zedd-d.Zd/S)0 SpawnTestsFwith_env use_bytescCsd|_tj}|tj||s*d|j}n8ttj|_t t |_ |j |j|j <d|j |jf}t |d}||Wdn1s0Ytj|g}|rdd|D}dd|jD|_|S) Nzimport sys; sys.exit(%s)z4import sys, os; magic = os.environ[%r]; sys.exit(%s)rcSsg|]}t|qSrr@rqrrr r f r z*SpawnTests.create_args..cSs"i|]\}}t|t|qSrr@)rkvrrr g sz*SpawnTests.create_args..)rrrHrwrIrcrrrr&r0Zuuid4rkrrrarri)r(rrrrr rrrr create_argsP s(    ( zSpawnTests.create_argsspawnlcCs4|}tjtj|dg|R}|||jdSr`)rrrP_WAITr0rr(rrrrr test_spawnll szSpawnTests.test_spawnlspawnlecCs>|jdd}tjtj|dg||jR}|||jdSNT)rr)rrrrrr0rrrrr test_spawnler s  zSpawnTests.test_spawnlespawnlpcCs4|}tjtj|dg|R}|||jdSr`)rrrrr0rrrrr test_spawnlpx szSpawnTests.test_spawnlpspawnlpecCs>|jdd}tjtj|dg||jR}|||jdSr)rrrrrr0rrrrr test_spawnlpe~ s  zSpawnTests.test_spawnlpercCsT|}ttj|d|}|||jttjt|d|}|||jdSr`)rrrrr0rrrrrr test_spawnv s zSpawnTests.test_spawnvspawnvecCs6|jdd}ttj|d||j}|||jdSrrrrrrr0rrrrr test_spawnve s zSpawnTests.test_spawnvespawnvpcCs.|}ttj|d|}|||jdSr`)rrrrr0rrrrr test_spawnvp szSpawnTests.test_spawnvpspawnvpecCs6|jdd}ttj|d||j}|||jdSr)rrrrrr0rrrrr test_spawnvpe s zSpawnTests.test_spawnvpecCs0|}ttj|d|}tj||jddS)Nrr)rrrrrZ wait_processr)r(rr'rrr test_nowait szSpawnTests.test_nowaitcCs8|jddd}ttj|d||j}|||jdS)NTrrrrrrr test_spawnve_bytes szSpawnTests.test_spawnve_bytescCs>|}|ttjtj|d|ttjtj|dddSNrrI)rr\rrrrr(rrrr test_spawnl_noargs szSpawnTests.test_spawnl_noargscCsB|}|ttjtj|di|ttjtj|ddidSr)rr\rrrrrrrr test_spawnle_noargs szSpawnTests.test_spawnle_noargscCsv|}|ttjtj|dd|ttjtj|dg|ttjtj|dd|ttjtj|ddgdSNrrrrI)rr\rrrrrrrr test_spawnv_noargs s zSpawnTests.test_spawnv_noargscCs~|}|ttjtj|ddi|ttjtj|dgi|ttjtj|ddi|ttjtj|ddgidSr)rr\rrrrrrrr test_spawnve_noargs s zSpawnTests.test_spawnve_noargscCsttjddg}tj}d|d<z|tj|d||}WntyHYn0||dtj}d|d<z|tj|d||}WntyYn0||dtj}d |d <z|tj|d||}WntyYn0||dtj }| tj |t |d }| d Wdn1s*0Ytj|g}tj}d |d<|tj|d||}||ddS)NrrrrrrrrrrzPimport sys, os if os.getenv("FRUIT") != "orange=lemon": raise AssertionErrorz orange=lemon)rarrrrrrr0rrHrwrIrr)r(spawnrrrrr rrr _test_invalid_env s>           *  zSpawnTests._test_invalid_envcCs|tjdSr#)rrrrJrrr test_spawnve_invalid_env sz#SpawnTests.test_spawnve_invalid_envcCs|tjdSr#)rrrrJrrr test_spawnvpe_invalid_env sz$SpawnTests.test_spawnvpe_invalid_envN)rCrDrErrrrrrrrrrrrrrrrrrrrrrr rO sD              . rz>Skip due to platform/environment differences on *NIX buildbotsgetloginztest needs os.getloginc@seZdZddZdS) LoginTestscCst}|t|ddSr`)rrrr-)r(Z user_namerrr test_getlogin szLoginTests.test_getloginN)rCrDrErrrrr r sr getpriority setpriorityz'needs os.getpriority and os.setpriorityc@seZdZdZddZdS)ProgramPriorityTestsz0Tests for os.getpriority() and os.setpriority().cCsttjt}ttjt|dzttjt}|dkr^|dkr^td|n|||dWzttjt|Wn2ty}z|j t j krWYd}~n d}~00nPzttjt|Wn4ty }z|j t j krWYd}~n d}~000dS)NrUz?unable to reliably test setpriority at current nice level of %s) rr PRIO_PROCESSrrrr;r0r7r8ZEACCES)r(rZnew_priorrrr test_set_get_priority s&  z*ProgramPriorityTests.test_set_get_priorityN)rCrDrErrrrrr r src@sveZdZGdddejZddZeddZddZ d d Z d d Z d dZ ddZ ddZeZddZddZdS)SendfileTestServerc@s4eZdZddZddZddZddZd d Zd S) zSendfileTestServer.HandlercCs.tj||g|_d|_d|_|ddS)NTFs 220 ready )asynchat async_chat__init__ in_buffer accumulateclosedpush)r(connrrr r& s z#SendfileTestServer.Handler.__init__cCs |d}|jr|j|dS)N)recvrrrrvrrr handle_read- s z&SendfileTestServer.Handler.handle_readcCs d|jS)Nr )r3rrJrrr get_data2 sz#SendfileTestServer.Handler.get_datacCs|d|_dSr)rNrrJrrr handle_close5 sz'SendfileTestServer.Handler.handle_closecCsdSr#rrJrrr handle_error9 sz'SendfileTestServer.Handler.handle_errorN)rCrDrErrrrrrrrr Handler$ s rcCsptj|tj||tjtj| || d|j dd\|_ |_ d|_d|_t|_dS)NrrWF) threadingThreadrasyncore dispatcherZ create_socketsocketAF_INET SOCK_STREAMbindlisten getsocknamehostporthandler_instance_activeLock _active_lock)r(addressrrr r< s    zSendfileTestServer.__init__cCs|jSr#)r rJrrr rI szSendfileTestServer.runningcCs.|jr Jt|_tj||jdSr#)rrEvent_SendfileTestServer__flagrstartr(rJrrr rM s   zSendfileTestServer.startcCs|js Jd|_|dSr)rr r3rJrrr stopS s zSendfileTestServer.stopcCs&t|jddstdq|dS)NrFMbP?)rr rAr%rrJrrr r(X s zSendfileTestServer.waitcCsLd|_|j|jr@tjr@|jtjddd|jqt dS)NTrrU)timeoutrp) r rrrZ socket_mapr acquireZloopreleaseZ close_allrJrrr r` s    zSendfileTestServer.runcCs|\}}|||_dSr#)acceptrr )r(raddrrrr handle_accepti s z SendfileTestServer.handle_acceptcCs |dSr#)rNrJrrr handle_connectm sz!SendfileTestServer.handle_connectcCsdSr`rrJrrr writableq szSendfileTestServer.writablecCsdSr#rrJrrr rt szSendfileTestServer.handle_errorN)rCrDrErrrrpropertyrrrr(rrrrrrrrrr r" s   rsendfileztest needs os.sendfile()c@s eZdZddZejd o8ejd o8ejd Ze edZ e ej dkdZ e d d Ze d d Zd dZddZddZddZddZddZddZddZe ddZe dd Ze e d!d"Ze e d#d$Ze e eed%d&d'd(Zd)S)* TestSendfiles12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcdelinuxZsolarisZsunosz%requires headers and trailers supportrz(test is only meaningful on 32-bit buildscCst|_ttj|jdSr#)rZthreading_setuprkr!rHDATArBrrr rD s zTestSendfile.setUpClasscCstj|jttjdSr#)rZthreading_cleanuprkrIrHrBrrr rW s zTestSendfile.tearDownClasscCs~ttjdf|_|jt|_|j|jj|jj f|j d|j d|j |_ ttjd|_|j |_ dS)NrrUrrv)rrZHOSTserverrrclientconnectrr  settimeoutrrlsocknorrrHrrJrrr rK s     zTestSendfile.setUpcCs0|j|j|jjr&|jd|_dSr#)rrNr#r"rrrJrrr r s    zTestSendfile.tearDownc Ospztj|i|WStyh}z>|jtjkr2n"|jtjtjfvrRWYd}~qnWYd}~qd}~00qdS)zfA higher level wrapper representing how an application is supposed to use sendfile(). N)rrr7r8Z ECONNRESETEAGAINEBUSY)r(rrrrrr sendfile_wrapper s zTestSendfile.sendfile_wrappercCsd}d}d}|t|jkrd||j|j||}|dkr8qd||7}||7}|||k|||q ||t|j|jt j |j |j |j j}|t|t|j|||jdS)Nrr)r-r!r)r&rlrOr0r#shutdownr SHUT_RDWRrNr"r(r r)r( total_sentoffsetnbytessentrxrrr test_send_whole_file s$   z!TestSendfile.test_send_whole_filecCsd}t|jd}t|j|}d}||krj||j|j||}|dkrJqj||7}||7}|||kq$|jtj |j |j |j j }|jt|jdd}||t||t|t||||dS)NrrWr)r-r!r)r&rlrOr#r*rr+rNr"r(r rr0)r(r,r-Z must_sendr.r/rxr<rrr test_send_at_certain_offset s&   z(TestSendfile.test_send_at_certain_offsetc Cst|jd}zt|j|j|d}Wn2tyX}z|jtjkrDWYd}~nd}~00| |d|j t j |j |j|jj}| |ddS)Nrrr )r-r!rrr&rlr7r8EINVALr0r#r*rr+rNr"r(r r)r(r-r/rrxrrr test_offset_overflow s     z!TestSendfile.test_offset_overflowcCsT|t$}t|j|jddWdn1s40Y||jjtj dS)Nrr) r\r7rrr&rlr0rr8r2r(rrrr test_invalid_offset s 2z TestSendfile.test_invalid_offsetc Cs<tj|j|jddd|jr8tj|j|jdddddddS)Nrr)rrr-rpr)rrr-rpheaderstrailersr)rrr&rlSUPPORT_HEADERS_TRAILERSrJrrr test_keywords s  zTestSendfile.test_keywordscCsd}d|jdd}tj|j|jddddgd}||d||7}d}|t|krtt||d}||j|j||}|dkrq|||||7}||7}qJ| |t||j |j |j j}| t|t|dS) Nrsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyrrsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyr6i)r!rrr&rlZassertLessEqualr-minr)r0r#rNr"r(r rhash)r(r,Z expected_datar/r-r.rxrrr test_headers s.        zTestSendfile.test_headerscCstjd}d}|tj|t||t|dZ}tj|j| ddddgd|j |j |j j}||d Wdn1s0YdS) Nrsabcdefrvrrs123456s789r7sabcde123456789)rrHrwrIr!rrrr&rlr#rNr"r(r rr0)r(rZ file_datarSrxrrr test_trailers s      zTestSendfile.test_trailerscCsld|jj_|t2}tj|j|jddddgddWdn1sL0Y| |j j t j dS)NFrxrr: r"r rr\r7rrr&rlr0rr8r2r4rrr test_headers_overflow_32bits) s    $z)TestSendfile.test_headers_overflow_32bitscCsld|jj_|t2}tj|j|jddddgddWdn1sL0Y| |j j t j dS)NFrr@rArr>rBr4rrr test_trailers_overflow_32bits2 s    $z*TestSendfile.test_trailers_overflow_32bits SF_NODISKIOztest needs os.SF_NODISKIOc Cs\ztj|j|jddtjdWn8tyV}z |jtjtjfvrBWYd}~n d}~00dS)Nrr)r) rrr&rlrEr7r8r(r')r(rrrr test_flags; s zTestSendfile.test_flagsN)rCrDrEr!rarrIr8rrZrequires_headers_trailersmaxsizeZ requires_32brXrDrWrKrr)r0r1r3r5r9r=r?rCrDrrrFrrrr rx sN            rc CsttdsdSzttjddV}zt|ddWn.tydYWdWttjdS0Wdn1sz0YWttjnttj0dS)NsetxattrFrr user.testr T) rrrrrHrHrlr7rI)r rrr supports_extended_attributesG s   &rJz(no non-broken extended attribute supportrWr'c@s4eZdZddZddZddZddZd d Zd S) ExtendedAttributeTestsc KsJtj}|tj|t||t&}|||dfi|Wdn1sR0Y||jj t j ||} | | t |||ddfi|t | } | d|t ||| |||dfi|d|||ddtjfi||||dfi|d|t,}|||ddtjfi|Wdn1sN0Y||jj t j|t,}|||ddtjfi|Wdn1s0Y||jj t j |||ddtjfi|| d|t ||| |||dfi||t&}|||dfi|Wdn1sL0Y||jj t j | d|t ||| ||||dfi|d|||ddfi|||||dfi|d|||dfi|td d td D} | D]} ||| d fi|q |t ||t | t | BdS) N user.testr rIresbyez user.test2sfoosaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacss|]}d|VqdS)z user.test{}Nr{)rrrrr r} r z;ExtendedAttributeTests._check_xattrs_str..rr@)rrHrwrIr!r\r7r0rr8ENODATAr%rrr r XATTR_REPLACE XATTR_CREATEEEXISTrrBr) r(rrgetxattrrH removexattr listxattrrrrZ init_xattrZxattrmanythingrrr _check_xattrs_str] sL 4   < <  6 z(ExtendedAttributeTests._check_xattrs_strcOsN|jtg|Ri|ttj|jtjg|Ri|ttjdSr#)rWr&rrIrHrr!r rrr _check_xattrs s z$ExtendedAttributeTests._check_xattrscCs|tjtjtjtjdSr#rXrrRrHrSrTrJrrr test_simple sz"ExtendedAttributeTests.test_simplecCs |jtjtjtjtjdddS)NFrSrYrJrrr test_lpath sz!ExtendedAttributeTests.test_lpathcCs4dd}dd}dd}dd}|||||dS) NcWsDt|d&}tj|g|RWdS1s60YdSr)rrrRrlr1rr rrr rR s z1ExtendedAttributeTests.test_fds..getxattrcWsFt|dd&}tj|g|RWdn1s80YdSNr9r)rrrHrlr\rrr rH sz1ExtendedAttributeTests.test_fds..setxattrcWsFt|dd&}tj|g|RWdn1s80YdSr])rrrSrlr\rrr rS sz4ExtendedAttributeTests.test_fds..removexattrcWsDt|d&}tj|g|RWdS1s60YdSr)rrrTrlr\rrr rT s z2ExtendedAttributeTests.test_fds..listxattr)rX)r(rRrHrSrTrrr test_fds s zExtendedAttributeTests.test_fdsN)rCrDrErWrXrZr[r^rrrr rLW s 0rLget_terminal_sizezrequires os.get_terminal_sizec@seZdZddZddZdS) TermsizeTestsc Cszz t}WnLtyX}z4tjdks8|jtjtjfvrB|dWYd}~n d}~00| |j d| |j ddS)zCheck 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. rfailed to query terminal sizeNr) rr_r7rarr8r2ENOTTYrZZassertGreaterEqualcolumnslines)r(rtrrrr test_does_not_crash s  z!TermsizeTests.test_does_not_crashc Csztjddgtjdd}Wn$ttjtfyB|dYn0t|dt|df}zt t j }WnLty}z4t jdks|jtjtjfvr|d WYd }~n d }~00|||d S) zCheck 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. ZsttyrtT)rrzstty invocation failedrUrrraN)r check_outputDEVNULLrr6CalledProcessErrorrrZrrr_ra __stdin__rlr7rr8r2rbr0)r(rtr<rrrrr test_stty_match s"   zTermsizeTests.test_stty_matchN)rCrDrErerjrrrr r` sr` memfd_createzrequires os.memfd_createrrc@seZdZddZdS)MemfdCreateTestscCstdtj}||d|tj||t|t|ddd*}| d| | dWdn1sv0Ytd}|tj||t|dS)NZHirr9F)closefds memfd_creater) rrk MFD_CLOEXECrrwrNr]rrrr0tell)r(rqrSfd2rrr test_memfd_create s  . z"MemfdCreateTests.test_memfd_createN)rCrDrErqrrrr rl srlc@seZdZddZddZdS) OSErrorTestscCsGdddt}g|_g|_tjdur.tj}ntj}|j||j||tjdurbtj}n t tj}|j||jt ||jt ||j|j|_ dS)Nc@s eZdZdS)zOSErrorTests.setUp..StrNrCrDrErrrr Str srt) r&bytes_filenamesunicode_filenamesrrrHrZTESTFN_UNDECODABLErr!r|r}r)r(rtZdecodedencodedrrr rK s     zOSErrorTests.setUpc CsJ|jtjf|jtjdf|jtjf|jtjtjf|jtjf|jtjf|jtj fg}t j dkr| |j tjdf|j tjdf|jtjdf|jtjdf|jtjffn,| |jtjf|jtjdf|jtjdffttdr||jtjddfttdr||jtjddfttdr.||jtjdfttd rN||jtjdfttd rn||jtjdfttd r||jtjfttd rt j dkr||j tjdf||jtjdfn||jtjdfttd r(| |jtjf|jtjdf|jtjddf|jtjdffttdrH||jtjdfttdrf||jtj f|D]^}}}|D]}zdt!|t"t#fr||g|Rn>|$t%d ||g|RWdn1s0YWnLt&y}z |'|j(|t"|WYd}~n,d}~0t)y,Yn0|*d+|qxqjdS)Nrrsdstrr@rlchownrchflagslchflagschrootrrTrMsuserlchmodrGz should bezNo exception thrown by {}),rrr5rr:rrr rrIrarr>rurdrrvrrrr@rxrryrzr{rrTrRrHrSr|rGrr&r@ZassertWarnsRegexDeprecationWarningr7rrUnicodeDecodeErrorrr|)r(ZfuncsrfuncZ func_argsrrrrr test_oserror_filenamesz                             4(z"OSErrorTests.test_oserror_filenameN)rCrDrErKrrrrr rr srrc@seZdZddZdS) CPUCountTestscCs8t}|dur*||t||dn |ddS)Nrz&Could not determine the number of CPUs)r cpu_countr%r assertGreaterrZ)r(Zcpusrrr test_cpu_countLs  zCPUCountTests.test_cpu_countN)rCrDrErrrrr rKsrc@seZdZddZeedudddZeedudddZe e e d d d d Z d dZ ddZe e e ddddZddZddZe ejdkdddZe e e dddd Ze e e d!d"d#d$ZdS)%FDInheritanceTestscCsPtttj}|tj||t|dt|d|t|ddSNFT) rrrrrwrNr0rrrrrr test_get_set_inheritableVs  z+FDInheritanceTests.test_get_set_inheritableNz need fcntlcCsntttj}|tj||t|dt|tj }|tj M}t|tj ||t|ddSr) rrrrrwrNr0rfcntlF_GETFD FD_CLOEXECZF_SETFD)r(rqrrrr test_get_inheritable_cloexec^s z/FDInheritanceTests.test_get_inheritable_cloexeccCsftttj}|tj||t|tjtj @tj t |d|t|tjtj @ddS)NTr) rrrrrwrNr0rrrrrrrr test_set_inheritable_cloexecks z/FDInheritanceTests.test_set_inheritable_cloexecO_PATHzneed os.O_PATHcCsntttj}|tj||t|dt|d|t|dt|d|t|ddSr) rrrrrwrNr0rrrrrr test_get_set_inheritable_o_pathvs  z2FDInheritanceTests.test_get_set_inheritable_o_pathcCst}|t}t|Wdn1s20Y||jjtj |t}t |dWdn1sz0Y||jjtj |t}t |dWdn1s0Y||jjtj dSNTF) rrr\r7rrr0rr8rr)r(rqrrrr test_get_set_inheritable_badfs ( * *z0FDInheritanceTests.test_get_set_inheritable_badfcCs2tttj}|tj||t|ddSr)rrrrrwrNr0rrrrr rszFDInheritanceTests.test_openrzneed os.pipe()cCsPt\}}|tj||tj||t|d|t|ddSr)rrrwrNr0r)r(ZrfdZwfdrrr test_pipes  zFDInheritanceTests.test_pipecCsJtttj}|tj|t|}|tj||t|ddSr) rrrrrwrNrYr0rr(fd1rprrr test_dups  zFDInheritanceTests.test_dupcCs(td}|tj|||ddSNrUr)rrYrwrNrrrrr test_dup_standard_streams z+FDInheritanceTests.test_dup_standard_streamrrcCsHtdtj}|tj|t|}|tj||t|dS)NNUL)rrrrwrNrYr]rrrrr test_dup_nuls  zFDInheritanceTests.test_dup_nulrzneed os.dup2()cCstttj}|tj|tttj}|tj||t||||t |tttj}|tj||tj||dd|| t |dS)NF) inheritable) rrrrrwrNr0rrOrr])r(rqrpZfd3rrr rszFDInheritanceTests.test_dup2openptyzneed os.openpty()cCsPt\}}|tj||tj||t|d|t|ddSr)rrrwrNr0r)r(Z master_fdZslave_fdrrr test_openptys  zFDInheritanceTests.test_openpty)rCrDrErrrrrrrrrrrrrrrrarrrrrrrr rUs&      rc @sHeZdZddddejfdfddddd eed dfgZd d Zd dZdS)PathTConverterTests)rTrN)r:FrNrPFN)ryFrN)rzFrNrrrNc Cstj}tjdkrd}}nttj}t|}tt|tjtjB}| tj tj| tj |t|}t|}|j D]\}}} } |j |dVztt|} Wn"tyYWdqzYn0||||fD]`} | durq|j || d2| | g| R} | dur| | Wdq1s,0Yq|td | |g| RWdn1sl0Y|r| |g| R} | dur| | n>|td | |g| RWdn1s0YWdqz1s0YqzdS)Nr-r)rr1zto return str or bytesz os.PathLike)rrHrrr!rrr{rLrwrIrN functionsZsubTestrrassertRaisesRegexrc)r(Z str_filenameZ bytes_fspathbytes_filenamerqZ int_fspathZ str_fspathrZallow_fd extra_argsZ cleanup_fnrr1rrrr test_path_t_convertersL     *0  z)PathTConverterTests.test_path_t_convertercCsd}|t|dttdWdn1s80Y|t|dttdWdn1sv0Y|t|d tttWdn1s0YdS)Nz-__fspath__\(\) to return str or bytes, not %srrWfloatgQ@object)rrcrrrr)r(r@rrr &test_path_t_converter_and_custom_classs,,z:PathTConverterTests.test_path_t_converter_and_custom_class) rCrDrErF_OKrrrrrrrr rs ,rrrc@seZdZddZdS) BlockingTestscCsntttj}|tj||t|dt|d|t|dt|d|t|ddSr) rrrrrwrNr0rrrrrr rs  zBlockingTests.test_blockingN)rCrDrErrrrr rsrc@seZdZddZdS) ExportsTestscCs |dtj|dtjdS)Nrr)rr__all__rJrrr test_os_all!szExportsTests.test_os_allN)rCrDrErrrrr r src@s$eZdZddZddZddZdS) TestDirEntrycCs0tjtj|_|tj|jt|jdSr#)rr1realpathrrHrwrr4rJrrr rK'szTestDirEntry.setUpcCs|ttjdSr#)r\rcrDirEntryrJrrr test_uninstantiable,sz TestDirEntry.test_uninstantiablecCsjttj|jdd}ddt|jD}||tj||j dddl }| t |j ||dS)NrapythoncSsg|]}|qSrrrentryrrr r 1r z0TestDirEntry.test_unpickable..r)r!rr1r3scandirrr%rr0rrr\rcr)r(rrrrrr test_unpickable/s zTestDirEntry.test_unpickableN)rCrDrErKrrrrrr r&src@s eZdZejZddZd TestScandircCs>tjtj|_t|j|_|tj|jt |jdSr#) rr1rrrHr! bytes_pathrwrr4rJrrr rK;szTestScandir.setUpracCs2t|tr|jn|j}tj||}t|d|S)Nr)rr@rr1rr3r!)r(rr1rrrr r!As zTestScandir.create_filecCs2tddt|jD}|t|||S)Ncss|]}|j|fVqdSr#rrrrr r}Hsz*TestScandir.get_entries..)rcrrr1r0rBkeys)r(namesentriesrrr get_entriesGs  zTestScandir.get_entriescCsZ|rJt|D]:}|dsq |dvr&q |t||t|||||fq n |||dS)NZst_)st_devst_inost_nlink)rrIr0r)r(Zstat1Zstat2Z skip_fieldsrrrr assert_stat_equalMs   zTestScandir.assert_stat_equalcCs(t|j}|tt||dSr#)rrr1r\rcrorN)r( scandir_iterrrr rZs zTestScandir.test_uninstantiablecCs<|d}t|j}ddl}|t|j|||dS)Nrar) r!rrr1rr\rcrrN)r(rrrrrr r_s   zTestScandir.test_unpickablecCs2||tj||j|||jtj|j|||tj|jddj t|j}|| t |j || t|j ||tj|jtj|jdd}||j ddt |j ||j ddt|j |||tjdko| ||jdd|tjdkdS)NFrSr-)r%rrr0rr1r3inoderris_dirS_ISDIRris_fileS_ISREG is_symlinkr]r)r(rrrrrZ entry_statZ entry_lstatrrr check_entryfs>           zTestScandir.check_entryc Csttd}t}tj|jd}t||d}|rzt|tj|jdWn2t y}z| d|WYd}~n d}~00|rtj |tj|jdddt |tj|jd ddg}|r| d|r| d ||}|d}||ddd d |d}||dd dd |rD|d}||dd dd |r~|d}||ddd d|d }||d d dddS) Nrrraz link_file.txtr symlink_dirT)rsymlink_file.txt)rrF)rrrrr1r3r4r!rrrZrrr>rr) r(rrr;rrrrrrrr test_attributessB   $   zTestScandir.test_attributescCsNt|tr|jn|j}tt|}|t|d|d}||j ||Sr) rr@rr1rrrr0r-r)r(rr1rrrrr get_entrys zTestScandir.get_entrycCs|j|d}|tj|S)Nr)r!rrr1basename)r(rrrrr create_file_entrys zTestScandir.create_file_entryc Csp|}t}zNt|jtddtD}|t| tj |gWt|n t|0dS)Ncss|]}|j|fVqdSr#rrrrr r}r z5TestScandir.test_current_directory..) r!rr$r5r1rcrr0rBrr)r(rZold_dirrrrr test_current_directorys  z"TestScandir.test_current_directorycCs|}|t|ddS)Nz)rr0r~r(rrrr test_reprszTestScandir.test_reprcCs*|}|t|tj|jddS)Nra)rr0rfspathr1r3rrrr test_fspath_protocolsz TestScandir.test_fspath_protocolcCsNtd}|j|d}t|}||t||tjt|j|dS)Nz bytesfile.txtr) rr!rrr%r@r0r1r3)r(rZ bytes_entryrrrr test_fspath_protocol_bytess    z&TestScandir.test_fspath_protocol_bytescCstj|jd}t||d}t|tjdkrF||| | | | tjdkr| t |j||jddn0||d| t |j|j t |jdddS)Nrr-FrSr)rr1r3r4rr rrOrr]rrr\r6rrr)r(r1rrrr test_removed_dirs     zTestScandir.test_removed_dircCs|}t|j||tjdkr:|||| tjdkrv| t |j | |j ddn0|| d| t |j |j t |j dddS)Nr-FrSr)rrrIr1r]rrrOrrr\r6rrrrrrr test_removed_files   zTestScandir.test_removed_filecCsts|dS|d}t|tj|jd|ddg}|d}t || | d| | | || |j dd| |jdd|||t|j|jdddS)Nzcannot create symbolic linkraz symlink.txtrFrS)rrrZr!rrr1r3rrIrrr]rrrOrr\r6r)r(rrrrrr test_broken_symlinks"   zTestScandir.test_broken_symlinkc Csp|dt|j}tt|}|t|d||d}||jd||jttj |jddSNrarUrsfile.txt) r!rr!r1rrr0r-rr3)r( path_bytesrrrrr rWs  zTestScandir.test_bytesc Cs|dttfD]}|t|j}|ttt |}Wdn1sT0Y| t |d||d}| |j d| |jttj |jd|t|j t|t|jtqdSr)r!r|r}rr!r1 assertWarnsr}rrr0r-rr3rror@)r(rCrrrrrr test_bytes_like s   ,zTestScandir.test_bytes_likez.fd support for listdir required for this test.c Csv|tjtj|ddg}trJtdtj |jd| dt |j}t|}t |}Wdn1s0Ydd|D}| t||| |t||D]}| |j|j| t||j| ||jdktjtjvrtj|j|d}| ||tj|j|dd}| |jdd|qWdn1sh0YdS) NrarcSsg|] }|jqSrrrrrr r =r z'TestScandir.test_fd..rTF)rr7rS)rrrrVr!rrrr1r3rr;rr0rBrrrrrrW)r(Zexpected_namesrqrurrrrrrr test_fd0s*   & zTestScandir.test_fdcCs|ttjddS)NrI)r\r6rrrJrrr test_empty_pathJszTestScandir.test_empty_pathcCsN|dt|j}t|}|t|d|t|}|t|d|dS)NrarUr)r!rrr1rr0r-)r(rrZentries2rrr test_consume_iterator_twiceMs   z'TestScandir.test_consume_iterator_twicecCs$digfD]}|ttj|q dS)NgX9v?)r\rcrr)r(objrrr test_bad_path_typeXszTestScandir.test_bad_path_typecCsf|d|dt|j}t||||~Wdn1sX0YdSNra file2.txt)r!rrr1rsrNcheck_no_resource_warningr(rrrr test_close\s    zTestScandir.test_closecCsv|d|dt|j}t|Wdn1s>0Y|~Wdn1sh0YdSr)r!rrr1rsrrrrr test_context_managergs   & z TestScandir.test_context_managercCsT|d|dt|j }t||Wdn1sF0YdSr)r!rrr1rsrNrrrr test_context_manager_closeos   z&TestScandir.test_context_manager_closec Cs|d|d|tLt|j }t|ddWdn1sR0YWdn1sp0Y|~Wdn1s0YdS)NrarrUr)r!r\ZeroDivisionErrorrrr1rsrrrrr test_context_manager_exceptionvs   D z*TestScandir.test_context_manager_exceptioncCs|d|dt|j}t||t~tWdn1sR0Yt|j}t || ~Wdn1s0YdSr) r!rrr1rsrResourceWarningr gc_collectrrrrrr test_resource_warnings    &  z!TestScandir.test_resource_warningN)ra)ra)&rCrDrErrrKr!rrrrrrrrrrrrrrrrWrrrrrrVrrrrrrrrrrrrr r8s@  )      rc@s^eZdZeejZddZddZddZddZ d d Z d d Z d dZ ddZ ddZdS) TestPEP519cCs dD]}||||qdS)N)resgoodbyessome/path/and/filer0r)r(brrr test_return_bytesszTestPEP519.test_return_bytescCs dD]}||||qdS)N)ZhelloZgoodbyezsome/path/and/filer)r(rrrrr test_return_stringszTestPEP519.test_return_stringcCsLdD]B}t|}|||||dt||dt|qdS)N)path/like/objectpath/like/objectrr)rr0rrr!rA)r(rZpathlikerrr test_fsencode_fsdecodes z!TestPEP519.test_fsencode_fsdecodecCsB|d|td|tttj|ttdtjdS)Nz #feelthegilr)r0rrrO issubclassrPathLikerrJrrr rUszTestPEP519.test_pathlikecCs4tddi}ttt|fD]}|t|j|qdS)NZblahr)rorrr\rcr)r(Zvapororrr test_garbage_in_exception_outs z(TestPEP519.test_garbage_in_exception_outcCs|t|jdSr#)r\rcrrJrrr test_argument_requiredsz!TestPEP519.test_argument_requiredcCsR|t|jtdtddi}d|_|t|j||t|jttdS)Nr^ZfoorrU)r\rcrrro __fspath__r)r(crrr test_bad_pathlikes  zTestPEP519.test_bad_pathlikecCs8Gdddtj}|tt||tttjdS)Nc@s eZdZdS)z0TestPEP519.test_pathlike_subclasshook..ANrsrrrr Asr)rrr]rrrO)r(rrrr test_pathlike_subclasshooksz%TestPEP519.test_pathlike_subclasshookcCs|tjttjdSr#)r%rrr@types GenericAliasrJrrr test_pathlike_class_getitemsz&TestPEP519.test_pathlike_class_getitemN)rCrDrEr`rrrrrrUrrrrrrrrr rs  rc@seZdZddZdS) TimesTestscCsnt}||tjdD]}t||}||tqtjdkrj||jd||j d||j ddS)N)usersystem children_userchildren_systemelapsedr-r) rr5r% times_resultrrrr0rrr)r(r5Zfieldrrrr test_timess  zTimesTests.test_timesN)rCrDrErrrrr rsrforkc@seZdZddZdS) ForkTestscCs d}td|td|dddS)Nzif 1: import os from test import support pid = os.fork() if pid != 0: support.wait_process(pid, exitcode=0) rZ malloc_debug)Z PYTHONMALLOCrrrrr test_forks zForkTests.test_forkN)rCrDrEr rrrr rsr_fspathc@seZdZdZeejZdS)TestPEP519PurePythonz>Explicitly test the pure Python implementation of os.fspath().N)rCrDrErr`rr rrrrr r sr __main__)r)N)rrr contextlibrHr8rtrIrrr1rrr r,rrrraZ sysconfigr.rrrArrr0rtestrZ test.supportrrrr ImportErrorrr~pwdgetpwallrRrZ _testcapir r rGZtest.support.script_helperrrrrYrrrversionrIrgetgidrrr!ZTestCaser"rFrrraZBasicTestMappingProtocolrbrrr rr&r(rArZrdrhruZget_config_varZOS_URANDOM_DONT_USE_FDrrcontextmanagerrrrrrrrrr<rHrXrYr{rrrrrrr;rrrrrrrJZrequires_linux_versionrLr`rlrrrrrrrrrrrrr rCmainrrrr sd              Aae\ 'EG  ^;) -   M h#d%CGs/<0![H4VO Q0 ] yB Y: