a ze@sHddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZddlZddlZz ddlZWneydZYn0ddl m!Z!ddl"m#Z#m$Z$e#dZ%e#dZ&e#dZ'ej()dZ*ej()d Z+ej(dd d kZ,zddl-Z-ddl.Z.d Z/Wneyzd Z/Yn0z ddl0Z0WneydZ0Yn0ddZ1ddZ2dAddZ3ddZ4dBddZ5ddZ6ddZ7e7Z8ddZ9GdddZ:Gd d!d!e:ej;ZGd&d'd'e:ej;Z?Gd(d)d)e:ej;Z@Gd*d+d+e:ej;ZAGd,d-d-eAZBGd.d/d/e:ej;ZCGd0d1d1ej;ZDGd2d3d3ej;ZEGd4d5d5eFZGeHe8 d6Gd7d8d8eGej;ZIeHe* d9Gd:d;d;eGej;ZJGdd?d?ej;ZLeMd@krDeNdS)CN) make_archiveregister_archive_formatunregister_archive_formatget_archive_formatsErrorunpack_archiveregister_unpack_format RegistryErrorunregister_unpack_formatget_unpack_formats SameFileError_GiveupOnFastCopy)support)TESTFNFakePath2Z_SRCZ_DSTdarwinZsunosZaixTFcOstttddddS)NZEXDEVzInvalid cross-device link)OSErrorgetattrerrnoargskwargsrD/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_shutil.py _fake_rename5srcstfdd}|S)Ncs0z"tj}tt_|i|W|t_S|t_0dSN)osrenamer)rrZbuiltin_renamefuncrrwrap:szmock_rename..wrap) functoolswraps)r"r#rr!r mock_rename9sr&cCsVt|trtjj|}t||r"dnd}||Wdn1sH0YdS)Nwbw) isinstancetuplerpathjoinopenwrite)r+Zcontentbinaryfprrr write_fileDs  r1cCsrdd}t|d}dddt|D}t|d*}|||D]}||q@Wdn1sd0YdS)Ncss&||kr|V||8}q|r"|VdSrr)totalsteprrrchunksRs  zwrite_test_file..chunksi cSsg|]}ttjqSr)randomchoicestring ascii_lettersencode).0irrr [sz#write_test_file..r')minr,ranger-r.)r+sizer4bufsizechunkfZcsizerrrwrite_test_filePs   *rDcCsTt|trtjj|}t||r"dnd}|WdS1sF0YdS)Nrbr)r)r*rr+r,r-read)r+r/r0rrr read_filebs  rHcCs|g}tt|D]d}tj||}tj|rltj|sl||dt|D]}||d|qRq||q|S)N/) sortedrlistdirr+r,isdirislinkappendrlistdir)r+resnamepnrrrrOns  rOc CsttdsdSd}d}ztjdtdd }|j}|dWdn1sT0Yt|d }tjdtdd}|j}|}|}zt ||ddWnTt yYWdWdW|durt ||durt |dS0WdWdW|dur0t ||durDt |d SWdn1s^0YWdn1s~0YW|durt ||durt |n*|durt ||durt |0dS) NsendfileFr'dirdeletes 0123456789rErT) hasattrrtempfileNamedTemporaryFilegetcwdrQr.r-filenorTrrunlink)srcnamedstnamerCsrcdstinfdoutfdrrrsupports_file2file_sendfilezsH (      F      recCsJtrBtjdkrBtdtj}|ddd}t|ddkSdSdS) Niz/usr/bin/dump -o %s i T)AIXsysmaxsize subprocess getoutput executablesplitint)ZhdrsZmaxdatarrr _maxdataOKs rrc@seZdZdddZdS)BaseTestNcCs$tj|td}|tj||S)N)prefixrV)rZmkdtemprr\ addCleanuprrmtree)selfrtdrrrruszBaseTest.mkdtemp)N)__name__ __module__ __qualname__rurrrrrssrsc@seZdZddZejddZejddZe e ddd Z e e dd d Z d d Z eejdddkdeeedoedkdddZddZddZddZddZejdd Ze e dd!d"ZdS)# TestRmTreecCsX|}tj|d}t|ttj|ddt|}||tt |dS)NZkillmeZsomefilefoo) rurr+r,mkdirr1fsencodeassertIsInstancebytesshutilrw)rxtmpZvictimrrrtest_rmtree_works_on_bytess   z%TestRmTree.test_rmtree_works_on_bytescs|}tj|d}t|tj|d}t|||ttj || tj || tj |gfdd}tj ||d| td|ddtjj| dd||dddtdS) NrVlinkcs|dSrrNrerrorsrronerrorsz8TestRmTree.test_rmtree_fails_on_symlink..onerrorrrhrrX)rurr+r,rsymlink assertRaisesrrrw assertTrueexistslexists assertEquallenassertIsrMrrxrZdir_rrrrrtest_rmtree_fails_on_symlinks   z'TestRmTree.test_rmtree_fails_on_symlinkc Cs|}tj|d}tj|d}tj|d}|||fD]}t|q.onerrorrrhrrX)rurr+r,r_winapiCreateJunctionrvrr^rrrrwrrrrrrrMrrrrrtest_rmtree_fails_on_junctionss    z)TestRmTree.test_rmtree_fails_on_junctionsc Cs|}tj|d}tj|d}tj|d}|||fD]}t|q.onerrorrrXrrh)rZmktemprurFileNotFoundErrorrrwr1rr+r,NotADirectoryErrorassertIn exceptionfilenamerrrrrscandirrrmdir)rxrtmpdircmZ possible_argsrrrrtest_rmtree_errorss2 ( zTestRmTree.test_rmtree_errorsNcygwinz2This test can't be run on Cygwin (issue #1071513).geteuidrz9This test can't be run reliably as root (issue #1076467).cCs d|_tt|tjttjtd|_ tjtd|_ t |j t|j t tj}t |j j}t |j j}t jt jB}t|j |t|j |tt||tjt||tj|j ||tj|j |tjt|jd||jdddS)Nrabrrz1Expected call to onerror function did not happen.) errorStaterrrrvrrwr+r,child_file_pathchild_dir_pathrcreate_empty_filestatst_modeS_IREADS_IEXECchmodcheck_args_to_onerrorr)rxZ old_dir_modeZold_child_file_modeZold_child_dir_modeZnew_moderrr test_on_error4s*       zTestRmTree.test_on_errorcCs|jdkr|tjur$|||jn:|tjur>|||jn ||tj| |t |jg| t |dt |jd7_n4||tj||t | t |dt d|_dS)NrXrrhr)rrr^rrrrrrKrrr issubclassr)rxr"argexcrrrrSs    z TestRmTree.check_args_to_onerrorcsRzDtjfdd}|t_ttttdfdttWt_nt_0dS)Ncs|tkrtn|SdSr)rr)fnrrZ orig_lstatrrraiserqszFTestRmTree.test_rmtree_does_not_choke_on_failing_lstat..raiserr~)rlstatrrr1rrw)rxrrrr+test_rmtree_does_not_choke_on_failing_lstatns   z6TestRmTree.test_rmtree_does_not_choke_on_failing_lstatcstjtjtjtjhtjko0tjtjvo0tjtjv}|r| t j | t j j |}tj|d}t|zBt j}Gdddtfdd}|t _|t j |W|t _q|t _0n|t j |t j j dS)Nrc@s eZdZdS)zHTestRmTree.test_rmtree_uses_safe_fd_version_if_available..CalledN)rzr{r|rrrrCalledr5rcsdSrrrrrr_raiserszITestRmTree.test_rmtree_uses_safe_fd_version_if_available.._raiser)rr-rr^rsupports_dir_fdrK supports_fdsupports_follow_symlinksrr_use_fd_functionsrwavoids_symlink_attacksrur+r,r_rmtree_safe_fd Exceptionrr)rxrtmp_dirryZ real_rmtreerrrr-test_rmtree_uses_safe_fd_version_if_available~s,      z8TestRmTree.test_rmtree_uses_safe_fd_version_if_availablecCs<tj|d\}}t||ttj|t |dSNr) rZmkstemprurcloserrrrwremove)rxhandler+rrrtest_rmtree_dont_delete_files z'TestRmTree.test_rmtree_dont_delete_filec Csttzbtjtd}tjtd}t|t|||ttj |tj |ddWtj tddntj tdd0dS)NcheeseshopTr) rrrr+r,rrrrrwrxrarbrrrtest_rmtree_on_symlinks   z!TestRmTree.test_rmtree_on_symlinkc Csttzztjtd}tjtd}t|ttj|ddt||| t t j |t j |ddWt j tddnt j tdd0dS)NrrZspamr'Tr) rrrr+r,r-rrrrrrrwrrrrtest_rmtree_on_junctions   z"TestRmTree.test_rmtree_on_junction)rzr{r|rrskip_unless_symlinkrrunittest skipUnlessrrrrskipIfrkplatformrYrrrrrrrrrrrrrr}s2       $  r}c@seZdZddZddZejddZddZd d Z d d Z e j d ddZddZe eeddejddZddZejddZejddZddZddZd S)! TestCopyTreec Cs|}tj|d}|tj||tjtj|t|dfdt tj|dt|ddfdt ||| tj tj|d| tj tj|d| tj tj|ddt|df}||dt|ddf}||ddS)N destinationtest.txt123test_dir456)rurr+r,rvrrwdirnamer1rcopytreerisfilerLrHrrxsrc_dirdst_diractualrrrtest_copytree_simples"   z!TestCopyTree.test_copytree_simplec CsZ|}|}|tj||tj|t|dfdttj|dttj|dt|ddfdt|ddfdtj ||dd| tj tj|d| tj tj|d| tj tj|ddt |df}||dt |ddf}||d|t tj ||d dWdn1sL0YdS) Nznonexisting.txtrZ existing_dirz existing.txtzwill be replacedzhas been replacedT) dirs_exist_okF)rurvrrwr1rrr+r,rrrrLrHrrFileExistsErrorrrrrtest_copytree_dirs_exist_oks*    z(TestCopyTree.test_copytree_dirs_exist_okc Cs|}tj|d}tj|d}tj|d}t|t|t|dfdtj|d}tj|d}ttj|d|ttdrt|t j t j Bttd rtt d rt |t j t|}tj||d d |tjtj|ddttj|dd}tjd kr8|dr8|dd}||tj|dt|} ttdrt|| j|jttd r|| j|jdS)Nrarbsubzfile.txtr~rzsub/linklchmodlchflags UF_NODUMPTsymlinksntz\\?\)rurr+r,rr1rrYrrS_IRWXUS_IRWXOrrrrrrrMreadlinkrQ startswithrrst_flags) rxrrrZsub_dirsrc_linkdst_linksrc_statrdst_statrrrtest_copytree_symlinkss8        z#TestCopyTree.test_copytree_symlinksc Cs^tjj}tjj}|}z ||d}t|dfdt|dfdt||dt|ddfdt||dt|ddfdt||ddt||dd t|dddfdt|dd d fdzftd d}tj |||d | |||d| |||d| |||dWt |n t |0zjtd d }tj |||d | |||d| |||dd | |||ddWt |n t |0zTdd}tj |||d | |||dd d | |||ddWt |n t |0Wt |t tj |nt |t tj |0dS)Nrrrztest.tmprrZ test_dir2subdirZsubdir2ztest.pyz*.tmpignorezsubdir*cSsfg}|D]X}tj||}tj|rB|ddkrB||qtj|ddvr||q|S)Nrgr z.py)rr+r,rLrprNsplitext)ranamesrPrQr+rrr_filter0s   z8TestCopyTree.test_copytree_with_exclude.._filter)rr+r,rrur1rrignore_patternsrrrrwr)rxr,rrrpatternsrrrrtest_copytree_with_excludesR     z'TestCopyTree.test_copytree_with_excludecsVtjj}tjj}}||d}t||t||dttj|ddt|dddfdgfdd}|d}tj|||d  |||ddd|d}tjt |||d  |||ddd|d}t t |d }|tjtj|||d  |||dddtd dS) Nsourcerr rrcsT||t|tt|tt||D]}|tq>gSr)rNrstrlistrrset)rarrQZ invokationsrxrr_ignoreWs   z?TestCopyTree.test_copytree_arg_types_of_ignore.._ignorerr r )rr+r,rrurr1rrrpathlibPathrrrDirEntryrr)rxr,rrrrrZ src_dir_entryrrr!test_copytree_arg_types_of_ignoreIs8  z.TestCopyTree.test_copytree_arg_types_of_ignorec Csx|}tj|d}t|tj|d}|tj|t|dt |dfdttj|ddt |dfdttj|ddt j|d }|t j|t|dt ||| t|jt|j| ttj|djttj|dj| ttj|djttj|djtj|tj|d }| t|jt|jdS) Nrrizpermissive.txtrzrestrictive.txtrirrh)rurr+r,rrvrrwrr1rZrrrrrrp)rxrrrZrestrictive_subdirZrestrictive_subdir_dstrrr!test_copytree_retains_permissionsss6      z.TestCopyTree.test_copytree_retains_permissionszos.chmodcCs|}tj|d}|tj||tjtj|td|_ | tj t ||Wdn1sv0YdS)Nrzka-boom) rurr+r,rvrrwrPermissionError side_effectrrr)rxZ mock_patchrrrrrtest_copytree_winerrors z#TestCopyTree.test_copytree_winerrorcsfdd}gtjdttjdd}|Wdn1s`0Ytj |d t ddS)NcsRd|t|t|tjd|tjddSNr~)rNrrrrr+r,)rrrbflagrxrarr custom_cpfuns    zETestCopyTree.test_copytree_custom_copy_function..custom_cpfunrr~r( copy_functionrh) rurZrr-rr+r,rrrrr)rxr'rCrr%r"test_copytree_custom_copy_functions&z/TestCopyTree.test_copytree_custom_copy_functionmkfiforequires os.mkfifo()c Cs2ttztjtd}t|tj|d}zt|Wn2tyt}z|d|WYd}~n d}~00zt tt Wn^tj y}zD|j d}| t|d|d\}}}| d||WYd}~nd}~00|dWtjtdd tjt dd ntjtdd tjt dd 0dS) Nr Zmypipeos.mkfifo(): %srrhz`%s` is a named pipez$shutil.Error should have been raisedTr)rrrr+r,r+r!skipTestrrTESTFN2rrrrfailrw)rxr pipeerrarbZ error_msgrrrtest_copytree_named_pipes*  $ & z%TestCopyTree.test_copytree_named_pipecs|}tj|d}t|dfdttj|dt|ddfdgfdd}tj|||d|t d dS) Nrrrrrcs||fdSrrrarbZcopiedrr_copysz6TestCopyTree.test_copytree_special_func.._copyr(rX) rurr+r,r1rrrrr)rxrrr6rr5rtest_copytree_special_funcs z'TestCopyTree.test_copytree_special_funccCs|}tj|d}tdtj|dttj|dt|ddfd|tt j ||tj|d}t j ||dd| dt |tj|d }t j ||dd | dt |dS) NrZ IDONTEXISTrrr destination2T)ignore_dangling_symlinksZ destination3r)rurr+r,rrr1rrrr assertNotInrKrrxrrrrrtest_copytree_dangling_symlinkssz,TestCopyTree.test_copytree_dangling_symlinksc Cs.|}tj|d}ttj|dttj|dddWdn1sZ0Ytjtj|dtj|dddtj||dd | tj tj|d| dt tj|dtj|d }tj||dd | tj tj|d| dt tj|ddS) NrZreal_dirrr(Z link_to_dirT)target_is_directoryFrr8)rurr+r,rr-rrrrrMrrKrr;rrrtest_copytree_symlink_dirs  z&TestCopyTree.test_copytree_symlink_dircCs\|}|d}|tj|dtj|d}t|dt||}| dgt |dS)NdestTr~) rurvrrwrr+r,r1rrrK)rxrrrarvrrrtest_copytree_return_values  z'TestCopyTree.test_copytree_return_valuecCs|}|jtj|ddtj|dd}tj|dd}t|tj|d}t|dt ||}| dgt |dS)NTrtZpgZ somevendorz1.0Zpol) rurvrrwrr+r,makedirsr1rrrK)rxbase_dirrrrar@rrrtest_copytree_subdirectorys   z'TestCopyTree.test_copytree_subdirectoryN)rzr{r|rrrrr rrr rmockpatchr#r*rrYrr3r7r<r>rArErrrrrs( A*      rc@seZdZejddZeee ddejddZ e ee ddejdd Z ejd d Z eee d oeed oeeddddZejddZejejeee doe dkdddZddZddZejddZeee dd d!d"Zejd#d$Zejd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zejd/d0Zeee d1d2d3d4Zejd5d6Z eee d7d8d9d:Z!d;d<Z"d=d>Z#e e$pe%pe&d?d@dAZ'dBdCZ(dDS)ETestCopycCs|}tj|d}tj|d}tj|d}tj|d}t|dt|dt||t||t|tjtj Bt|tj | t|j t|j t |||t|j t|j tjdkrt|tj t |||t|j t|j t|tj t |||t|j t|j t|tj t |||t|j t|j dS)Nr~barbazquuxr)rurr+r,r1rrrrS_IRWXGrassertNotEqualrrcopymoderrQrxrrarbrrrrrtest_copymode_follow_symlinkss0         z&TestCopy.test_copymode_follow_symlinksrzrequires os.lchmodcCsp|}tj|d}tj|d}tj|d}tj|d}t|dt|dt||t||t|tjtj Bt|tjt |tj tj Bt |tj t j ||dd|t|jt|j|t|jt|jt |tj t j ||dd|t|jt|jt |tj t j ||dd|t|jt|jdSNr~rIrJrKFfollow_symlinks)rurr+r,r1rrrrrLrrrrNrrrrMrOrrr test_copymode_symlink_to_symlink7s0     z)TestCopy.test_copymode_symlink_to_symlinkz requires os.lchmod to be missingcCs|}tj|d}tj|d}tj|d}tj|d}t|dt|dt||t||tj||dddSrQ)rurr+r,r1rrrNrOrrr*test_copymode_symlink_to_symlink_wo_lchmodUs    z3TestCopy.test_copymode_symlink_to_symlink_wo_lchmodc Cs|}tj|d}tj|d}tj|d}tj|d}t|dt|}t||j|jdft|d| t|jt|jt ||t ||t tdrt |tj t tdrt tdrt|tjt|}t tdr tj||d d | |jt|jtj||d d t|}tjtjvrpd D]"} |t|| t|| d qLt tdr||j|jt tdrt |dr||j|jtj||d d |tt|jt|jdkdS)Nr~rIrJquxgE@rrrTrRFst_atimest_mtimerhrg?)rurr+r,r1rutimerXrYrMrrYrrrrrrcopystatrrassertLessEqualrrrrabs) rxrrarbrrr  src_link_statZ dst_link_statattrrrrtest_copystat_symlinksesJ             zTestCopy.test_copystat_symlinkschflags EOPNOTSUPPENOTSUPz)requires os.chflags, EOPNOTSUPP & ENOTSUPcCs|}tj|d}tj|d}t|dt|ddd}tj}zVtjtjfD]}||t_t ||qT|tjtjt_| t t j ||W|t_n|t_0dS)Nrfile2xxxcstddfdd }|S)NTrRcs_dSr)r)r+flagsrSerrexrr_chflags_raiserszlTestCopy.test_copystat_handles_harmless_chflags_errors..make_chflags_raiser.._chflags_raiserr)rhrjrrgrmake_chflags_raiserszSTestCopy.test_copystat_handles_harmless_chflags_errors..make_chflags_raiser) rurr+r,r1rarrbrcrr[rr)rxrrrdrlZ old_chflagsrhrrr-test_copystat_handles_harmless_chflags_errorss   z6TestCopy.test_copystat_handles_harmless_chflags_errorscs |}tj|dtdtj|d}t|dt|tddtddt||t t t t ||t dt |dt |t|dt tjdfdd }z4tj|t_t||dt |Wt_nt_0d d fd d }z"tj |t_ t|Wt_ nt_ 0tj|dtj|d}tt||tddt|ddt|dtj|d}tj|d}t||t||t|t|||t |dd|t |dddS)Nr~rIuser.foo42zuser.bar43EPERMcs&|dkrn|||fi|dS)Nrnr)fnamer_valr) orig_setxattros_errorrr_raise_on_user_foosz3TestCopy.test_copyxattr.._raise_on_user_fooTrRcs |krttjd||dS)NzOperation not supportedrR)rrrc)rrrS)orig_listxattrrarr _raise_on_srcs z.TestCopy.test_copyxattr.._raise_on_srcZ the_originalZthe_original_rozuser.the_valuesfiddlyi$Zthe_copyZ the_copy_ro)rurr+r,r1r _copyxattrsetxattrrrJ listxattrgetxattrrrrrqrrr[)rxrrbrvrxZsrcroZdstror)rwrtrurartest_copyxattrsZ                  zTestCopy.test_copyxattrrrroot privileges requiredcCs|}tj|d}tj|d}t|dt||t|ddtj|ddddtj|d}tj|d }t|dt||tj||dd| tj |dddd| t tj |dtj||dd| t |dddS) Nr~rJz trusted.foororpFrRrIrV) rurr+r,r1rrzrryrr|rr)rxrrarrbrrrrtest_copyxattr_symlinkss     z TestCopy.test_copyxattr_symlinkscCsPd}|}t||fdtj||}|}|||tj||}||fS)Nrre)rur1rr+r,)rxmethodrrrrtmpdir2rdrrr _copy_files zTestCopy._copy_filecCsB|tj\}}|tj||t|j t|j dSr) rrcopyrrr+rrrr)rxrrdrrr test_copyszTestCopy.test_copycCs |}tj|d}tj|d}tj|d}t|dt||ttdrft|tj tj Bt j ||dd| tj||t|t|t|t j ||dd|tj||t|t|ttdr|t|jt|jdS)Nr~rIrJrTrRF)rurr+r,r1rrYrrrrrrrrMrrHrrrrr)rxrrarbrrrrtest_copy_symlinkss&      zTestCopy.test_copy_symlinksrZzrequires os.utimecCs|tj\}}|tj|t|}t|}||j |j dD] }| t ||t ||dqJt tdrt |dr|t |dt |ddS)NrWrhrar) rrcopy2rrr+rrrrr\rrY)rxrrdZ file1_statZ file2_statr_rrr test_copy21s     zTestCopy.test_copy2c Cs|}tj|d}tj|d}tj|d}t|dt||ttdrft|tj tj Bttdrttdrt |tj t|}t |}tj||dd|tj||t|t|t|tj||d d|tj||t|t|t |}tjtjvrVd D]"}|t||t||d q2ttdr||j|j||j|jttdrt|d r||j|jdS) Nr~rIrJrrrTrRFrWrhr)rurr+r,r1rrYrrrrrrrrrrrMrrHrrrrZrr\rrrMr) rxrrarbrr r^r r_rrrtest_copy2_symlinksBs<          zTestCopy.test_copy2_symlinkscCsr|}tj|d}tj|d}t|dt|ddt|||t |dt |dt |dS)Nr~rIrnro) rurr+r,r1rzrrrr|r)rxrrarbrrrtest_copy2_xattres    zTestCopy.test_copy2_xattrcCstjtjfD]v}|}|}tj|d}t|d|||}||tj|d||tj|d}||tj|dq dS)Nr~rI) rrrrurr+r,r1r)rxrrrrar@rrrtest_copy_return_valuers  zTestCopy.test_copy_return_valuecCs|tjdSr)_test_copy_dirrrrxrrr test_copy_dir~szTestCopy.test_copy_dircCs|tjdSr)rrrrrrrtest_copy2_dirszTestCopy.test_copy2_dircCsx|}tj|d}|}tj|d}t|dtjdkrFt}nt}| ||||| |||||||dSNr~does_not_exist/win32) rurr+r,r1rkrr!IsADirectoryErrorr)rxZ copy_funcrsrc_filerrbrhrrrrs  zTestCopy._test_copy_dircCs|}tj|d}tj|d}tj|d}tj|d}t|dt||tj||dd|tj || t |t |t||| tj |dS)Nrarbrrr~FrR) rurr+r,r1rrcopyfilerrMrrr)rxrrarbrrrrrtest_copyfile_symlinkss   zTestCopy.test_copyfile_symlinksrzrequires os.linkc Cstttjtd}tjtd}zt|d}|dWdn1sR0Yzt||Wn2ty}z| d|WYd}~n d}~00| t j t j ||t|d }||dWdn1s0Yt|Wt jtddnt jtdd0dS) Nrrr(cheddarz os.link(): %srFTr)rrrr+r,r-r.rr!r.rrr rrrGrrw)rxrarbrCr2rrr'test_dont_copy_file_onto_link_to_itselfs  ($ . z0TestCopy.test_dont_copy_file_onto_link_to_itselfc Cstttjtd}tjtd}zt|d}|dWdn1sR0Ytd||t j t j ||t|d }| | dWdn1s0Yt|Wt jtddnt jtdd0dS)Nrrr(rrFTr)rrrr+r,r-r.rrrr rrrGrrw)rxrarbrCrrr*test_dont_copy_file_onto_symlink_to_itselfs  (  . z3TestCopy.test_dont_copy_file_onto_symlink_to_itselfr+r,c CszttWn2ty@}z|d|WYd}~n d}~00z6|tjtjtt |tjtjt tWt tn t t0dS)Nr-) rr+rr!r.rrSpecialFileErrorrr/__file__r)rxr2rrrtest_copyfile_named_pipes$z!TestCopy.test_copyfile_named_pipecCsl|}|}tj|d}tj|d}t|dt||}|tj|| t |t |dS)NrIr~) rurr+r,r1rrrrrrH)rxrrdst_filerr@rrrtest_copyfile_return_values  z#TestCopy.test_copyfile_return_valuecCsX|}tj|d}t|d|ttj|||t tj||| t |ddSr$) rurr+r,r1rr rrrrrH)rxrrrrrtest_copyfile_same_files  z TestCopy.test_copyfile_same_filezMOn MACOS, Solaris and Windows the errors are not confusing (though different)cCsD|}tj|d}tj|d}t|d|ttj||dS)Nr~r) rurr+r,r1rrrr)rxrrrbrrrtest_copyfile_nonexistent_dirs  z&TestCopy.test_copyfile_nonexistent_dircCs|}tj|d}|}tj|d}t|dtjdkrFt}nt}| |t j ||| |t j ||| |t j ||dSr) rurr+r,r1rkrr!rrrr)rxrrrrbrhrrrtest_copyfile_copy_dirs  zTestCopy.test_copyfile_copy_dirN))rzr{r|rrrPrrrYrrTrrUr`rrmZskip_unless_xattrr}rrrrrrrrrrrrrrrrrrMACOSSOLARISrrrrrrrrHsh    (  ?    "         rHc@sveZdZeddZddZd7ddZee e dd d d Z ed d Z ee e ddddZee e ddddZddZeddZee edddZddZdd Zed!d"Zd#d$Zd%d&Zd'd(Zd)d*Zed+d,Zed-d.Zeee oJe! d/d0d1Z"ed2d3Z#d4d5Z$d6S)8 TestArchivesc Cs|d\}}|}t|tj|}tjtj|d}t |*tj |}t |d|d}Wdn1s|0Y| ||d| tj|| t|t|d$}||gdWdn1s0Yt |t |d|d}Wdn1s(0Y| ||d | tj|| t|t|d $}||gdWdn1s0YdS) Nrarchivegztar..tar.gzzr:gz)rz./subz./sub2z./file1z./file2z ./sub/file3tar.tarrF) _create_filesrurrr+rr,basenamer change_cwdabspathrrrrtarfileZ is_tarfiler-assertCountEqualgetnames) rxroot_dirrDrwork_dir rel_base_name base_nametarballZtfrrrtest_make_tarballs0    , " . zTestArchives.test_make_tarballcCsFt|(}|}|t|WdS1s80YdSr)rr-rsortr*)rxr+rrrrr_tarinfo9s zTestArchives._tarinfodistcCs|}tj||}tj|ddt|dfdt|dfdttj|dt|ddfdttj|d|rt|d fd||fS) NT)exist_okrrerdrZfile3Zsub2outer)rurr+r,rCr1r)rxrDrrrrrr?szTestArchives._create_filesrzNeed the tar command to runcCs |\}}tj|d}t|d||}|||d|tj|tj|d}ddd|g}t j ||t j d|tj||| || |t|d||}|||d|tj|t|d||d d }|||d|tj|dS) Nrrrz archive2.tarrz-cfcwdstdoutrT)dry_run) rrr+r,rurrrrrm check_callDEVNULLr)rxrrDrrZtarball2Ztar_cmdrrrtest_tarfile_vs_tarMs(   z TestArchives.test_tarfile_vs_tarc Cs|\}}|}t|tj|}tjtj|d}t |(tj |}t |d|}Wdn1sx0Y| ||d| tj|| t|t|$}||gdWdn1s0Yt |*tj |}t |d||}Wdn1s.0Y| ||d| tj|| t|t|$}||gdWdn1s0YdS)Nrzip.zip)dist/ dist/sub/ dist/sub2/ dist/file1 dist/file2dist/sub/file3r)rrrrrr)rrurrr+rr,rrrrrrrrzipfile is_zipfileZipFilernamelist) rxrrDrrrrrPzfrrrtest_make_zipfilens2     *  "  .  zTestArchives.test_make_zipfilerzNeed the zip command to runc Cs |\}}tj|d}t|d||}|||d|tj|tj|d}dddd|g}t j ||t j d|tj|t |}|}Wdn1s0Yt |}|} Wdn1s0Y|t|t| dS)Nrrrz archive2.zipz-qz-rr)rrr+r,rurrrrrmrrrrrrJ) rxrrDrrZarchive2zip_cmdrrZnames2rrrtest_zipfile_vs_zips   & &z TestArchives.test_zipfile_vs_zipunzipzNeed the unzip command to runc Cs|\}}tj|d}t|d||}|||d|tj|dd|g}t |zt j |t j dWn\t jy}zB|jjdd}d |vr|d d }||||WYd}~n d}~00Wdn1s0YdS) Nrrrrz-t)stderrreplacerzunrecognized option: tzunzip doesn't support -tz{} **Unzip Output** {})rrr+r,rurrrrrrrm check_outputSTDOUTCalledProcessErroroutputdecoder.r0format) rxrrDrrrrZdetailsmsgrrrtest_unzip_zipfiles    zTestArchives.test_unzip_zipfilecCs*|}tj|d}|tt|ddS)Nrre)rurr+r,r ValueErrorr)rxrrrrrtest_make_archiveszTestArchives.test_make_archivecCstr"tdd}tdd}nd}}|\}}tj| d}t |d||||d}| tj |t |d||}| tj |t |d||||d}| tj |t |d||ddd}| tj |dS) NrrootrrownergrouprZ kjhkjhkjgZoihohoh) UID_GID_SUPPORTgrpgetgrgidpwdgetpwuidrrr+r,rurrr)rxrrrrDrrPrrrtest_make_archive_owner_groups(    z*TestArchives.test_make_archive_owner_groupRequires grp and pwd supportc Cs|\}}tj|d}tdd}tdd}t |$t |d|d||d}Wdn1sn0Y| tj |t|}z6|D] }||jd||jdqW|n |0dS)Nrrrrr)rrr+r,rurrrrrrrrrrr-Z getmembersruidgidr) rxrrDrrr archive_namermemberrrrtest_tarfile_root_owners   $  z$TestArchives.test_tarfile_root_ownercCstt}dd}td|gdzFztdd|dWntyHYn0|t|Wtdn td0dS)Nc_s tdSr) RuntimeError)rkwrrr_breakssz3TestArchives.test_make_archive_cwd.._breaksrexxx file)r)rr\rrrurrr)rxZ current_dirrrrrtest_make_archive_cwds z"TestArchives.test_make_archive_cwdcCsZ|}t|4|tddd|tjdWdn1sL0YdS)Ntestrztest.tar rurrrrrrr+rrxrrrrtest_make_tarfile_in_curdir s z(TestArchives.test_make_tarfile_in_curdircCsZ|}t|4|tddd|tjdWdn1sL0YdS)Nrrztest.ziprrrrrtest_make_zipfile_in_curdirs z(TestArchives.test_make_zipfile_in_curdircCs|ttdd|ttdddd|ttdddddgtddddgd d d tD}|d|tdd d tD}|d|dS) NrerhcSstSrxrrrrr5z;TestArchives.test_register_archive_format..cSstSrrrrrrr r5)rhrX)rhrXrcSstSrrrrrrr#r5rcSsg|] \}}|qSrrr;rQparamsrrrr=$r5z=TestArchives.test_register_archive_format..cSsg|] \}}|qSrrrrrrr=(r5)r TypeErrorrrrrr:)rxformatsrrrtest_register_archive_formats z)TestArchives.test_register_archive_formatcCs.||dd||tj||tdS)NcSs|Srrr+rrrr.r5z3TestArchives.check_unpack_archive..)#check_unpack_archive_with_converterrrr)rxrrrrcheck_unpack_archive-sz!TestArchives.check_unpack_archivec Cs|\}}t|}|dtj|d}t||||}|}t||||| t|||} t|||| |d| t| || t j t|t |j tt|t dddS)Nrr)rre)rrOrrr+r,rurrrrr ReadErrorrr) rxr converterrrDexpectedrrrZtmpdir3rrrr2s  z0TestArchives.check_unpack_archive_with_convertercCs|ddS)Nrrrrrrtest_unpack_archive_tarGsz$TestArchives.test_unpack_archive_tarcCs|ddS)Nrrrrrrtest_unpack_archive_gztarJsz&TestArchives.test_unpack_archive_gztarcCs|ddS)Nbztarrrrrrtest_unpack_archive_bztarNsz&TestArchives.test_unpack_archive_bztarz(AIX MAXDATA must be 0x20000000 or largercCs|ddS)Nxztarrrrrrtest_unpack_archive_xztarRsz&TestArchives.test_unpack_archive_xztarcCs|ddS)Nrrrrrrtest_unpack_archive_zipWsz$TestArchives.test_unpack_archive_zipcst}fdd}tdddg|dgtddttd dg|tdtd dg|d dgd ftddgd fttd t|dS) Ncs(|d|d|ddS)Nrh stuff.booxx)r)r extract_dirextrarrr_boo_s  z/TestArchives.test_unpack_registry.._booZBooz.booz.b2)rrhrrZBoo2r) r rrrr r rr:r)rxrrrrrtest_unpack_registry[s   z!TestArchives.test_unpack_registryN)r)%rzr{r|rZ requires_zlibrrrrrrwhichrrrrrrrrrrrrrrr r Z requires_bz2r Z requires_lzmarrjrrrrrrrrrrsZ #    $            rc@sLeZdZeeeddddZeedeee dddd Z d S) TestMisc disk_usagez)disk_usage not available on this platformcCsttjt}dD]}|t||tq| |j d| |j d| |j d| |j |j | |j |j ttdS)N)r2usedfreer)rrrr+rrrrrqZ assertGreaterr2rassertGreaterEqualr)rxusager_rrrtest_disk_usagexszTestMisc.test_disk_usagerchownzrequires os.chowncs}tj|dtdttWdn1sH0YttjddWdn1s0YttjddWdn1s0Yt tdWdn1s0Yt tdWdn1s&0Yt }t }d fd d }t|||||t|||tj|d||tj|d||d t|||||||t|||||tj||d|||tj||d|||d z t |d }t|d }WntyHYn60t|||||t|||||||dS)Nrztesting chown functionznon-existing username)userznon-existing groupname)rspamgQ @cs:t}|dur ||j|dur6||jdSr)rrrst_uidst_gid)r+rrsrrxrr check_chowns  z(TestMisc.test_chown..check_chown)rr)NN)rurZrr1rrrr LookupErrorrrgetuidgetgidrrrrKeyError)rxrrrr%rrrr$r test_chownsR   ( , , * ,           zTestMisc.test_chownN) rzr{r|rrrYrrrrr*rrrrrvs  rc@seZdZddZddZddZddZd d Ze e e d oHe d kd ddZ ddZddZeejdkdddZddZddZddZddZd d!Zd"d#Zeejdkd$d%d&Zeejdkd$d'd(Zd)S)* TestWhichcCst|jdd|_tj|jddd|_t|jjtj | |jj tj |jj\|_|_|j|_tj|_d|_dS)NZTmp)rtz.ExerVrtsuffixz.EXE)rutemp_dirrZr[ temp_filerrrQrS_IXUSRrvrr+rprVfileenv_pathcurdirextrrrrsetUpszTestWhich.setUpcCs&tj|j|jd}|||jjdSNr)rrr1rVrr/rQrxr@rrr test_basicszTestWhich.test_basiccCs(tj|jj|jd}|||jjdSr6)rrr/rQr.rr7rrrtest_absolute_cmdszTestWhich.test_absolute_cmdcCstj|j\}}tj||j}tj|d,tj ||j d}| ||Wdn1s`0Ytj|jd(tj ||d}| |Wdn1s0YdSr6) rr+rprVr,r1rrrrr.r assertIsNone)rxrDtail_dirrelpathr@rrrtest_relative_cmds*zTestWhich.test_relative_cmdcCstj|j}tj|jdPtj|j|d}t j dkrT| |tj |j |jn ||Wdn1sr0YdS)Nrr)rr+rrVrrrrr1rkrrr,r3r:)rxrDr@rrrtest_cwds  zTestWhich.test_cwdrrznon-root user requiredcCsRt|jjtjt|jjtjr.|dt j |j |j tjd}| |dS)Nzcan't set the file read-only)r+mode)rrr/rQrraccessW_OKr.rrr1rVr:r7rrrtest_non_matching_modes  z TestWhich.test_non_matching_modecCsjtj|j\}}tj|d8tj|j|d}| |tj ||jWdn1s\0YdSr6) rr+rprVrrrrr1rr,)rxrDr;r@rrrtest_relative_pathszTestWhich.test_relative_pathcCstjd|jd}||dS)Nzfoo.exer)rrrVr:r7rrrtest_nonexistent_file szTestWhich.test_nonexistent_filerzpathext check is Windows-onlycCs<tj|jdd|jd}|||jjdd|jdS)Nr)rrr1rVrr/rQr4r7rrrtest_pathext_checkingszTestWhich.test_pathext_checkingcCsRt6}|j|d<t|j}|||jjWdn1sD0YdSNPATH) rEnvironmentVarGuardr2rrr1rr/rQrxenvr@rrrtest_environ_paths   zTestWhich.test_environ_pathc Cst}d|d<tjjd|jddttd|jRt|j&t |j }| |Wdn1sr0YWdn1s0YWdn1s0YWdn1s0YdS)NrrH os.confstrT return_valuecreatedefpath) rrIrrFrGrV swap_attrrrrrr1r:rJrrrtest_environ_path_emptys    z!TestWhich.test_environ_path_emptyc Cs:tj|jj}tjdkrBtj}t|t r4t |}tj ||}t }tj|d<tjjd|jddt td|jjt|j}||t |j(t|j}|||Wdn1s0YWdn1s0YWdn1s 0YWdn1s,0YdS)NrrHrMTrNrQ)rr+rr/rQrkrr3r)rrr,rrIpathseprrFrGrVrRrrr1r:rr)rxZ expected_cwdr3rKr@rrrtest_environ_path_cwd(s$         zTestWhich.test_environ_path_cwdc Cs8t}|ddtjjdtddLttd|j t |j }Wdn1s^0YWdn1s|0Y| ||jjtjjd|j ddJttddt |j }Wdn1s0YWdn1s0Y| ||jjWdn1s*0YdS)NrHrMT)r"rPrQrNr)rrIpoprrFrGrrRrrVrrr1rr/rQrJrrrtest_environ_path_missing>s    H  Hz#TestWhich.test_environ_path_missingc Cstj|j}tj|jd\t4}|j|d<tj |j dd}| |Wdn1s`0YWdn1s~0YdS)NrrHr) rr+rrVrrrIr2rrr1r:)rxrDrKr@rrrtest_empty_pathPs zTestWhich.test_empty_pathcCsNt2}|ddt|j}||Wdn1s@0YdSrG)rrIrVrrr1r:rJrrrtest_empty_path_no_PATHXs   z!TestWhich.test_empty_path_no_PATHztest specific to WindowscCsd}tj|jd|d}t|jtj||j tj |j}tj |d}t 6}||d<tj||jd}|||jWdn1s0YdS)N.xyzTmp2r,rPATHEXTr)rZr[r.rrrQrr0rvrr+rrrrIrrrrxr4Z temp_filexyzZprogramrKr@rrr test_pathext^s  zTestWhich.test_pathextcCsd}tj|jd|d}||jtj|j}tj |d}t <}|d|d<t j ||jd}|||jWdn1s0YdS)NrZr[r,r;r\r)rZr[r.rvrrr+rrQrrrIrrrr]rrrtest_pathext_with_empty_strps  z%TestWhich.test_pathext_with_empty_strN)rzr{r|r5r8r9r=r>rrrYrrrBrCrDrrkrrFrLrSrUrWrXrYr^r`rrrrr+s2       r+c@seZdZddZdS)TestWhichBytescCsXt|t|j|_t|j|_t|jj|j_t|j|_t|j |_ dSr) r+r5rrrVr1r/rQr3r4rrrrr5s  zTestWhichBytes.setUpN)rzr{r|r5rrrrrasrac@seZdZddZddZddZddZd d Zd d Zd dZ e ddZ e ddZ ddZ e ddZddZe ddZddZeejjdddZd d!Zd"d#Zd$d%Zd&d'Zeje d(d)Zeje d*d+Zeje d,d-Z eje d.d/Z!d0d1Z"d2d3Z#e d4d5Z$e d6d7Z%d8d9Z&ee'ed:ove(d;kove'ed<ove'e)d=ove'e)d>d?d@dAZ*dBS)CTestMovecCsvd}||_||_tj|j||_tj|j||_t|jd}| dWdn1sh0YdS)Nr~r'r ) rurrrr+r,rrr-r.)rxrrCrrrr5s  zTestMove.setUpcCst|d}|}Wdn1s(0Yt||t|d }|||Wdn1sn0Y|tj|dSNrE) r-rGrmoverrrr+r)rxrarbreal_dstrCcontentsrrr_check_move_files  &  .zTestMove._check_move_filecCsFtt|}t||||tt||tj|dSr) rJrrKrrdrrr+r)rxrarbrerfrrr_check_move_dirs zTestMove._check_move_dircCs||j|j|jdSr)rgrrrrrrtest_move_fileszTestMove.test_move_filecCs||j|j|jdSr)rgrrrrrrrtest_move_file_to_dirszTestMove.test_move_file_to_dircCs"t|j}|||j|jdSr)rrrrgrr)rxrarrr"test_move_file_to_dir_pathlike_srcs z+TestMove.test_move_file_to_dir_pathlike_srccCs"t|j}||j||jdSr)rrrrgrrrxrbrrr"test_move_file_to_dir_pathlike_dsts z+TestMove.test_move_file_to_dir_pathlike_dstcCs |dSr)rirrrrtest_move_file_other_fssz TestMove.test_move_file_other_fscCs |dSr)rjrrrrtest_move_file_to_dir_other_fssz'TestMove.test_move_file_to_dir_other_fsc Cs@tj|d}z||j||Wt|n t|0dSr)rZrrurhrrrwrxrrrr test_move_dirszTestMove.test_move_dircCs |dSr)rqrrrrtest_move_dir_other_fsszTestMove.test_move_dir_other_fsc Cs,||j|jtj|jtj|jdSr)rhrrrr+r,rrrrrtest_move_dir_to_dirs zTestMove.test_move_dir_to_dircCs |dSr)rsrrrrtest_move_dir_to_dir_other_fssz&TestMove.test_move_dir_to_dir_other_fsc Cs4||jtjj|jtj|jtj|jdSr)rhrrr+seprr,rrrrrtest_move_dir_sep_to_dirsz!TestMove.test_move_dir_sep_to_dirzrequires os.path.altsepc Cs4||jtjj|jtj|jtj|jdSr)rhrrr+altseprr,rrrrrtest_move_dir_altsep_to_dirsz$TestMove.test_move_dir_altsep_to_dircCsHt|jdWdn1s"0Y|tjtj|j|jdS)Nr')r-rrrrrdrrrrrr"test_existing_file_inside_dest_dirsz+TestMove.test_existing_file_inside_dest_dircCs*tj|jd}|tjtj|j|dSNrI)rr+r,rrrrrdrlrrrtest_dont_move_dir_in_itselfsz%TestMove.test_dont_move_dir_in_itselfc CsrttzVdD]B\}}tjt|}tjt|}|jt||d||fdqWt tn t t0dS)N))srcdirz srcdir/destz?_destinsrc() wrongly concluded that dst (%s) is not in src (%s)r) rrrr+r,rr _destinsrcrrwrrrrtest_destinsrc_false_negatives   z&TestMove.test_destinsrc_false_negativec CsrttzVdD]B\}}tjt|}tjt|}|jt||d||fdqWt tn t t0dS)N))r|zsrc/dest)r|z srcdir.newz;_destinsrc() wrongly concluded that dst (%s) is in src (%s)r}) rrrr+r,rrr~rrwrrrrtest_destinsrc_false_positives   z&TestMove.test_destinsrc_false_positivecCs\tj|jd}t|j|t||j| tj |j| tj |j|jdSrz) rr+r,rrrrrdrrrMsamefilerlrrrtest_move_file_symlinks zTestMove.test_move_file_symlinkcCsld}tj|j|}t|j|t||jtj|j|}| tj || tj |j|dSrz) rr+r,rrrrrdrrrMr)rxrrbZ final_linkrrrtest_move_file_symlink_to_dir sz&TestMove.test_move_file_symlink_to_dircCsztj|jd}tj|jd}t||tj|jd}t|||tj || tj |tj |dSNrJrIrK) rr+r,rrrrrdrrMrrealpathrxrarbrrrrtest_move_dangling_symlinks  z#TestMove.test_move_dangling_symlinkcCs|tj|jd}tj|jd}t|t||tj|jd}t||| tj || tj ||dSr) rr+r,rrrrrrdrrMrrrrrtest_move_dir_symlink"s   zTestMove.test_move_dir_symlinkc Cs6t|j|j}||tj|jtj|jdSr) rrdrrrrr+r,rr7rrrtest_move_return_value.szTestMove.test_move_return_valuecCs6t|jtj|jd}||tj|jddSrz)rrdrrr+r,rrr7rrr test_move_as_rename_return_value3sz)TestMove.test_move_as_rename_return_valuecs8gfdd}tj|j|j|d|tddS)Ncs||fdSrrr4Zmovedrrr6:sz7TestMove.test_move_file_special_function.._copyr(rh)rrdrrrrrxr6rrrtest_move_file_special_function7s z(TestMove.test_move_file_special_functioncsdgfdd}ttj|jdttj|jdtj|j|j|d| t ddS)Ncs||fdSrrr4rrrr6Bsz6TestMove.test_move_dir_special_function.._copychildZchild1r(r) rrrr+r,rrrdrrrrrrrtest_move_dir_special_function?s  z'TestMove.test_move_dir_special_functionc Cs~||_tjtj|jtj|j}||j|z.t |j|| tj |Wt |n t |0dSr)rurrr+r,rrupperrMrrdrrLrrprrrtest_move_dir_caseinsensitiveIs  z&TestMove.test_move_dir_caseinsensitiverrr SF_IMMUTABLE UF_OPAQUEr~c Cs0ztttttj|ttj tt | t t vtttj ttjtdtttj|ttj tt | t t vWtjtrtttj tttjt rtt tj tt nNtjtrtttj tttjt r*tt tj tt 0dS)Nr)rr TESTFN_SRCrrrrr!rrd TESTFN_DSTrrKrZ os_helperrr+r,rrwrrrrtest_move_dir_permission_deniedZs,      z(TestMove.test_move_dir_permission_deniedN)+rzr{r|r5rgrhrirjrkrmr&rnrorqrrrsrtrvrrrr+rwrxryr{rrrrrrrrrrrrrrYrrrrrrrrbsh              rbc@s`eZdZGdddeZddZeedddZ eeddd Z eedd d Z d S) TestCopyFilec@s:eZdZdZdZdZd ddZddZdd Zd d Z dS) zTestCopyFile.FauxFNTcCs||_||_dSr)_raise_in_exit_suppress_at_exit)rxZ raise_in_exitZsuppress_at_exitrrr__init__szTestCopyFile.Faux.__init__cGsdS)Nrr)rxrrrrrGszTestCopyFile.Faux.readcCs d|_dS)NT)_enteredrrrr __enter__szTestCopyFile.Faux.__enter__cCs&|||f|_|jr d|_td|jS)NT Cannot close) _exited_withr_raisedrr)rxexc_typeexc_valexc_tbrrr__exit__s  zTestCopyFile.Faux.__exit__)FT) rzr{r|rrrrrGrrrrrrFauxs rc Csrddd}ttd|F|ttddWdn1sF0YWdn1sd0YdS)NrFcSs|dkrtddS)NsrcfilezCannot open "srcfile"rkrr?rrr_opensz4TestCopyFile.test_w_source_open_fails.._openr-rdestfile)rF)rrRrrrrrxrrrrtest_w_source_open_failss  z%TestCopyFile.test_w_source_open_failszskipped on macOScs|d fdd }ttd|tddWdn1sF0Y|j|jdtu| jdj d dS) NrFcs |dkr S|dkrtddS)NrrCannot open "destfile"rkrrrrrs z2TestCopyFile.test_w_dest_open_fails.._openr-rrrrh)r)rF) rrrRrrrrrrrrrrrrtest_w_dest_open_failss* z#TestCopyFile.test_w_dest_open_failscs||dd fdd }ttd|tddWdn1sR0Y|j|j|j|jdt u| jd j d dS) NTrFcs|dkr S|dkrSdSNrrrrrrrrrs z3TestCopyFile.test_w_dest_close_fails.._openr-rrrrh)r)rF) rrrRrrrrrrrrrrrrrtest_w_dest_close_failss *   z$TestCopyFile.test_w_dest_close_failsc s|d|d fdd }ttd|F|ttddWdn1s^0YWdn1s|0Y|j|j| j |j ddu|j dS) NTrFcs|dkr S|dkrSdSrrrrrrrs z5TestCopyFile.test_w_source_close_fails.._openr-rrr)rF) rrrRrrrrrrrrrrrrrtest_w_source_close_failss  H   z&TestCopyFile.test_w_source_close_failsN) rzr{r|objectrrrrrrrrrrrrr}s     rc@sxeZdZdZeddZeddZddZej dd Z d d Z d d Z ddZ ddZeejdkdddZdS)TestCopyFileObji cCstt|jdSr)rDrFILESIZEclsrrr setUpClassszTestCopyFileObj.setUpClasscCsttttdSr)rr^rr/rrrr tearDownClasss zTestCopyFileObj.tearDownClasscCsttdSrrr^r/rrrrtearDownszTestCopyFileObj.tearDownc csbttdD}ttd}||fVWdn1s60YWdn1sT0YdSNrEr'r-rr/rrrr get_filess  zTestCopyFileObj.get_filesc Cslt|dN}t|d$}|||Wdn1s@0YWdn1s^0YdSrc)r-rrG)rxrarbfsrcfdstrrrassert_files_eqs  zTestCopyFileObj.assert_files_eqcCsH| \}}t||Wdn1s.0Y|ttdSr)rr copyfileobjrrr/rrrr test_contents*zTestCopyFileObj.test_contentcCs<| \}}t||Wdn1s.0YdSr)rrrrrrrtest_file_not_closeds z$TestCopyFileObj.test_file_not_closedcCs`|D\}}t|||||j|||jWdn1sR0YdSr)rrrrtellrrrrrtest_file_offsets z TestCopyFileObj.test_file_offsetrz Windows onlycCs~tjd}tttWdn1s.0Y||jdddt j t dd}| dWdn1s0Y|j}|tj|tjd}t|tWdn1s0Y||jdddt j t dd}Wdn1s0Y|j}|tj|tjd}t|tWdn1sd0Y||tdS) Nzshutil._copyfileobj_readintorrXiFrUsfoor)rrFrGrrrr/r call_argsrZr[rr\r.rQrvrr^r)rxmrCrrrrr test_win_impl s"*(* ,zTestCopyFileObj.test_win_implN)rzr{r|r classmethodrrr contextlibcontextmanagerrrrrrrrrrQrrrrrrs   rc@seZdZdZdZdZeddZeddZdd Z e j d d Z d d Z ddZddZddZddZddZddZddZddZdS)_ZeroCopyFileTestir5rcCsDtt|jttd}||_Wdn1s60YdSrc)rDrrr-rGFILEDATA)rrCrrrr) s   z_ZeroCopyFileTest.setUpClasscCsttdSr)rr^rrrrrr0 sz_ZeroCopyFileTest.tearDownClasscCsttdSrrrrrrr4 sz_ZeroCopyFileTest.tearDownc csbttdD}ttd}||fVWdn1s60YWdn1sT0YdSrrrrrrr7 s  z_ZeroCopyFileTest.get_filescOs tddS)Nzmust be implemented in subclass)NotImplementedError)rxrrrrr zerocopy_fun= sz_ZeroCopyFileTest.zerocopy_funcCs$||||dSr)rrrr5rrrrreset@ sz_ZeroCopyFileTest.resetc Cs| \}}|||Wdn1s.0Y|ttdd|j|L\}}tjd}t t tWdn1s0YWdn1s0YdS)NTr/zshutil.copyfileobj) rrrrHr/rrrFrGrrr)rxrarbrrrrtest_regular_copyH s**z#_ZeroCopyFileTest.test_regular_copyc Cs||j|J\}}|t|||Wdn1sF0YWdn1sd0Y|ttdd|j dS)NTr) rvrrrrrrrHrrrrrrtest_same_fileR s   Hz _ZeroCopyFileTest.test_same_filecCsZtjtd}|t}t|dWdn1s<0Y||j j |dS)Nrnew) rZrrr\rrrrrrr)rxrQrrrrtest_non_existent_srcZ s *z'_ZeroCopyFileTest.test_non_existent_srcc stdtd|fdd|fddtdWdn1sT0YtdF}td}|||Wdn1s0YWdn1s0Y|tdd d dS) Nrarbcs tSrrr^r)r_rrrc r5z3_ZeroCopyFileTest.test_empty_file..cs tSrrr)r`rrrd r5r'rETrr5)rrvr-rrrHrr)r`r_rtest_empty_file` s   Hz!_ZeroCopyFileTest.test_empty_filecCsHtjj|jtd"|ttjtt Wdn1s:0YdS)Nr") rrFrG PATCHPOINTZeroDivisionErrorrrrrr/rrrrtest_unhandled_exceptionn s  z*_ZeroCopyFileTest.test_unhandled_exceptionc Cstjj|jttjddr|J\}}|t | ||Wdn1sV0YWdn1st0YWdn1s0YdSNyor) rrFrGrrrEINVALrrr rrrrrtest_exception_on_first_callt s    z._ZeroCopyFileTest.test_exception_on_first_callc Cs|tjj|jttjddN|&\}}|t|j ||Wdn1sP0YWdn1sn0YdSr) rrFrGrrrENOSPCrrrrrrrtest_filesystem_full~ s   z&_ZeroCopyFileTest.test_filesystem_fullN)rzr{r|rrrrrrrrrrrrrrrrrrrrrrrr# s&     rzos.sendfile() not supportedc@sXeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS)TestZeroCopySendfile os.sendfilecCs t||Sr)r_fastcopy_sendfile)rxrrrrrr sz!TestZeroCopySendfile.zerocopy_func Cst|j|}ttdR}|t|||Wdn1sF0Yt ||Wdn1sp0YWdn1s0Y| t tdd|jdS)Nr'Tr) ioBytesIOrr-r/rr rrrrrHrrrrtest_non_regular_file_src s   *Hz.TestZeroCopySendfile.test_non_regular_file_srcc Csttd}tn}|t|||Wdn1sB0Yt||| d| | |j Wdn1s0YWdn1s0YdS)NrEr) r-rrrrr rrrseekrrGrrrrrtest_non_regular_file_dst s   *  z.TestZeroCopySendfile.test_non_regular_file_dstc sfdd}gtjtjjdd|dr|J\}}|t}t ||Wdn1sf0YWdn1s0YWdn1s0Y| |j j t j dS)Ncs,sd|i|SttjddS)Nr)rNrrEBADFrr&Z orig_sendfilerrrT s zDTestZeroCopySendfile.test_exception_on_second_call..sendfilerT)rPr")rrTrrFrGrrrrrrrrr)rxrTrarbrrrrtest_exception_on_second_call s  fz2TestZeroCopySendfile.test_exception_on_second_callc CstjjdtdH}| \}}t||Wdn1s@0YWdn1s^0Y|tt dd|j dS)Nos.fstatrTr) rrFrGrrrrrrHr/rrxrrarbrrrtest_cant_get_size s  <z'TestZeroCopySendfile.test_cant_get_sizec Cstj}d|_tjjd|dH}| \}}t||Wdn1sP0YWdn1sn0Y|t t dd|j dS)NirrOTr) rrFMockst_sizerGrrrrrHr/rrxrFrrarbrrrtest_small_chunks s  <z&TestZeroCopySendfile.test_small_chunksc Cstj}|jd|_tjjd|dH}| \}}t||Wdn1sV0YWdn1st0Y| t t dd|j dS)Ni@rrTr) rrFrrrrGrrrrrHr/rrrrrtest_big_chunk s   <z#TestZeroCopySendfile.test_big_chunkcCstjjdtd}|ttjtt|j dd}| |t j tttttddd|tjtd|ttjttd|j dd}| |d Wdn1s0YdS) NrrrrshelloTr3i)rrFrGrrrrrr/rrrr+getsizerr^r1rv)rxr blocksizerrrtest_blocksize_arg s"  z'TestZeroCopySendfile.test_blocksize_argc Csztjj|jttjddr}|J\}}|t t ||Wdn1sX0YWdn1sv0YWdn1s0Ytj|j}t t tWdn1s0YWdt _ndt _0dS)NrrT)rrFrGrrrENOTSOCKrrr rrrrr/_USE_CP_SENDFILErrrrtest_file2file_not_supported s  H  z1TestZeroCopySendfile.test_file2file_not_supportedN) rzr{r|rrrrrrrrrrrrrrr s     rz macOS onlyc@seZdZdZddZdS)TestZeroCopyMACOSzposix._fcopyfilecCst||tjSr)r_fastcopy_fcopyfileposix_COPYFILE_DATArrrrr szTestZeroCopyMACOS.zerocopy_funN)rzr{r|rrrrrrr src@s^eZdZddZddZddZee e j dee edd d d Zd d ZdS)TestGetTerminalSizecCs(t}||jd||jddS)Nr)rget_terminal_sizercolumnslines)rxr@rrrtest_does_not_crash sz'TestGetTerminalSize.test_does_not_crashcCst&}d|d<|d=t}Wdn1s40Y||jdt&}|d=d|d<t}Wdn1s0Y||jddS)NZ777COLUMNSLINESi Z888ix)rrIrrrrrrxrKr@rrrtest_os_environ_first s & &z)TestGetTerminalSize.test_os_environ_firstcCs`t(}d|d<d|d<t}Wdn1s60Y||jd||jddS)NrerZyyyrr)rrIrrrrrrrrrtest_bad_environ s  &z$TestGetTerminalSize.test_bad_environz not on ttyrzneed os.get_terminal_size()c Csztddg}Wn$tttjfy>|dYn0t|dt|df}t $}|d=|d=t }Wdn1s0Y| ||dS)NZsttyr@zstty invocation failedrhrrr)rmrrrprr!rr.rqrrIrrr)rxr@rrKrrrrtest_stty_match( s   &z#TestGetTerminalSize.test_stty_matchc Cst}|d=|d=ttddtjdd}Wdn1sF0Y||jd||jdt t j dJ}ttd|tjd d}Wdn1s0YWdn1s0Y||jd ||jd Wdn1s0YdS) Nrr __stdout__) )fallbackr rr()(rr) rrIrRrkrrrrrr-rdevnull)rxrKr@rCrrr test_fallback@ s * Hz!TestGetTerminalSize.test_fallbackN)rzr{r|rr r rrrisattyrkr r]rYr rrrrrr s   rc@seZdZddZdS)PublicAPITestscCsP|ttdgd}ttds,tjdkr6|d|ttjt|dS)N__all__)rrrNr[rrrrdrwrr ExecErrorrrrrr rr rrrrrr statvfsrr) rrYrrrQrNrrr)rxZ target_apirrrtest_module_all_attributeW s  z(PublicAPITests.test_module_all_attributeN)rzr{r|rrrrrrT sr__main__)F)F)OrZ unittest.mockrrZrkrrZos.pathrr$rrmr6r8rrrrrrrrrr r r r r rrr ImportErrorrrZ test.supportrrr/rrrrrrrjrrrrrr&r1rDrHrOreZSUPPORTS_SENDFILErrrsZTestCaser}rrHrrr+rarbrrrrrrrrrrzmainrrrrs8               [gP< s\Jd v N