bgWdZddlZddlZddlmZddlmZeddZGddeZGd 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 s/builddir/build/BUILD/cloudlinux-venv-1.0.7/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.assertLessExceptWindows1sC   *   . . . . . OOE5 ) ) ) ) )rcp|jr|||dS|||dSr$)r%r' assertEqualr(s rassertLessExceptPosixz&FakeStatTestBase.assertLessExceptPosix7sC   + OOE5 ) ) ) ) )   UE * * * * *rc>|5||j|j5||j}dddn #1swxYwY||j}||fcdddS#1swxYwYdSr$) mock_timeopenrrr"rcreatedcloseds ropen_close_new_filez$FakeStatTestBase.open_close_new_file=s ^^   # #4>4955 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|j5}||j}|d||j}dddn #1swxYwY||j}dddn #1swxYwY|||fSNfoo)r0r1rrr"write)rfr3writtenr4s ropen_write_close_new_filez*FakeStatTestBase.open_write_close_new_fileDs* ^^   4 44>4955 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|j5||j}dddn #1swxYwY||j}|||fcdddS#1swxYwYdSr$)r0 create_filerr"r1rrbeforeopenedr4s r open_closezFakeStatTestBase.open_closeNs< ^^   * *   T^ , , ,^^DN33F4>4955 8 877 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8^^DN33F66) * * * * * * * * * * * * * * * * * *s6AC*B CB CB !CC C c|5||j||j}||j|j5}||j}|d||j}dddn #1swxYwY||j}||||fcdddS#1swxYwYdSr7)r0r>rr"r1rr9)rr@r:rAr;r4s ropen_write_closez!FakeStatTestBase.open_write_closeYs_ ^^   3 3   T^ , , ,^^DN33F4>4955 977..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 3s7AC7*A C4 C7C C7C "C77C;>C;c|5||j||j}||j|j5}||j}|||j}dddn #1swxYwY||j}||||fcdddS#1swxYwYdSr$)r0r>rr"r1rflush)rr@r:rAflushedr4s ropen_flush_closez!FakeStatTestBase.open_flush_closefs] ^^   3 3   T^ , , ,^^DN33F4>4955 977 ..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 37AC6*A B?3 C6?C C6C "C66C:=C:cf|5||j||j}||j|j5}||j}|d||j}|||j}dddn #1swxYwY||j}|||||fcdddS#1swxYwYdSr7)r0r>rr"r1rr9rF)rr@r:rAr;rGr4s ropen_write_flushz!FakeStatTestBase.open_write_flushss ^^   < <   T^ , , ,^^DN33F4>4955 977..88 ..88  9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 ^^DN33F67GV; < < < < < < < < < < < < < < < < < rr"r1readrF)rr@r:rArOrGr4s ropen_read_flushz FakeStatTestBase.open_read_flushs} ^^   9 9   T^ , , ,^^DN33F4>3// 9177~~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 /C, 0#D  D$'D$c|5||j|j5}||j}|||j}dddn #1swxYwY||j}|||fcdddS#1swxYwYdSr$)r0r1rrr"rO)rr:r3rOr4s ropen_read_close_new_filez)FakeStatTestBase.open_read_close_new_files2 ^^   ) )4>4955 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 !CCCc|5||j||j}||j|j5}||j}|||j}dddn #1swxYwY||j}||||fcdddS#1swxYwYdSr$)r0r>rr"r1rrO)rr@r:rArOr4s ropen_read_closez FakeStatTestBase.open_read_closes] ^^   0 0   T^ , , ,^^DN33F4>4955 677~~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 0rIc|\}}||j|j||j|j||j|jdS)zq When a file is created on opening and closed again, no timestamps are updated on close. N)r5r-rrrr2s 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')rr3r;r4s 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)rBr+rr-r&rr'rr?s 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)rBr-rrrr?s 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)rDr+rr-r&rr'rrr@rAr;r4s 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)rHr+rr-r&rr'rrr@rArGr4s 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)rHr-rrrras 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)rTr-rrr&rrr@rArOr4s 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)rRr-rr&rr)rr3rOr4s rcheck_open_read_close_new_filez/FakeStatTestBase.check_open_read_close_new_file1s !% = = ? ?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)rDr-rr+rr&rr'r^s r!check_open_write_close_non_w_modez2FakeStatTestBase.check_open_write_close_non_w_modeAs +/*?*?*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)rKr&rr-rr'rr+rr@rAr;rGr4s r#check_open_write_flush_close_w_modez4FakeStatTestBase.check_open_write_flush_close_w_modeUsh483H3H3J3J0& 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)rKr-rr+rr&rrms r'check_open_write_flush_close_non_w_modez8FakeStatTestBase.check_open_write_flush_close_non_w_modemsj 483H3H3J3J0& &/::: '*:;;; $$W%5w7GHHH )6?;;; &/::: '*:;;; W-w/?@@@ W-v??? &/::: '*:;;; $$W%5w7GHHH W-v?????r)__name__ __module__ __qualname__r r"r+r.r5r<rBrDrHrKrPrRrTrVrXrZr\r_rbrdrgrirkrnrp __classcell__rs@rrrs         *** +++ ###((( * * * 3 3 3 3 3 3 < < < 9 9 9))) 0 0 0 < < <;;; ;;; ;;; ;;;(<<<(<<<&999&999 ;;;(@@@0@@@@@@@rrcHeZdZfdZdZdZdZdZdZdZ dZ xZ S) TestFakeModeWcdtt|d|_dSNw)r rwr rrs rr zTestFakeModeW.setUp* mT""((*** rc.|dSr$rVrs rtest_open_close_new_filez&TestFakeModeW.test_open_close_new_file &&(((((rc.|dSr$rXr~s rtest_open_write_close_new_filez,TestFakeModeW.test_open_write_close_new_file ,,.....rc.|dSr$rZr~s rtest_open_closezTestFakeModeW.test_open_close $$&&&&&rc.|dSr$r_r~s rtest_open_write_closez#TestFakeModeW.test_open_write_close **,,,,,rc.|dSr$rbr~s rtest_open_flush_closez#TestFakeModeW.test_open_flush_closerrc.|dSr$rnr~s rtest_open_write_flush_closez)TestFakeModeW.test_open_write_flush_close 0022222rc||jd5}|t5|dddn #1swxYwYddddS#1swxYwYdSryr1r assertRaisesOSErrorrOrr:s rtest_read_raiseszTestFakeModeW.test_read_raises YYt~s + + q""7++                                   4A0A A0A A0A A00A47A4 rqrrrsr rrrrrrrrtrus@rrwrws)))///'''------333rrwceZdZdZdS) TestRealModeWcdSNTr~s rrzTestRealModeW.use_real_fstrNrqrrrsrrrrrr#rrcNeZdZfdZdZdZdZdZdZdZ dZ d Z xZ S) TestFakeModeWPluscdtt|d|_dS)Nzw+)r rr rrs rr zTestFakeModeWPlus.setUp+ &&,,... rc.|dSr$r}r~s rrz*TestFakeModeWPlus.test_open_close_new_filerrc.|dSr$rr~s rrz0TestFakeModeWPlus.test_open_write_close_new_filerrc.|dSr$rir~s rtest_open_read_close_new_filez/TestFakeModeWPlus.test_open_read_close_new_file ++-----rc.|dSr$rr~s rrz!TestFakeModeWPlus.test_open_closerrc.|dSr$rr~s 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)rTr+rr-r&rr'rrfs rtest_open_read_closez&TestFakeModeWPlus.test_open_read_closes (,';';'='=$f $$V_foFFF $-888 888 V_fo>>> V_dm<<< 888 999 $-888 88888rc.|dSr$rr~s rrz'TestFakeModeWPlus.test_open_flush_closerrc.|dSr$rr~s rrz-TestFakeModeWPlus.test_open_write_flush_closerr rqrrrsr rrrrrrrrrtrus@rrrs)))///...'''---999*---3333333rrceZdZdZdS)TestRealModeWPluscdSrrr~s rrzTestRealModeWPlus.use_real_fsrrNrrrrrrrrrcHeZdZfdZdZdZdZdZdZdZ dZ xZ S) TestFakeModeAcdtt|d|_dSNa)r rr rrs rr zTestFakeModeA.setUpr{rc.|dSr$r}r~s rrz&TestFakeModeA.test_open_close_new_filerrc.|dSr$rr~s rrz,TestFakeModeA.test_open_write_close_new_filerrc.|dSr$r\r~s rrzTestFakeModeA.test_open_close ((*****rc.|dSr$rkr~s rrz#TestFakeModeA.test_open_write_close ..00000rc.|dSr$rdr~s rrz#TestFakeModeA.test_open_flush_closerrc.|dSr$rpr~s rrz)TestFakeModeA.test_open_write_flush_close 4466666rc||jd5}|t5|dddn #1swxYwYddddS#1swxYwYdSrrrs rrzTestFakeModeA.test_read_raisesrrrrus@rrrs)))///+++111111777rrceZdZdZdS) TestRealModeAcdSrrr~s rrzTestRealModeA.use_real_fsrrNrrrrrrrrrcNeZdZfdZdZdZdZdZdZdZ dZ d Z xZ S) TestFakeModeAPluscdtt|d|_dS)Nza+)r rr rrs rr zTestFakeModeAPlus.setUprrc.|dSr$r}r~s rrz*TestFakeModeAPlus.test_open_close_new_filerrc.|dSr$rr~s rrz0TestFakeModeAPlus.test_open_write_close_new_filerrc.|dSr$rr~s rrz/TestFakeModeAPlus.test_open_read_close_new_file rrc.|dSr$rr~s rrz!TestFakeModeAPlus.test_open_close rrc.|dSr$rr~s rrz'TestFakeModeAPlus.test_open_write_closerrc.|dSr$rgr~s rrz&TestFakeModeAPlus.test_open_read_close --/////rc.|dSr$rr~s rrz'TestFakeModeAPlus.test_open_flush_closerrc.|dSr$rr~s rrz-TestFakeModeAPlus.test_open_write_flush_closerrrrus@rrrs)))///...+++1110001117777777rrceZdZdZdS)TestRealModeAPluscdSrrr~s rrzTestRealModeAPlus.use_real_fsrrNrrrrrrrrrc<eZdZfdZdZdZdZdZdZxZ S) TestFakeModeRcdtt|d|_dSrM)r rr rrs rr zTestFakeModeR.setUp"r{rc.|dSr$rr~s rrzTestFakeModeR.test_open_close&rrc.|dSr$rr~s rrz"TestFakeModeR.test_open_read_close)rrc.|dSr$rr~s 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)rPr-rrr&r)rr@rArOrGr4s rtest_open_read_flush_closez(TestFakeModeR.test_open_read_flush_close/sd 150D0D0F0F-gv &/::: $-888 (8999 )6?;;; &/::: V_dm<<< (8999 )6?;;; &/::: $-888 (8999 )6?;;;;;rc|t5||jd5 dddn #1swxYwYddddS#1swxYwYdSrMrrr1rr~s rtest_open_not_existing_raisesz+TestFakeModeR.test_open_not_existing_raisesEs   w ' '  4>3//                                   3AA AA A A AA!$A!) rqrrrsr rrrrrrtrus@rrr!s+++000111<<<,rrceZdZdZdS) TestRealModeRcdSrrr~s rrzTestRealModeR.use_real_fsLrrNrrrrrrKrrrcBeZdZfdZdZdZdZdZdZdZ xZ S)TestFakeModeRPluscdtt|d|_dSNzr+)r rr rrs rr zTestFakeModeRPlus.setUpQrrc.|dSr$rr~s rrz!TestFakeModeRPlus.test_open_closeUrrc.|dSr$rr~s rrz'TestFakeModeRPlus.test_open_write_closeXrrc.|dSr$rr~s rrz&TestFakeModeRPlus.test_open_read_close[rrc.|dSr$rr~s rrz'TestFakeModeRPlus.test_open_flush_close^rrc.|dSr$rr~s rrz-TestFakeModeRPlus.test_open_write_flush_closearrc|t5||jd5 dddn #1swxYwYddddS#1swxYwYdSrrr~s rrz/TestFakeModeRPlus.test_open_not_existing_raisesds   w ' '  4>400                                   r) rqrrrsr rrrrrrrtrus@rrrPs+++111000111777rrceZdZdZdS)TestRealModeRPluscdSrrr~s rrzTestRealModeRPlus.use_real_fskrrNrrrrrrjrrr__main__)__doc__runittest collectionsrpyfakefs.tests.test_utilsrrrrwrrrrrrrrrrrrqmainrrrrs-, """"""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