B
    u9as                 @   s  d dl Z d dlZd dlZd dl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mZ d dlmZmZ ejddgdZejddgdZejd	d
 ZG dd dZG dd dee
jZG dd de
jZx"d D ]Zeeeeee qW [e
edG dd dee
jZG dd deZ G dd deZ!G dd dej"Z#e
edG dd dej"Z$G dd dej"Z%e
edG dd  d ej"Z&e'd!kre
(  dS )"    N)	randrangeshuffle)MutableMapping)mapping_testssupportcollections_collections)Zblocked)Zfreshc          	   c   s0   t j|  }|t j| < z
d V  W d |t j| < X d S )N)sysmodules)nameZreplacementZoriginal_module r   '/usr/lib/python3.7/test_ordered_dict.pyreplaced_module   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]S )^OrderedDictTestsc          
   C   s`  | j }| t |ddgd  W d Q R X dddddg}| t|t| | | t|f t| | | t|| | | t|ddddgddd	 | | t|d
d dg | t|d
d dg | t|d
 | t|dd | t|j |dddddg}|jddgddd | t| dddddddg d S )N)a   )b   )c   )d   )e   )r   	   r   r   )r   r   *   )self)r   r   )other)r   r   r   )r   ,   )r   7   )f      r   )gr   )r#   r"   )	OrderedDictassertRaises	TypeErrorassertEqualsorteddictitemslist__init__)r   r$   pairsr   r   r   r   	test_init   s$    zOrderedDictTests.test_initc             C   sJ   | j }dddddddg}t| ||}|f |}| t| | d S )N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   )r#   r"   )r$   r   r'   r+   r*   )r   r$   r*   Zargdictr   r   r   r   test_4687   s    
zOrderedDictTests.test_468c          
   C   s$  | j }| t | ddgd  W d Q R X dddddg}| }|t| | t| | | }|jf t| | t| | | }|| | t| | | }|jddddgddd	 | t| | | }|jd
d | t| dg | }|ji d | t| di fg | }|jddddd | tt| ddddg |dddddg}|jddgddd | t| dddddddg | t| jd | t| jdd | t|j | t| jd | t| jdd | t|j d S )N)r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   r   )r   r      )r   )r   r0   )r   r   r!   r"      )redbluer   r   )r3   r!   )r   r"   )r2   r   )r   r1   )r   r   )r   r   )r    r!   r   )r#   r   )r#   r"   r   r   )	r$   r%   r&   updater)   r'   r(   r*   r+   )r   r$   r-   odr   r   r   r   test_update?   sH    
zOrderedDictTests.test_updatec                s4   g  G  fddd}|  |  |  dg d S )Nc                   s$   e Zd Z fddZ fddZdS )z.OrderedDictTests.test_init_calls.<locals>.Spamc                s     d dS )Nkeysr   )append)r   )callsr   r   r7   p   s    
z3OrderedDictTests.test_init_calls.<locals>.Spam.keysc                s     d dS )Nr*   r   )r8   )r   )r9   r   r   r*   s   s    
z4OrderedDictTests.test_init_calls.<locals>.Spam.itemsN)__name__
__module____qualname__r7   r*   r   )r9   r   r   Spamo   s   r=   r7   )r$   r'   )r   r=   r   )r9   r   test_init_callsm   s    z OrderedDictTests.test_init_callsc             C   s   | j }|d}| t| dd dD  |jdd d}| t| dd dD  |jddd}| t| dd dD  d S )Nabcc             S   s   g | ]}|d fqS )Nr   ).0r   r   r   r   
<listcomp>}   s    z2OrderedDictTests.test_fromkeys.<locals>.<listcomp>)valuec             S   s   g | ]}|d fqS )Nr   )r@   r   r   r   r   rA      s    r   c             S   s   g | ]}|d fqS )r   r   )r@   r   r   r   r   rA      s    )r$   fromkeysr'   r+   r*   )r   r$   r5   r   r   r   test_fromkeysz   s    
zOrderedDictTests.test_fromkeysc             C   s(   | j }| | t | t|t d S )N)r$   assertIsInstancer   
assertTrue
issubclass)r   r$   r   r   r   test_abc   s    zOrderedDictTests.test_abcc             C   sV   | j }ddddddg}t| ||}| t|t| |  | t|d d S )N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   r   )r$   r   r'   lenclear)r   r$   r-   r5   r   r   r   
test_clear   s    zOrderedDictTests.test_clearc          	   C   sx   | j }ddddddg}||}|d= | d| | t |d= W d Q R X | t| |d d |d	d    d S )
N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   r   r   r   )r$   assertNotInr%   KeyErrorr'   r+   r*   )r   r$   r-   r5   r   r   r   test_delitem   s    zOrderedDictTests.test_delitemc          	   C   sL   | j }|dddddg}d|d< d|d	< | t| ddd
dddg d S )N)r   r   )r   r   )r   r   )r   r   )r   r   
   r      r    )r   rO   )r    rP   )r$   r'   r+   r*   )r   r$   r5   r   r   r   test_setitem   s    zOrderedDictTests.test_setitemc             C   s"  | j }ddddddg}t| ||}| t|dd |D  | t| d	d |D  | t| d
d |D  | t| | | tt|dd t|D  | tt| dd t|D  | tt| dd t|D  | tt| tt| d S )N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   c             S   s   g | ]}|d  qS )r   r   )r@   tr   r   r   rA      s    z3OrderedDictTests.test_iterators.<locals>.<listcomp>c             S   s   g | ]}|d  qS )r   r   )r@   rR   r   r   r   rA      s    c             S   s   g | ]}|d  qS )r   r   )r@   rR   r   r   r   rA      s    c             S   s   g | ]}|d  qS )r   r   )r@   rR   r   r   r   rA      s    c             S   s   g | ]}|d  qS )r   r   )r@   rR   r   r   r   rA      s    c             S   s   g | ]}|d  qS )r   r   )r@   rR   r   r   r   rA      s    )r$   r   r'   r+   r7   valuesr*   reversed)r   r$   r-   r5   r   r   r   test_iterators   s    zOrderedDictTests.test_iteratorsc          	   C   sH   | j }|d}t|}t|}||= | t t| W d Q R X d S )Nr?   )r$   rC   iternextr%   	Exception)r   r$   r5   itkeyr   r   r   %test_detect_deletion_during_iteration   s    
z6OrderedDictTests.test_detect_deletion_during_iterationc          	   C   s   | j }| t |ddgd  W d Q R X dddddg}||}| t|dd |D  | t| dd |D  | t| d	d |D  | t| | | tt|td
d t|D  d S )N)r   r   )r   r   )r   r   )r   r   )r   r   c             S   s   g | ]}|d  qS )r   r   )r@   rR   r   r   r   rA      s    z:OrderedDictTests.test_sorted_iterators.<locals>.<listcomp>c             S   s   g | ]}|d  qS )r   r   )r@   rR   r   r   r   rA      s    c             S   s   g | ]}|d  qS )r   r   )r@   rR   r   r   r   rA      s    c             S   s   g | ]}|d  qS )r   r   )r@   rR   r   r   r   rA      s    )	r$   r%   r&   r'   r(   r7   rS   r*   rT   )r   r$   r-   r5   r   r   r   test_sorted_iterators   s    z&OrderedDictTests.test_sorted_iteratorsc             C   s   | j }| }g }| t|| | t| | | t| | | t| | | tt|| | tt| | | tt| | | tt| | d S )N)r$   r'   r+   r7   rS   r*   rT   )r   r$   r5   emptyr   r   r   test_iterators_empty   s    z%OrderedDictTests.test_iterators_emptyc          	   C   sv   | j }ddddddg}t| ||}x|rB| | |  q(W | t |  W d Q R X | t|d d S )N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   r   )r$   r   r'   popitempopr%   rM   rI   )r   r$   r-   r5   r   r   r   test_popitem   s    zOrderedDictTests.test_popitemc             C   sf   | j }dd tdD }||}xtdD ]}|d q*W |d |jdd | t|d d S )Nc             S   s   g | ]}||fqS r   r   )r@   ir   r   r   rA      s    z6OrderedDictTests.test_popitem_last.<locals>.<listcomp>   r1   T)lastrP   )r$   ranger_   r'   rI   )r   r$   r-   objrb   r   r   r   test_popitem_last   s    
z"OrderedDictTests.test_popitem_lastc          	   C   s*  | j }ddddddg}t| ||}t| x&|rT| \}}| ||| q0W | t |d W d Q R X | t|d | ||d	d	 G d
d d|}|dd}| |ddd | |ddd | |ddd | |jdddd | t |d W d Q R X d S )N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   Zxyzr   i90  c               @   s   e Zd Zdd ZdS )z*OrderedDictTests.test_pop.<locals>.Missingc             S   s   dS )Nr   r   )r   rZ   r   r   r   __missing__   s    z6OrderedDictTests.test_pop.<locals>.Missing.__missing__N)r:   r;   r<   rh   r   r   r   r   Missing   s   ri   r   )r   r   r   r   r!   )default)r$   r   r`   r'   r%   rM   rI   )r   r$   r-   r5   kvri   mr   r   r   test_pop   s(    
zOrderedDictTests.test_popc             C   s   | j }ddddddg}t| ||}||}| || |dd  |d d  }||}| || | |t| | t|| | |||d d  d S )	N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   r   )r$   r   r'   ZassertNotEqualr)   )r   r$   r-   Zod1Zod2r   r   r   test_equality	  s    zOrderedDictTests.test_equalityc                s   j }ddddddg}||  fdd}|   |t  |t  td	jL xDttjd
 D ]2}j|d |t	t
 | W d Q R X qrW W d Q R X |tt  | }|  || ||  d S )N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   c                sn   d|  f } |  | |   t|  t   t| t  t| t  d S )Nz
copy: %s
od: %s)assertIsNotr'   r+   r*   rI   type)dupmsg)r5   r   r   r   check  s    z,OrderedDictTests.test_copying.<locals>.checkr   r   )proto)r$   copyZdeepcopyr   modulere   pickleHIGHEST_PROTOCOLsubTestloadsdumpsevalreprr4   )r   r$   r-   ru   rv   Zupdate_testr   )r5   r   r   test_copying  s     .
zOrderedDictTests.test_copyingc             C   sB   | j }ddddddg}||}| tdd | d	 D  d S )
N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   c             s   s   | ]}t |tkV  qd S )N)rr   r+   )r@   Zpairr   r   r   	<genexpr><  s    z5OrderedDictTests.test_yaml_linkage.<locals>.<genexpr>r   )r$   rF   all
__reduce__)r   r$   r-   r5   r   r   r   test_yaml_linkage4  s    z"OrderedDictTests.test_yaml_linkagec             C   sr   | j }ddddddg}||}| |jt | | d  d|_| |jd	 d | | d d	di d S )
N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   r   rO   x)r$   rE   __dict__r)   assertIsNoner   r   r'   )r   r$   r-   r5   r   r   r   test_reduce_not_too_fat>  s    z(OrderedDictTests.test_reduce_not_too_fatc          	   C   s   | j }| }||d< td| jd x\tdtjd D ]H}tt||}| || | 	t
| dg | |d | q4W W d Q R X d S )Nr   r   ro   )r$   r   rx   re   ry   rz   r|   r}   rq   r'   r+   r7   ZassertIs)r   r$   r5   rv   rs   r   r   r   test_pickle_recursiveI  s    z&OrderedDictTests.test_pickle_recursivec             C   sT   | j }|ddddddg}| t|d | tt|| | t| d d S )	N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   zIOrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])zOrderedDict())r$   r'   r   r~   )r   r$   r5   r   r   r   	test_reprV  s    
zOrderedDictTests.test_reprc             C   s,   | j }|d}||d< | t|d d S )Nr?   r   z@OrderedDict([('a', None), ('b', None), ('c', None), ('x', ...)]))r$   rC   r'   r   )r   r$   r5   r   r   r   test_repr_recursive^  s
    

z$OrderedDictTests.test_repr_recursivec             C   sP   | j }| }| |d< t|}| |t | |d< t|}| |t d S )Nr   )r$   rS   r   rE   strr*   )r   r$   r5   rr   r   r   test_repr_recursive_valuesf  s    z+OrderedDictTests.test_repr_recursive_valuesc             C   s   | j }ddddddg}t| ||}t| }| |ddd	 | t| | | |d
dd | t| d d | |jdddd G dd d|}| | ddd d S )N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   r   rO   r   r   ro   )r   rO   r#   r   )rj   c               @   s   e Zd Zdd ZdS )z1OrderedDictTests.test_setdefault.<locals>.Missingc             S   s   dS )Nr   r   )r   rZ   r   r   r   rh     s    z=OrderedDictTests.test_setdefault.<locals>.Missing.__missing__N)r:   r;   r<   rh   r   r   r   r   ri     s   ri   r   )r$   r   r+   r*   r'   
setdefault)r   r$   r-   r5   Z
pair_orderri   r   r   r   test_setdefaultt  s    z OrderedDictTests.test_setdefaultc             C   s\   | j }| }d|d< d|d< |d= | t| dg d|d< | t| ddg d S )Nr   r   r   r   )r   r   )r   r   )r$   r'   r+   r*   )r   r$   r5   r   r   r   test_reinsert  s    zOrderedDictTests.test_reinsertc          	   C   s  | j }|d}| t|td |d | t|td |dd | t|td |dd | t|td |d | t|td |jddd	 | t|td
 | t |d W d Q R X | t |dd W d Q R X d S )Nabcder   Zabdecr   Zcabder   r   F)rd   Zbcader   )r$   rC   r'   r+   move_to_endr%   rM   )r   r$   r5   r   r   r   test_move_to_end  s"    


z!OrderedDictTests.test_move_to_endc             C   s   | j }|d}|jddd | t|td |jddd | t|td |d}|d | t|td |d | t|td	 d S )
Nr?   r   F)rd   Zcabr   ZacbZbcaZbac)r$   rC   r   r'   r+   )r   r$   r5   r   r   r   test_move_to_end_issue25406  s    



z,OrderedDictTests.test_move_to_end_issue25406c             C   s6   | j }tdd}|f |}| t|t| d S )Nr   )r   )r$   r)   ZassertGreaterr	   	getsizeof)r   r$   r   r5   r   r   r   test_sizeof  s    

zOrderedDictTests.test_sizeofc             C   sL   | j }d }||}| | t|  | | t|  d S )Nz@the quick brown fox jumped over a lazy dog yesterday before dawn)r$   splitrC   r'   r7   r)   r*   )r   r$   sr5   r   r   r   
test_views  s
    
zOrderedDictTests.test_viewsc             C   s<   | j }G dd d|}dddg}| t|| | d S )Nc               @   s   e Zd Zdd ZdS )z3OrderedDictTests.test_override_update.<locals>.MyODc             _   s
   t  d S )N)rX   )r   argskwdsr   r   r   r4     s    z:OrderedDictTests.test_override_update.<locals>.MyOD.updateN)r:   r;   r<   r4   r   r   r   r   MyOD  s   r   )r   r   )r   r   )r   r   )r$   r'   r+   r*   )r   r$   r   r*   r   r   r   test_override_update  s    
z%OrderedDictTests.test_override_updatec             C   s8   | j }d }xtdD ]}|d |fg}qW ~t  d S )Ni  )r$   re   r   
gc_collect)r   r$   rf   _r   r   r   test_highly_nested  s    z#OrderedDictTests.test_highly_nestedc                sn   | j }g  G  fddd|}d }x$tdD ]}|d |fg}||_q,W ~t  |  tttd d S )Nc                   s   e Zd Z fddZdS )z:OrderedDictTests.test_highly_nested_subclass.<locals>.MyODc                s     | j d S )N)r8   rb   )r   )deletedr   r   __del__  s    zBOrderedDictTests.test_highly_nested_subclass.<locals>.MyOD.__del__N)r:   r;   r<   r   r   )r   r   r   r     s   r   d   )r$   re   rb   r   r   r'   r+   rT   )r   r$   r   rf   rb   r   )r   r   test_highly_nested_subclass  s    
z,OrderedDictTests.test_highly_nested_subclassc       	      C   s   | j }G dd d}dd }d}||}||}|||}| }d||< d||< d||< d|d< ||= ||= | t| |dfdg d S )	Nc               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
z9OrderedDictTests.test_delitem_hash_collision.<locals>.Keyc             S   s   || _ tt| | _d S )N)_hashr   idrB   )r   hashr   r   r   r,     s    zBOrderedDictTests.test_delitem_hash_collision.<locals>.Key.__init__c             S   s   | j S )N)r   )r   r   r   r   __hash__  s    zBOrderedDictTests.test_delitem_hash_collision.<locals>.Key.__hash__c             S   s&   y| j |j kS  tk
r    dS X d S )NF)rB   AttributeError)r   r   r   r   r   __eq__  s    z@OrderedDictTests.test_delitem_hash_collision.<locals>.Key.__eq__c             S   s   | j S )N)rB   )r   r   r   r   __repr__  s    zBOrderedDictTests.test_delitem_hash_collision.<locals>.Key.__repr__N)r:   r;   r<   r,   r   r   r   r   r   r   r   Key  s   r   c             S   s$   d}| |d @ }|d> | |  d S )Nr1   r   r   r   )r   ZMINSIZErb   r   r   r   blocking_hash  s    zCOrderedDictTests.test_delitem_hash_collision.<locals>.blocking_hashr   .after)r   .)r$   r'   r+   r*   )	r   r$   r   r   Z	COLLIDINGrZ   Z	collidingZblockingr5   r   r   r   test_delitem_hash_collision  s    z,OrderedDictTests.test_delitem_hash_collisionc          	   C   s   | j }G dd d}| }xtdD ]}| }|||< q$W | t t|  W d Q R X | t t|  W d Q R X | t t| W d Q R X | t |  W d Q R X d S )Nc               @   s   e Zd Zdd ZdS )z-OrderedDictTests.test_issue24347.<locals>.Keyc             S   s   t dS )Ni )r   )r   r   r   r   r     s    z6OrderedDictTests.test_issue24347.<locals>.Key.__hash__N)r:   r;   r<   r   r   r   r   r   r     s   r   r   )	r$   re   r%   rM   r+   rS   r*   r   rw   )r   r$   r   r5   rb   rZ   r   r   r   test_issue24347  s    z OrderedDictTests.test_issue24347c             C   s0   | j }G dd d}| }d|| < |  d S )Nc               @   s   e Zd Zdd ZdS )z-OrderedDictTests.test_issue24348.<locals>.Keyc             S   s   dS )Nr   r   )r   r   r   r   r   &  s    z6OrderedDictTests.test_issue24348.<locals>.Key.__hash__N)r:   r;   r<   r   r   r   r   r   r   %  s   r   r   )r$   r_   )r   r$   r   r5   r   r   r   test_issue24348"  s
    
z OrderedDictTests.test_issue24348c             C   sT   | j }| }xBdD ]:}x4dD ],}t|dkr8|jdd || }|||< qW qW d S )NZ0123456789ABCDEFr   F)rd   )r$   rI   r_   )r   r$   r5   Zc0Zc1rZ   r   r   r   test_issue24667.  s    

z OrderedDictTests.test_issue24667c             C   s.   | j }| }t|dd | dt| d S )Nspamr   NULL)r$   r)   __setitem__rL   r   )r   r$   r5   r   r   r   test_dict_setitemG  s    z"OrderedDictTests.test_dict_setitemc          	   C   sJ   | j }| }d|d< d|d< t|d | t t| W d Q R X d S )Nr   r   r   ham)r$   r)   __delitem__r%   rM   r   )r   r$   r5   r   r   r   test_dict_delitemM  s    z"OrderedDictTests.test_dict_delitemc             C   s:   | j }| }d|d< d|d< t| | dt| d S )Nr   r   r   r   r   )r$   r)   rJ   rL   r   )r   r$   r5   r   r   r   test_dict_clearV  s    
z OrderedDictTests.test_dict_clearc          	   C   sJ   | j }| }d|d< d|d< t|d | t t| W d Q R X d S )Nr   r   r   r   )r$   r)   r`   r%   rM   r   )r   r$   r5   r   r   r   test_dict_pop^  s    zOrderedDictTests.test_dict_popc          	   C   sH   | j }| }d|d< d|d< t| | t t| W d Q R X d S )Nr   r   r   r   )r$   r)   r_   r%   rM   r   )r   r$   r5   r   r   r   test_dict_popitemg  s    
z"OrderedDictTests.test_dict_popitemc             C   s.   | j }| }t|dd | dt| d S )Nr   r   r   )r$   r)   r   rL   r   )r   r$   r5   r   r   r   test_dict_setdefaultp  s    z%OrderedDictTests.test_dict_setdefaultc             C   s.   | j }| }t|dg | dt| d S )N)r   r   r   )r$   r)   r4   rL   r   )r   r$   r5   r   r   r   test_dict_updatev  s    z!OrderedDictTests.test_dict_updatec                sF   | j  G  fddd}d |j|< t|}~t  | |  d S )Nc                   s   e Zd Z  ZdS )z/OrderedDictTests.test_reference_loop.<locals>.AN)r:   r;   r<   r5   r   )r$   r   r   A  s   r   )r$   r5   weakrefrefgcZcollectr   )r   r   r   r   )r$   r   test_reference_loop|  s    

z$OrderedDictTests.test_reference_loopc             C   sP   t | t| j t | dd | j t | dd | j t | dd | j d S )Nc             S   s   t |  S )N)rV   r7   )r   r   r   r   <lambda>      z<OrderedDictTests.test_free_after_iterating.<locals>.<lambda>c             S   s   t |  S )N)rV   rS   )r   r   r   r   r     r   c             S   s   t |  S )N)rV   r*   )r   r   r   r   r     r   )r   Zcheck_free_after_iteratingrV   r$   )r   r   r   r   test_free_after_iterating  s    z*OrderedDictTests.test_free_after_iteratingN)1r:   r;   r<   r.   r/   r6   r>   rD   rH   rK   rN   rQ   rU   r[   r\   r^   ra   rg   rn   rp   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      s\   .		

		'			r   c               @   s   e Zd ZeZejZdS )PurePythonOrderedDictTestsN)r:   r;   r<   py_collrx   r$   r   r   r   r   r     s   r   c               @   s   e Zd ZeZeZdS )CPythonBuiltinDictTestsN)r:   r;   r<   builtinsrx   r)   r$   r   r   r   r   r     s   r   ztest_init test_update test_abc test_clear test_delitem test_setitem test_detect_deletion_during_iteration test_popitem test_reinsert test_override_update test_highly_nested test_highly_nested_subclass test_delitem_hash_collision z0requires the C version of the collections modulec               @   s:   e Zd ZeZejZejZejdd Z	dd Z
dd ZdS )CPythonOrderedDictTestsc             C   s|  | j }tj}tj}| j}|d|d }|d}|d}|d}| }	||	|d d|   d|	_||	|d d|   |	d	d
 tdD  ||	|d|  d d|  d|   |	dd
 tddD  ||	|d|  d d|  d|   ||		 |d ||	
 |d ||	 |d |d}
|t|	|
 |t|		 |
 |t|	
 |
 |t|	 |
 d S )NZnQ2P3PnPn2PZ2nP2nZn2PPZPn2Pr1   r   r   c             S   s   g | ]}||fqS r   r   )r@   rb   r   r   r   rA     s    z=CPythonOrderedDictTests.test_sizeof_exact.<locals>.<listcomp>r   c             S   s   g | ]}||fqS r   r   )r@   rb   r   r   r   rA     s    rO      ZiP2n2P)r$   structcalcsizer   Zcalcobjsizecheck_sizeofr   r4   re   r7   r*   rS   rV   )r   r$   r   sizeru   Z	basicsizeZ	entrysizepZnodesizer5   Zitersizer   r   r   test_sizeof_exact  s0    &&z)CPythonOrderedDictTests.test_sizeof_exactc          	   C   s   | j }|d}| t|td | t2 x*t|D ]\}}|| | |d q:W W d Q R X | t x|D ]}d |d< qxW W d Q R X | t x|D ]
}|d= qW W d Q R X | t|td d S )Nr   r   r    r   Zbdeaf)	r$   rC   r'   r+   r%   RuntimeError	enumerater   Z
assertLess)r   r$   r5   rb   rk   r   r   r    test_key_change_during_iteration  s    



z8CPythonOrderedDictTests.test_key_change_during_iterationc             C   s   | j }ddddddg}||}xdD ]}t||}t| dd  }xxttjd D ]f}| j||d	N t| }t| t	||}	t
|	}
| t|
| | t|| W d Q R X qTW q$W d S )
N)r   r   )r   r   )r   r   )r   r   )r   r   )r    r!   )r7   rS   r*   r   )method_nameZprotocol)r$   getattrr+   re   ry   rz   r{   rV   rW   r}   r|   r'   )r   r$   r-   r5   r   ZmethZexpectedrb   rY   r   Z	unpickledr   r   r   test_iterators_pickling  s    



z/CPythonOrderedDictTests.test_iterators_picklingN)r:   r;   r<   c_collrx   r$   r   r   Zcpython_onlyr   r   r   r   r   r   r   r     s    r   c               @   s"   e Zd ZeZG dd dejZdS )"PurePythonOrderedDictSubclassTestsc               @   s   e Zd ZdS )z.PurePythonOrderedDictSubclassTests.OrderedDictN)r:   r;   r<   r   r   r   r   r$     s   r$   N)r:   r;   r<   r   rx   r$   r   r   r   r   r     s   r   c               @   s"   e Zd ZeZG dd dejZdS )CPythonOrderedDictSubclassTestsc               @   s   e Zd ZdS )z+CPythonOrderedDictSubclassTests.OrderedDictN)r:   r;   r<   r   r   r   r   r$     s   r$   N)r:   r;   r<   r   rx   r$   r   r   r   r   r     s   r   c               @   s    e Zd Zedd Zdd ZdS )PurePythonGeneralMappingTestsc             C   s   t j| _d S )N)r   r$   	type2test)clsr   r   r   
setUpClass  s    z(PurePythonGeneralMappingTests.setUpClassc             C   s   |   }| t|j d S )N)_empty_mappingr%   rM   r_   )r   r   r   r   r   ra     s    z*PurePythonGeneralMappingTests.test_popitemN)r:   r;   r<   classmethodr   ra   r   r   r   r   r     s   r   c               @   s    e Zd Zedd Zdd ZdS )CPythonGeneralMappingTestsc             C   s   t j| _d S )N)r   r$   r   )r   r   r   r   r     s    z%CPythonGeneralMappingTests.setUpClassc             C   s   |   }| t|j d S )N)r   r%   rM   r_   )r   r   r   r   r   ra     s    z'CPythonGeneralMappingTests.test_popitemN)r:   r;   r<   r   r   ra   r   r   r   r   r   
  s   r   c               @   s    e Zd Zedd Zdd ZdS )PurePythonSubclassMappingTestsc             C   s   G dd dt j}|| _d S )Nc               @   s   e Zd ZdS )z@PurePythonSubclassMappingTests.setUpClass.<locals>.MyOrderedDictN)r:   r;   r<   r   r   r   r   MyOrderedDict  s   r   )r   r$   r   )r   r   r   r   r   r     s    z)PurePythonSubclassMappingTests.setUpClassc             C   s   |   }| t|j d S )N)r   r%   rM   r_   )r   r   r   r   r   ra     s    z+PurePythonSubclassMappingTests.test_popitemN)r:   r;   r<   r   r   ra   r   r   r   r   r     s   r   c               @   s    e Zd Zedd Zdd ZdS )CPythonSubclassMappingTestsc             C   s   G dd dt j}|| _d S )Nc               @   s   e Zd ZdS )z=CPythonSubclassMappingTests.setUpClass.<locals>.MyOrderedDictN)r:   r;   r<   r   r   r   r   r   (  s   r   )r   r$   r   )r   r   r   r   r   r   &  s    z&CPythonSubclassMappingTests.setUpClassc             C   s   |   }| t|j d S )N)r   r%   rM   r_   )r   r   r   r   r   ra   ,  s    z(CPythonSubclassMappingTests.test_popitemN)r:   r;   r<   r   r   ra   r   r   r   r   r   #  s   r   __main__))r   
contextlibrw   r   ry   Zrandomr   r   r   r	   Zunittestr   Zcollections.abcr   Ztestr   r   Zimport_fresh_moduler   r   contextmanagerr   r   ZTestCaser   r   r   methodsetattrr   Z
skipUnlessr   r   r   ZBasicTestMappingProtocolr   r   r   r   r:   mainr   r   r   r   <module>   sJ   
    u	I


