a zet @sBddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddlm Z z ddl!Z!Wne"y dZ!Yn0z ddl#Z#Wne"yFdZ#Yn0z ddl$Z$Wne"yldZ$Yn0zddl%Z%dde%&DZ'Wne"e(fygZ'Yn0zddl)m*Z*m+Z+Wne"yej,Z*Z+Yn0ddl-m.Z.dd lm/Z/m0Z0d Z1e2e d re 3dkZ1e2ed rGdddej<Z?Gdddej<Z@ddlmAZAGdddeAjBZCGdd d ej<ZDeEe2e d!d"Gd#d$d$eDZFGd%d&d&eDZGeEe2e d!d"Gd'd(d(eFZHGd)d*d*ej<ZIeEe2e d+d,Gd-d.d.ej<ZJGd/d0d0ej<ZKGd1d2d2ej<ZLGd3d4d4ej<ZMeEe2e d5d6Gd7d8d8ej<ZNeOd9d:kpeOd;d:kpeOd<d:kZPeQePd=eQejd>kd?Gd@dAdAej<ZRejSddBdCZTeEe2e dDdEGdFdGdGej<ZUeEejdHkdIGdJdKdKej<ZVGdLdMdMej<ZWGdNdOdOej<ZXeQejdHkdPGdQdRdRej<ZYeQejdHkdPGdSdTdTej<ZZeEejdHkdIGdUdVdVej<Z[eEejdHkdIGdWdXdXej<Z\eEe2e dYdZGd[d\d\ej<Z]eEejdHkdIej^Gd]d^d^ej<Z_eEejdHkdIGd_d`d`ej<Z`eEejdHkdIGdadbdbej<Zaej^Gdcddddej<ZbGdedfdfej<ZcGdgdhdhej<ZdGdidjdjej<ZeGdkdldlej<ZfegdmeEe2e dndoGdpdqdqej<ZheEe2e drone2e dsdtGdudvdvej<ZiGdwdxdxejjejkZleEe2e dydzGd{d|d|ej<Zmd}d~ZneEendeodddGdddej<ZpeEe2e ddGdddej<ZqeEe2e ddeoddGdddej<ZrGdddej<ZsGdddej<ZtGdddej<ZuGdddej<ZveEe2e ddGdddej<ZwGdddej<ZxGdddej<ZyGdddej<ZzGdddej<Z{Gdddej<Z|e2e dr,Gddde{Z}e~dkr>edS)N)support) socket_helper) win32_is_iotcCsg|] }|jqS)pw_uid).0urr@/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_os.py 2r )INT_MAXPY_SSIZE_T_MAXassert_python_ok) unix_shellFakePathFgeteuid thread_infoZ linuxthreadsZfreebsdcCsttt|d|S)Nzrequires os.%s)unittest skipUnlesshasattrosnamerrr requires_os_funcOsrcontentcCs:t|dd}||Wdn1s,0YdS)Nxbr)openwrite)filenameZcontentfprrr create_fileSsr!c@s$eZdZddZddZddZdS) MiscTestscCst}||tdSN)rgetcwdassertIsInstancestrselfcwdrrr test_getcwdYszMiscTests.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"Xs5r"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_offsetKs<           (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 rKzszStatAttributeTests.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_1686475 s  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_deviceTs z)StatAttributeTests.test_stat_block_deviceN)rCrDrErKrrrrrrrrrrrarrrr r rrrrrr rys2A  +       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_subsecondfs    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_utimens"  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)Nc SsNtj|\}}t|tj}ztj|||dWt|n t|0dS)N)rr))rr1rrrr+rN)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_timerBr.rrJr test_utime_currents zUtimeTests.test_utime_currentcsfdd}|dS)NcstjddSr#rCr=rJrr r#sz3UtimeTests.test_utime_current_old..set_timerDr.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(r1rootrJrLbufokrrr get_file_systems   zUtimeTests.get_file_systemcCsJ||jdkr|dd}t|j||f|t|jj|dS)NZNTFSz requires NTFSr) rPr;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_argumentss0 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__0szJUtimeTests.test_issue31577..get_bad_int..BadInt.__divmod__N)rCrDrErZrrXrr BadInt/sr[r)rYr[rrXr 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+rTr8rUr:rVr<r>rBrErFrPrQrWrrr^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 rKAs   zEnvironTests.setUpcCs:tjtj|jtjr6tjtj|jdSr#)rrclearupdatercrdrerfrJrrr rHs   zEnvironTests.tearDowncCs ddddS)NZVALUE1ZVALUE2ZVALUE3)ZKEY1ZKEY2ZKEY3rrJrrr rgOszEnvironTests._referencecCstjtjSr#)rrrkrJrrr _empty_mappingRs zEnvironTests._empty_mappingzrequires a shellcCsbtjtjjddtdt(}|}||dWdn1sT0YdS)NZWorld)ZHELLOz%s -c 'echo $HELLO') rrrkrlpopenrrnstripr0)r(rnrrrr test_update2Ws   zEnvironTests.test_update2cCsxtdtV}t|}|t|d|t|d|t|d|tt|Wdn1sj0YdS)Nz %s -c 'echo "line1 line2 line3"'zline1 zline2 zline3 )rrnriterr0nextr\ StopIteration)r(rnitrrr test_os_popen_iter`szEnvironTests.test_os_popen_itercCs8tjD](\}}|t|t|t|tq dSr#)rrrhr0ror&)r(rjvalrrr test_keyvalue_typesmsz EnvironTests.test_keyvalue_typescCs.|D]\}}|tj||q dSr#)rgrhr0rrgetrirrr test_itemsrszEnvironTests.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)rrjrrrr zsz-EnvironTests.test___repr__..N)rrr0reprr{r3rh)r(envrrr test___repr__wszEnvironTests.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/pythonrHz/flying/circusPATHr~rHrHT)recordrr)rPATHrabcabc)rdefpathrpathsepr3rrbassertSequenceEqual get_exec_pathrdwarningscatch_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@) rrarrrZrrr0redecode)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(rrrr~procrrr test_putenv_unsetenvs     z!EnvironTests.test_putenv_unsetenvrVrcCs~dD].}|ttftj|d|ttftj|qtjdkrzdd}|ttj|d|ttjd||ttj|dS)N)rHz=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)rqrrrrr0)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#)rrrrhrJrrr .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_symlinkrrI 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 rKlsT               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(rrrMdirsrrrr 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 supportTrRrz+Didn't follow symlink with followlinks=True)rrrZrrrr0r)r(walk_itrMrrrrr 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..) rrrrrr0rr1r3rdrOrr) r(errorsrrMrrdir1Zpath1Zpath1newrootsdir2rrr 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 ) rr1r3rrHrrr0rrr;)r(depthrZitersrr<rtrrr test_walk_many_open_filess" z#WalkTests.test_walk_many_open_files)N) rCrDrErrrKrrrrrrr rrrr rbsE 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(rrrMrrZroot_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 itertoolsproductrlrrsetr rr0) r( walk_kwargs fwalk_kwargsrr7r<rMrrrootfdrrr _compare_to_walk1s zFwalkTests._compare_to_walkcCsdtji}|||dS)Nr)rrHr)r(rrrr test_compare_to_walkCs zFwalkTests.test_compare_to_walkc CsTzBtdtj}dtji}|}||d<|||Wt|n t|0dS)N.rr)rrrrrHrrrN)r(rqrrrrr test_dir_fdGs zFwalkTests.test_dir_fdcCs|tjdddD]h\}}tj|df}|j|d|iD]B\}}}}t|t||t t |t |t |Bq2qdS)Nr rWrr7) rrrrHr rfstatrr0rr)r(rr7rrMrrrrrr test_yields_correct_dir_fdQs    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(rrbrootbdirsbfilesrMrrrrr rps"  zBytesWalkTests.walkN)rCrDrErrrrrr rnsrc@seZdZdZdddZdS)BytesFwalkTestsrrc ostjt|g|Ri|D]t\}}}}t|}tttj|} tttj|} || | |fVtttj| |dd<tttj| |dd<qdSr#)rr r rArr!) r(rrrr"r#r$topfdrMrrrrr r ~s* zBytesFwalkTests.fwalkN)r)rCrDrErr rrrr r%{sr%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)rr2/) rr1r3rrHumaskrr\r7rI)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)Nrrr0zCannot set S_ISGID for dir.z No support for S_ISGID dir mode.Tr1)rr1r3rrHrS_ISGIDr4S_IMODElstatrrrrSkipTestr)r(r1r7rr5Zexisting_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)NrrrFr1T) 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+r/r6r;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) rrMr-rZrrrHrEr?rFr0)r(groupsZgid_1Zgid_2rJrKrrr test_chown_gids   zChownFileTests.test_chown_gidrUz0test needs root privilege and more than one usercCsvtdd\}}ttjj}ttj||ttjj}|||ttj||ttjj}|||dSNrW) all_usersrrrrHrFr?rEr0)r(uid_1uid_2rKrJrrr test_chown_with_roots z#ChownFileTests.test_chown_with_rootz2test needs non-root account and more than one usercCsltdd\}}ttjj}|t0ttj||ttj||Wdn1s^0YdSrP) rQrrrrHrFr\rr?)r(rRrSrKrrr test_chown_without_permissions  z,ChownFileTests.test_chown_without_permissioncCsttjdSr#)rr rrHrArrr tearDownClassszChownFileTests.tearDownClassN)rCrDrE classmethodrCrLrrrrrO root_in_posixr-rQrTrUrVrrrr r@s     r@c@s4eZdZddZddZddZddZd d Zd S) RemoveDirsTestscCsttjdSr#)rrrrHrJrrr rK#szRemoveDirsTests.setUpcCsttjdSr#)rrrHrJrrr r&szRemoveDirsTests.tearDowncCsxtjtjd}t|tj|d}t|t||tj||tj||tjtjdS)Ndiradirb) rr1r3rrHr4r= assertFalserr(rZr[rrr test_remove_all)s   zRemoveDirsTests.test_remove_allcCstjtjd}t|tj|d}t|ttj|dt||tj || tj || tj tjdSNrZr[file.txt) rr1r3rrHr4r!r=r\rrOr]rrr test_remove_partial3s   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^rarbrrrr rY"s   rYc@seZdZddZdS) DevNullTestscCsttjdd"}|d|Wdn1s60Yttjd }||dWdn1sr0YdS)Nr9rhellorvr )rrdevnullrrNr0rnrRrrr test_devnullLs  &zDevNullTests.test_devnullN)rCrDrErfrrrr rcKsrcc@s,eZdZddZddZddZddZd S) URandomTestscCsr|ttdd|ttdd|ttdd|ttdd|ttdddS)NrrUrVri)r0r-rurandomrJrrr test_urandom_lengthUs z URandomTests.test_urandom_lengthcCs0td}||ttd}|||dSN)rrhr%r@rr(Zdata1Zdata2rrr test_urandom_value\s   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_subprocessbs z#URandomTests.get_urandom_subprocesscCs$|d}|d}|||dSrj)rqrrlrrr test_urandom_subprocessms  z$URandomTests.test_urandom_subprocessN)rCrDrErirmrqrrrrrr rgTs rg 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)rrsr7r8rrr:)rBr=rrr rCus   zGetRandomTests.setUpClasscCs*td}||t|t|ddSrj)rrsr%r@r0r-r(rxrrr test_getrandom_types  z"GetRandomTests.test_getrandom_typecCstd}||ddS)Nrr )rrsr0)r(emptyrrr test_getrandom0s zGetRandomTests.test_getrandom0cCs|ttddS)N GRND_RANDOM)rOrrrJrrr test_getrandom_randomsz$GetRandomTests.test_getrandom_randomcCs*ztdtjWnty$Yn0dSNrU)rrs GRND_NONBLOCKBlockingIOErrorrJrrr test_getrandom_nonblocks z&GetRandomTests.test_getrandom_nonblockcCs$td}td}|||dSrj)rrsrrlrrr test_getrandom_values  z#GetRandomTests.test_getrandom_valueN) rCrDrErWrCrvrxrzr~rrrrr rtss rtZHAVE_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(rrcrperrrrr 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(rrrprZout2Zerr2rrr 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)NnotepadrrrH)r\rrrrJrrr test_execv_with_bad_arglist sz%ExecTests.test_execv_with_bad_arglistcCsB|ttjdgd|ttjdgi|ttjddgidS)NrrH)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 argumentsr~rZenv_pathrrr _test_internal_execvpe+sN    6    $     z ExecTests._test_internal_execvpecCs"|ttjdkr|tdS)Nr,)rr&rrr@rJrrr test_internal_execvpe_str\s  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_envas   0  0  z!ExecTests.test_execve_invalid_envrzWin32-specific testc CsbztddgiWn>tyR}z&||jdup:|jdkWYd}~nd}~00|ddS)NrHargrzNo OSError raised)rrr7rOwinerrorrrrrr test_execve_with_empty_pathvs 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(rNrrr 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 rK szLinkTests.setUpcCs,|j|jfD]}tj|r t|q dSr#)rrrr1rrI)r(filerrr rs 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_bytes szLinkTests.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 r s  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_setuid4s zPosixUidGidTests.test_setuidsetgidztest needs os.setgid()cCsFtdkr ts |ttjd|ttjd|ttj|jdSr) rrHAVE_WHEEL_GROUPr\r7rrcr GID_OVERFLOWrJrrr test_setgid;szPosixUidGidTests.test_setgidseteuidztest needs os.seteuid()cCsBtdkr|ttjd|ttjd|ttj|jdSr) rrr\r7rrcsetegidrrrJrrr test_seteuidBs zPosixUidGidTests.test_seteuidrztest needs os.setegid()cCsFtdkr ts |ttjd|ttjd|ttj|jdSr) rrrr\r7rrcrrrJrrr test_setegidIszPosixUidGidTests.test_setegidsetreuidztest needs os.setreuid()cCsntdkr|ttjdd|ttjdd|ttjdd|ttj|jd|ttjd|jdSr)rrr\r7rrcrrrJrrr test_setreuidPs  zPosixUidGidTests.test_setreuidcCsttjddgdS)Nrz,import os,sys;os.setreuid(-1,-1);sys.exit(0)rrrarrJrrr test_setreuid_neg1Ysz#PosixUidGidTests.test_setreuid_neg1setregidztest needs os.setregid()cCsrtdkr"ts"|ttjdd|ttjdd|ttjdd|ttj|jd|ttjd|jdSr) rrrr\r7rrcrrrJrrr test_setregidas zPosixUidGidTests.test_setregidcCsttjddgdS)Nrz,import os,sys;os.setregid(-1,-1);sys.exit(0)rrJrrr test_setregid_neg1jsz#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 rKts6           zPep383Tests.setUpcCst|jdSr#)r rrrJrrr rszPep383Tests.tearDownc Csv|j}tt|j}|||t}z:ttj|tttttjWt|n t|0dSr#) rrrrrr0r$r5r2)r(r<foundZcurrent_directoryrrr test_listdirs  "zPep383Tests.test_listdircCs.|jD]"}ttj|j|d}|qdSNrv)rrrr1r3rrN)r(rrSrrr test_opens zPep383Tests.test_openrrcCs*|jD]}tj|j|}t|qdSr#)rrr1r3rr)r(rfullnamerrr test_statvfss zPep383Tests.test_statvfscCs&|jD]}ttj|j|qdSr#)rrrr1r3r)r(rrrr test_stats zPep383Tests.test_statN) rCrDrErKrr rrrrrrrrrrr rrs%   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_pathB sz/Win32ListdirTests.test_listdir_no_extended_pathcCshdtjtj}|tt||jdt tjtj}|tt|dd|jDdS)z&Test when the path starts with '\\?\'.\\?\\\?\cSsg|]}t|qSrr?r@rrr r [ r z@Win32ListdirTests.test_listdir_extended_path..N) rr1rIrrHr0rArr<r r>rrr test_listdir_extended_pathN s  z,Win32ListdirTests.test_listdir_extended_pathN)rCrDrErrKrrBrErrrr 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)NrDrC) startswithrr@)rrrr k sz/ReadlinkTests.assertPathEqual..rj)rr1normcaserarr0)r(leftrightZ has_prefixrrr assertPathEquale s     zReadlinkTests.assertPathEqualcCsT|tj|j|tj|j|tj|j|tj|jdSr#) rOrr1rfilelink_targetfilelinkb_targetr\filelink filelinkbrJrrr rKs szReadlinkTests.setUpcCs0t|j}|ttj|j|ttj|dSr#)rrNr\r7rrF)r(rNrrr test_not_symlinky s zReadlinkTests.test_not_symlinkcCs(|ttjd|ttjtddS)Nz missing-link)r\r6rrFrrJrrr test_missing_link~ s zReadlinkTests.test_missing_linkcCsBt|j|j|tj|jt|j}|t ||jdSr#) rrrNrPrwrrIrrMrF)r(rPrrr test_pathlike s zReadlinkTests.test_pathlikecCsNt|j|j|tj|jtt|j}| ||j| |t dSr#) rrrOrQrwrrIrFrrMr%r@r>rrr test_pathlike_bytes s z!ReadlinkTests.test_pathlike_bytescCsJt|j|j|tj|jt|j}|||j| |t dSr#) rrrOrQrwrrIrFrMr%r@r>rrr test_bytes s  zReadlinkTests.test_bytesN)rCrDrErPrr1rIrrNr rQrOrMrKrRrSrskip_unless_symlinkrTrUrVrrrr rG^ s     rGc@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_targetrNdirlinkrP missing_linkrJrrr rK s zWin32SymlinkTests.setUpcCsRtj|jrt|jtj|jr4t|jtj|jrNt|jdSr#) rr1rrPrrZr rGr[rJrrr r s   zWin32SymlinkTests.tearDowncCs`t|j|j|tj|j|tj|j|tj|j| |j|jdSr#) rrrYrZrOr1rr-islink check_statrJrrr test_directory_link s z%Win32SymlinkTests.test_directory_linkcCs`t|j|j|tj|j|tj|j|tj|j| |j|jdSr#) rrrNrPrOr1risfiler\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#)rarrr[rJrrr ,test_remove_directory_link_to_missing_target sz>Win32SymlinkTests.test_remove_directory_link_to_missing_targetcCs ||tj|jdSr#)rar\rr1r-r[rJrrr .test_isdir_on_directory_link_to_missing_target sz@Win32SymlinkTests.test_isdir_on_directory_link_to_missing_targetcCs|t|jdSr#)rarr 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#)r0rrrr9r )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)rr1rIrrHr3rwrr4r!r$r5rrelpathrrr0r)r(Zlevel1rerfrZorig_dirrrrr test_12084 s2        zWin32SymlinkTests.test_12084C:\Users\All UsersC:\ProgramDatazTest directories not foundcCs"td}|tj|ddS)Nrirj)rrFrOr1samefile)r(rrrr test_29248 s zWin32SymlinkTests.test_29248c Csd}tjj|gd}d||f||f|dd|ddfg}|D]\}}zt||WntynYn$0zt|WntyYn0ztt|t|WntyYqD0zt|WqDtyYqD0qDdS)NZXXXXXXXXXXXXXXXXXXXXXXXXXXXrVrG)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,rMrr r < sz6Win32SymlinkTests.test_appexeclink..z*.exez Testing withz$test requires an app execution alias)rr1 expandvarsr-rZfnmatchfilterrrr9r:r9r0rr\S_ISLNKrst_reparse_tagZIO_REPARSE_TAG_APPEXECLINK)r(aliasesaliasrrrqr test_appexeclink7 s       z"Win32SymlinkTests.test_appexeclinkN)rCrDrErPrr1rIrrNrZr;rYr[rKrr^r`rarbrcrdr]rhrrrGrrlroryrrrr rX s,   #  #rXc@sDeZdZdZejejeZ ddZ ddZ ddZ dd Z d S) Win32JunctionTestsZ junctiontestcCs(tj|jsJtj|jr$JdSr#)rr1rjunction_targetrGjunctionrJrrr rKQ szWin32JunctionTests.setUpcCstj|jrt|jdSr#)rr1rGr|rIrJrrr rU szWin32JunctionTests.tearDowncCst|j|j|tj|j|tj|j|tj |j| t |jt |j| t |jt |j|tj|j| tjd|jtjt|jdS)NrC)_winapiCreateJunctionr{r|rOrr1rGrr-rrr9r0r\r\rJrFrJrrr test_create_junctionY sz'Win32JunctionTests.test_create_junctioncCs\t|j|j|tj|j|tj|jt |j| tj|jdSr#) r}r~r{r|rOrr1rrGrIr\rJrrr test_unlink_removes_junctionf s  z/Win32JunctionTests.test_unlink_removes_junctionN)rCrDrEr|rr1r;rIrr{rKrrrrrrr rzL s  rzc@seZdZddZdS) 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,rJrz Kernel32.dllT)Zuse_last_errorrUz\\?\C:z\\?\NULz \\?\CONINrV)r import_moduleZctypes.wintypesZWinDLLrrZGetCurrentProcessrrZGetProcessHandleCountZLPDWORDr!r Zbyrefr0rrr_getfinalpathname Exceptionrr) r(r,rJZkernelZhprocZ handle_countrOZ before_count filenames_rZ handle_deltarrr test_getfinalpathname_handlesp sB            z*Win32NtTests.test_getfinalpathname_handlesN)rCrDrErrrrr rn src@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@)rIrdevice_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)rCrDrErrrrrrrarrHrlocalerrrrr 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_windows s 0 z,PidTests.test_waitstatus_to_exitcode_windowsSIGKILLzneed signal.SIGKILLcs6dtjd}tjfdd}|j| |ddS)Nzimport time; time.sleep(rcst|dSr#)rr%)r&signumrr kill_process! sz?PidTests.test_waitstatus_to_exitcode_kill..kill_process)rr)rZ LONG_TIMEOUTr+rr)r(rrrrr test_waitstatus_to_exitcode_kill 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?rprrr r > r z*SpawnTests.create_args..cSs"i|]\}}t|t|qSrr?)rkvrrr ? sz*SpawnTests.create_args..)rrrHrwrIrbrrr~r&r/Zuuid4rjrrrarrh)r(rrrrr rrrr create_args( s(    ( zSpawnTests.create_argsspawnlcCs4|}tjtj|dg|R}|||jdSr`)rrrP_WAITr0rr(rrrrr test_spawnlD szSpawnTests.test_spawnlspawnlecCs>|jdd}tjtj|dg||jR}|||jdSNT)rr)rrrrr~r0rrrrr test_spawnleJ s  zSpawnTests.test_spawnlespawnlpcCs4|}tjtj|dg|R}|||jdSr`)rrrrr0rrrrr test_spawnlpP szSpawnTests.test_spawnlpspawnlpecCs>|jdd}tjtj|dg||jR}|||jdSr)rrrrr~r0rrrrr test_spawnlpeV s  zSpawnTests.test_spawnlpercCsT|}ttj|d|}|||jttjt|d|}|||jdSr`)rrrrr0rrrrrr test_spawnv\ s zSpawnTests.test_spawnvspawnvecCs6|jdd}ttj|d||j}|||jdSrrrrrr~r0rrrrr test_spawnvef s zSpawnTests.test_spawnvespawnvpcCs.|}ttj|d|}|||jdSr`)rrrrr0rrrrr test_spawnvpl szSpawnTests.test_spawnvpspawnvpecCs6|jdd}ttj|d||j}|||jdSr)rrrrr~r0rrrrr test_spawnvper s zSpawnTests.test_spawnvpecCs0|}ttj|d|}tj||jddS)Nrr)rrrrrZ wait_processr)r(rr&rrr test_nowaitx szSpawnTests.test_nowaitcCs8|jddd}ttj|d||j}|||jdS)NTrrrrrrr test_spawnve_bytes~ szSpawnTests.test_spawnve_bytescCs>|}|ttjtj|d|ttjtj|dddSNrrH)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|ddgdSNrrrrH)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 r' 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)recvrrrrurrr handle_read s z&SendfileTestServer.Handler.handle_readcCs d|jS)Nr )r3rrJrrr get_data sz#SendfileTestServer.Handler.get_datacCs|d|_dSr)rNrrJrrr handle_close sz'SendfileTestServer.Handler.handle_closecCsdSr#rrJrrr handle_error 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#)rrJrrr r! szSendfileTestServer.runningcCs.|jr Jt|_tj||jdSr#)rrEvent_SendfileTestServer__flagrstartr'rJrrr r % s   zSendfileTestServer.startcCs|js Jd|_|dSr)rrr3rJrrr stop+ s zSendfileTestServer.stopcCs&t|jddstdq|dS)NrFMbP?)rrr@r$r rJrrr r'0 s zSendfileTestServer.waitcCsLd|_|j|jr@tjr@|jtjddd|jqt dS)NTr rU)timeoutro) rr rrZ socket_mapracquireZloopreleaseZ close_allrJrrr r8 s    zSendfileTestServer.runcCs|\}}|||_dSr#)acceptrr)r(raddrrrr handle_acceptA s z SendfileTestServer.handle_acceptcCs |dSr#)rNrJrrr handle_connectE sz!SendfileTestServer.handle_connectcCsdSr`rrJrrr writableI szSendfileTestServer.writablecCsdSr#rrJrrr rL szSendfileTestServer.handle_errorN)rCrDrErrrrpropertyrr r r'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_setuprjr!rHDATArArrr rC\ s zTestSendfile.setUpClasscCstj|jttjdSr#)rZthreading_cleanuprjrIrHrArrr rVa s zTestSendfile.tearDownClasscCs~ttjdf|_|jt|_|j|jj|jj f|j d|j d|j |_ ttjd|_|j |_ dS)NrrUrrv)rrZHOSTserverr rclientconnectrr settimeoutrrlsocknorrrHrrJrrr rKf s     zTestSendfile.setUpcCs0|j|j|jjr&|jd|_dSr#)rrNrrrr rJrrr rr 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_wrappery 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-rr"rrlrOr0rshutdownr SHUT_RDWRrNrr'rr)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-rr"rrlrOrr#rr$rNrr'rrr0)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-rrrrrlr7r8EINVALr0rr#rr$rNrr'rr)r(r&r(rrxrrr test_offset_overflow s     z!TestSendfile.test_offset_overflowcCsT|t$}t|j|jddWdn1s40Y||jjtj dS)Nrr) r\r7rrrrlr0rr8r+r(rrrr test_invalid_offset s 2z TestSendfile.test_invalid_offsetc Cs<tj|j|jddd|jr8tj|j|jdddddddS)Nrr)rrr&ror)rrr&roheaderstrailersr)rrrrlSUPPORT_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) Nrsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyrrsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyr/i)rrrrrlZassertLessEqualr-minr"r0rrNrr'rrhash)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) Nrsabcdefrvrrs123456s789r0sabcde123456789)rrHrwrIr!rrrrrlrrNrr'rrr0)r(rZ file_datarSrxrrr test_trailers s      zTestSendfile.test_trailerscCsld|jj_|t2}tj|j|jddddgddWdn1sL0Y| |j j t j dS)NFrxrr3 rrrr\r7rrrrlr0rr8r+r-rrr test_headers_overflow_32bits s    $z)TestSendfile.test_headers_overflow_32bitscCsld|jj_|t2}tj|j|jddddgddWdn1sL0Y| |j j t j dS)NFrr9r:rr7r;r-rrr test_trailers_overflow_32bits s    $z*TestSendfile.test_trailers_overflow_32bits SF_NODISKIOztest needs os.SF_NODISKIOc Cs\ztj|j|jddtjdWn8tyV}z |jtjtjfvrBWYd}~n d}~00dS)Nrr)r) rrrrlr>r7r8r!r )r(rrrr test_flags s zTestSendfile.test_flagsN)rCrDrErrarrHr1rrZrequires_headers_trailersmaxsizeZ requires_32brWrCrVrKrr"r)r*r,r.r2r6r8r<r=rrr?rrrr rP sN            rc CsttdsdSzttjddV}zt|ddWn.tydYWdWttjdS0Wdn1sz0YWttjnttj0dS)NsetxattrFrr user.testr T) rrrrrHrArlr7rI)r rrr supports_extended_attributes s   &rCz(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 rBrdsbyez user.test2sfoosaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacss|]}d|VqdS)z user.test{}Nrz)rrrrr r|` r z;ExtendedAttributeTests._check_xattrs_str..rr9)rrHrwrIr!r\r7r0rr8ENODATAr%rrr r XATTR_REPLACE XATTR_CREATEEEXISTrrAr) r(rrgetxattrrA removexattr listxattrrrrZ init_xattrZxattrmanythingrrr _check_xattrs_str5 sL 4   < <  6 z(ExtendedAttributeTests._check_xattrs_strcOsN|jtg|Ri|ttj|jtjg|Ri|ttjdSr#)rPr&rrIrHrr r rrr _check_xattrse s z$ExtendedAttributeTests._check_xattrscCs|tjtjtjtjdSr#rQrrKrArLrMrJrrr test_simplel sz"ExtendedAttributeTests.test_simplecCs |jtjtjtjtjdddS)NFrRrRrJrrr test_lpathp sz!ExtendedAttributeTests.test_lpathcCs4dd}dd}dd}dd}|||||dS) NcWsDt|d&}tj|g|RWdS1s60YdSr )rrrKrlr1rr rrr rKu s z1ExtendedAttributeTests.test_fds..getxattrcWsFt|dd&}tj|g|RWdn1s80YdSNr9r)rrrArlrUrrr rAx sz1ExtendedAttributeTests.test_fds..setxattrcWsFt|dd&}tj|g|RWdn1s80YdSrV)rrrLrlrUrrr rL{ sz4ExtendedAttributeTests.test_fds..removexattrcWsDt|d&}tj|g|RWdS1s60YdSr )rrrMrlrUrrr rM~ s z2ExtendedAttributeTests.test_fds..listxattr)rQ)r(rKrArLrMrrr test_fdst s zExtendedAttributeTests.test_fdsN)rCrDrErPrQrSrTrWrrrr rE/ s 0rEget_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) rrXr7rarr8r+ENOTTYrZZassertGreaterEqualcolumnslines)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 failedrUrrrZN)r check_outputDEVNULLrr6CalledProcessErrorrrZrrrXra __stdin__rlr7rr8r+r[r0)r(rtr<rrrrr test_stty_match s"   zTermsizeTests.test_stty_matchN)rCrDrEr^rcrrrr rY srY memfd_createzrequires os.memfd_createrrc@seZdZddZdS)MemfdCreateTestscCstdtj}||d|tj||t|t|ddd*}| d| | dWdn1sv0Ytd}|tj||t|dS)NZHirr9F)closefds memfd_creater) rrdZ MFD_CLOEXECrrwrNr\rrrr0tell)r(rqrSfd2rrr test_memfd_create s  . z"MemfdCreateTests.test_memfd_createN)rCrDrErirrrr re srec@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 srl) r&bytes_filenamesunicode_filenamesrrrHrZTESTFN_UNDECODABLErr r|r}r)r(rlZdecodedencodedrrr 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?rlchownrchflagslchflagschrootrrMrFsuserlchmodrFz should bezNo exception thrown by {}),rrr5rr9rrr rrIrarr=rmrdrrnrrrr?rprrqrrrsrrMrKrArLrtrFrr&r@ZassertWarnsRegexDeprecationWarningr7rrUnicodeDecodeErrorrr{)r(ZfuncsrfuncZ func_argsrrrrr test_oserror_filename sz                             4(z"OSErrorTests.test_oserror_filenameN)rCrDrErKrxrrrr rj srjc@seZdZddZdS) CPUCountTestscCs8t}|dur*||t||dn |ddS)Nrz&Could not determine the number of CPUs)r cpu_countr%r assertGreaterrZ)r(Zcpusrrr test_cpu_count$s  zCPUCountTests.test_cpu_countN)rCrDrEr|rrrr ry#sryc@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_inheritable.s  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_cloexec6s z/FDInheritanceTests.test_get_inheritable_cloexeccCsftttj}|tj||t|tjtj @tj t |d|t|tjtj @ddS)NTr) rrrrrwrNr0rrrrrrrr test_set_inheritable_cloexecCs 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_pathNs  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_badfZs ( * *z0FDInheritanceTests.test_get_set_inheritable_badfcCs2tttj}|tj||t|ddSr)rrrrrwrNr0rrrrr riszFDInheritanceTests.test_openrzneed os.pipe()cCsPt\}}|tj||tj||t|d|t|ddSr)rrrwrNr0r)r(ZrfdZwfdrrr test_pipens  zFDInheritanceTests.test_pipecCsJtttj}|tj|t|}|tj||t|ddSr) rrrrrwrNrYr0rr(fd1rhrrr test_dupvs  zFDInheritanceTests.test_dupcCs(td}|tj|||ddSNrUr)rrYrwrNr{rrrr test_dup_standard_stream~s 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(rqrhZfd3rrr rszFDInheritanceTests.test_dup2openptyzneed os.openpty()cCsPt\}}|tj||tj||t|d|t|ddSr)rrrwrNr0r)r(Z master_fdZslave_fdrrr test_openptys  zFDInheritanceTests.test_openpty)rCrDrErrrrrrrrrrrrrrrrarrrrrrrr r}-s&      r}c @sHeZdZddddejfdfddddd eed dfgZd d Zd dZdS)PathTConverterTests)rTrN)r9FrNrPFN)rqFrN)rrFrNrrrNc 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_allszExportsTests.test_os_allN)rCrDrErrrrr rsrc@s$eZdZddZddZddZdS) TestDirEntrycCs0tjtj|_|tj|jt|jdSr#)rr1realpathrrHrwrr4rJrrr rKszTestDirEntry.setUpcCs|ttjdSr#)r\rcrDirEntryrJrrr test_uninstantiablesz TestDirEntry.test_uninstantiablecCsjttj|jdd}ddt|jD}||tj||j dddl }| t |j ||dS)Nr`pythoncSsg|]}|qSrrrentryrrr r r z0TestDirEntry.test_unpickable..r)r!rr1r3scandirrr%rr0rrr\rcr)r(rrrrrr test_unpickables zTestDirEntry.test_unpickableN)rCrDrErKrrrrrr rsrc@s eZdZejZddZd TestScandircCs>tjtj|_t|j|_|tj|jt |jdSr#) rr1rrrHr  bytes_pathrwrr4rJrrr rKszTestScandir.setUpr`cCs2t|tr|jn|j}tj||}t|d|S)Nr)rr@rr1rr3r!)r(rr1rrrr r!s zTestScandir.create_filecCs2tddt|jD}|t|||S)Ncss|]}|j|fVqdSr#rrrrr r| sz*TestScandir.get_entries..)rbrrr1r0rAkeys)r(namesentriesrrr get_entriess  zTestScandir.get_entriescCsZ|rJt|D]:}|dsq |dvr&q |t||t|||||fq n |||dS)NZst_)st_devst_inost_nlink)rrHr0r)r(Zstat1Zstat2Z skip_fieldsrrrr assert_stat_equal%s   zTestScandir.assert_stat_equalcCs(t|j}|tt||dSr#)rrr1r\rcrorN)r( scandir_iterrrr r2s zTestScandir.test_uninstantiablecCs<|d}t|j}ddl}|t|j|||dS)Nr`r) r!rrr1rr\rcrrN)r(rrrrrr r7s   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)NFrRr,)r%rrr0rr1r3inoderris_dirS_ISDIRris_fileS_ISREG is_symlinkr\r)r(rrrrrZ entry_statZ entry_lstatrrr check_entry>s>           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) Nrrr`z link_file.txtr symlink_dirT)rsymlink_file.txt)rrF)rrrrr1r3r4r!rrrZrrr=rr) r(rrr;rrrrrrrr test_attributesZsB   $   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$r5r1rbrr0rArr)r(rZold_dirrrrr test_current_directorys  z"TestScandir.test_current_directorycCs|}|t|ddS)Nz)rr0r}r(rrrr test_reprszTestScandir.test_reprcCs*|}|t|tj|jddS)Nr`)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,FrRr)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,FrRr)rrrIr1r\rrrOrrr\r6rrr{rrrr 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 linkr`z symlink.txtrFrR)rrrZr!rrr1r3rrIr{rr\rrrOrr\r6r)r(rrrrrr test_broken_symlinks"   zTestScandir.test_broken_symlinkc Csp|dt|j}tt|}|t|d||d}||jd||jttj |jddSNr`rUrsfile.txt) r!rr r1rrr0r-rr3)r( path_bytesrrrrr rVs  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 assertWarnsrurrr0r-rr3rror@)r(rBrrrrrr test_bytes_likes   ,zTestScandir.test_bytes_likez.fd support for listdir required for this test.c Cst|tjtj|ddg}trJtdtj |jd| dt |jtj }zt|}t |}Wdn1s0Ydd|D}|t||||t||D]}||j|j|t||j|||jdktjtjvrtj|j|d}|||tj|j|dd}||jdd|qWt|n t|0dS) Nr`rcSsg|] }|jqSrrrrrr r r z'TestScandir.test_fd..rSF)rr7rR)rrrrUr!rrrr1r3rrrrr0rArrrrrrVrN)r(Zexpected_namesrqrtrrrrrrr test_fds.   & zTestScandir.test_fdcCs|ttjddS)NrH)r\r6rrrJrrr test_empty_path%szTestScandir.test_empty_pathcCsN|dt|j}t|}|t|d|t|}|t|d|dS)Nr`rUr)r!rrr1rr0r-)r(rrZentries2rrr test_consume_iterator_twice(s   z'TestScandir.test_consume_iterator_twicecCs$digfD]}|ttj|q dS)NgX9v?)r\rcrr)r(objrrr test_bad_path_type3szTestScandir.test_bad_path_typecCsf|d|dt|j}t||||~Wdn1sX0YdSNr` file2.txt)r!rrr1rrrNcheck_no_resource_warningr(rrrr test_close7s    zTestScandir.test_closecCsv|d|dt|j}t|Wdn1s>0Y|~Wdn1sh0YdSr)r!rrr1rrrrrrr test_context_managerBs   & z TestScandir.test_context_managercCsT|d|dt|j }t||Wdn1sF0YdSr)r!rrr1rrrNrrrr test_context_manager_closeJs   z&TestScandir.test_context_manager_closec Cs|d|d|tLt|j }t|ddWdn1sR0YWdn1sp0Y|~Wdn1s0YdS)Nr`rrUr)r!r\ZeroDivisionErrorrrr1rrrrrrr test_context_manager_exceptionQs   D z*TestScandir.test_context_manager_exceptioncCs|d|dt|j}t||t~tWdn1sR0Yt|j}t || ~Wdn1s0YdSr) r!rrr1rrrResourceWarningr gc_collectrrrrrr test_resource_warning[s    &  z!TestScandir.test_resource_warningN)r`)r`)&rCrDrErrrKr!rrrrrrrrrrrrrrrrVrrrrrrUrrrrrrrrrrrrr rs@  )      rc@s^eZdZeejZddZddZddZddZ d d Z d d Z d dZ ddZ ddZdS) TestPEP519cCs dD]}||||qdS)N)rdsgoodbyessome/path/and/filer0r)r(brrr test_return_bytespszTestPEP519.test_return_bytescCs dD]}||||qdS)N)ZhelloZgoodbyezsome/path/and/filer)r(rrrrr test_return_stringtszTestPEP519.test_return_stringcCsLdD]B}t|}|||||dt||dt|qdS)N)path/like/objectpath/like/objectrr)rr0rrr rA)r(rZpathlikerrr test_fsencode_fsdecodexs z!TestPEP519.test_fsencode_fsdecodecCsB|d|td|tttj|ttdtjdS)Nz #feelthegilr)r0rrrO issubclassrPathLikerrJrrr rTszTestPEP519.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..ANrkrrrr 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_rrrrrrTrrrrrrrrr rjs  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 rsr_fspathc@seZdZdZeejZdS)TestPEP519PurePythonz>Explicitly test the pure Python implementation of os.fspath().N)rCrDrErr_rrrrrrr rsr__main__)r)N)rrr contextlibrGr8rsrHrrr0rrr r+rrrraZ sysconfigr.rr@rrr/rtestrZ test.supportrrrr ImportErrorrr}pwdgetpwallrQrZ _testcapir r r@Ztest.support.script_helperrrrrXrrrversionrHrgetgidrrr!ZTestCaser"rFrrr`ZBasicTestMappingProtocolrarrr rr%r'r@rYrcrgrtZget_config_varZOS_URANDOM_DONT_USE_FDrrcontextmanagerrrrrrrrrr;rGrWrXrzrrrrrrr:rrrrrrrCZrequires_linux_versionrErYrerjryr}rrrrrrrrrCmainrrrr s^              Aae_ 'EG  ^;) -   M h#d%CGs/<0!1H4VO Q0 ] yB \: