#CPpdZddlZddlZddlmZddlmZeddZGddeZGd d eZ Gd d e Z Gd deZ Gdde Z GddeZ Gdde ZGddeZGddeZGddeZGddeZGddeZGdd eZed!krejdSdS)"z&Unit tests for file timestamp updates.N) namedtuple)RealFsTestCaseFileTimezst_ctime, st_atime, st_mtimeceZdZfdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZxZS)FakeStatTestBasect||d|_|jrdnd|_d|_dS)N some_fileg?g{Gz?)supersetUpcheck_linux_and_windows make_path file_pathis_macos sleep_timemodeself __class__s t/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pyfakefs/tests/fake_stat_time_test.pyr zFakeStatTestBase.setUpsX   $$&&& 44!%8##D c|j|}|rtj|jntjt |j|j|j S)N)st_ctimest_atimest_mtime) osstat use_real_fstimesleeprrrrr)rpathrs r stat_timezFakeStatTestBase.stat_time$sqw||D!!       Jt ' ' ' ' IKKK]]]    rcp|jr|||dS|||dSN) is_windows_fsassertLessEqual assertLessrtime1time2s rassertLessExceptWindowsz(FakeStatTestBase.assertLessExceptWindows2sC   *   . . . . . OOE5 ) ) ) ) )rcp|jr|||dS|||dSr$)r%r' assertEqualr(s rassertLessExceptPosixz&FakeStatTestBase.assertLessExceptPosix8sC   + OOE5 ) ) ) ) )   UE * * * * *rcB|5||j|jd5||j}dddn #1swxYwY||j}||fcdddS#1swxYwYdSNutf8encoding) mock_timeopenrrr"rcreatedcloseds ropen_close_new_filez$FakeStatTestBase.open_close_new_file>s ^^   # #4>49vFF 9 9..88 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9^^DN33FF?  # # # # # # # # # # # # # # # # # #s4#BA BA# #B&A# ' BBBc|5||j|jd5}||j}|d||j}dddn #1swxYwY||j}dddn #1swxYwY|||fSNr1r2foo)r4r5rrr"write)rfr7writtenr8s ropen_write_close_new_filez*FakeStatTestBase.open_write_close_new_fileEs. ^^   4 44>49vFF 9!..88..88 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9^^DN33F  4 4 4 4 4 4 4 4 4 4 4 4 4 4 4''s5#B?A B B?B B?B B??CCc|5||j||j}||j|jd5||j}dddn #1swxYwY||j}|||fcdddS#1swxYwYdSr0)r4 create_filerr"r5rrbeforeopenedr8s r open_closezFakeStatTestBase.open_closeOs@ ^^   * *   T^ , , ,^^DN33F4>49vFF 8 877 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8^^DN33F66) * * * * * * * * * * * * * * * * * *s6AC ,B C B C B !C  C C c |5||j||j}||j|jd5}||j}|d||j}dddn #1swxYwY||j}||||fcdddS#1swxYwYdSr;)r4rBrr"r5rr=)rrDr>rEr?r8s ropen_write_closez!FakeStatTestBase.open_write_closeZsc ^^   3 3   T^ , , ,^^DN33F4>49vFF 9!77..88 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9^^DN33F67F2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3s7AC9,A C6 C9C C9 C "C99C=C=c |5||j||j}||j|jd5}||j}|||j}dddn #1swxYwY||j}||||fcdddS#1swxYwYdSr0)r4rBrr"r5rflush)rrDr>rEflushedr8s ropen_flush_closez!FakeStatTestBase.open_flush_closegsa ^^   3 3   T^ , , ,^^DN33F4>49vFF 9!77 ..88 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9^^DN33F67F2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 37AC8,A C5 C8C C8C "C88C<?C<cj|5||j||j}||j|jd5}||j}|d||j}|||j}dddn #1swxYwY||j}|||||fcdddS#1swxYwYdSr;)r4rBrr"r5rr=rJ)rrDr>rEr?rKr8s ropen_write_flushz!FakeStatTestBase.open_write_flushts ^^   < <   T^ , , ,^^DN33F4>49vFF 9!77..88 ..88  9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 ^^DN33F67GV; < < < < < < < < < < < < < < < < < rErRrKr8s ropen_read_flushz FakeStatTestBase.open_read_flushs ^^   9 9   T^ , , ,^^DN33F4>3@@ 9A77~~dn55 ..88  9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 ^^DN33F64&8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9s7AD"'A7C* D"*C. .D"1C. 2#D""D&)D&c|5||j|jd5}||j}|||j}dddn #1swxYwY||j}|||fcdddS#1swxYwYdSr0)r4r5rrr"rR)rr>r7rRr8s ropen_read_close_new_filez)FakeStatTestBase.open_read_close_new_files6 ^^   ) )4>49vFF 6!..88~~dn55 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6^^DN33FD&( ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s5#CA B  C B CB !CC Cc |5||j||j}||j|jd5}||j}|||j}dddn #1swxYwY||j}||||fcdddS#1swxYwYdSr0)r4rBrr"r5rrR)rrDr>rErRr8s ropen_read_closez FakeStatTestBase.open_read_closesa ^^   0 0   T^ , , ,^^DN33F4>49vFF 6!77~~dn55 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6^^DN33F64/ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0rMc|\}}||j|j||j|j||j|jdS)zq When a file is created on opening and closed again, no timestamps are updated on close. N)r9r-rrrr6s rcheck_open_close_new_filez*FakeStatTestBase.check_open_close_new_filesp 2244 )6?;;; )6?;;; )6?;;;;;rc|\}}}||j|j||j|j||j|j||j|j||j|j||j|jdS)z When a file is created on opening, st_ctime is updated under Posix, and st_mtime is updated on close. N)r@r-rr+rr&rr')rr7r?r8s rcheck_open_write_close_new_filez0FakeStatTestBase.check_open_write_close_new_files $(#A#A#C#C & )7+;<<< $$W%5vGGG )7+;<<< W-v??? )7+;<<< (&/:::::rc|\}}}||j|j||j|j||j|j||j|j||j|j||j|jdS)z When an existing file is opened with 'w' or 'w+' mode, st_ctime (Posix only) and st_mtime are updated on open (truncating), but not on close. N)rFr+rr-r&rr'rrCs rcheck_open_close_w_modez(FakeStatTestBase.check_open_close_w_modes "&!2!2 $$V_foFFF &/::: V_fo>>> &/::: 999 &/:::::rc|\}}}||j|j||j|j||j|j||j|j||j|j||j|jdS)zz When an existing file is opened with any mode other than 'w' or 'w+', no timestamps are updated. N)rFr-rrrrCs rcheck_open_close_non_w_modez,FakeStatTestBase.check_open_close_non_w_modes "&!2!2 &/::: &/::: &/::: &/::: &/::: &/:::::rcx|\}}}}||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|jdS)z When an existing file is opened with 'w' or 'w+' mode and is then written to, st_ctime (Posix only) and st_mtime are updated on open (truncating) and again on close (flush), but not when written to. N)rHr+rr-r&rr'rrrDrEr?r8s rcheck_open_write_close_w_modez.FakeStatTestBase.check_open_write_close_w_modes +/*?*?*A*A' $$V_foFFF '*:;;; $$W%5vGGG V_fo>>> '*:;;; W-v??? 999 '*:;;; (&/:::::rcx|\}}}}||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|jdS)z When an existing file is opened with 'w' or 'w+' mode (truncating), st_ctime (Posix only) and st_mtime are updated. No updates are done on flush or close. N)rLr+rr-r&rr'rrrDrErKr8s rcheck_open_flush_close_w_modez.FakeStatTestBase.check_open_flush_close_w_modes +/*?*?*A*A' $$V_foFFF '*:;;; )6?;;; V_fo>>> '*:;;; )6?;;; 999 '*:;;; )6?;;;;;rcx|\}}}}||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|jdS)z When an existing file is opened with any mode other than 'w' or 'w+', flushed and closed, no timestamps are updated. N)rLr-rrrrds r!check_open_flush_close_non_w_modez2FakeStatTestBase.check_open_flush_close_non_w_mode s +/*?*?*A*A' &/::: '*:;;; )6?;;; &/::: '*:;;; )6?;;; &/::: '*:;;; )6?;;;;;rcx|\}}}}||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|jdS)zo Reading from a file opened with 'r', 'r+', or 'a+' mode updates st_atime under Posix. N)rWr-rrr&rrrDrErRr8s r check_open_read_close_non_w_modez1FakeStatTestBase.check_open_read_close_non_w_modes (,';';'='=$f &/::: $-888 888 &/::: V_dm<<< 888 &/::: $-888 88888rc|\}}}||j|j||j|j||j|j||j|j||j|j||j|jdS)z| When a file is created with 'w+' or 'a+' mode and then read from, st_atime is updated under Posix. N)rUr-rr&rr)rr7rRr8s rcheck_open_read_close_new_filez/FakeStatTestBase.check_open_read_close_new_file2s !% = = ? ?v )4=999 888 W-t}=== 888 )4=999 88888rcx|\}}}}||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|jdS)z When an existing file is opened with 'a', 'a+' or 'r+' mode and is then written to, st_ctime (Posix only) and st_mtime are updated close (flush), but not on opening or when written to. N)rHr-rr+rr&rr'ras r!check_open_write_close_non_w_modez2FakeStatTestBase.check_open_write_close_non_w_modeBs +/*?*?*A*A' &/::: '*:;;; $$W%5vGGG &/::: '*:;;; W-v??? &/::: '*:;;; (&/:::::rc:|\}}}}}||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|jdS)a When an existing file is opened with 'w' or 'w+' mode and is then written to, st_ctime (Posix only) and st_mtime are updated on open (truncating). Under Posix, st_mtime is updated on flush, under Windows, on close instead. N)rOr&rr-rr'rr+rrDrEr?rKr8s r#check_open_write_flush_close_w_modez4FakeStatTestBase.check_open_write_flush_close_w_modeVsh483H3H3J3J0& V_fo>>> W-w/?@@@ '*:;;; )6?;;; V_fo>>> '*:;;; W-w/?@@@ W-v??? 999 '*:;;; $$W%5w7GHHH W-v?????rc:|\}}}}}||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|jdS)z When an existing file is opened with 'a', 'a+' or 'r+' mode and is then written to, st_ctime and st_mtime are updated on flush under Posix. Under Windows, only st_mtime is updated on close instead. N)rOr-rr+rr&rrps r'check_open_write_flush_close_non_w_modez8FakeStatTestBase.check_open_write_flush_close_non_w_modensj 483H3H3J3J0& &/::: '*:;;; $$W%5w7GHHH )6?;;; &/::: '*:;;; W-w/?@@@ W-v??? &/::: '*:;;; $$W%5w7GHHH W-v?????r)__name__ __module__ __qualname__r r"r+r.r9r@rFrHrLrOrSrUrWrYr[r]r_rbrergrjrlrnrqrs __classcell__rs@rrrs         *** +++ ###((( * * * 3 3 3 3 3 3 < < < 9 9 9))) 0 0 0 < < <;;; ;;; ;;; ;;;(<<<(<<<&999&999 ;;;(@@@0@@@@@@@rrcHeZdZfdZdZdZdZdZdZdZ dZ xZ S) TestFakeModeWcVtd|_dS)Nwr r rrs rr zTestFakeModeW.setUp   rc.|dSr$rYrs rtest_open_close_new_filez&TestFakeModeW.test_open_close_new_file &&(((((rc.|dSr$r[rs rtest_open_write_close_new_filez,TestFakeModeW.test_open_write_close_new_file ,,.....rc.|dSr$r]rs rtest_open_closezTestFakeModeW.test_open_close $$&&&&&rc.|dSr$rbrs rtest_open_write_closez#TestFakeModeW.test_open_write_close **,,,,,rc.|dSr$rers rtest_open_flush_closez#TestFakeModeW.test_open_flush_closerrc.|dSr$rqrs rtest_open_write_flush_closez)TestFakeModeW.test_open_write_flush_close 0022222rc||jdd5}|t5|dddn #1swxYwYddddS#1swxYwYdS)Nr|r1r2r5r assertRaisesOSErrorrRrr>s rtest_read_raiseszTestFakeModeW.test_read_raises YYt~sVY < < ""7++                                   4A2A A2A A2!A "A22A69A6 rtrurvr rrrrrrrrwrxs@rrzrzs)))///'''------333rrzceZdZdZdS) TestRealModeWcdSNTrs rrzTestRealModeW.use_real_fstrNrtrurvrrrrrr#rrcNeZdZfdZdZdZdZdZdZdZ dZ d Z xZ S) TestFakeModeWPluscVtd|_dS)Nzw+r}rs rr zTestFakeModeWPlus.setUp   rc.|dSr$rrs rrz*TestFakeModeWPlus.test_open_close_new_filerrc.|dSr$rrs rrz0TestFakeModeWPlus.test_open_write_close_new_filerrc.|dSr$rlrs rtest_open_read_close_new_filez/TestFakeModeWPlus.test_open_read_close_new_file ++-----rc.|dSr$rrs rrz!TestFakeModeWPlus.test_open_closerrc.|dSr$rrs rrz'TestFakeModeWPlus.test_open_write_closerrcx|\}}}}||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|jdS)z When an existing file is opened with 'w+' mode and is then written to, st_ctime (Posix only) and st_mtime are updated on open (truncating) and again on close (flush). Under Posix, st_atime is updated on read. N)rWr+rr-r&rr'rris rtest_open_read_closez&TestFakeModeWPlus.test_open_read_closes (,';';'='=$f $$V_foFFF $-888 888 V_fo>>> V_dm<<< 888 999 $-888 88888rc.|dSr$rrs rrz'TestFakeModeWPlus.test_open_flush_closerrc.|dSr$rrs rrz-TestFakeModeWPlus.test_open_write_flush_closerr rtrurvr rrrrrrrrrwrxs@rrrs)))///...'''---999*---3333333rrceZdZdZdS)TestRealModeWPluscdSrrrs rrzTestRealModeWPlus.use_real_fsrrNrrrrrrrrrcHeZdZfdZdZdZdZdZdZdZ dZ xZ S) TestFakeModeAcVtd|_dS)Nar}rs rr zTestFakeModeA.setUpr~rc.|dSr$rrs rrz&TestFakeModeA.test_open_close_new_filerrc.|dSr$rrs rrz,TestFakeModeA.test_open_write_close_new_filerrc.|dSr$r_rs rrzTestFakeModeA.test_open_close ((*****rc.|dSr$rnrs rrz#TestFakeModeA.test_open_write_close ..00000rc.|dSr$rgrs rrz#TestFakeModeA.test_open_flush_closerrc.|dSr$rsrs rrz)TestFakeModeA.test_open_write_flush_close 4466666rc||jdd5}|t5|dddn #1swxYwYddddS#1swxYwYdS)Nrr1r2rrs rrzTestFakeModeA.test_read_raisesrrrrxs@rrrs)))///+++111111777rrceZdZdZdS) TestRealModeAcdSrrrs rrzTestRealModeA.use_real_fsrrNrrrrrrrrrcNeZdZfdZdZdZdZdZdZdZ dZ d Z xZ S) TestFakeModeAPluscVtd|_dS)Nza+r}rs rr zTestFakeModeAPlus.setUprrc.|dSr$rrs rrz*TestFakeModeAPlus.test_open_close_new_filerrc.|dSr$rrs rrz0TestFakeModeAPlus.test_open_write_close_new_filerrc.|dSr$rrs rrz/TestFakeModeAPlus.test_open_read_close_new_file rrc.|dSr$rrs rrz!TestFakeModeAPlus.test_open_close rrc.|dSr$rrs rrz'TestFakeModeAPlus.test_open_write_closerrc.|dSr$rjrs rrz&TestFakeModeAPlus.test_open_read_close --/////rc.|dSr$rrs rrz'TestFakeModeAPlus.test_open_flush_closerrc.|dSr$rrs rrz-TestFakeModeAPlus.test_open_write_flush_closerrrrxs@rrrs)))///...+++1110001117777777rrceZdZdZdS)TestRealModeAPluscdSrrrs rrzTestRealModeAPlus.use_real_fsrrNrrrrrrrrrc<eZdZfdZdZdZdZdZdZxZ S) TestFakeModeRcVtd|_dSNrQr}rs rr zTestFakeModeR.setUp#r~rc.|dSr$rrs rrzTestFakeModeR.test_open_close'rrc.|dSr$rrs rrz"TestFakeModeR.test_open_read_close*rrc.|dSr$rrs rrz#TestFakeModeR.test_open_flush_close-rrc:|\}}}}}||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|j||j|jdS)z When an existing file is opened with 'r' mode, read, flushed and closed, st_atime is updated after reading under Posix. N)rSr-rrr&r)rrDrErRrKr8s rtest_open_read_flush_closez(TestFakeModeR.test_open_read_flush_close0sd 150D0D0F0F-gv &/::: $-888 (8999 )6?;;; &/::: V_dm<<< (8999 )6?;;; &/::: $-888 (8999 )6?;;;;;rc|t5||jd5 dddn #1swxYwYddddS#1swxYwYdSrrrr5rrs rtest_open_not_existing_raisesz+TestFakeModeR.test_open_not_existing_raisesFs   w ' '  4>3//                                   3AA AA A A AA!$A!) rtrurvr rrrrrrwrxs@rrr"s+++000111<<<,rrceZdZdZdS) TestRealModeRcdSrrrs rrzTestRealModeR.use_real_fsMrrNrrrrrrLrrrcBeZdZfdZdZdZdZdZdZdZ xZ S)TestFakeModeRPluscVtd|_dSNzr+r}rs rr zTestFakeModeRPlus.setUpRrrc.|dSr$rrs rrz!TestFakeModeRPlus.test_open_closeVrrc.|dSr$rrs rrz'TestFakeModeRPlus.test_open_write_closeYrrc.|dSr$rrs rrz&TestFakeModeRPlus.test_open_read_close\rrc.|dSr$rrs rrz'TestFakeModeRPlus.test_open_flush_close_rrc.|dSr$rrs rrz-TestFakeModeRPlus.test_open_write_flush_closebrrc|t5||jd5 dddn #1swxYwYddddS#1swxYwYdSrrrs rrz/TestFakeModeRPlus.test_open_not_existing_raiseses   w ' '  4>400                                   r) rtrurvr rrrrrrrwrxs@rrrQs+++111000111777rrceZdZdZdS)TestRealModeRPluscdSrrrs rrzTestRealModeRPlus.use_real_fslrrNrrrrrrkrrr__main__)__doc__runittest collectionsrpyfakefs.tests.test_utilsrrrrzrrrrrrrrrrrrtmainrrrrs-, """"""444444 :j"@ A Ak@k@k@k@k@~k@k@k@\ $:M -3-3-3-3-3(-3-3-3`) $:M 77777(777<) '''''$'''TM (4)  zHMOOOOOr