a ze@s<ddlZddlmZddlZddlZddlZddlZddlZddlm Z m Z m Z e dZ eee ddZeee ddZGdd d ejZGd d d ejZGd d d ejZGdddejZGdddeZGdddeejZGdddeejZdefddZdZGdddZe dkr8e!dS)N)support) bigmemtest_1G_4Gzlibcopyzrequires Compress.copy()zrequires Decompress.copy()c@seZdZddZdS)VersionTestCasecCs|tjdtjddS)Nr) assertEqualrZLIB_RUNTIME_VERSION ZLIB_VERSIONselfrB/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_zlib.pytest_library_versionsz$VersionTestCase.test_library_versionN)__name__ __module__ __qualname__rrrrrrsrc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)ChecksumTestCasecCs0|tdtdd|tdddS)Nrabc)r rcrc32 assertTruer rrrtest_crc32start!sz ChecksumTestCase.test_crc32startcCs@|tddd|tddd|tddddSNrri)r rrr rrrtest_crc32empty%sz ChecksumTestCase.test_crc32emptycCs0|tdtdd|tdddS)Nrrrr)r radler32rr rrrtest_adler32start*sz"ChecksumTestCase.test_adler32startcCs@|tddd|tddd|tddddSr)r rrr rrrtest_adler32empty.sz"ChecksumTestCase.test_adler32emptycCs|tddd|tddd|tddd|tddd|tdtdd|tdtdddS)Nspenguinrl !KriCi i r rrrr rrr test_penguins3s zChecksumTestCase.test_penguinscCsTd}|t|d|tdd|t||d|tdddS)Nabcdefghijklmnop@u(spami=Cl *iOr!)r foorrrtest_crc32_adler32_unsigned<s z,ChecksumTestCase.test_crc32_adler32_unsignedcCsHd}d}|t|||t|||tdtddS)Nr#r$r%)r binasciirr)r r&crcrrrtest_same_as_binascii_crc32Ds z,ChecksumTestCase.test_same_as_binascii_crc32N) rrrrrrr r"r'r*rrrrrs rc@s&eZdZeeddddddZdS)ChecksumBigBufferTestCaserF)sizememusedry_runcCs4dtd}|t|d|t|ddS)NsnyanriM"B>la )rr rrr)r r-datarrrtest_big_bufferOs z)ChecksumBigBufferTestCase.test_big_bufferN)rrrrrr1rrrrr+Msr+c@sBeZdZddZddZddZddZd d Zej d d Z d S)ExceptionTestCasecCs|tjtjdddS)NsERROR ) assertRaisesrerrorcompressr rrr test_badlevelXszExceptionTestCase.test_badlevelcCs|ttj|ttj|ttj|ttjdddddgfD]D}|ttj||ttj||ttj||ttj|qHdS)N*abcr)r4 TypeErrorrrrr6 decompress)r argrrr test_badargs^szExceptionTestCase.test_badargscCs6|ttjdtjd|ttjdtjtjddS)Nrr)r4 ValueErrorr compressobjDEFLATED MAX_WBITSr rrrtest_badcompressobjisz%ExceptionTestCase.test_badcompressobjcCs|ttjddS)N)r4r?r decompressobjr rrrtest_baddecompressobjpsz'ExceptionTestCase.test_baddecompressobjcCs,|ttjd|ttjddS)NrrD)r4r?rrEflushr rrrtest_decompressobj_badflushtsz-ExceptionTestCase.test_decompressobj_badflushcCs|td$tddtjdWdn1s60Y|td&tdtjdWdn1sx0Y|td$ttjdWdn1s0YdS)Nz int too largerr)assertRaisesRegex OverflowErrorrr<sysmaxsizerErGr rrr test_overflowys 24zExceptionTestCase.test_overflowN) rrrr7r>rCrFrHrZ cpython_onlyrNrrrrr2Vs r2c@seZdZddZddZdS)BaseCompressTestCasecCsBd}t|d}||t|d}z||Wd}nd}0dS)Nr3r)random randbyteslen)r r-Z compress_funcZ_1Mr0rrrcheck_big_compress_buffers  z.BaseCompressTestCase.check_big_compress_buffercCsfd|}zt|d}Wd}nd}0||}z.|t|||t|ddWd}nd}0dS)Nxrr)rr6r rSstrip)r r-Zdecompress_funcr0 compressedrrrcheck_big_decompress_buffers z0BaseCompressTestCase.check_big_decompress_bufferN)rrrrTrXrrrrrOs rOc@seZdZddZddZddZddZeed d d d d Z eed dd ddZ ee dd ddZ ddZ eejdkdee ddd ddZdS)CompressTestCasecCs tt}|t|tdSN)rr6 HAMLET_SCENEr r<r xrrr test_speechs zCompressTestCase.test_speechcCsxtjtdd}|t|t|ttjtddWdn1sN0Y|tj|tjtjdtdS)N)level)r0r`)wbitsbufsize) rr6r[r r<r4r;rB DEF_BUF_SIZEr\rrr test_keywordss , zCompressTestCase.test_keywordscCsPtd}t|}|tt|||t|fD]}|t||q4dSN)r[rr6r bytearrayr<)r r0r]obrrrtest_speech128s  zCompressTestCase.test_speech128cCs*tt}|tjdtj|dddS)NzAError -5 while decompressing data: incomplete or truncated streamrD)rr6r[rJr5r<r\rrrtest_incomplete_streams  z'CompressTestCase.test_incomplete_streamrPr_r-r.cCsdd}|||dS)NcSs t|dSNr)rr6srrrrz;CompressTestCase.test_big_compress_buffer..)rTr r-r6rrrtest_big_compress_buffersz)CompressTestCase.test_big_compress_buffercCs||tjdSrZ)rXrr<)r r-rrrtest_big_decompress_buffersz+CompressTestCase.test_big_decompress_bufferrcCs.td}t|d}|t|d||dSNr3rrI)r[rr6r r<)r r-r0rWrrrtest_large_bufsizes z#CompressTestCase.test_large_bufsizecCs0td}t|d}|t|dt|dSrt)r[rr6r r< CustomInt)r r0rWrrrtest_custom_bufsizes z$CompressTestCase.test_custom_bufsizerequires 64bit platformdr,cCsBd|}z*t|d}|t||Wd}}n d}}0dSNrUr)rr6r r<)r r-r0comprrrtest_64bit_compresss  z$CompressTestCase.test_64bit_compressN)rrrr^rdrirjrrrqrsrrurwunittest skipUnlessrLrMr}rrrrrYs      rYc@seZdZddZddZddZddZd]d dZddZd^ddZ d_ddZ ddZ ddZ ddZ ddZddZdd Zeeed!d"d#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zee d7d8d9d:Z!d;d<Z"e#d=d>Z$e#d?d@Z%e&dAdBZ'e&dCdDZ(dEdFZ)dGdHZ*ee+dIdJd8dKdLZ,ee+dIdMd8dNdOZ-ee.j/dPkdQee dRdSd8dTdUZ0ee.j/dPkdQee dRdJd8dVdWZ1ee.j/dPkdQee dRdXd8dYdZZ2d[d\Z3d S)`CompressObjectTestCasec Cstd}t|}|t|fD]>}t}||}|}|tj|j||||q||ft|t|ffD]R\}}t } | ||} | } ||| | | | j t | | jt qvdSre)r[rr6rgr@rGr4r5r rEr<assertIsInstanceunconsumed_tailbytes unused_data) r ZdatasrcZdatazipr0cox1x2Zv1Zv2dcoy1y2rrr test_pairs   z CompressObjectTestCase.test_pairc Csd}tj}d}d}tj}tj|||||dd}tj|dd}|t|jtdWdn1sh0Y|t"|j ttdWdn1s0Y|t| }|j |t td| } | t| dS) Nrr r)r`methodramemLevelstrategyzdictrar)r0) max_length) rrA Z_FILTEREDr@rEr4r;r6r[r<rGrSr ) r r`rrarrrdor]yrrrrds( * 0z$CompressObjectTestCase.test_keywordsc Cspd}tj}d}d}tj}t|||||}|t}|}t|} | ||} | } | t| | dS)Nrrrr) rrArr@r6r[rGrEr<r ) r r`rrarrrrrrrrrrrtest_compressoptions s  z+CompressObjectTestCase.test_compressoptionsc Cstd}t}g}tdt|dD] }|||||dq$||d|}t }| d|}|}| |||dS)Nrfrr) r[rr@rangerSappendr6rGjoinrEr<r ) r r0rbufsicombufrrrrrrtest_compressincrementals z/CompressObjectTestCase.test_compressincrementalFNr@c Csf|pt}|d}t}g}tdt||D] }||||||q,||d|} t | } | | t | || t } g}tdt| |D]H}|| | |||| d| jdt| j| d| jq|r|| n$| d} | r(|| nq(q| d| jdt| j| d| j| |d|dS)Nrfrrz"(A) uct should be b'': not %d longz"(B) uct should be b'': not %d long)r[rr@rrSrr6rGrr<rrr rErr) r rGsourcecxdcxr0rrrrZdecombufrchunkrrrtest_decompinc*sD        z%CompressObjectTestCase.test_decompinccCs|jdddSNT)rG)rr rrrtest_decompincflushSsz*CompressObjectTestCase.test_decompincflushc Cs|pt}|d}t}g}tdt||D] }||||||q,||d|}| |t |dt } g}|} | r| | |} | t| |kdt| |f|| | j } q|| | |d|ddS)Nrfrrcompressed data failurechunk too big (%d>%d)Wrong data retrievedr[rr@rrSrr6rGrr r<rE assertFalser) r rrrr0rrrrrcbrrrrtest_decompimaxVs.   z&CompressObjectTestCase.test_decompimaxc Cs>td}t}g}tdt|dD] }|||||dq$||d|}| |t |dt }g}|}|rdt|d} | || } | t| | kdt| | f|| |j }q|r||n>| r&| d| } | t| | kdt| | f|| q| |d|d dS) Nrfrrrrrr3rrr) r rGr0rrrrrrrrrrrtest_decompressmaxlenqs<     z,CompressObjectTestCase.test_decompressmaxlencCs|jdddSr)rr rrrtest_decompressmaxlenflushsz1CompressObjectTestCase.test_decompressmaxlenflushcCs,t}|t|jdd|d|jdS)NrrD)rrEr4r?r<r r)r rrrrtest_maxlenmiscsz&CompressObjectTestCase.test_maxlenmisccCsHtd}|t|tjt|d}t}|||t j |dSNr3r) r[Z assertGreaterrSrrcr6rEr r<rLrMr r0rWrrrrtest_maxlen_larges  z(CompressObjectTestCase.test_maxlen_largecCs>td}t|d}t}|||t|dddS)Nr3rrz)r[rr6rEr r<rvrrrrtest_maxlen_customs z)CompressObjectTestCase.test_maxlen_customcCs:d}t}||d}|||j7}||jddS)Ns xKLJMrr)rrEr<rr )r ZcdatarZddatarrrtest_clear_unconsumed_tails  z1CompressObjectTestCase.test_clear_unconsumed_tailc Csgd}tddtjdD}|dkr4|ddd|D}td }|D]}td D]}zDt|}||dd }| |}||d d} | } Wnt d ||Yn0| t d ||| | g|d||f~qZqNdS)N) Z_NO_FLUSH Z_SYNC_FLUSH Z_FULL_FLUSHZ_PARTIAL_FLUSHcss|]}t|VqdSrZ)int).0vrrr rz6CompressObjectTestCase.test_flushes...)rrrr_Z_BLOCKcSs g|]}tt|rtt|qSr)hasattrrgetattr)roptrrr s z7CompressObjectTestCase.test_flushes..r3i z!Error for flush mode={}, level={}rz*Decompress failed: flush mode=%i, level=%i)tuplerr splitrr[rr@r6rGprintformatr r<r) r Zsync_optverr0syncr`objabcdrrr test_flushess2     z#CompressObjectTestCase.test_flushesrzrequires zlib.Z_SYNC_FLUSHc Csddl}ttj}t}z |}Wn6ty^z |}WntyX|}Yn0Yn0|d| d}| |}| tj }| ||}|||ddS)NrriDz17K random source doesn't match)rQrr@Z_BEST_COMPRESSIONrEZ WichmannHillAttributeErrorRandomseedrRr6rGrr<r ) r rQrrgenr0firstsecondZexpandedrrrtest_odd_flushs          z%CompressObjectTestCase.test_odd_flushcCs6ttj}||t}||ddS)Nr)rr@rrrGrEr )r rrrrrtest_empty_flushs z'CompressObjectTestCase.test_empty_flushcCst}|}t|d|}tj|d}|||}tj |d}| | |||t }| tj |j |dS)Nrr)r[rrQshufflerrr@r6rGrEr r<r4r5)r hwordsrrZcdrrrrtest_dictionarys    z&CompressObjectTestCase.test_dictionarycCstjtd}tjtd}tdd}|||tj}||dd|tj}||dd|tj}||||||||dd||||dddS)Nrirzi) rr@r[rEr6rGrr r<)r rrZpieced0d1Zd2rrrtest_dictionary_streamings   z0CompressObjectTestCase.test_dictionary_streamingcCsfd}|t|d|tjtj|ddt}||dd}||7}||ddS)N xKEsfoo)r rr<r4r5rErG)r r]rrrrr!test_decompress_incomplete_streams z8CompressObjectTestCase.test_decompress_incomplete_streamcCsld}t}||j||dd||j||dd||j|||jdSNrr)rrEreofr<rrGr r]rrrrtest_decompress_eof(s   z*CompressObjectTestCase.test_decompress_eofcCsNd}t}||j||dd||j|||jdSr)rrErrr<rGrrrr%test_decompress_eof_incomplete_stream3s  z.r)r[rstrswapcaserdeepcopyrr@rrr6rGrr r<) r Zdata0Zdata1funcZc0bufs0c1bufs1s0s1rrrtest_compresscopy{s     z(CompressObjectTestCase.test_compresscopycCsLt}|t||t|j|ttj||ttj|dSrZ) rr@r6r[rGr4r?rr)r rrrrtest_badcompresscopys  z+CompressObjectTestCase.test_badcompresscopyc Cst}t|}||tddtjtjfD]}t}g}|| |dd||}|dd}|| |ddd |}|| |ddd |} | || | ||q,dS)NcSs|SrZrrrrrrorz. r) r[rr6rrrrrErr<rr ) r r0r|rrrrrrrrrrtest_decompresscopys      z*CompressObjectTestCase.test_decompresscopycCsVtt}t}||||t|j|ttj||ttj |dSrZ) rr6r[rEr<rGr4r?rr)r r0rrrrtest_baddecompresscopys  z-CompressObjectTestCase.test_baddecompresscopyc Cs\ttjdD]H}|ttjf$tttj |Wdq1sL0YqdSrl) rpickleHIGHEST_PROTOCOLr4r; PicklingErrordumpsrr@rr protorrrtest_compresspicklesz*CompressObjectTestCase.test_compresspicklec CsXttjdD]D}|ttjf tt|Wdq1sH0YqdSrl) rr r r4r;r r rrEr rrrtest_decompresspicklesz,CompressObjectTestCase.test_decompresspicklerPr_cs&tdfdd}|||dS)Nrcs|SrZ)r6rGrmrrrrorzACompressObjectTestCase.test_big_compress_buffer..)rr@rTrprrrrqs  z/CompressObjectTestCase.test_big_compress_bufferrrcs$tfdd}|||dS)Ncs|SrZ)r<rGrmrrrrorzCCompressObjectTestCase.test_big_decompress_buffer..)rrErX)r r-r<rrrrss z1CompressObjectTestCase.test_big_decompress_bufferrxryrzr,cCsnd|}td}t}z@|||}|||}|||Wd}}}nd}}}0dSr{)rr@rEr6rGr<r )r r-r0rrr|rrrrr}s z*CompressObjectTestCase.test_64bit_compresscCsrd}d|}t||}t}z<|||}|||j|||Wd}}}nd}}}0dS)Nr#rU)rr6rEr<rGr r)r r-r0Zunusedr|rrrrrtest_large_unused_datasz-CompressObjectTestCase.test_large_unused_datarcCsnd|}t}zJt|d}||d|}|||||jdWd}}}nd}}}0dS)NrUrrr)rrEr6r<rGr r)r r-r0rr|rrrrtest_large_unconsumed_tails  z1CompressObjectTestCase.test_large_unconsumed_tailc Cs tjdddd}t|dkr0|dn|dsDd|d<ttt|}|dk}tj dd d }| t | }| t|d t |r| t|dt | t|d t |tjd t|d Wdn1s0Ytjd d}| ||t tjd d}|tjd ||Wdn1sN0Ytj ddd }| t | }| t|dt | t|d t |r| t|dt | t|dt tjdd}| ||t tj ddd }| t | }| t|dt tjdd}| ||t tj ddd }| t | }| t|dt | t|dt tjdd}| ||t tj ddd }| t | } | t| dt | t| d t td }| || t dS)N-rrrr,0rD)rrrr_rrI)r`ra/zinvalid window size)rar)ii)rr rrSr isnumericrmaprr@r6r[rGr r<rJr5rE) r rZsupports_wbits_0rZzlib15rZzlib9Z deflate15Zdeflate9gziprrr test_wbitss\   *  *    z!CompressObjectTestCase.test_wbits)FNrr)Nrr)F)4rrrrrdrrrrrrrrrrrrr~rrrrrrrrrrrrrrrrrrequires_Compress_copyrrrequires_Decompress_copyrrrrrrqrsrLrMr}rrrrrrrrsl )                      rcs4|dur||dfddt|DS)z=Return a list of number lines randomly chosen from the sourceN csg|]}qSr)choice)rn generatorZsourcesrrr@rz choose_lines..)rrr)rZnumberrr$rr#r choose_lines;s  r%s LAERTES O, fear me not. I stay too long: but here my father comes. Enter POLONIUS A double blessing is a double grace, Occasion smiles upon a second leave. LORD POLONIUS Yet here, Laertes! aboard, aboard, for shame! The wind sits in the shoulder of your sail, And you are stay'd for. There; my blessing with thee! And these few precepts in thy memory See thou character. Give thy thoughts no tongue, Nor any unproportioned thought his act. Be thou familiar, but by no means vulgar. Those friends thou hast, and their adoption tried, Grapple them to thy soul with hoops of steel; But do not dull thy palm with entertainment Of each new-hatch'd, unfledged comrade. Beware Of entrance to a quarrel, but being in, Bear't that the opposed may beware of thee. Give every man thy ear, but few thy voice; Take each man's censure, but reserve thy judgment. Costly thy habit as thy purse can buy, But not express'd in fancy; rich, not gaudy; For the apparel oft proclaims the man, And they in France of the best rank and station Are of a most select and generous chief in that. Neither a borrower nor a lender be; For loan oft loses both itself and friend, And borrowing dulls the edge of husbandry. This above all: to thine ownself be true, And it must follow, as the night the day, Thou canst not then be false to any man. Farewell: my blessing season this in thee! LAERTES Most humbly do I take my leave, my lord. LORD POLONIUS The time invites you; go; your servants tend. LAERTES Farewell, Ophelia; and remember well What I have said to you. OPHELIA 'Tis in my memory lock'd, And you yourself shall keep the key of it. LAERTES Farewell. c@seZdZddZdS)rvcCsdS)Nrzrr rrr __index__szCustomInt.__index__N)rrrr&rrrrrvsrv__main__)"r~testrr(rr rQrLZ test.supportrrr import_modulerrrr@rrErZTestCaserrr+r2objectrOrYrr%r[rvrmainrrrrs@     . -A]A