ȿ NdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z m Z m Z mZddlmZmZejdkZGdd e jeZGd d eZGd d eZGddeZGddeZedkrejdSdS)zTests for `fake_filesystem_shutil` if used in `fake_filesystem_unittest.TestCase`. Note that almost all of the functionality is delegated to the real `shutil` and works correctly with the fake filesystem because of the faked `os` module. N)Path)fake_filesystem_unittest)get_uidset_uidis_rootIS_PYPY)RealFsTestMixinskip_if_symlink_not_supportedwin32c8eZdZddZdZdZedZdS)RealFsTestCaserunTestcntj||tj|dSN)rTestCase__init__r )self methodNames |/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pyfakefs/tests/fake_filesystem_shutil_test.pyrzRealFsTestCase.__init__$s2 )224DDD &&&&&ctj|tj|_t |_td|sn| |j |_ t|_t|_ | |j d|jdSdS)N)r setUposgetcwdcwdruidr use_real_fs setUpPyfakefsfs filesystemopencreate_basepathset_disk_usage base_pathrs rrzRealFsTestCase.setUp(sd###9;;99 !! 9    "gDODGDI  " " " G " "4 8 8 8 8 8  9 9rcVt|jtj|dSr)rrr tearDownr&s rr(zRealFsTestCase.tearDown5s) &&&&&rcb|rtjdkS|jjS)Nr )rsysplatformr! is_windows_fsr&s rr,zRealFsTestCase.is_windows_fs9s.      +<7* *,,rN)r)__name__ __module__ __qualname__rrr(propertyr,rrr r #sa'''' 9 9 9'''--X---rr ceZdZejeddZdZdZeje ddZ ejeddZ ejeddZ eje dd Z d Z d Zd Zd ZdZdZdZdZejeddZdZdZdZdZdZdZdZdZdZdZ dZ!dS) FakeShutilModuleTestPosix specific behaviorc|d}|||jj|d}|jj|d}|||j|d|||jj|d}|jj|d}|||t5tj ||ddddS#1swxYwYdS)Nrootpathdir1dir2mzf1.txt) make_path create_dirrpathjoinchmod create_file assertRaisesPermissionErrorshutilmove)r root_path dir1_path dir2_path old_file_path new_file_paths rtest_catch_permission_errorz0FakeShutilModuleTest.test_catch_permission_errorAsaNN:..   """GL%%i88 GL%%i88   """  i'''  """ )))X>>  )))X>>  '''    / / 6 6 K } 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6sEE Ec|d}tj|d}||tj|d}|||tj|tj || tj|| tj|| tj|dS)Nxyzzysubdirsubfile) r:rr<r=r;r? assertTrueexistsrBrmtree assertFalser directorydir_path file_paths r test_rmtreez FakeShutilModuleTest.test_rmtreeQsNN7++ 7<< 844 !!!GLLI66  ### y11222 i     22333 11222  2233333rc^|d}tj|d}||tj|d}||t j|dz|tj ||tj ||tj |dS)NrKrLrM/) r:rr<r=r;r?rBrPrQrOrRs rtest_rmtree_with_trailing_slashz4FakeShutilModuleTest.test_rmtree_with_trailing_slash]sNN7++ 7<< 844 !!!GLLI66  ### i#o&&&  22333 11222  2233333rzWindows specific behaviorc||d}|tj|dtj|d}|||j|d|t5tj |dddn #1swxYwY| tj ||j|ddS)Nfoobarbazi$) check_windows_onlyr:r?rr<r=r>r@OSErrorrBrPrNrOrrTrUs r4test_rmtree_without_permission_for_a_file_in_windowszIFakeShutilModuleTest.test_rmtree_without_permission_for_a_file_in_windowshs= !!!>>%(( h66777GLL511  ###  i'''   w ' ' $ $ M( # # # $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ y11222  i'''''sC((C,/C,c0||d}|tj|dtj|d}|||j|dts|t5tj |dddn #1swxYwY| tj ||j|ddStj ||tj |dS)Nr[r\r]r9i)check_posix_onlyr:r?rr<r=r>rr@r`rBrPrNrOrQras r1test_rmtree_without_permission_for_a_dir_in_posixzFFakeShutilModuleTest.test_rmtree_without_permission_for_a_dir_in_posixus >>%(( h66777GLL511  ###  h&&&yy 8""7++ ( ( h''' ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( OOBGNN955 6 6 6 GMM(E * * * * * M( # # #   RW^^I66 7 7 7 7 7sC66C:=C:c||d}|tj|dtj|d}||t |d5tj|dddn #1swxYwY| tj |dSNr[r\r]utf8)encoding) rdr:r?rr<r=r"rBrPrQrOras r test_rmtree_with_open_file_posixz5FakeShutilModuleTest.test_rmtree_with_open_file_posixs >>%(( h66777GLL511  ### )f - - - $ $ M( # # # $ $ $ $ $ $ $ $ $ $ $ $ $ $ $  2233333s#CC Ccj||d}|tj|dtj|d}||t |d5|t5tj |dddn #1swxYwYdddn #1swxYwY| tj |dSrg) r_r:r?rr<r=r"r@r`rBrPrNrOras r.test_rmtree_with_open_file_fails_under_windowszCFakeShutilModuleTest.test_rmtree_with_open_file_fails_under_windowss{ !!!>>%(( h66777GLL511  ### )f - - - ( (""7++ ( ( h''' ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( x0011111s6#C6>C C6C# #C6&C# 'C66C:=C:cd}|t5tj|dddn #1swxYwY tj|ddS#t$r|dYdSwxYw)N nonexistingT) ignore_errorsz(rmtree raised despite ignore_errors True)r@r`rBrPfail)rrSs rtest_rmtree_non_existing_dirz1FakeShutilModuleTest.test_rmtree_non_existing_dirs!   w ' ' % % M) $ $ $ % % % % % % % % % % % % % % % B M)4 8 8 8 8 8 8 B B B II@ A A A A A A Bs!>AA A""BBcXGddfd}|d}d_d_ tj||n%#t $r|dYnwxYw|j|j|d_d_ tj|d | n%#t $r|d YnwxYw| j|jddS) NceZdZdS)PFakeShutilModuleTest.test_rmtree_non_existing_dir_with_handler..NonLocalN)r-r.r/r1rrNonLocalrts Drruc$d_|_dSNT) errorHandled errorPath)_r< _error_inforus r error_handlerzUFakeShutilModuleTest.test_rmtree_non_existing_dir_with_handler..error_handlers$(H !!%H   rrnF)onerrorz/rmtree raised exception despite onerror definedT)ror~z2rmtree raised exception despite ignore_errors True) r:rxryrBrPr`rprN assertEqualrQ)rr|rSrus @r)test_rmtree_non_existing_dir_with_handlerz>FakeShutilModuleTest.test_rmtree_non_existing_dir_with_handlers         & & & & &NN=11 % I M)] ; ; ; ; ; I I I IIG H H H H H I -... +Y777 % L M)4 O O O O O L L L IIJ K K K K K L ./// +R00000s#AA10A18CC21C2c||dd}|j|jj|d||jj|tj || |jj|dS)Nr[r\res) r_r:rmakedirsr<r=rNrOrBrPrQ)rr%s rtest_rmtree_in_windowsz+FakeShutilModuleTest.test_rmtree_in_windowss !!!NN5%00  **9e<<===  ++I66777 i    ,,Y7788888rc|d}|d}||tj|d|tj||tj|tj |||tj|| tj |j tj |j dS)NrK xyzzy_copy) r:r?rr>rNr<rOrQrBcopyrstatst_modersrc_filedst_files r test_copyzFakeShutilModuleTest.test_copys>>'**>>,// """ 5!!! x00111 11222 Hh''' x00111 **2BGH4E4E4MNNNNNrcJt|d}t|d}d}|dz }|dz }|||tj||tj||ksJdS)N source_dir target_dirz Test contentsztest.txtcontents) copy_function)rr:r?rBcopytreecopy2 read_text)rrr test_contents source_file target_files r test_copytree_with_copy_functionz5FakeShutilModuleTest.test_copytree_with_copy_functions$..6677 $..6677 '  :-  :-  }=== JflKKKK$$&&-777777rc|t|d}tj|d}tj||dt|d}tj||dz }|d|d}| t|5tj ||dddn #1swxYwY|d z }d|d}| t|5tj ||ddddS#1swxYwYdS) Nhome1r7r9drive1znew.txtz[Errno 13] Permission denied: '')msgr8)rdrr:rr<r=rr>touchr@rArBrrC)rdst_dirsrc_dir2src_dirrrdst_dir2s rtest_permission_error_messagez2FakeShutilModuleTest.test_permission_error_messages t~~g..//7<<00 H et~~h//00 GY&::::   C  8 8 , , L7 + + + , , , , , , , , , , , , , , ,V#;;;;   C  8 8 , , K( + + + , , , , , , , , , , , , , , , , , ,s$1DDDE((E,/E,cZ|d}|d}tj|d}||||tj|d|tj||tj|| tj|tj |||tj|| tj |jtj |jdS)NrKparentr)r:rr<r=r?r;r>rNrOrQrBrrrr)rrparent_directoryrs rtest_copy_directoryz(FakeShutilModuleTest.test_copy_directorys@>>'**>>(337<< 0':: """ ())) 5!!! x00111 '788999 11222 H./// x00111 **2BGH4E4E4MNNNNNrc|d}||tj|d|d}|||tj||tj|tj||tj |}tj |}| |j |j | |j |j d| |j|jddSNrKrrrplaces)r:r?rr>rNr<rOrBcopystatrrrassertAlmostEqualst_atimest_mtimerrrsrc_statdst_stats r test_copystatz"FakeShutilModuleTest.test_copystats2>>'** """ 5!!!>>,// """ x00111 x00111(+++78$$78$$ )8+;<<< x0(2CANNN x0(2CANNNNNrz#Functionality not supported in PyPycPt|d}|||d}|d}||||||t j||ddS)zRegression test for #799rKsym1sym2F)follow_symlinksN)r r:r?create_symlinkrBr)rfrrs rtest_copystat_symlinksz+FakeShutilModuleTest.test_copystat_symlinkss &''' NN7 # # ~~f%%~~f%% D!$$$ D!$$$dE::::::rc|d}||tj|d|d}|tj||tj|tj |||tj|tj |}tj |}| |j |j | |j|jd| |j|jddSr)r:r?rr>rNr<rOrQrBrrrrrrrrs r test_copy2zFakeShutilModuleTest.test_copy2 s@>>'** """ 5!!!>>,// x00111 11222 Xx((( x0011178$$78$$ )8+;<<< x0(2CANNN x0(2CANNNNNrc|d}|d}tj|d}||||tj|d|tj||tj|| tj|tj |||tj|tj |}tj |}| |j|j||j|jd||j|jddS)NrKrrrrr)r:rr<r=r?r;r>rNrOrQrBrrrrrrr)rrrrrrs rtest_copy2_directoryz)FakeShutilModuleTest.test_copy2_directory/s>>'**>>(337<< 0':: """ ())) 5!!! x00111 '788999 11222 X/000 x0011178$$78$$ )8+;<<< x0(2CANNN x0(2CANNNNNrc|d}|d}|||d|z|tj|d|tj||tj|tj |||tj||tjtj|d|tjtj|ddS)NrKrz %s/subdirrMrL) r:r;r?rr<r=rNrOrQrBrr src_directory dst_directorys r test_copytreez"FakeShutilModuleTest.test_copytreeAsKw// |44   &&&  m3444 mY??@@@ }55666  66777 }555 }55666 rw||M8'L'LMMNNN rw||M9'M'MNNOOOOOrc|d}|d}|||tj||tj||t5tj ||ddddS#1swxYwYdSNrKr) r:r?rNrr<rOrQr@r`rBr)rrrs rtest_copytree_src_is_filez.FakeShutilModuleTest.test_copytree_src_is_fileNs>>'**|44  """ x00111  66777   w ' ' 5 5 OHm 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s>C!!C%(C%c|d}d}|j|}|j}|j}|t j|| t j|tj |||t j|| t j||j |}| ||j| ||jdS)Nz/original_xyzzyz /moved_xyzzy) skip_real_fsr r?st_inost_devrNrr<rOrQrBrC get_objectr)rrr src_objectsrc_inosrc_dev dst_objects r!test_move_file_in_same_filesystemz6FakeShutilModuleTest.test_move_file_in_same_filesystemWs& $!W((22 ## x00111 11222 Hh''' x00111 11222W''11  *"3444 *"344444rc||}|d}|jj|d}|j|}|j}|j }tj ||| tj ||tj ||j|}|||j|||j dS)Noriginal_xyzzy moved_xyzzy)rcreate_mount_pointr:rr<r=r r?rrrBrCrNrOrQrassertNotEqual)r mount_pointrrrrrrs r$test_move_file_into_other_filesystemz9FakeShutilModuleTest.test_move_file_into_other_filesystemis --// >>"2337<$$[-@@W((22 ## Hh''' x00111 11222W''11  GZ%6777 GZ%677777rc|d}|d}tj|d}|||||tj||tj|tj |||tj||tj|dS)NrKrS) r:rr<r=r?r;rNrOrQrBrC)rrrrs rtest_move_file_into_directoryz2FakeShutilModuleTest.test_move_file_into_directory{s>>'**{33 7<< w77 """  &&& x00111 11222 Hm,,, x00111 1122222rcJ|d}|d}|||tj|d|tj|d|tj||tj|tj |||tj||tjtj|d|tjtj|d|tj|dS)NrrrMrL) r:r;r?rr<r=rNrOrQrBrCrs rtest_move_directoryz(FakeShutilModuleTest.test_move_directorysy'788 }55   &&& mY??@@@  ]H==>>> }55666  66777 M=111 }55666 rw||M9'M'MNNOOO rw||M8'L'LMMNNN  6677777rc||dd}|j|dt j|}|d|j|d|j|d|j |d|| }|j j |d}|j j |d}|j|dt j|}|d|dS) Nr[r\st_sizerXrrr)rd)rr:r r?rB disk_usagertotalusedfreerrr<r=)rrUrrrTs rtest_disk_usagez$FakeShutilModuleTest.test_disk_usages< NN5%00  Is333&y11  z/000 jo... jo... ):666--// 7<$$[%88GL%%h66  Is333&x00  *55555rc||dd}|j|dt |}t j|}|d|j|d|j |d|j |d|dS)Nr[r\rrrrr) rr:r r?rrBrrrrr)rrUr<rs rtest_disk_usage_with_pathz.FakeShutilModuleTest.test_disk_usage_with_paths NN5%00  Is333I&t,,  z/000 jo... jo... ):66666rcT|jrdnd}|j|d|S)NzM:z/mountr) total_size)r,r add_mount_point)rrs rrz'FakeShutilModuleTest.create_mount_points4"0>ddh   <<<rN)"r-r.r/unittestskipIf is_windowsrIrVrYrbrerjrlrqrrrrrrrrrrrrrrrrrrrrr1rrr3r3@skX_Z!:;; 6 6<; 6 4 4 4 4 4 4X_^%@AA ( (BA (X_Z!:;;88<;8 X_Z!:;;44<;4X_^%@AA 2 2BA 2BBB111:999 O O O 8 8 8,,,( O O O O O OX_WCDD ; ;ED ; O O OOOO$ P P P555555$888$ 3 3 3 8 8 8666" 7 7 7rr3ceZdZdZdS)RealShutilModuleTestcdSrwr1r&s rrz RealShutilModuleTest.use_real_fstrNr-r.r/rr1rrrr#rrceZdZfdZdZdZdZdZdZe j e ddZ d Z e j e dd Zd Zd Zd ZxZS)FakeCopyFileTestcHtdSr)superr()r __class__s rr(zFakeCopyFileTest.tearDowns rc|d}|d}d}||||tj||tj|tj|||tj|| ||dS)NrKrcontents of filer) r:r?rNrr<rOrQrBcopyfilecheck_contentsrrrrs rtest_common_casez!FakeCopyFileTest.test_common_cases>>'**>>,//% H555 x00111 11222(+++ x00111 Hh/////rcd|d}|}d}||||tj||tj5tj ||ddddS#1swxYwYdS)NrKrr) r:r?rNrr<rOr@rBErrorrrs r0test_raises_if_source_and_dest_are_the_same_filezAFakeCopyFileTest.test_raises_if_source_and_dest_are_the_same_files>>'**% H555 x00111   v| , , 0 0 OHh / / / 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0sB%%B),B)ct|d}|d}d}|||||||t j||tj 5tj ||ddddS#1swxYwYdS)Nr[r\rr) r r:r?rrNrr<rOr@rBrrrs r'test_raises_if_dest_is_a_symlink_to_srcz8FakeCopyFileTest.test_raises_if_dest_is_a_symlink_to_srcs%'''>>%((>>%((% H555 Hh/// x00111   v| , , 0 0 OHh / / / 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s9CC #C c@|d}|d}d}d}|||||||tj||tj|t j|||tj||||dS)NrKrcontents of source filecontents of dest filer) r:r?rNrr<rOrBrr)rrr src_contents dst_contentss r,test_succeeds_if_dest_exists_and_is_writablez=FakeCopyFileTest.test_succeeds_if_dest_exists_and_is_writables>>'**>>,//0 .  L999 L999 x00111 x00111(+++ x00111 Hl33333rc|d}|d}d}d}||||||tj|d|tj||tj|trtj ||||jj|| |5}| d| dddn #1swxYwYnG| t5tj ||dddn #1swxYwYtj|ddS)NrKrr r rr^)r:r?rr>rNr<rOrrBrr"rreadr@r`)rrrrrrs r.test_raises_if_dest_exists_and_is_not_writablez?FakeCopyFileTest.test_raises_if_dest_exists_and_is_not_writables>>'**>>,//0 .  L999 L999 5!!! x00111 x00111 99 4 OHh / / / OODGL//99 : : :8$$ F  !:AFFHHEEE F F F F F F F F F F F F F F F""7++ 4 4(333 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5!!!!!s$)E55E9<E9F==GGr4c|||d}|dd}tj|d}d}|||||tj|d|tj ||tj |tsJ| t5tj||ddddS#1swxYwYdStj|||tj ||||dS)NrKtmpr[r rr9)rdr:rr<r=r?r;r>rNrOrr@r`rBrr)rrrrrs r3test_raises_if_dest_dir_is_not_writable_under_posixzDFakeCopyFileTest.test_raises_if_dest_dir_is_not_writable_under_posixs >>'**....7<<110  L999     %    x00111 w//000yy 8""7++ 4 4(333 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 OHh / / / OOBGNN844 5 5 5   , 7 7 7 7 7s/EEEcN|d}|d}|tj||t 5tj||ddddS#1swxYwYdSr) r:rQrr<rOr@r`rBrrs rtest_raises_if_src_doesnt_existz0FakeCopyFileTest.test_raises_if_src_doesnt_exists>>'**>>,// 11222   w ' ' 0 0 OHh / / / 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s7BB!Bc||d}|d}d}|||tj|d|tj|tsJ| t5tj ||ddddS#1swxYwYdStj |||tj|| ||dS)NrKrr rr)rdr:r?rr>rNr<rOrr@r`rBrr)rrrrs rtest_raises_if_src_not_readablez0FakeCopyFileTest.test_raises_if_src_not_readablesl >>'**>>,//0  L999 5!!! x00111yy 8""7++ 4 4(333 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 OHh / / / OOBGNN844 5 5 5   , 7 7 7 7 7sC**C.1C.cx|d}|d}|||tj||t5tj ||ddddS#1swxYwYdSr) r:r;rNrr<rOr@r`rBrrs r!test_raises_if_src_is_a_directoryz2FakeCopyFileTest.test_raises_if_src_is_a_directory.s>>'**>>,// !!! x00111   w ' ' 0 0 OHh / / / 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s B//B36B3c|d}|dd}d}||||||tj||tj||t5tj ||ddddS#1swxYwYdS)NrKrr[r r) r:r?r;rNrr<rOr@r`rBr)rrrrs r"test_raises_if_dest_is_a_directoryz3FakeCopyFileTest.test_raises_if_dest_is_a_directory6s >>'**....0  L999     x00111 w//000   w ' ' / / OHg . . . / / / / / / / / / / / / / / / / / /sC;;C?C?c^tj}tj}d}ttj||d5}|ddddn #1swxYwYtj||tj |dS)Nzfoo.pdfwbsstub) tempfilemkdtempr"rr<r=writerBrCrP)rrrfilenamefps rtest_moving_dir_into_dirz)FakeCopyFileTest.test_moving_dir_into_dirAs%'' %''  "',,z844d ; ; r HHW                    J +++ j!!!!!sA99A=A=)r-r.r/r(rrr rrrrrrrrrrr' __classcell__)rs@rrrs 0 0 0000 0 0 0 4 4 4""",X_Z!:;;88<;8&000X_Z!:;;88<;8 000 / / / " " " " " " "rrceZdZdZdS)RealCopyFileTestcdSrwr1r&s rrzRealCopyFileTest.use_real_fsNrrNrr1rrr*r*Mrrr*__main__)__doc__rrBr*r"rpathlibrpyfakefsrpyfakefs.helpersrrrrpyfakefs.tests.test_utilsr r r+rrr r3rrr*r-mainr1rrr3s  ------????????????TTTTTTTT \W $ ------6---:ttttt>tttn / N"N"N"N"N"~N"N"N"b'  zHMOOOOOr