B
    u9a(B  ã               @   sF   d Z ddlZddlZddlmZ ddlmZmZ G dd„ dejƒZdS )z,
Tests common to list and UserList.UserList
é    N)Ú
cmp_to_key)ÚsupportÚ	seq_testsc                   sü   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d„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Z‡ fd#d$„Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Z‡ fd/d0„Z‡ fd1d2„Zd3d4„ Zd5d6„ Zd7d8„ Z‡  ZS )9Ú
CommonTestc             C   s¦   |   |  g ¡|  ¡ ¡ |  dddg¡}| ¡  |   ||  g ¡¡ |  dddg¡}| dddg¡ |   ||  dddg¡¡ |  |¡}|  t|ƒt|ƒ¡ |   ||¡ d S )Né   é   é   é   é   é   )ÚassertEqualÚ	type2testÚ__init__ZassertNotEqualÚid)ÚselfÚaÚb© r   ú /usr/lib/python3.7/list_tests.pyÚ	test_init   s    
zCommonTest.test_initc          	   C   s,   g }d}|   t|¡ |d  W d Q R X d S )Nz'list indices must be integers or slicesr   )ÚassertRaisesRegexÚ	TypeError)r   r   Úmsgr   r   r   Útest_getitem_error!   s    zCommonTest.test_getitem_errorc          	   C   s,   g }d}|   t|¡ d|d< W d Q R X d S )Nz'list indices must be integers or slicesÚpythonr   )r   r   )r   r   r   r   r   r   Útest_setitem_error'   s    zCommonTest.test_setitem_errorc             C   s¶   g }dddg}|   |¡}|   |¡}|  t|ƒt|ƒ¡ |  t|ƒt|ƒ¡ |  t|ƒt|ƒ¡ |  t|ƒd¡ |  t|ƒd¡ | |¡ | d¡ |  t|ƒd¡ |  t|ƒd¡ d S )Nr   r   r   z	[0, 1, 2]r   z[0, 1, 2, [...], 3])r   r   ÚstrÚreprÚappend)r   Zl0Úl2Za0Úa2r   r   r   Ú	test_repr-   s    




zCommonTest.test_reprc             C   sB   |   g ¡}x$tt ¡ d ƒD ]}|   |g¡}qW |  tt|¡ d S )Néd   )r   ÚrangeÚsysÚgetrecursionlimitÚassertRaisesÚRecursionErrorr   )r   r   Úir   r   r   Útest_repr_deep>   s    
zCommonTest.test_repr_deepc          	   C   s¦   |   tdƒ¡}| |¡ | tddƒ¡ | |¡ | d¡ zVttjdƒ}| t|ƒ¡ W d Q R X ttjdƒ}|  	| 
¡ t|ƒ¡ W d Q R X W d t tj¡ X d S )NéÈ   i  ÚwÚr)r   r#   r   ÚextendÚopenr   ZTESTFNÚwriter   r   Úreadr   ÚosÚremove)r   ÚdÚfor   r   r   Ú
test_printD   s    


"zCommonTest.test_printc             C   sÊ   |   tdƒ¡}|  t|jtdddƒdddg¡ |  t|jtddƒd¡ |  t|jtdddƒddg¡ |  t|jdd¡ dddg|tdddƒ< |  ||   ddddddd	d
ddddddddddddg¡¡ d S )Né   r   é
   r   r   r   Úxr	   r   é   é	   é   é   é   é   é   é   é   é   é   )	r   r#   r&   Ú
ValueErrorÚ__setitem__Úslicer   Ú__getitem__r   )r   r   r   r   r   Útest_set_subscriptR   s     zCommonTest.test_set_subscriptc          	   C   sz   |   tdƒ¡}t|ƒ}|  t|ƒ|   tdddƒ¡¡ |  tt|¡ |  tt|   ¡ ƒƒ|   ¡ ¡ |  tt	tdddgƒ¡ d S )Nr6   rC   éÿÿÿÿr   r   r   )
r   r#   Úreversedr   Úlistr&   ÚStopIterationÚnextr   Úlen)r   r   r,   r   r   r   Útest_reversed]   s    
zCommonTest.test_reversedc          
   C   sÌ  |   ddg¡}d|d< d|d< |  ||   ddg¡¡ d|d< |  ||   ddg¡¡ d|d< |  ||   ddg¡¡ |  t|jdd¡ |  t|jdd¡ |   g ¡}|  t|jdd¡ |  t|jdd¡ |  t|j¡ |   dddd	d
g¡}d|d< d|d< d	|d< |  ||   ddd	d	d
g¡¡ d|d< d|d< d|d< |  ||   dddd	d
g¡¡ d|d< d|d< |  ||   dddddg¡¡ d|d< d|d< |  ||   dddddg¡¡ d}|  t|¡ d|d< W d Q R X d S )Nr   r   r"   r*   rI   éþÿÿÿéýÿÿÿr   r   r	   r
   r   r9   éX   éc   é   r:   z'list indices must be integers or slicesr   r   )r   r   r&   Ú
IndexErrorrE   r   r   )r   r   r   r   r   r   Útest_setitemg   s@    
zCommonTest.test_setitemc             C   sÂ   |   ddg¡}|d= |  |dg¡ |d= |  |g ¡ |   ddg¡}|d= |  |dg¡ |d= |  |g ¡ |   ddg¡}|  t|jd¡ |  t|jd¡ |   g ¡}|  t|jd¡ |  t|j¡ d S )Nr   r   rP   rI   rQ   r   )r   r   r&   rU   Ú__delitem__r   )r   r   r   r   r   Útest_delitemŒ   s     
zCommonTest.test_delitemc             C   s‚  ddg}|   |¡}x
tddƒD ]ü}|d |… |d |…< |  ||¡ |d d … }|d |… |d |…< |  ||¡ ||d … ||d …< |  ||¡ |d d … }||d … ||d …< |  ||¡ x^tddƒD ]P}|||… |||…< |  ||¡ |d d … }|||… |||…< |  ||¡ qÈW q W |d d … }ddg|d d…< |  |ddddg¡ g |dd …< |  |g ¡ |   ddddd	g¡}||d d…< |  ||   ddddd	d	g¡¡ |   ddddd	g¡}||dd …< |  ||   dddddd	g¡¡ |   ddddd	g¡}||dd…< |  ||   dddddd	d	g¡¡ |   g ¡}ttd
ƒƒ|d d …< |  ||   td
ƒ¡¡ |  t|jtddd	ƒ¡ |  t|j¡ d S )Nr   r   rQ   r	   rP   rI   r   r   r
   r7   )r   r#   r   Útupler&   r   rE   rF   )r   Úlr   r(   r    ÚjZaa2r   r   r   Útest_setslice¢   sL    
 
zCommonTest.test_setslicec             C   s®  |   ddg¡}|dd…= |dd…= |  ||   g ¡¡ |   ddg¡}|dd…= |dd…= |  ||   g ¡¡ |   ddg¡}|dd…= |  ||   dg¡¡ |   ddg¡}|dd…= |  ||   dg¡¡ |   ddg¡}|dd …= |d d…= |  ||   g ¡¡ |   ddg¡}|dd …= |d d…= |  ||   g ¡¡ |   ddg¡}|dd …= |  ||   dg¡¡ |   ddg¡}|dd …= |  ||   dg¡¡ |   ddg¡}|d d …= |  ||   g ¡¡ d S )Nr   r   r   rP   rI   )r   r   )r   r   r   r   r   Útest_delsliceÐ   s>    












zCommonTest.test_delslicec             C   sR   |   g ¡}| d¡ | d¡ | d¡ |  ||   dddg¡¡ |  t|j¡ d S )Nr   r   r   )r   r   r   r&   r   )r   r   r   r   r   Útest_appendù   s    



zCommonTest.test_appendc             C   s
  |   dg¡}|   d¡}|d d … }| |¡ |  ||| ¡ | |   g ¡¡ |  ||| ¡ | |¡ |  ||   ddddddg¡¡ |   d¡}| d¡ |  |tdƒ¡ |  t|jd ¡ |  t|j¡ G dd„ dƒ}|   dd	d
dg¡}| |ƒ ¡ |  |dd	d
dg¡ d S )Nr   )r   r   r   ÚspamÚeggsÚspameggsc               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )z*CommonTest.test_extend.<locals>.CustomIterc             S   s   | S )Nr   )r   r   r   r   Ú__iter__  s    z3CommonTest.test_extend.<locals>.CustomIter.__iter__c             S   s   t ‚d S )N)rL   )r   r   r   r   Ú__next__  s    z3CommonTest.test_extend.<locals>.CustomIter.__next__c             S   s   t jS )N)r$   Úmaxsize)r   r   r   r   Ú__length_hint__  s    z:CommonTest.test_extend.<locals>.CustomIter.__length_hint__N)Ú__name__Ú
__module__Ú__qualname__rb   rc   re   r   r   r   r   Ú
CustomIter  s   ri   r   r   r	   )r   r-   r   rK   r&   r   )r   Za1r    r   ri   r   r   r   Útest_extend  s$    




zCommonTest.test_extendc             C   s²   |   dddg¡}| dd¡ | dd¡ | dd¡ |  |ddddddg¡ |d d … }| dd¡ | dd¡ | d	d
¡ |  ||   ddddddddd
g	¡¡ |  t|j¡ d S )Nr   r   r   rP   rI   Zfooi8ÿÿÿÚleftr*   Úright)r   Úinsertr   r&   r   )r   r   r   r   r   r   Útest_insert#  s    $zCommonTest.test_insertc             C   sž   |   dddg¡}| ¡  |  |ddg¡ | d¡ |  |dg¡ |  t|jd¡ | d¡ |  |g ¡ |  t|j¡ |  t|jdd¡ |   ddddd	g¡}d S )
NrI   r   r   r
   é*   r7   r6   é   é(   )r   Úpopr   r&   rU   r   )r   r   r   r   r   Útest_pop2  s    

zCommonTest.test_popc                sŠ  |   dddg¡}| d¡ |  |ddg¡ | d¡ |  |dg¡ | d¡ |  |g ¡ |  t|jd¡ |  t|j¡ G dd„ dtƒ‰ G ‡ fdd„dƒ}|   ddddg¡}|  ˆ |j|ƒ ¡ G ‡ fd	d
„d
ƒ}|   d¡}| d¡ |  ||   d¡¡ | d¡ |  ||   d¡¡ |  t|jd¡ |  ||   d¡¡ |   dd|ƒ dg¡}|   |¡}|  ˆ |jd¡ x$t||ƒD ]\}}|  ||¡ qlW d S )Nr   r   c               @   s   e Zd ZdS )z&CommonTest.test_remove.<locals>.BadExcN)rf   rg   rh   r   r   r   r   ÚBadExcL  s   rt   c                   s   e Zd Z‡ fdd„ZdS )z&CommonTest.test_remove.<locals>.BadCmpc                s   |dkrˆ ƒ ‚dS )Nr   Fr   )r   Úother)rt   r   r   Ú__eq__P  s    z-CommonTest.test_remove.<locals>.BadCmp.__eq__N)rf   rg   rh   rv   r   )rt   r   r   ÚBadCmpO  s   rw   r   r   c                   s   e Zd Z‡ fdd„ZdS )z'CommonTest.test_remove.<locals>.BadCmp2c                s
   ˆ ƒ ‚d S )Nr   )r   ru   )rt   r   r   rv   Y  s    z.CommonTest.test_remove.<locals>.BadCmp2.__eq__N)rf   rg   rh   rv   r   )rt   r   r   ÚBadCmp2X  s   rx   ZabcdefghcijÚcZ
abdefghcijZ	abdefghijr   r   )	r   r2   r   r&   rD   r   Ú	ExceptionÚzipÚassertIs)r   r   rw   rx   r3   Úer8   Úyr   )rt   r   Útest_remove?  s4    






zCommonTest.test_removec          
      s¤   t ƒ  ¡  |  ddddddg¡‰ˆ d¡ |  tˆjddd¡ |  ˆ|  dddddg¡¡ G dd„ dƒ‰ |  ¡ ‰‡ ‡fd	d
„tdƒD ƒˆd d …< |  tˆjd ¡ d S )NrP   rI   r   r   r   r	   c               @   s   e Zd Zdd„ Zdd„ ZdS )z&CommonTest.test_index.<locals>.EvilCmpc             S   s
   || _ d S )N)Úvictim)r   r€   r   r   r   r   u  s    z/CommonTest.test_index.<locals>.EvilCmp.__init__c             S   s   | j d d …= dS )NF)r€   )r   ru   r   r   r   rv   w  s    z-CommonTest.test_index.<locals>.EvilCmp.__eq__N)rf   rg   rh   r   rv   r   r   r   r   ÚEvilCmpt  s   r   c                s   g | ]}ˆ ˆƒ‘qS r   r   )Ú.0Ú_)r   r   r   r   ú
<listcomp>{  s    z)CommonTest.test_index.<locals>.<listcomp>r"   )	ÚsuperÚ
test_indexr   r2   r&   rD   Úindexr   r#   )r   )Ú	__class__)r   r   r   r†   l  s    

 zCommonTest.test_indexc             C   sf   |   dddddg¡}|d d … }| ¡  |  |dddddg¡ | ¡  |  ||¡ |  t|jd¡ d S )NrP   rI   r   r   r   ro   )r   Úreverser   r&   r   )r   ÚuÚu2r   r   r   Útest_reverse  s    zCommonTest.test_reversec             C   sŠ   |   dddg¡}| ¡  |  |g ¡ |   g ¡}| ¡  |  |g ¡ |   g ¡}| d¡ | ¡  | d¡ |  |dg¡ |  t|jd ¡ d S )Nr   r   r	   r   )r   Úclearr   r   r&   r   )r   rŠ   r   r   r   Ú
test_clear‰  s    



zCommonTest.test_clearc             C   sÜ   |   dddg¡}| ¡ }|  |dddg¡ |   g ¡}| ¡ }|  |g ¡ |   ddg¡}| ¡ }| d¡ |  |ddg¡ |  ||dg ¡ |   ddddgdg¡}| ¡ }|  ||¡ |  |d |d ¡ |  t|jd ¡ d S )	Nr   r   r   r   r   r(   r	   r
   )r   Úcopyr   r   r|   r&   r   )r   rŠ   Úvr   r   r   Ú	test_copyš  s     

zCommonTest.test_copyc          
      s  |   ddg¡}| ¡  |  |ddg¡ |   dddddg¡}| ¡  |  ||   dddddg¡¡ |  t|jdd¡ dd„ }|jt|ƒd	 |  ||   dddddg¡¡ d
d„ }|   tdƒ¡‰ ˆ jt|ƒd	 |  tˆ jd¡ ‡ fdd„}| jtˆ jt|ƒd	 |  tˆ jdddd¡ d S )Nr   r   r   rI   rP   ro   c             S   s    | |krdS | |k rdS dS d S )Nr   r   rI   r   )r   r   r   r   r   Úrevcmp½  s
    z$CommonTest.test_sort.<locals>.revcmp)Úkeyc             S   s2   | d |d  }}||krdS ||k r*dS dS d S )Nr   r9   r   rI   r   r   )r8   r~   ZxmodZymodr   r   r   ÚmyComparisonÈ  s    z*CommonTest.test_sort.<locals>.myComparisonr<   c                s*   ˆ   d¡ | |krdS | |k r"dS dS d S )Nr   r   rI   )r   )r8   r~   )Úzr   r   ÚselfmodifyingComparisonÕ  s    
z5CommonTest.test_sort.<locals>.selfmodifyingComparison)r   Úsortr   r&   r   r   r#   rD   )r   rŠ   r’   r”   r–   r   )r•   r   Ú	test_sort²  s$    
zCommonTest.test_sortc             C   s*   |   d¡}d|d d…< |  |tdƒ¡ d S )Nr_   Úhr   Zham)r   r   rK   )r   rŠ   r   r   r   Ú
test_sliceâ  s    
zCommonTest.test_slicec                sl   t ƒ  ¡  |  ddg¡}|}|ddg7 }|  ||¡ |  d¡}|d7 }|  ||  d¡¡ |  t|jd ¡ d S )Nr   r   r   r   r_   r`   ra   )r…   Ú	test_iaddr   r|   r   r&   r   Ú__iadd__)r   rŠ   r‹   )rˆ   r   r   r›   ç  s    

zCommonTest.test_iaddc                s8   t ƒ  ¡  |  g ¡}t|ƒ}|d9 }|  t|ƒ|¡ d S )Nr7   )r…   Ú	test_imulr   r   r   )r   ÚsZoldid)rˆ   r   r   r   ô  s
    

zCommonTest.test_imulc             C   sŽ  |   dddddg¡}|d d d…= |  ||   ddg¡¡ |   tdƒ¡}|dd d…= |  ||   dddg¡¡ |   tdƒ¡}|dd d…= |  ||   ddddg¡¡ |   tdƒ¡}|d d d	…= |  ||   dddddd
dddg	¡¡ |   tdƒ¡}dgd |d d d…< |  ||   ddddddddddg
¡¡ |   tdƒ¡}dgd |d d d…< |  ||   ddddddd
dddg
¡¡ |   tdƒ¡}||d d d…< |  ||   ddddg¡¡ |   tdƒ¡}|d d … }|d d … }|   ddg¡|dd…< |   ddg¡|tddƒ< |   ddg¡|dd…< |  ||¡ |  ||¡ |   tdƒ¡}ttdƒƒ|d d d…< |  ||   ddddddddddg
¡¡ |   tdƒ¡}|dd dd> …= d S )Nr   r   r   r   r	   r
   rP   r7   iè  r   r9   rT   r:   rI   éüÿÿÿZtwoÚelementsiM  )r   r   r#   rF   rY   )r   r   r   ry   r   r   r   Útest_extendedslicingû  sD    $&&&zCommonTest.test_extendedslicingc             C   s$   G dd„ dt ƒ}|  tt|ƒ ¡ d S )Nc               @   s   e Zd Zdd„ ZdS )z9CommonTest.test_constructor_exception_handling.<locals>.Fc             S   s   t ‚d S )N)ÚKeyboardInterrupt)r   r   r   r   rb   '  s    zBCommonTest.test_constructor_exception_handling.<locals>.F.__iter__N)rf   rg   rh   rb   r   r   r   r   ÚF&  s   r£   )Úobjectr&   r¢   rK   )r   r£   r   r   r   Ú#test_constructor_exception_handling$  s    z.CommonTest.test_constructor_exception_handlingc          	   C   s€   |   dddg¡}t|ƒ}t|ƒ}x|D ]}t|ƒ q&W | d¡ |  t|ƒg ¡ |  t|ƒdg¡ |  ||   ddddg¡¡ d S )Nr   r   r   r:   )r   ÚiterrM   r   r   rK   )r   r   ZexhitZempitr8   r   r   r   Útest_exhausted_iterator+  s    

z"CommonTest.test_exhausted_iterator) rf   rg   rh   r   r   r   r!   r)   r5   rH   rO   rV   rX   r\   r]   r^   rj   rn   rs   r   r†   rŒ   rŽ   r‘   r˜   rš   r›   r   r¡   r¥   r§   Ú__classcell__r   r   )rˆ   r   r      s8   
%.)	!-
0)r   )	Ú__doc__r$   r1   Ú	functoolsr   Ztestr   r   r   r   r   r   r   Ú<module>   s
   