B
    18™\!ˆ  ã               @   sB  d dl Z d dlmZ d dlZd dlZd dlZd dlZd dlmZm	Z	m
Z
 e d¡Ze  ee ¡ dƒd¡Ze  ee ¡ dƒd¡ZG dd	„ d	e jƒZG d
d„ de jƒZG dd„ de jƒZG dd„ de jƒZG dd„ deƒZG dd„ dee jƒZG dd„ dee jƒZdefdd„Zdefdd„ZdZG dd„ dƒZe dkr>e  !¡  dS )é    N)Úsupport)Ú
bigmemtestÚ_1GÚ_4GÚzlibÚcopyzrequires Compress.copy()zrequires Decompress.copy()c               @   s   e Zd Zdd„ ZdS )ÚVersionTestCasec             C   s   |   tjd tjd ¡ d S )Nr   )ÚassertEqualr   ÚZLIB_RUNTIME_VERSIONÚZLIB_VERSION)Úself© r   úR/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/test/test_zlib.pyÚtest_library_version   s    z$VersionTestCase.test_library_versionN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r      s   r   c               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚChecksumTestCasec             C   s0   |   t d¡t dd¡¡ |  t dd¡¡ d S )Nó    r   s   abcl   ÿÿ )r	   r   Úcrc32Ú
assertTrue)r   r   r   r   Útest_crc32start    s    z ChecksumTestCase.test_crc32startc             C   s@   |   t dd¡d¡ |   t dd¡d¡ |   t dd¡d¡ d S )Nr   r   é   i°  )r	   r   r   )r   r   r   r   Útest_crc32empty$   s    z ChecksumTestCase.test_crc32emptyc             C   s0   |   t d¡t dd¡¡ |  t dd¡¡ d S )Nr   r   s   abcl   ÿÿ )r	   r   Úadler32r   )r   r   r   r   Útest_adler32start)   s    z"ChecksumTestCase.test_adler32startc             C   s@   |   t dd¡d¡ |   t dd¡d¡ |   t dd¡d¡ d S )Nr   r   r   i°  )r	   r   r   )r   r   r   r   Útest_adler32empty-   s    z"ChecksumTestCase.test_adler32emptyc             C   sˆ   |   t dd¡d¡ |   t dd¡d¡ |   t dd¡d¡ |   t dd¡d¡ |   t d¡t dd¡¡ |   t d¡t dd¡¡ d S )Ns   penguinr   l    !ƒK r   i”ª¶CiöÏi÷Ö)r	   r   r   r   )r   r   r   r   Útest_penguins2   s    zChecksumTestCase.test_penguinsc             C   sT   d}|   t |¡d¡ |   t d¡d¡ |   t || ¡d¡ |   t d¡d¡ d S )Ns   abcdefghijklmnopl   “@u( s   spami=ÿÚCl    * i²O)r	   r   r   r   )r   Úfoor   r   r   Útest_crc32_adler32_unsigned;   s
    z,ChecksumTestCase.test_crc32_adler32_unsignedc             C   sH   d}d}|   t |¡|¡ |   t |¡|¡ |   t d¡t d¡¡ d S )Ns   abcdefghijklmnopl   “@u( s   spam)r	   Úbinasciir   r   )r   r   Úcrcr   r   r   Útest_same_as_binascii_crc32C   s
    z,ChecksumTestCase.test_same_as_binascii_crc32N)
r   r   r   r   r   r   r   r   r   r"   r   r   r   r   r      s   	r   c               @   s&   e Zd Zeed ddddd„ ƒZdS )ÚChecksumBigBufferTestCaseé   r   F)ÚsizeÚmemuseÚdry_runc             C   s4   dt d  }|  t |¡d¡ |  t |¡d¡ d S )Ns   nyanr   iM"B>l   ía )r   r	   r   r   r   )r   r%   Údatar   r   r   Útest_big_bufferN   s    z)ChecksumBigBufferTestCase.test_big_bufferN)r   r   r   r   r   r)   r   r   r   r   r#   L   s   r#   c               @   sB   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zej	dd„ ƒZ
dS )ÚExceptionTestCasec             C   s   |   tjtjdd¡ d S )Ns   ERRORé
   )ÚassertRaisesr   ÚerrorÚcompress)r   r   r   r   Útest_badlevelW   s    zExceptionTestCase.test_badlevelc             C   s–   |   ttj¡ |   ttj¡ |   ttj¡ |   ttj¡ xXdd dddg fD ]D}|   ttj|¡ |   ttj|¡ |   ttj|¡ |   ttj|¡ qJW d S )Né*   Ú Úabcr   )r,   Ú	TypeErrorr   r   r   r.   Ú
decompress)r   Úargr   r   r   Útest_badargs]   s    zExceptionTestCase.test_badargsc             C   s6   |   ttjdtjd¡ |   ttjdtjtjd ¡ d S )Nr   r   )r,   Ú
ValueErrorr   ÚcompressobjÚDEFLATEDÚ	MAX_WBITS)r   r   r   r   Útest_badcompressobjh   s    z%ExceptionTestCase.test_badcompressobjc             C   s   |   ttjd¡ d S )Néÿÿÿÿ)r,   r7   r   Údecompressobj)r   r   r   r   Útest_baddecompressobjo   s    z'ExceptionTestCase.test_baddecompressobjc             C   s,   |   tt ¡ jd¡ |   tt ¡ jd¡ d S )Nr   r<   )r,   r7   r   r=   Úflush)r   r   r   r   Útest_decompressobj_badflushs   s    z-ExceptionTestCase.test_decompressobj_badflushc          	   C   sŠ   |   td¡ t ddtjd ¡ W d Q R X |   td¡ t ¡  dtjd ¡ W d Q R X |   td¡ t ¡  tjd ¡ W d Q R X d S )Nzint too larger   é   r   )ÚassertRaisesRegexÚOverflowErrorr   r4   ÚsysÚmaxsizer=   r?   )r   r   r   r   Útest_overflowx   s     zExceptionTestCase.test_overflowN)r   r   r   r/   r6   r;   r>   r@   r   Úcpython_onlyrF   r   r   r   r   r*   U   s   r*   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚBaseCompressTestCasec                sL   d‰ d  ‡ fdd„tdƒD ƒ¡}||t|ƒ d  }z||ƒ W d d }X d S )Ni   r   c                s"   g | ]}t  d ˆ  ¡ ˆ d¡‘qS )é   Úlittle)ÚrandomÚgetrandbitsÚto_bytes)Ú.0Úi)Ú_1Mr   r   ú
<listcomp>ˆ   s   zBBaseCompressTestCase.check_big_compress_buffer.<locals>.<listcomp>r+   r   )ÚjoinÚrangeÚlen)r   r%   Zcompress_funcr(   r   )rP   r   Úcheck_big_compress_bufferƒ   s    z.BaseCompressTestCase.check_big_compress_bufferc             C   s^   d| }zt  |d¡}W d d }X ||ƒ}z*|  t|ƒ|¡ |  t| d¡ƒd¡ W d d }X d S )Nó   xr   r   )r   r.   r	   rT   Ústrip)r   r%   Zdecompress_funcr(   Ú
compressedr   r   r   Úcheck_big_decompress_buffer‘   s    z0BaseCompressTestCase.check_big_decompress_bufferN)r   r   r   rU   rY   r   r   r   r   rH   ‚   s   rH   c               @   s¢   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zeed	 d
ddd„ ƒZ	eed	 dddd„ ƒZ
eedddd„ ƒZdd„ Ze ejdkd¡eed dddd„ ƒƒZdS )ÚCompressTestCasec             C   s    t  t¡}|  t  |¡t¡ d S )N)r   r.   ÚHAMLET_SCENEr	   r4   )r   Úxr   r   r   Útest_speech£   s    
zCompressTestCase.test_speechc          	   C   sd   t jtdd}|  t  |¡t¡ |  t¡ t jtdd W d Q R X |  t j|t jt jdt¡ d S )Né   )Úlevel)r(   r_   )ÚwbitsÚbufsize)	r   r.   r[   r	   r4   r,   r3   r:   ÚDEF_BUF_SIZE)r   r\   r   r   r   Útest_keywords§   s    
zCompressTestCase.test_keywordsc             C   sT   t d }t |¡}|  t t|ƒ¡|¡ x&|t|ƒfD ]}|  t |¡|¡ q6W d S )Né€   )r[   r   r.   r	   Ú	bytearrayr4   )r   r(   r\   Úobr   r   r   Útest_speech128±   s
    
zCompressTestCase.test_speech128c             C   s*   t  t¡}|  t jdt j|d d… ¡ d S )NzAError -5 while decompressing data: incomplete or truncated streamr<   )r   r.   r[   rB   r-   r4   )r   r\   r   r   r   Útest_incomplete_stream¹   s    
z'CompressTestCase.test_incomplete_streami   r^   )r%   r&   c             C   s   dd„ }|   ||¡ d S )Nc             S   s   t  | d¡S )Nr   )r   r.   )Úsr   r   r   Ú<lambda>Ä   r   z;CompressTestCase.test_big_compress_buffer.<locals>.<lambda>)rU   )r   r%   r.   r   r   r   Útest_big_compress_bufferÂ   s    z)CompressTestCase.test_big_compress_bufferé   c             C   s   |   |tj¡ d S )N)rY   r   r4   )r   r%   r   r   r   Útest_big_decompress_bufferÇ   s    z+CompressTestCase.test_big_decompress_bufferr   c             C   s.   t d }t |d¡}|  t |d|¡|¡ d S )Nr+   r   rA   )r[   r   r.   r	   r4   )r   r%   r(   rX   r   r   r   Útest_large_bufsizeË   s    z#CompressTestCase.test_large_bufsizec             C   s0   t d }t |d¡}|  t |dtƒ ¡|¡ d S )Nr+   r   rA   )r[   r   r.   r	   r4   Ú	CustomInt)r   r(   rX   r   r   r   Útest_custom_bufsizeÒ   s    z$CompressTestCase.test_custom_bufsizel        zrequires 64bit platforméd   r$   c             C   s:   d| }z"t  |d¡}|  t  |¡|¡ W d d  }}X d S )NrV   r   )r   r.   r	   r4   )r   r%   r(   Úcompr   r   r   Útest_64bit_compress×   s
    z$CompressTestCase.test_64bit_compressN)r   r   r   r]   rc   rg   rh   r   r   rk   rm   r   rn   rp   ÚunittestÚ
skipUnlessrD   rE   rs   r   r   r   r   rZ   ¡   s   
	rZ   c               @   sö  e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd]dd„Zdd„ Zd^dd„Z	d_dd„Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Ze eed!ƒd"¡d#d$„ ƒZd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zee d7d8d9d:„ ƒZ!d;d<„ Z"e#d=d>„ ƒZ$e#d?d@„ ƒZ%e&dAdB„ ƒZ'e&dCdD„ ƒZ(dEdF„ Z)dGdH„ Z*ee+dI dJd8dKdL„ ƒZ,ee+dI dMd8dNdO„ ƒZ-e e.j/dPkdQ¡ee dR dSd8dTdU„ ƒƒZ0e e.j/dPkdQ¡ee dR dJd8dVdW„ ƒƒZ1e e.j/dPkdQ¡ee dR dXd8dYdZ„ ƒƒZ2d[d\„ Z3d
S )`ÚCompressObjectTestCasec             C   sÖ   t d }t |¡}xN|t|ƒfD ]>}t ¡ }| |¡}| ¡ }|  tj|j¡ |  || |¡ q W xn||ft|ƒt|ƒffD ]R\}}t 	¡ }	|	 
|| ¡}
|	 ¡ }|  ||
| ¡ |  |	jt¡ |  |	jt¡ q|W d S )Nrd   )r[   r   r.   re   r8   r?   r,   r-   r	   r=   r4   ÚassertIsInstanceÚunconsumed_tailÚbytesÚunused_data)r   ZdatasrcZdatazipr(   ÚcoÚx1Úx2Zv1Úv2ÚdcoÚy1Úy2r   r   r   Ú	test_pairä   s    

"z CompressObjectTestCase.test_pairc       
   	   C   sÂ   d}t j}d}d}t j}t j|||||dd}t j|dd}|  t¡ |jtd W d Q R X |  t¡ |j	t  t¡d W d Q R X | t¡| 
¡  }|j	|ttƒd| 
¡  }	|  t|	¡ d S )	Nrl   iôÿÿÿé	   r   )r_   Úmethodr`   ÚmemLevelÚstrategyÚzdict)r`   r‡   )r(   )Ú
max_length)r   r9   Ú
Z_FILTEREDr8   r=   r,   r3   r.   r[   r4   r?   rT   r	   )
r   r_   r„   r`   r…   r†   r{   Údor\   Úyr   r   r   rc   ÷   s&    z$CompressObjectTestCase.test_keywordsc             C   sp   d}t j}d}d}t j}t  |||||¡}| t¡}| ¡ }t  |¡}	|	 || ¡}
|	 ¡ }|  	t|
| ¡ d S )Nrl   iôÿÿÿrƒ   )
r   r9   r‰   r8   r.   r[   r?   r=   r4   r	   )r   r_   r„   r`   r…   r†   r{   r|   r}   r   r€   r   r   r   r   Útest_compressoptions  s    

z+CompressObjectTestCase.test_compressoptionsc       	   	   C   s–   t d }t ¡ }g }x4tdt|ƒdƒD ] }| | |||d … ¡¡ q&W | | ¡ ¡ d |¡}t 	¡ }| 
d |¡¡}| ¡ }|  ||| ¡ d S )Nrd   r   é   r   )r[   r   r8   rS   rT   Úappendr.   r?   rR   r=   r4   r	   )	r   r(   r{   ÚbufsrO   Úcombufr   r€   r   r   r   r   Útest_compressincremental  s     
z/CompressObjectTestCase.test_compressincrementalFNr   é@   c          	   C   sp  |pt }|d }t ¡ }g }x4tdt|ƒ|ƒD ] }| | |||| … ¡¡ q.W | | ¡ ¡ d |¡}	t 	|	¡}
|  
|
t¡ |  ||
¡ t ¡ }g }x\tdt|	ƒ|ƒD ]H}| | 	|	||| … ¡¡ |  d|jdt|jƒ ¡ |  d|j¡ qªW |r| | ¡ ¡ n&x$| 	d¡}|r*| |¡ nP qW |  d|jdt|jƒ ¡ |  d|j¡ |  |d |¡¡ d S )Nrd   r   r   z"(A) uct should be b'': not %d longz"(B) uct should be b'': not %d long)r[   r   r8   rS   rT   rŽ   r.   r?   rR   r4   rw   ry   r	   r=   rx   rz   )r   r?   ÚsourceÚcxÚdcxr(   r{   r   rO   r   Zdecombufr   Úchunkr   r   r   Útest_decompinc*  s>     




z%CompressObjectTestCase.test_decompincc             C   s   | j dd d S )NT)r?   )r—   )r   r   r   r   Útest_decompincflushS  s    z*CompressObjectTestCase.test_decompincflushc          	   C   sú   |pt }|d }t ¡ }g }x4tdt|ƒ|ƒD ] }| | |||| … ¡¡ q.W | | ¡ ¡ d |¡}|  	|t 
|¡d¡ t ¡ }	g }|}
xD|
rÒ|	 
|
|¡}|  t|ƒ|kdt|ƒ|f ¡ | |¡ |	j}
qW | |	 ¡ ¡ |  	|d |¡d¡ d S )Nrd   r   r   zcompressed data failurezchunk too big (%d>%d)zWrong data retrieved)r[   r   r8   rS   rT   rŽ   r.   r?   rR   r	   r4   r=   ÚassertFalserx   )r   r“   r”   r•   r(   r{   r   rO   r   r   Úcbr–   r   r   r   Útest_decompimaxV  s*     


z&CompressObjectTestCase.test_decompimaxc          	   C   sJ  t d }t ¡ }g }x4tdt|ƒdƒD ] }| | |||d … ¡¡ q&W | | ¡ ¡ d |¡}|  	|t 
|¡d¡ t ¡ }g }|}xT|rÚdt|ƒd  }	| 
||	¡}
|  t|
ƒ|	kdt|
ƒ|	f ¡ | |
¡ |j}qˆW |rð| | ¡ ¡ nBx@|
r0| 
d|	¡}
|  t|
ƒ|	kdt|
ƒ|	f ¡ | |
¡ qòW |  	|d |¡d	¡ d S )
Nrd   r   r   r   zcompressed data failurer   r+   zchunk too big (%d>%d)zWrong data retrieved)r[   r   r8   rS   rT   rŽ   r.   r?   rR   r	   r4   r=   r™   rx   )r   r?   r(   r{   r   rO   r   r   rš   rˆ   r–   r   r   r   Útest_decompressmaxlenq  s6     


z,CompressObjectTestCase.test_decompressmaxlenc             C   s   | j dd d S )NT)r?   )rœ   )r   r   r   r   Útest_decompressmaxlenflush‘  s    z1CompressObjectTestCase.test_decompressmaxlenflushc             C   s,   t  ¡ }|  t|jdd¡ |  d|j¡ d S )Nr   r<   )r   r=   r,   r7   r4   r	   rx   )r   r   r   r   r   Útest_maxlenmisc”  s    z&CompressObjectTestCase.test_maxlenmiscc             C   sH   t d }|  t|ƒtj¡ t |d¡}t ¡ }|  | |t	j
¡|¡ d S )Nr+   r   )r[   ÚassertGreaterrT   r   rb   r.   r=   r	   r4   rD   rE   )r   r(   rX   r   r   r   r   Útest_maxlen_largeš  s
    z(CompressObjectTestCase.test_maxlen_largec             C   s>   t d }t |d¡}t ¡ }|  | |tƒ ¡|d d… ¡ d S )Nr+   r   rq   )r[   r   r.   r=   r	   r4   ro   )r   r(   rX   r   r   r   r   Útest_maxlen_custom£  s    z)CompressObjectTestCase.test_maxlen_customc             C   s:   d}t  ¡ }| |d¡}|| |j¡7 }|  |jd¡ d S )Ns
   xœKLJ Mr   r   )r   r=   r4   rx   r	   )r   Zcdatar   Zddatar   r   r   Útest_clear_unconsumed_tail©  s
    z1CompressObjectTestCase.test_clear_unconsumed_tailc             C   s  ddddg}t dd„ tj d¡D ƒƒ}|dkr8| d	¡ d
d„ |D ƒ}td }x®|D ]¦}x tdƒD ]”}yDt |¡}| |d d… ¡}| 	|¡}| |dd … ¡}	| 	¡ }
W n   t
d ||¡ƒ ‚ Y nX |  t d |||	|
g¡¡|d||f ¡ ~qbW qTW d S )NÚ
Z_NO_FLUSHÚZ_SYNC_FLUSHÚZ_FULL_FLUSHÚZ_PARTIAL_FLUSHc             s   s   | ]}t |ƒV  qd S )N)Úint)rN   Úvr   r   r   ú	<genexpr>¸  s    z6CompressObjectTestCase.test_flushes.<locals>.<genexpr>Ú.)r   rl   é   r^   ÚZ_BLOCKc             S   s    g | ]}t t|ƒrtt|ƒ‘qS r   )Úhasattrr   Úgetattr)rN   Úoptr   r   r   rQ   ½  s    z7CompressObjectTestCase.test_flushes.<locals>.<listcomp>rI   r+   i¸  z!Error for flush mode={}, level={}r   z*Decompress failed: flush mode=%i, level=%i)Útupler   r
   ÚsplitrŽ   r[   rS   r8   r.   r?   ÚprintÚformatr	   r4   rR   )r   Zsync_optÚverr(   Úsyncr_   ÚobjÚaÚbÚcÚdr   r   r   Útest_flushes²  s.    




z#CompressObjectTestCase.test_flushesr¤   zrequires zlib.Z_SYNC_FLUSHc       	      C   s²   dd l }t tj¡}t ¡ }y| ¡ }W n: tk
rb   y| ¡ }W n tk
r\   |}Y nX Y nX | d¡ t	dd|d}| 
|¡}| tj¡}| || ¡}|  ||d¡ d S )Nr   r   i D  )Ú	generatorz17K random source doesn't match)rK   r   r8   ÚZ_BEST_COMPRESSIONr=   ZWichmannHillÚAttributeErrorÚRandomÚseedÚgenblockr.   r?   r¤   r4   r	   )	r   rK   r{   r   Úgenr(   ÚfirstÚsecondZexpandedr   r   r   Útest_odd_flushÒ  s     

z%CompressObjectTestCase.test_odd_flushc             C   s6   t  t j¡}|  | ¡ ¡ t  ¡ }|  | ¡ d¡ d S )Nr   )r   r8   r½   r   r?   r=   r	   )r   r{   r   r   r   r   Útest_empty_flushô  s    z'CompressObjectTestCase.test_empty_flushc             C   s‚   t }| ¡ }t |¡ d |¡}tj|d}| |¡| ¡  }tj	|d}|  
| |¡| ¡  |¡ t 	¡ }|  tj|j|¡ d S )Nr   )r‡   )r[   r±   rK   ÚshufflerR   r   r8   r.   r?   r=   r	   r4   r,   r-   )r   ÚhÚwordsr‡   r{   Zcdr   r   r   r   Útest_dictionaryþ  s    

z&CompressObjectTestCase.test_dictionaryc             C   sÀ   t jtd}t jtd}tdd… }| |¡| t j¡ }| |dd … ¡| t j¡ }| |d d… ¡| t j¡ }|  | |¡|¡ |  | |¡|dd … ¡ |  | |¡|d d… ¡ d S )N)r‡   iè  iÜ  rq   iœÿÿÿ)	r   r8   r[   r=   r.   r?   r¤   r	   r4   )r   r{   rŠ   ZpieceÚd0Úd1Úd2r   r   r   Útest_dictionary_streaming  s    z0CompressObjectTestCase.test_dictionary_streamingc             C   sf   d}|   t |¡d¡ |  tjtj|d d… ¡ t ¡ }| |d d… ¡}|| ¡ 7 }|   |d¡ d S )Ns   xœKËÏ ‚Es   fooéûÿÿÿ)r	   r   r4   r,   r-   r=   r?   )r   r\   r   r‹   r   r   r   Ú!test_decompress_incomplete_stream  s    z8CompressObjectTestCase.test_decompress_incomplete_streamc             C   sl   d}t  ¡ }|  |j¡ | |d d… ¡ |  |j¡ | |dd … ¡ |  |j¡ | ¡  |  |j¡ d S )Ns   xœKËÏ ‚ErÏ   )r   r=   r™   Úeofr4   r   r?   )r   r\   r   r   r   r   Útest_decompress_eof(  s    z*CompressObjectTestCase.test_decompress_eofc             C   sN   d}t  ¡ }|  |j¡ | |d d… ¡ |  |j¡ | ¡  |  |j¡ d S )Ns   xœKËÏ ‚ErÏ   )r   r=   r™   rÑ   r4   r?   )r   r\   r   r   r   r   Ú%test_decompress_eof_incomplete_stream3  s    z<CompressObjectTestCase.test_decompress_eof_incomplete_streamc       
      C   s  d}d}t  |¡}|| }xþdD ]ö}xðddt|ƒt|ƒfD ]Ø}t  ¡ }d}x†tdt|ƒ|ƒD ]r}	|	t|ƒk rz|  |jd¡ |dkr¬|| ||	|	| … ¡7 }|  |jd¡ q\|| |j||	|	| …  |¡7 }q\W || 	¡ 7 }|  
|j¡ |  ||¡ |  |jd¡ |  |j|¡ q:W q W d S )Ns   abcdefghijklmnopqrstuvwxyzs
   0123456789)r   iè  r   rl   r   r   )r   r.   rT   r=   rS   r	   rz   r4   rx   r?   r   rÑ   )
r   r“   Ú	remainderr‹   r\   ÚmaxlenÚstepr   r(   rO   r   r   r   Útest_decompress_unused_data<  s*    

 z2CompressObjectTestCase.test_decompress_unused_datac             C   s\   d}t jt j |d}| |¡| ¡  }t jt j |d}| |¡| ¡  }|  ||¡ d S )Ns   abcdefghijklmnopqrstuvwxyz)r`   r‡   )r   r8   r:   r.   r?   r=   r4   r	   )r   r‡   r{   rr   r   Úuncompr   r   r   Ú#test_decompress_raw_with_dictionaryW  s    z:CompressObjectTestCase.test_decompress_raw_with_dictionaryc             C   sN   d}d}t  |¡}t  ¡ }| |d¡ ~t  |¡}|  | ¡ |dd … ¡ d S )Ns   abcdefghijklmnopqrstuvwxyzs   QWERTYUIOPASDFGHJKLZXCVBNMr   )r   r.   r=   r4   r	   r?   )r   Zinput1Zinput2r(   r   r   r   r   Útest_flush_with_freed_input_  s    

z2CompressObjectTestCase.test_flush_with_freed_inputr   )r%   r&   c             C   sF   t d }t |d¡}t ¡ }| |d¡ |  | |¡|dd … ¡ d S )Nr+   r   )r[   r   r.   r=   r4   r	   r?   )r   r%   Úinputr(   r   r   r   r   Útest_flush_large_lengthk  s
    z.CompressObjectTestCase.test_flush_large_lengthc             C   sH   t d }t |d¡}t ¡ }| |d¡ |  | tƒ ¡|dd … ¡ d S )Nr+   r   )r[   r   r.   r=   r4   r	   r?   ro   )r   rÛ   r(   r   r   r   r   Útest_flush_custom_lengtht  s
    z/CompressObjectTestCase.test_flush_custom_lengthc       	      C   sÌ   t }ttt dƒ ¡ dƒ}t tj¡}g }| | |¡¡ | 	¡ }|d d … }| | |¡¡ | | 
¡ ¡ d |¡}| | |¡¡ | | 
¡ ¡ d |¡}|  t |¡|| ¡ |  t |¡|| ¡ d S )NÚasciir   )r[   ry   ÚstrÚswapcaser   r8   r½   rŽ   r.   r   r?   rR   r	   r4   )	r   Zdata0Zdata1Zc0Úbufs0Zc1Úbufs1Ús0Ús1r   r   r   Útest_compresscopy{  s    

z(CompressObjectTestCase.test_compresscopyc             C   s,   t  ¡ }| t¡ | ¡  |  t|j¡ d S )N)r   r8   r.   r[   r?   r,   r7   r   )r   r¹   r   r   r   Útest_badcompresscopy’  s    
z+CompressObjectTestCase.test_badcompresscopyc       	      C   s²   t }t |¡}|  |t¡ t ¡ }g }| | |d d… ¡¡ | ¡ }|d d … }| | |dd … ¡¡ d 	|¡}| | |dd … ¡¡ d 	|¡}|  
||¡ |  
||¡ d S )Né    r   )r[   r   r.   rw   ry   r=   rŽ   r4   r   rR   r	   )	r   r(   rr   rË   rá   rÌ   râ   rã   rä   r   r   r   Útest_decompresscopyš  s    


z*CompressObjectTestCase.test_decompresscopyc             C   s6   t  t¡}t  ¡ }| |¡ | ¡  |  t|j¡ d S )N)	r   r.   r[   r=   r4   r?   r,   r7   r   )r   r(   rº   r   r   r   Útest_baddecompresscopy²  s
    

z-CompressObjectTestCase.test_baddecompresscopyc          
   C   sL   xFt tjd ƒD ]4}|  ttjf¡ t t tj	¡|¡ W d Q R X qW d S )Nr   )
rS   ÚpickleÚHIGHEST_PROTOCOLr,   r3   ÚPicklingErrorÚdumpsr   r8   r½   )r   Úprotor   r   r   Útest_compresspickle»  s    z*CompressObjectTestCase.test_compresspicklec          
   C   sH   xBt tjd ƒD ]0}|  ttjf¡ t t ¡ |¡ W d Q R X qW d S )Nr   )	rS   rê   rë   r,   r3   rì   rí   r   r=   )r   rî   r   r   r   Útest_decompresspickleÀ  s    z,CompressObjectTestCase.test_decompresspicklei   r^   c                s&   t  d¡‰ ‡ fdd„}|  ||¡ d S )Nr   c                s   ˆ   | ¡ˆ  ¡  S )N)r.   r?   )ri   )r¹   r   r   rj   Ê  r   zACompressObjectTestCase.test_big_compress_buffer.<locals>.<lambda>)r   r8   rU   )r   r%   r.   r   )r¹   r   rk   Ç  s    
z/CompressObjectTestCase.test_big_compress_bufferrl   c                s$   t  ¡ ‰ ‡ fdd„}|  ||¡ d S )Nc                s   ˆ   | ¡ˆ  ¡  S )N)r4   r?   )ri   )rº   r   r   rj   Ð  r   zCCompressObjectTestCase.test_big_decompress_buffer.<locals>.<lambda>)r   r=   rY   )r   r%   r4   r   )rº   r   rm   Í  s    z1CompressObjectTestCase.test_big_decompress_bufferl        zrequires 64bit platformrq   r$   c             C   sb   d| }t  d¡}t  ¡ }z4| |¡| ¡  }| |¡| ¡  }|  ||¡ W d d  } }}X d S )NrV   r   )r   r8   r=   r.   r?   r4   r	   )r   r%   r(   r{   rŠ   rr   rØ   r   r   r   rs   Ó  s    
z*CompressObjectTestCase.test_64bit_compressc             C   sf   d}d| }t  |¡| }t  ¡ }z0| |¡| ¡  }|  ||j¡ |  ||¡ W d d  } }}X d S )Ns   abcdefghijklmnoprV   )r   r.   r=   r4   r?   r	   rz   )r   r%   r(   Zunusedrr   rŠ   rØ   r   r   r   Útest_large_unused_dataà  s    z-CompressObjectTestCase.test_large_unused_datar«   c             C   sb   d| }t  ¡ }z>t  |d¡}| |d¡| ¡  }|  ||¡ |  |jd¡ W d d  } }}X d S )NrV   r   r   r   )r   r=   r.   r4   r?   r	   rx   )r   r%   r(   rŠ   rr   rØ   r   r   r   Útest_large_unconsumed_tailî  s    z1CompressObjectTestCase.test_large_unconsumed_tailc       
   	   C   sâ  t j dd¡d  d¡}t|ƒdk r0| d¡ n|d  ¡ sDd|d< ttt|ƒƒ}|dk}t j	dd	d
}| 
t¡| ¡  }|  t  |d	¡t¡ |r¦|  t  |d¡t¡ |  t  |d¡t¡ |  t jd¡ t  |d¡ W d Q R X t jdd}|  | |¡t¡ t jdd}|  t jd¡ | |¡ W d Q R X t j	ddd
}| 
t¡| ¡  }|  t  |d¡t¡ |  t  |d	¡t¡ |r|  t  |d¡t¡ |  t  |d¡t¡ t jdd}|  | |¡t¡ t j	ddd
}| 
t¡| ¡  }|  t  |d¡t¡ t jdd}|  | |¡t¡ t j	ddd
}| 
t¡| ¡  }|  t  |d¡t¡ |  t  |d¡t¡ t jdd}|  | |¡t¡ t j	ddd
}| 
t¡| ¡  }	|  t  |	d¡t¡ |  t  |	d¡t¡ t  d¡}|  | |	¡t¡ d S )Nú-r   r   rª   r$   Ú0r<   )r   rl   r^   r«   rA   )r_   r`   é/   zinvalid window sizeé   )r`   rƒ   é)   iñÿÿÿi÷ÿÿÿé   )r   r
   r±   rT   rŽ   Ú	isnumericr°   Úmapr§   r8   r.   r[   r?   r	   r4   rB   r-   r=   )
r   r¨   Zsupports_wbits_0r{   Zzlib15r   Zzlib9Z	deflate15Zdeflate9Úgzipr   r   r   Ú
test_wbitsû  s\    
z!CompressObjectTestCase.test_wbits)FNr   r’   )Nr   r’   )F)4r   r   r   r‚   rc   rŒ   r‘   r—   r˜   r›   rœ   r   rž   r    r¡   r¢   r»   rt   ru   r­   r   rÅ   rÆ   rÊ   rÎ   rÐ   rÒ   rÓ   r×   rÙ   rÚ   r   r   rÜ   rÝ   Úrequires_Compress_copyrå   ræ   Úrequires_Decompress_copyrè   ré   rï   rð   r   rk   rm   rD   rE   rs   rñ   rò   rü   r   r   r   r   rv   â   sT   
)

 		 !
			rv   i   c                sj   | dk	r|  | ¡ |j‰ ||k s(|dk r,|}tƒ }x2td||ƒD ]"}|t‡ fdd„t|ƒD ƒƒ7 }q@W |S )zDlength-byte stream of random data from a seed (in step-byte blocks).Nrl   r   c             3   s   | ]}ˆ d dƒV  qdS )r   éÿ   Nr   )rN   r\   )Úrandintr   r   r©   >  s    zgenblock.<locals>.<genexpr>)rÀ   r   ry   rS   )rÀ   ÚlengthrÖ   r¼   ZblocksrO   r   )r   r   rÁ   5  s    
"rÁ   c                s4   |dk	rˆ   |¡ |  d¡‰‡ ‡fdd„t|ƒD ƒS )z=Return a list of number lines randomly chosen from the sourceNÚ
c                s   g | ]}ˆ   ˆ¡‘qS r   )Úchoice)rN   Ún)r¼   Úsourcesr   r   rQ   H  s    z choose_lines.<locals>.<listcomp>)rÀ   r±   rS   )r“   ÚnumberrÀ   r¼   r   )r¼   r  r   Úchoose_linesC  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               @   s   e Zd Zdd„ ZdS )ro   c             C   s   dS )Nrq   r   )r   r   r   r   Ú__int__Ž  s    zCustomInt.__int__N)r   r   r   r  r   r   r   r   ro     s   ro   Ú__main__)"rt   Útestr   r    rê   rK   rD   Ztest.supportr   r   r   Úimport_moduler   ru   r­   r8   rý   r=   rþ   ÚTestCaser   r   r#   r*   ÚobjectrH   rZ   rv   rÁ   r  r[   ro   r   Úmainr   r   r   r   Ú<module>   s<   
.	-A    WG
