a zeO@sddlZddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z m Z mZmZmZmZddlmZddlZddlZGdddZGd d d eejZGd d d eejZGd ddZGdddeejZGdddeejZddZedkredS)N)array)proxywraps)TESTFNTESTFN_UNICODEcheck_warnings make_bad_fd cpython_only swap_attr gc_collect)UserListc@szeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zeejd)kd*d+d,Zd-d.Zd/d0Zed1d2Zed3d4Zed5d6Z ed7d8Z!ed9d:Z"ed;d<Z#ed=d>Z$ed?d@Z%edAdBZ&edCdDZ'dEdFZ(edGdHZ)edIdJZ*edKdLZ+dMS)N AutoFileTestscCs|td|_dSNw)FileIOrfselfrD/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_fileio.pysetUpszAutoFileTests.setUpcCs|jr|jttdSN)rcloseosremoverrrrrtearDowns zAutoFileTests.tearDowncCs\t|j}|ttd||j||jd|_t| t t |ddS)N tell) rrwritebytesrange assertEqualrrr assertRaisesReferenceErrorgetattr)rprrr testWeakRefss  zAutoFileTests.testWeakRefscCs|jttd||jd|jd||jd|jd||jd|jdd||jd|jdd||jd|jdd||jddS) Nrr)rrr r!r"rseekrrrr testSeekTell)s  zAutoFileTests.testSeekTellcCsF|j}||jd||jddD]}|ttft||dq&dS)NwbF)modeclosedZoops)rr"r1r2r#AttributeError TypeErrorsetattr)rrattrrrrtestAttributes7s zAutoFileTests.testAttributescCs@tj}ttdr,t|j}t|d|}||jj |dS)Nfstat st_blksize) ioDEFAULT_BUFFER_SIZEhasattrrr8rfilenor%r"_blksize)rZblksizeZfstrrr testBlksizeCs   zAutoFileTests.testBlksizecCsx|jtgd|jtd}|td}||}Wdn1sR0Y||d||ddS)Nr*r-rabcdefghrefgh) rrr r bytearrayrrreadintor")rZbarnrrrtestReadintoByteArrayMs ( z#AutoFileTests.testReadintoByteArraycCs|jtgd|jttd}|td}||}Wdn1sV0Y| |d| |dttdj dddgd}|td}||}Wdn1s0Y| t|d| |ddS) Nr@rBrCrDrEHr-)shape) rrr r memoryviewrFrrrGr"cast)rmrrHrrr_testReadintoMemoryviewWs  (  (z%AutoFileTests._testReadintoMemoryviewcCsF|jtgd|jtdd}|td}||}Wdn1sT0Y||tdgd||dtdd}|td}||}Wdn1s0Y||tdgd||dtd d}|td}||}Wdn1s0Y||td d ||ddS) Nr@BrBrC)r*r-rrAefghrEb)r*r-rrQrRrSrTIrD) rrr rrrrrGr")rarrHrrr_testReadintoArraygs"  (  (  *z AutoFileTests._testReadintoArraycCsFddg}|j||j|td|_|j}||ddSNs123s456rbs123456)r writelinesrrrreadr"rlbufrrrtestWritelinesList}s    z AutoFileTests.testWritelinesListcCsJtddg}|j||j|td|_|j}||ddSrZ)r rr\rrrr]r"r^rrrtestWritelinesUserLists     z$AutoFileTests.testWritelinesUserListcCs>|t|jjgd|t|jjd|t|jjddS)N)r*r-abc)r#r4rr\rrrrtestWritelinesErrorsz!AutoFileTests.testWritelinesErrorcCst|jd|j|td|_||jdd|jd||jdd||j dddgdS)Ns hi bye abcrCrshi sbye abc) rrrrrr"r]r.readline readlinesrrrrtest_none_argss   zAutoFileTests.test_none_argscCs|t|jjddS)NzHello!)r#r4rrrrrr test_rejectszAutoFileTests.test_rejectcCs||t|jd|j|jj|jjf|j`|t|jd|j|j|jjf|j|t|jd|jfdS)Nz(<%s.FileIO name=%r mode=%r closefd=True>z&<%s.FileIO fd=%r mode=%r closefd=True>z<%s.FileIO [closed]>)r"reprr modulenamenamer1r=rrrrrtestReprs     zAutoFileTests.testReprc Cs~tttj}z^|j|ddd0}|t|d|j|j|j fWdn1sV0YWt |n t |0dS)NrCF)closefdz)<%s.FileIO name=%r mode=%r closefd=False>) ropenrO_RDONLYrr"rkrlrmr1r)rfdrrrrtestReprNoCloseFDs $zAutoFileTests.testReprNoCloseFDc Csht|jd|jD|tt|jWdn1s<0YWdn1sZ0YdS)Nrm)r rr# RuntimeErrorrkrrrrtestRecursiveReprs zAutoFileTests.testRecursiveReprcCs|j}||||j|t|jd|||j| t d}|t |j d||j|||jdS)NrrC) rZ assertFalseisattyr2r# ValueErrorr]r assertTruerrr4rGrrrrr testErrorss    zAutoFileTests.testErrorscCsgd}|j||jj|D]}t|j|}|t|q$|t|jj|t|jjt d|t|jj |t|jj d|t|jj |t|jj d|t|jj |t|jj ddS)N) r=rwseekablereadablewritabler]readallrgrhrtruncateflushr*r) rrryr2r%r#rxr4rGrFr.rr\)rmethodsZ methodnamemethodrrr testMethodss  zAutoFileTests.testMethodsc Cs`z|ddWn@tyP}z(||jd||jdWYd}~nd}~00|ddS)N.rCrShould have raised OSError)rOSErrorassertNotEqualerrnor"filenamefail)rerrr testOpendirs $zAutoFileTests.testOpendirntz&test only works on a POSIX-like systemcCsdtdtj}|t}||dWdn1s:0Yt|||jj t j dS)NrrC) rrprqr#rrrr" exceptionrZEISDIR)rrrcmrrr testOpenDirFDs  * zAutoFileTests.testOpenDirFDcstfdd}|S)Ncsn|j}t|z0||Wz|jWqjtyBYqj0n$z|jWntyfYn00dSr)rrrr=rrzfuncrrwrappers   z'AutoFileTests.ClosedFD..wrapperrrrrrrClosedFDs zAutoFileTests.ClosedFDcstfdd}|S)Ncs|j}t|ztz||Wn4tyX}z||jtjWYd}~nd}~00|dWz|jWqtyYq0n$z|jWntyYn00dS)Nr) rrrr=rr"rEBADFr)rrrrrrrs&   z-AutoFileTests.ClosedFDRaises..wrapperrrrrrClosedFDRaisesszAutoFileTests.ClosedFDRaisescCs |dSr)rrzrrrtestErrnoOnCloseszAutoFileTests.testErrnoOnClosecCs|ddS)Na)rrzrrrtestErrnoOnClosedWritesz$AutoFileTests.testErrnoOnClosedWritecCs|ddSNr)r.rzrrrtestErrnoOnClosedSeeksz#AutoFileTests.testErrnoOnClosedSeekcCs |dSr)rrzrrrtestErrnoOnClosedTell"sz#AutoFileTests.testErrnoOnClosedTellcCs|ddSr)rrzrrrtestErrnoOnClosedTruncate&sz'AutoFileTests.testErrnoOnClosedTruncatecCs |dSr)r|rzrrrtestErrnoOnClosedSeekable*sz'AutoFileTests.testErrnoOnClosedSeekablecCs |dSr)r}rzrrrtestErrnoOnClosedReadable.sz'AutoFileTests.testErrnoOnClosedReadablecCs |dSr)r~rzrrrtestErrnoOnClosedWritable2sz'AutoFileTests.testErrnoOnClosedWritablecCs |dSr)r=rzrrrtestErrnoOnClosedFileno6sz%AutoFileTests.testErrnoOnClosedFilenocCs||ddS)NF)r"rwrzrrrtestErrnoOnClosedIsatty:sz%AutoFileTests.testErrnoOnClosedIsattycCsFz|jWnty Yn0|td|_t|j|jS)NrC)rrrrrrr=rrrr ReopenForRead>s zAutoFileTests.ReopenForReadcCs|}|ddS)Nr*)rr]rzrrrtestErrnoOnClosedReadGsz#AutoFileTests.testErrnoOnClosedReadcCs|}|dSr)rrrzrrrtestErrnoOnClosedReadallLsz&AutoFileTests.testErrnoOnClosedReadallcCs |}tdd}||dS)NrUs xxxxxxxxxx)rrrG)rrrXrrrtestErrnoOnClosedReadintoQs z'AutoFileTests.testErrnoOnClosedReadintoN),__name__ __module__ __qualname__rrr'r/r7r?rIrOrYrarbrerirjrnrsrur{rrunittestskipIfrrmrrrrrrrrrrrrrrrrrrrrrrsf                      rc@seZdZejZdZdS)CAutoFileTests_ioN)rrrrrrlrrrrrWsrc@seZdZejZdZdS)PyAutoFileTests_pyioN)rrrrrrlrrrrr[src@seZdZddZddZddZddZd d Ze e d kd d dZ ddZ ddZddZddZddZddZddZddZdd Zd!S)"OtherFileTestsc Csz|td}||d||d||d||td}||d||d||d||td}||d||d||d||d|tj dkrz|dd}Wnt yYnp0||d||dtj d krhd tj vrhtj d sh||d||d|Wt tn t t0dS) NrFTrCza+win32z/dev/ttyrXdarwinZbsd)ZsunosZaix)rrr"r}r~r|rrwsysplatformr startswithrunlinkrzrrr testAblesbsB       zOtherFileTests.testAblesc CsHdD]>}z|t|}Wnty*Yq0||d|qdS)N)rvZaUzwU+rwrtz%r is an invalid file mode)rrrxrr)rr1rrrrtestInvalidModeStringss z%OtherFileTests.testInvalidModeStringsc CszfdD]F}|t|d"}||j|dWdq1sB0YqWtjtrttntjtr~tt0dS)N) )rr0)r0r0)zwb+rb+)zw+br)rXab)rr)ab+r)za+br)rCr[)r[r[)rr)zr+brrr*)rrr"r1rpathexistsr)rZmodesrrrrtestModeStringss4  zOtherFileTests.testModeStringscCs&|ttd}|ttdSr)rstrrrrrrzrrrtestUnicodeOpenszOtherFileTests.testUnicodeOpenc Csztd}Wn ty.|dtYn0||d}zZ|d|ttd }|| dWdn1s0YWt tn t t0dS)Nasciizcould not encode %r to asciirrfr[) rencodeUnicodeEncodeErrorskipTestrrrrpr"r]rrrfnrrrr testBytesOpens    0zOtherFileTests.testBytesOpenutf-8z%test only works for utf-8 filesystemsc Csztd}Wn ty.|dtYn0||d}zZ|d|ttd }|| dWdn1s0YWt tn t t0dS)Nrzcould not encode %r to utf-8rrfr[) rrrrrrrrpr"r]rrrrrrtestUtf8BytesOpens    0z OtherFileTests.testUtf8BytesOpencCs2d}|t|j|d|t|jt|dddS)Nzfoobarrr)r#rxrr )rZ fn_with_NULrrrtestConstructorHandlesNULCharssz-OtherFileTests.testConstructorHandlesNULCharscCsJ|t|jd|t|jttjdkrFddl}|t|jtdS)Nirr) r#rxrrr rrmsvcrtZ get_osfhandle)rrrrr testInvalidFds  zOtherFileTests.testInvalidFdc Csd}z|t|}WnXtyl}z@|jddkrXt|}t|vsJ||vrX|d|WYd}~n d}~00||d|dS)NZqwertyrz&bad error message for invalid mode: %szno error for invalid mode: %s)rrrxargsrrr)rZbad_modermsgsrrrtestBadModeArguments$z"OtherFileTests.testBadModeArgumentcCs|td}|tttd||d|d||d|| dt j d|d||d|| dt j d| dS)Nrrr)rr+) rrrr rFr!r"rrr.r:SEEK_ENDrrzrrr testTruncates   zOtherFileTests.testTruncatec s2fdd}z|Wttn tt0dS)Ncstd}|ttd|td}|d}|ttdkrZd||dkrxd|| |dkrd||t j t}|dkrȈd|dS) Nr zr+r)z(Read on file opened for update failed %rzFile pos after read wrong %dz!File pos after ftruncate wrong %dz"File size after ftruncate wrong %d) rrrr r!rr]rrrrrgetsize)rdatasizerrr bug801631s       z7OtherFileTests.testTruncateOnWindows..bug801631)rrr)rrrrrtestTruncateOnWindowss z$OtherFileTests.testTruncateOnWindowsc Csz~ttd}|d|ttd}|d|ttd}|}|||dWzttWqYq0nzttWn Yn00dS)Nr0sspamrseggsr[sspameggs)rprrrr]r"rr)rrdrrr testAppends&     zOtherFileTests.testAppendcCs|t|jddddS)N1r)r#r4rrrrrtestInvalidInit#szOtherFileTests.testInvalidInitcCsztdd\}||jg|t|jg||jg|t|jdd||jgWdn1sl0YdS)NTquietz/some/invalid/namer)rr"warningsr#r4rrx)rrrrr testWarnings&s  zOtherFileTests.testWarningscsRGdddtGfddd|jtttj}||t|dS)Nc@s eZdZdS)z=OtherFileTests.testUnclosedFDOnException..MyExceptionN)rrrrrrr MyException/rrcs eZdZfddZZS)z:OtherFileTests.testUnclosedFDOnException..MyFileIOcs"|dkrdt|||S)Nrmzblocked setting name)super __setattr__)rrmvalue)rMyFileIO __class__rrr1szFOtherFileTests.testUnclosedFDOnException..MyFileIO.__setattr__)rrrr __classcell__rrr)rrr0sr) Exceptionrrrp__file__rqr#r)rrrrrrtestUnclosedFDOnException.s z(OtherFileTests.testUnclosedFDOnExceptionN)rrrrrrrrrrrgetfilesystemencodingrrrrrrrrrrrrrrr`s$*   rc@s*eZdZejZdZeddZddZdS)COtherFileTestsrcCs8ddl}|t|j|jd|t|j|jddS)Nrr*) _testcapir#r4rZINT_MAXZINT_MIN)rrrrrtestInvalidFd_overflow>sz&COtherFileTests.testInvalidFd_overflowcCsv|td}|}Wdn1s*0Ytt}|}Wdn1s\0Y|||dS)Nr[)rrr]r open_coder")rrexpectedactualrrrtest_open_codeEs & &zCOtherFileTests.test_open_codeN) rrrrrrlr rrrrrrr:s  rc@seZdZejZdZddZdS)PyOtherFileTestsrc Cs|td}|}Wdn1s*0Ytdd\}tt}|}Wdn1sh0Y|||||jgWdn1s0YdS)Nr[Tr) rrr]rrZ_open_code_with_warningr"rr)rrrrrrrrrSs&  & zPyOtherFileTests.test_open_codeN)rrrrrrlrrrrrrOsrcCstjtrttdSr)rrrrrrrrrtearDownModule`s r__main__) rrr:rrrweakrefr functoolsrZ test.supportrrrr r r r collectionsr rrrZTestCaserrrrrrrmainrrrrs.   $ E[