B
    u9a[                 @   s4  d dl mZ d dlZd dlmZmZ d dlZd dlZd dlZd dl	Z	d dl
Z
d dlZdZdd ZG dd dZG d	d
 d
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ZG dd dejZG dd deZG dd dejZG dd dejZdZdeiZd"ddZedkr0ed d! dS )#    )dequeN)support	seq_testsi c               c   s   t dV  d S )N   )SyntaxError r   r    /usr/lib/python3.7/test_deque.pyfail   s    r	   c               @   s   e Zd Zdd ZdS )BadCmpc             C   s   t d S )N)RuntimeError)selfotherr   r   r   __eq__   s    zBadCmp.__eq__N)__name__
__module____qualname__r   r   r   r   r   r
      s   r
   c               @   s   e Zd Zdd Zdd ZdS )	MutateCmpc             C   s   || _ || _d S )N)r   result)r   r   r   r   r   r   __init__   s    zMutateCmp.__init__c             C   s   | j   | jS )N)r   clearr   )r   r   r   r   r   r      s    
zMutateCmp.__eq__N)r   r   r   r   r   r   r   r   r   r      s   r   c               @   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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d7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1e2j3Z3e2j4d_d` Z5daS )b	TestBasicc                s  t tdd  td xtddD ]} | q(W x ttddD ]} | qJW | t ttdd | t d  fdd	td
D }| |ttdd | t ttdd  fdd	td
D }|	  | |ttdd | t ttdd d S )Niix   i  i8r   iX  c                s   g | ]}   qS r   )popleft).0i)dr   r   
<listcomp>)   s    z)TestBasic.test_basics.<locals>.<listcomp>   2   c                s   g | ]}   qS r   )pop)r   r   )r   r   r   r   -   s       )
r   ranger   appendreversed
appendleftassertEquallistlenreverse)r   r   leftrightr   )r   r   test_basics   s    zTestBasic.test_basicsc          	   C   s  |  ttdd |  ttdd ttd}t|dd}| t|g  | t|d | t|dd	d
g | |ttdd |d | t|d	d
dg |	d | t|dd	d
g |
ddg | t|d
ddg |d	dg | t|dd	d
g ttddd}|| ttj ttjd}z:|t| |  ttjd}| | t| W d |  ttj X ttdd d}| t|d ttjd}z:|t| |  ttjd}| | t| W d |  ttj X d S )Nabc
      )maxlenzdeque([7, 8, 9], maxlen=3)      	      r   wrz%deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))assertRaises
ValueErrorr   iterr!   r%   r&   reprr"   r$   extend
extendleftr   unlinkTESTFNopenwritestrcloseread)r   itr   for   r   r   test_maxlen2   sJ    


zTestBasic.test_maxlenc             C   s   t td}t|dd | t|g  t td}tdd}|| | t|g  t td}tdd}|| | t|g  d S )Nd   r   )r1   )r:   r!   r   r%   r&   r<   r=   )r   rE   r   r   r   r   test_maxlen_zero\   s    



zTestBasic.test_maxlen_zeroc          	   C   s   |  t jd  |  tdjd  |  tdddjd |  tdddjd |  tdddjd | t td}d|_W d Q R X d S )Nr,      )r1      r   r/   )r%   r   r1   r8   AttributeError)r   r   r   r   r   test_maxlen_attributek   s    zTestBasic.test_maxlen_attributec          	   C   sj  xXdddd d fD ]B}t |}t|}x,dD ]$}| |||||||f q.W qW | t|j | t|jdd G d	d
 d
}tdd| dg}| t|jd tdddg}| t|j|  G dd d}| }tddd|ddg}||_| t|jd td gd }x t	t
|D ]}|d q$W |d | |dd | |d d d S )N ZabracadabraZ
simsalabimi  r,   Zabcdefghijklmnopqrstuvwxyzr   rK   c               @   s   e Zd Zdd ZdS )z(TestBasic.test_count.<locals>.BadComparec             S   s   t d S )N)ArithmeticError)r   r   r   r   r   r   ~   s    z/TestBasic.test_count.<locals>.BadCompare.__eq__N)r   r   r   r   r   r   r   r   
BadCompare}   s   rP   r0   c               @   s   e Zd Zdd ZdS )z-TestBasic.test_count.<locals>.MutatingComparec             S   s   | j   dS )NT)r   r   )r   r   r   r   r   r      s    
z4TestBasic.test_count.<locals>.MutatingCompare.__eq__N)r   r   r   r   r   r   r   r   MutatingCompare   s   rQ   rJ         r-   r   )r&   r   r%   countr8   	TypeErrorrO   r   r   r!   r'   rotate)r   sr   ZletterrP   rQ   mr   r   r   r   
test_countu   s.    
(
zTestBasic.test_countc             C   s  t d}|  x~|t dt dt  t|gD ]^}| ||kt|t|koZt|t|k | ||kt|t|kot|t|k  q.W tt d}x|D ]}x|D ]}| ||kt|t|k||f | ||kt|t|k||f | ||k t|t|k ||f | ||kt|t|k||f | ||kt|t|k||f | ||kt|t|k||f qW qW d S )Nxabcr,   ab)	rN   abr[   Zbar,   ZxbarZ   Zcba)r   r   r&   r%   typemap)r   r   eargsxyr   r   r   test_comparisons   s     ",2


"""""zTestBasic.test_comparisonsc          	   C   s   d}t t|}xt|D ]}| ||k qW | |d |k t t|}t|d||d < | t ||k W d Q R X t t|}t ||d < | t ||k W d Q R X d S )Nr   r   FrK   )r   r!   
assertTruer   r8   r   r
   )r   nr   r   r   r   r   test_contains   s    zTestBasic.test_containsc             C   sX   t d}| t|jd |d | t|td || | t|td d S )Nr\   r   bcdabcdabcdabcd)r   r8   rU   r<   r%   r&   )r   r   r   r   r   test_extend   s    

zTestBasic.test_extendc          	   C   s   t  }t d}t d}| || t   | || t d | || t d | || t d | || t d | || t   | || t d | || t d t ddd}t d}| || t d | t t dd  W d Q R X d S )	Nr,   defabcdefabcabcrJ   )r1   ZghZefgh)r   r%   assertIsNotr8   rU   )r   r   r`   fghr   r   r   test_add   s     zTestBasic.test_addc             C   sD   t d}|d7 }| t|td ||7 }| t|td d S )Nr\   rh   ri   rj   )r   r%   r&   )r   r   r   r   r   	test_iadd   s
    zTestBasic.test_iaddc             C   s   t d}| t|jd |d | t|ttd || | t|td t  }|td | t|tttd | t|jt	  d S )Nr\   r   rh   ri   Zabcddcbai  )
r   r8   rU   r=   r%   r&   r#   r!   r   r	   )r   r   r   r   r   test_extendleft   s    

zTestBasic.test_extendleftc             C   s   d}t t|}tt|}xbt|D ]V}|  |d t dk r\|| || xtdt| t|D ]}qtW q&W t d}| |d d | |d d t  }| 	t
|jd | 	t
|jd d S )	Nr   r   g      ?r   ZsupermanrW   r-   rf   )r   r!   r&   r   r   randomr"   r'   r%   r8   
IndexError__getitem__)r   rf   r   lr   jr   r   r   test_getitem   s"    


zTestBasic.test_getitemc             C   s  xdD ]}t t|}x"t|D ]}| ||| q W | t ||d  W d Q R X t t|}t|d||d < | t || W d Q R X t t|}t ||d < | t || W d Q R X qW d}d}t |d }t	|d }xtdt
|d  dt
|d  D ]}xtdt
|d  dt
|d  D ]~}xv|d D ]j}	y||	||}
W n: tk
r   | t ||	|| W d Q R X Y nX | ||	|||
 qTW qFW qW d S )	N)r   rK      (   r   r   FrK   	ABCDEFGHIZrR   )r   r!   r%   indexr8   r9   r   r   r
   r&   r'   )r   rf   r   r   elementsZ
nonelementrW   startstopZelementtargetr   r   r   
test_index   s6    
((zTestBasic.test_indexc          	   C   s0   t d}| t |ddd}W d Q R X d S )NZAAAzHello worldr   rJ   )r   r8   r9   r   )r   r   r   r   r   r   test_index_bug_24913#  s    zTestBasic.test_index_bug_24913c             C   sl   d}xbt dt|d  dt|d  D ]<}td}td}||d ||d | t|| q(W d S )Nr~   r   rK   rR   r   )r!   r'   r   r&   insertr%   )r   r   r   r   rW   r   r   r   test_insert(  s    (zTestBasic.test_insertc          	   C   s   d}t |t|d}| t |dd  W d Q R X d}xjtt| t|D ]R}t |t|d d}||d |dkr| || d qP| ||d  d qPW d S )NABC)r1   rK   r~   r   r   r   )r   r'   r8   rw   r   r!   r%   )r   datar   r   r   r   r   r   test_insert_bug_261942  s    zTestBasic.test_insert_bug_26194c          	   C   sJ  x4dD ],}t  }||9 }| |t   | |j qW x<dD ]4}t d}||9 }| |t d|  | |j q<W xFdD ]>}t dd}||9 }| |t dt|d  | |jd qzW x<dD ]4}t d}||9 }| |t d|  | |j qW xJdD ]B}t dd}||9 }| |t d| dd   | |jd q W d S )N)ir-   r   r   rK   r/   i  r\   )
ir-   r   r   rK   r/   i  i  i  i  i  rm   i)r   r%   ZassertIsNoner1   min)r   rf   r   r   r   r   	test_imulA  s2    






zTestBasic.test_imulc             C   s  t d}| |d t   | |d t   | |d t d | |d t d | |d t d | |d | | t  d t   | t  d t   | t  d	 t   | d| t   | d| t   | d| t d | d| t d | d| t d t dd	d
}| |d t   | |d t   | |d t d | |d t d | |d t d d S )Nr,   r   r   r   rK   rn   r0   Z	abcabcabcrR   )r1   Zbcabcr|   )r   r%   ro   )r   r   r   r   r   test_mul`  s*    zTestBasic.test_mulc             C   s   d}t t|}xt|D ]}d| ||< qW | t|dd t|D  t|}x0td| ddD ]}d| ||< d| ||< qfW | t|| d S )	Nr   r/   c             S   s   g | ]}d | qS )r/   r   )r   r   r   r   r   r     s    z*TestBasic.test_setitem.<locals>.<listcomp>r   r   r-   r2   )r   r!   r%   r&   )r   rf   r   r   ry   r   r   r   test_setitemz  s    zTestBasic.test_setitemc             C   s   d}t t|}| t|j| d  | t|j| x`t|D ]T}| t|||  tt| t|}|| }| 	|| ||= | 
|| q@W | t|d d S )Ni  r   r   )r   r!   r8   rw   __delitem__r%   r'   rv   Z	randrangeassertInZassertNotIn)r   rf   r   r   rz   valr   r   r   test_delitem  s    zTestBasic.test_delitemc          	   C   s   d}dd t |D }xtt |D ]h}t|d | }| }| t|tt|d |  | |d  |  | t||d |  q W | t|jd d S )Ni  c             S   s   g | ]}t   qS r   )rv   )r   r   r   r   r   r     s    z*TestBasic.test_reverse.<locals>.<listcomp>r   )	r!   r   r(   r%   r&   r#   ZassertIsr8   rU   )r   rf   r   r   r   r7   r   r   r   test_reverse  s     zTestBasic.test_reversec             C   s@  t d}t|}t|}|d | d|d t|}|d | d|d |  | t || xt|d D ]}t|}t|}|| xt|D ]}|d qW | t |t | ||  | t || |||  | t || q~W xt|d D ]}t|}t|}||  xt|D ]}|d qBW | t |t | || | t || |||  | t || qW t|}t|}|td  |j}xttd D ]}|  qW | t |t | | t	|jd	 | t	|jdd
 t }|  | |t  d S )Nabcder   rN   Zeabcdr-   Zbcdear0      rb   r/   )
tupler'   r   rV   r%   joinr!   BIGr8   rU   )r   rW   rf   r   r   r`   rz   Zdrr   r   r   test_rotate  sX    



zTestBasic.test_rotatec             C   s   t d}| t|d |  | t|d |  | t|d | t|j | t|d |d | t|d |d | t|d |	  | t|d d S )Nr[   rK   r   r   cr   )
r   r%   r'   r   r   r8   rw   r"   r$   r   )r   r   r   r   r   test_len  s    

zTestBasic.test_lenc             C   s&   t  }| t|j | t|j d S )N)r   r8   rw   r   r   )r   r   r   r   r   test_underflow  s    zTestBasic.test_underflowc             C   s`   t td}| t|d |  | t|d | t|g  |  | t|g  d S )NrH   r   )r   r!   r%   r'   r   r&   )r   r   r   r   r   
test_clear  s    zTestBasic.test_clearc             C   s   t d}|d | |t d |d | |t d | t|jd | |t d t ddt dg}t |}| t|jd x$t||D ]\}}| ||k qW xHdD ]@}t dg}|	t
||dg | t|jd | |t   qW d S )	NZabcdefghcijr   Z
abdefghcijZ	abdefghijr\   r]   )TFr[   )r   remover%   r8   r9   r
   r   zipre   r<   r   rw   )r   r   r`   rb   rc   matchr   r   r   test_remove  s"    



zTestBasic.test_removec             C   sJ   t td}tt|}| t|t| || | dt| d S )Nr   z...)r   r!   evalr;   r%   r&   r"   r   )r   r   r`   r   r   r   	test_repr  s
    
zTestBasic.test_reprc          	   C   s   t td}|| zRttj ttjd}t||dd |  ttjd}| 	|
 t| W d |  ttj X d S )Nr   r6   rN   )fileendr7   )r   r!   r"   r   r>   r?   r@   printrC   r%   rD   r;   )r   r   rF   r   r   r   
test_print  s    
zTestBasic.test_printc             C   s$   |  ttddd |  ttd d S )Nr,   rK   r0   r   )r8   rU   r   )r   r   r   r   	test_init   s    zTestBasic.test_initc             C   s   |  tttd d S )Nr,   )r8   rU   hashr   )r   r   r   r   	test_hash$  s    zTestBasic.test_hashc             C   s   xdD ]z}t t|}|j|j }}x<t|tD ].}|| | }||| kr0| |||  q0W | t|ttt| t qW d S )N)r   r   rK   rH   i  )r   r!   r"   r   r   r%   r&   )r   sizer   r"   r   r   rb   r   r   r   #test_long_steadystate_queue_popleft'  s    
z-TestBasic.test_long_steadystate_queue_popleftc             C   s   xdD ]}t tt|}|j|j }}x<t|tD ].}|| | }||| kr4| |||  q4W | ttt|ttt| t qW d S )N)r   r   rK   rH   i  )r   r#   r!   r$   r   r   r%   r&   )r   r   r   r"   r   r   rb   r   r   r   $test_long_steadystate_queue_popright2  s    
z.TestBasic.test_long_steadystate_queue_poprightc             C   s^   t  }|j|j }}xttD ]}|| qW x*ttD ]}| }||kr8| || q8W d S )N)r   r"   r   r!   r   r%   )r   r   r"   r   r   rb   r   r   r   test_big_queue_popleft>  s    z TestBasic.test_big_queue_popleftc             C   s^   t  }|j|j }}xttD ]}|| qW x*ttD ]}| }||kr8| || q8W d S )N)r   r$   r   r!   r   r%   )r   r   r"   r   r   rb   r   r   r   test_big_queue_poprightI  s    z!TestBasic.test_big_queue_poprightc             C   sr   t  }|j|j }}xttD ]}|| qW x.tttD ]}| }||kr<| || q<W | t|d d S )Nr   )r   r"   r   r!   r   r#   r%   r'   )r   r   r"   r   r   rb   r   r   r   test_big_stack_rightS  s    zTestBasic.test_big_stack_rightc             C   sr   t  }|j|j }}xttD ]}|| qW x.tttD ]}| }||kr<| || q<W | t|d d S )Nr   )r   r$   r   r!   r   r#   r%   r'   )r   r   r"   r   r   rb   r   r   r   test_big_stack_left^  s    zTestBasic.test_big_stack_leftc             C   s@   t td}t |}| t|t| | t|t| d S )Nr   )r   r!   assertNotEqualidr%   r&   )r   r   r`   r   r   r   test_roundtrip_iter_initi  s    z"TestBasic.test_roundtrip_iter_initc             C   s   xt tdt tddfD ]j}xdttjd D ]R}t||}t|}| t|t| | t	|t	| | |j
|j
 q0W qW d S )Nr   rH   r   )r   r!   pickleHIGHEST_PROTOCOLdumpsloadsr   r   r%   r&   r1   )r   r   r   rW   r`   r   r   r   test_pickleo  s     
zTestBasic.test_picklec             C   s   xt dt ddfD ]t}|| xdttjd D ]R}tt||}| t|t| | 	t|d t| | 	|j
|j
 q2W qW d S )Nr,   r0   r   r-   )r   r"   r!   r   r   r   r   r   r   r%   r1   )r   r   r   r`   r   r   r   test_pickle_recursivex  s    
zTestBasic.test_pickle_recursivec       
      C   s  t td}dd |D }xttjd D ]}t|}t||f|}t|\}}xt|D ]\}}	|	||< qbW | t	|t	| | t
|| t| t||f|}t|\}}xt|D ]\}}	|	||< qW | t	|t	| | t
||dd   x tdt|D ]}t| qW t||f|}t|\}}xt|D ]\}}	|	||< qTW | t	|t	| | t
|g  | tt| t||f|}t|\}}xt|D ]\}}	|	||< qW | t	|t	| | t
|g  q,W d S )Nr   c             S   s   g | ]}|d  qS )g)\(?r   )r   r   r   r   r   r     s    z2TestBasic.test_iterator_pickle.<locals>.<listcomp>r   )r   r!   r   r   r:   r   r   	enumerater%   r^   r&   nextr'   r8   StopIteration)
r   Zorigr   protoZitorgdumprE   r   r   rb   r   r   r   test_iterator_pickle  s@    zTestBasic.test_iterator_picklec             C   sb   dg}t |g}t|}| t|t| d|d< | t|t| | t|t| d S )Nr/   r5   r   )r   copyZdeepcopyr%   r&   r   r   )r   mutr   r`   r   r   r   test_deepcopy  s    

zTestBasic.test_deepcopyc          	   C   s   dg}t |g}t|}| t|t| d|d< | t|t| | t|t| xtdD ]}xtddD ]r}dd t|D }|dkrt |nt ||}| }| || | |j|j | t	d	d
 t
||D  qxW qhW d S )Nr/   r5   r   rR   r-      c             S   s   g | ]}t   qS r   )rv   )r   rz   r   r   r   r     s    z'TestBasic.test_copy.<locals>.<listcomp>c             s   s   | ]\}}||kV  qd S )Nr   )r   rb   rc   r   r   r   	<genexpr>  s    z&TestBasic.test_copy.<locals>.<genexpr>)r   r   r%   r&   r   r   r!   r1   re   allr   )r   r   r   r`   r   r1   rW   r   r   r   	test_copy  s    

zTestBasic.test_copyc             C   s`   dg}t |g}| }| t|t| d|d< | t|t| | t|t| d S )Nr/   r5   r   )r   r   r%   r&   r   r   )r   r   r   r`   r   r   r   test_copy_method  s    
zTestBasic.test_copy_methodc             C   s:   x4dt dfD ]$}| ttt|tt| qW d S )Nri   i  )r!   r%   r&   r#   r   )r   rW   r   r   r   test_reversed  s    zTestBasic.test_reversedc             C   sH   t tt }x4dtdfD ]$}| t|t|tt| qW d S )Nri   i  )r^   r#   r   r!   r%   r&   )r   klassrW   r   r   r   test_reversed_new  s    zTestBasic.test_reversed_newc             C   s6   dd l }t }x"tdD ]}|d |  qW d S )Nr   rH   r   )gcr   r!   r"   collect)r   r   r   r   r   r   r   test_gc_doesnt_blowup  s
    
zTestBasic.test_gc_doesnt_blowupc             C   s   G dd dt }xntdD ]b}| }t|}|dkrDt|dg}ntt|dg}t||_~~t	  | 
| d kd qW d S )Nc               @   s   e Zd ZdS )z,TestBasic.test_container_iterator.<locals>.CN)r   r   r   r   r   r   r   C  s   r   rK   r   r   zCycle was not collected)objectr!   weakrefrefr   r#   r:   rb   r   r   re   )r   r   r   objr   	containerr   r   r   test_container_iterator  s    

z!TestBasic.test_container_iteratorc             C   s   d}t d}td| }| tt | | j}|t ||  |td||  |td|d  ||  |td| |d|   |tdd|  |d|   d S )	N@   Z2P4nPzP%dPPr\   r   rK   *   +   )	r   Zcalcvobjsizestructcalcsizer%   r   
__sizeof__r   check_sizeof)r   ZBLOCKLENZbasesizeZ	blocksizeZcheckr   r   r   test_sizeof  s    
zTestBasic.test_sizeofN)6r   r   r   r+   rG   rI   rM   rY   rd   rg   rk   rs   rt   ru   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   cpython_onlyr   r   r   r   r   r      sb   *
!&
5	
		)			r   c               @   s$   e Zd Zdd Zdd Zdd ZdS )TestVariousIteratorArgsc             C   s   xddt ddt dddfD ]}xDtjtjtjtjtjtjfD ]$}| t	t
||t	|| q>W | tt
t| | tt
t| | tt
t| qW d S )NZ123rN   i  )Zdog333333?i  i  rR   )r!   r   SequenceZIterFuncZIterGenZIterFuncStopZ	itermultiZiterfuncr%   r&   r   r8   rU   ZIterNextOnlyZ
IterNoNextZeroDivisionErrorZ
IterGenExc)r   rW   rq   r   r   r   test_constructor  s     
$z(TestVariousIteratorArgs.test_constructorc             C   s*   t d}t|}|  | tt| d S )NZabcdefg)r   r:   r   r8   r   r   )r   r   rE   r   r   r   test_iter_with_altered_data  s    z3TestVariousIteratorArgs.test_iter_with_altered_datac             C   s*   t  }t|}|d | tt| d S )Nr/   )r   r:   r"   r8   r   r   )r   r   rE   r   r   r   !test_runtime_error_on_empty_deque  s    
z9TestVariousIteratorArgs.test_runtime_error_on_empty_dequeN)r   r   r   r   r   r   r   r   r   r   r     s   
r   c               @   s   e Zd ZdS )DequeN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd Zdd ZdS )DequeWithBadIterc             C   s   t d S )N)rU   )r   r   r   r   __iter__  s    zDequeWithBadIter.__iter__N)r   r   r   r   r   r   r   r   r     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 )TestSubclassc                s4  t td  td xtddD ]} | q&W x ttddD ]} | qHW | t ttdd | t d  fddtd	D }| |ttdd
 | t ttd
d  fddtd	D }|	  | |ttdd | t ttd
d  
  | t d d S )N   r   i  i8r   iX  c                s   g | ]}   qS r   )r   )r   r   )r   r   r   r   *  s    z,TestSubclass.test_basics.<locals>.<listcomp>r   r   c                s   g | ]}   qS r   )r   )r   r   )r   r   r   r   .  s    r    )r   r!   r   r"   r#   r$   r%   r&   r'   r(   r   )r   r   r)   r*   r   )r   r   r+      s"    zTestSubclass.test_basicsc             C   s  t d}| }| t|t| | t|t| t |}| t|t| | t|t| xhttjd D ]V}t||}t	|}| 
t|t| | t|t| | t|t| qxW t ddd}| }| t|t| | t|t| t |}| t|t| | t|t| xjttjd D ]X}t||}t	|}| 
t|t| | t|t| | t|t| qNW d S )Nr,   r   r   rJ   )r1   )r   __copy__r%   r^   r&   r!   r   r   r   r   r   r   )r   r   r`   r   rW   r   r   r   test_copy_pickle6  s4    

zTestSubclass.test_copy_picklec             C   s  xt tjd D ] }xtdtddfD ]}|| tt||}| t|t| | 	t
|t
| | 	|j|j | }| }| 	t|t| | 	|| ||_tt||}| 	t|jt| q,W x,tdtddfD ]}| ttj|| qW qW d S )Nr   r,   r0   rK   )r!   r   r   r   r"   r   r   r   r   r%   r^   r1   r   rb   r   r8   rU   )r   r   r   r`   ddeer   r   r   r   Z  s     
z"TestSubclass.test_pickle_recursivec             C   s<   t d}t|}| t|t| d }| tt| d S )NZgallahad)r   r   proxyr%   rB   r8   ReferenceError)r   r   pr   r   r   test_weakrefo  s
    
zTestSubclass.test_weakrefc             C   s8   G dd dt }|dddg}|dddg}||k d S )	Nc               @   s   e Zd Zdd ZdS )z-TestSubclass.test_strange_subclass.<locals>.Xc             S   s   t g S )N)r:   )r   r   r   r   r   x  s    z6TestSubclass.test_strange_subclass.<locals>.X.__iter__N)r   r   r   r   r   r   r   r   Xw  s   r   r   rK   r0   rJ   rR   r   )r   )r   r   Zd1Zd2r   r   r   test_strange_subclassv  s    z"TestSubclass.test_strange_subclassc          	   C   sn   G dd dt }| }dd }||_| t |d  W d Q R X | t |t dddg  W d Q R X d S )	Nc               @   s   e Zd ZdS )z&TestSubclass.test_bug_31608.<locals>.XN)r   r   r   r   r   r   r   r     s   r   c             _   s   dgS )Nr   r   )clsra   kwargsr   r   r   bad___new__  s    z0TestSubclass.test_bug_31608.<locals>.bad___new__r   r   rK   r0   )r   __new__r8   rU   )r   r   r   r   r   r   r   test_bug_31608  s    zTestSubclass.test_bug_31608N)r   r   r   r+   r   r   r   r   r   r   r   r   r   r   r   r     s   $	r   c               @   s   e Zd ZdddZdS )SubclassWithKwargsr   c             C   s   t |  d S )N)r   r   )r   newargr   r   r   r     s    zSubclassWithKwargs.__init__N)r   )r   r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd Zdd ZdS )TestSubclassWithKwargsc             C   s   t dd d S )Nr   )r   )r   )r   r   r   r   test_subclass_with_kwargs  s    z0TestSubclassWithKwargs.test_subclass_with_kwargsN)r   r   r   r   r   r   r   r   r     s   r   c               @   s0   e Zd ZeZdd Zdd Zdd Zdd Zd	S )
TestSequencec             C   s   d S )Nr   )r   r   r   r   r{     s    zTestSequence.test_getitemc             C   s   d S )Nr   )r   r   r   r   test_getslice  s    zTestSequence.test_getslicec             C   s   d S )Nr   )r   r   r   r   test_subscript  s    zTestSequence.test_subscriptc             C   s   |  d d S )Nz-Exhausted deque iterator doesn't free a deque)ZskipTest)r   r   r   r   test_free_after_iterating  s    z&TestSequence.test_free_after_iteratingN)	r   r   r   r   Z	type2testr{   r   r  r  r   r   r   r   r     s
   r   a
  
Example from the Library Reference:  Doc/lib/libcollections.tex

>>> from collections import deque
>>> d = deque('ghi')                 # make a new deque with three items
>>> for elem in d:                   # iterate over the deque's elements
...     print(elem.upper())
G
H
I
>>> d.append('j')                    # add a new entry to the right side
>>> d.appendleft('f')                # add a new entry to the left side
>>> d                                # show the representation of the deque
deque(['f', 'g', 'h', 'i', 'j'])
>>> d.pop()                          # return and remove the rightmost item
'j'
>>> d.popleft()                      # return and remove the leftmost item
'f'
>>> list(d)                          # list the contents of the deque
['g', 'h', 'i']
>>> d[0]                             # peek at leftmost item
'g'
>>> d[-1]                            # peek at rightmost item
'i'
>>> list(reversed(d))                # list the contents of a deque in reverse
['i', 'h', 'g']
>>> 'h' in d                         # search the deque
True
>>> d.extend('jkl')                  # add multiple elements at once
>>> d
deque(['g', 'h', 'i', 'j', 'k', 'l'])
>>> d.rotate(1)                      # right rotation
>>> d
deque(['l', 'g', 'h', 'i', 'j', 'k'])
>>> d.rotate(-1)                     # left rotation
>>> d
deque(['g', 'h', 'i', 'j', 'k', 'l'])
>>> deque(reversed(d))               # make a new deque in reverse order
deque(['l', 'k', 'j', 'i', 'h', 'g'])
>>> d.clear()                        # empty the deque
>>> d.pop()                          # cannot pop from an empty deque
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in -toplevel-
    d.pop()
IndexError: pop from an empty deque

>>> d.extendleft('abc')              # extendleft() reverses the input order
>>> d
deque(['c', 'b', 'a'])



>>> def delete_nth(d, n):
...     d.rotate(-n)
...     d.popleft()
...     d.rotate(n)
...
>>> d = deque('abcdef')
>>> delete_nth(d, 2)   # remove the entry at d[2]
>>> d
deque(['a', 'b', 'd', 'e', 'f'])



>>> def roundrobin(*iterables):
...     pending = deque(iter(i) for i in iterables)
...     while pending:
...         task = pending.popleft()
...         try:
...             yield next(task)
...         except StopIteration:
...             continue
...         pending.append(task)
...

>>> for value in roundrobin('abc', 'd', 'efgh'):
...     print(value)
...
a
d
e
b
f
c
g
h


>>> def maketree(iterable):
...     d = deque(iterable)
...     while len(d) > 1:
...         pair = [d.popleft(), d.popleft()]
...         d.append(pair)
...     return list(d)
...
>>> print(maketree('abcdefgh'))
[[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]]


libreftestc             C   s   dd l }tttttf}tj|  | r|t|dr|dd l	}d gd }x2t
t|D ]"}tj|  |  | ||< qNW t| ddlm} t||  d S )Nr   gettotalrefcountrR   )
test_deque)sysr   r   r   r   r   r   Zrun_unittesthasattrr   r!   r'   r   r  r   testr  Zrun_doctest)verboser  Ztest_classesr   Zcountsr   r  r   r   r   	test_main  s"    


r
  __main__T)r	  )N)collectionsr   Zunittestr  r   r   r   r   r   r   rv   r   r   r	   r
   r   ZTestCaser   r   r   r   r   r   r   Z
CommonTestr   r  Z__test__r
  r   r   r   r   r   <module>   s<        gqw

