o
    HXhn~                     @   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 d dl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d D ]Zeeeeee qu[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 dS )#    N)	randrangeshuffle)MutableMapping)mapping_testssupport)import_helpercollections_collections)Zblocked)Zfreshc              	   c   s:    t j|  }|t j| < zd V  W |t j| < d S |t j| < w N)sysmodules)nameZreplacementZoriginal_module r   @/opt/python-3.10.19/usr/lib/python3.10/test/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]d^ Z1e2j3d_d` Z4daS )bOrderedDictTestsc                 C   s^  | j }| t |ddgd  W d    n1 sw   Y  g d}| t|t| | | t|di t| | | t|| | | t|g dddd | | t|dd	 d
g | t|dd dg | t|d | t|dd | t|j |g d}|jddgddd | t| g d d S )Na   b   r   r   c   d   e   r   r   )r   	   r   r   r!   r   r    *   self)r'   r%   other)r)   r%   r   r   r   r   )r   ,   )r    7   r   f      r   gr   r   r   r   r   r   r-   )r2   r0   )	OrderedDictassertRaises	TypeErrorassertEqualsorteddictitemslist__init__)r'   r4   pairsr   r   r   r   	test_init"   s2   "zOrderedDictTests.test_initc                 C   sD   | j }g d}t| ||}|di |}| t| | d S )Nr3   r   )r4   r   r7   r;   r:   )r'   r4   r:   Zargdictr   r   r   r   test_468:   s   zOrderedDictTests.test_468c                 C   s  | j }| t | ddgd  W d    n1 sw   Y  g d}| }|t| | t| | | }|jdi t| | t| | | }|| | t| | | }|jg d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| g d |g d}|jddgddd | t| g d | t| jd | t| jdd | t|j | t| jd | t| jdd | t|j d S )Nr   r   r   r"   r   r!   r$      r&   )r'   r@   r(   r)   r/   r0      )redbluer)   r'   ))rC   r/   )r)   r0   )rB   r!   )r'   rA   r*   r   r-   r   r1   r3   r%   r   )	r4   r5   r6   updater9   r7   r8   r:   r;   )r'   r4   r=   odr   r   r   r   test_updateB   sN   
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                         d dS )Nkeysr   appendr&   Zcallsr   r   rH   s      
z3OrderedDictTests.test_init_calls.<locals>.Spam.keysc                    rG   )Nr:   r   rI   r&   rK   r   r   r:   v   rL   z4OrderedDictTests.test_init_calls.<locals>.Spam.itemsN)__name__
__module____qualname__rH   r:   r   rK   r   r   Spamr   s    rP   rH   )r4   r7   )r'   rP   r   rK   r   test_init_callsp   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      g | ]}|d fqS r
   r   .0r   r   r   r   
<listcomp>       z2OrderedDictTests.test_fromkeys.<locals>.<listcomp>valuec                 S   rS   r
   r   rT   r   r   r   rV      rW   r   c                 S   rS   r   r   rT   r   r   r   rV      rW   )r4   fromkeysr7   r;   r:   r'   r4   rE   r   r   r   test_fromkeys}   s   
"zOrderedDictTests.test_fromkeysc                 C   s(   | j }| | t | t|t d S r
   )r4   assertIsInstancer   
assertTrue
issubclass)r'   r4   r   r   r   test_abc   s   zOrderedDictTests.test_abcc                 C   sN   | j }g d}t| ||}| t|t| |  | t|d d S N)r   r   r   )r   r   r   r   r-   r   )r4   r   r7   lenclearr'   r4   r=   rE   r   r   r   
test_clear   s   zOrderedDictTests.test_clearc                 C   s   | j }g d}||}|d= | d| | t |d= W d    n1 s'w   Y  | t| |d d |dd    d S )Nrc   r   r   r   )r4   assertNotInr5   KeyErrorr7   r;   r:   rf   r   r   r   test_delitem   s   ,zOrderedDictTests.test_delitemc                 C   s>   | j }|g d}d|d< d|d< | t| g d d S )N)r   r   r   r   r   r   r   
   r      r.   )rk   r   )r   rm   rl   r   )r.   rn   r4   r7   r;   r:   r\   r   r   r   test_setitem   s   zOrderedDictTests.test_setitemc                 C   s  | j }g d}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 )	Nrc   c                 S      g | ]}|d  qS rZ   r   rU   tr   r   r   rV      rW   z3OrderedDictTests.test_iterators.<locals>.<listcomp>c                 S   rq   rZ   r   rr   r   r   r   rV      rW   c                 S   rq   r   r   rr   r   r   r   rV      rW   c                 S   rq   rZ   r   rr   r   r   r   rV      rW   c                 S   rq   rZ   r   rr   r   r   r   rV      rW   c                 S   rq   rt   r   rr   r   r   r   rV      rW   )r4   r   r7   r;   rH   valuesr:   reversedrf   r   r   r   test_iterators   s$   $zOrderedDictTests.test_iteratorsc                 C   s^   | j }|d}t|}t|}||= | t t| W d    d S 1 s(w   Y  d S )NrR   )r4   r[   iternextr5   	Exception)r'   r4   rE   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    n1 sw   Y  g d}||}| t|dd |D  | t| dd |D  | t| dd |D  | t| | | tt|tdd t|D  d S )	Nr   r   r   c                 S   rq   rZ   r   rr   r   r   r   rV      rW   z:OrderedDictTests.test_sorted_iterators.<locals>.<listcomp>c                 S   rq   rZ   r   rr   r   r   r   rV      rW   c                 S   rq   rt   r   rr   r   r   r   rV      rW   c                 S   rq   rZ   r   rr   r   r   r   rV      rW   )	r4   r5   r6   r7   r8   rH   ru   r:   rv   rf   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 r
   )r4   r7   r;   rH   ru   r:   rv   )r'   r4   rE   emptyr   r   r   test_iterators_empty   s   z%OrderedDictTests.test_iterators_emptyc                 C   s   | j }g d}t| ||}|r| | |  |s| t |  W d    n1 s1w   Y  | t|d d S rb   )r4   r   r7   popitempopr5   ri   rd   rf   r   r   r   test_popitem   s   
zOrderedDictTests.test_popitemc                 C   sb   | j }dd tdD }||}tdD ]}|d q|d |jdd | t|d d S )Nc                 S      g | ]}||fqS r   r   rU   ir   r   r   rV      rW   z6OrderedDictTests.test_popitem_last.<locals>.<listcomp>   rA   Tlastrn   )r4   ranger   r7   rd   )r'   r4   r=   objr   r   r   r   test_popitem_last   s   
z"OrderedDictTests.test_popitem_lastc                 C   sJ  | j }g d}t| ||}t| |r&| \}}| ||| |s| t |d W d    n1 s;w   Y  | 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    d S 1 sw   Y  d S )Nrc   Zxyzr   i90  c                   @      e Zd Zdd ZdS )z*OrderedDictTests.test_pop.<locals>.Missingc                 S      dS Nr   r   r'   r|   r   r   r   __missing__     z6OrderedDictTests.test_pop.<locals>.Missing.__missing__NrM   rN   rO   r   r   r   r   r   Missing      r   r   r   r   r!   r   r/   default)r4   r   r   r7   r5   ri   rd   )r'   r4   r=   rE   kvr   mr   r   r   test_pop   s.   
"zOrderedDictTests.test_popc                 C   s   | j }g d}t| ||}||}| || |dd  |d d  }||}| || | |t| | t|| | |||d d  d S )Nrc   r   )r4   r   r7   ZassertNotEqualr9   )r'   r4   r=   Zod1Zod2r   r   r   test_equality  s   zOrderedDictTests.test_equalityc              
      s  j }g d}||  fdd}|   |t  |t  tdj3 ttjd D ]#}j|d |t	t
 | W d    n1 sRw   Y  q4W d    n1 sbw   Y  |tt  | }|  || ||  d S )Nrc   c                    sn   d|  f } |  | |   t|  t   t| t  t| t  d S )Nz
copy: %s
od: %s)assertIsNotr7   r;   r:   rd   type)dupmsgrE   r'   r   r   check"  s   z,OrderedDictTests.test_copying.<locals>.checkr   r   )proto)r4   copydeepcopyr   moduler   pickleHIGHEST_PROTOCOLsubTestloadsdumpsevalreprrD   )r'   r4   r=   r   r   Zupdate_testr   r   r   test_copying  s(   
zOrderedDictTests.test_copyingc                 C   s:   | j }g d}||}| tdd | d D  d S )Nrc   c                 s   s    | ]	}t |tkV  qd S r
   )r   r;   )rU   Zpairr   r   r   	<genexpr>?  s    z5OrderedDictTests.test_yaml_linkage.<locals>.<genexpr>r   )r4   r_   all
__reduce__rf   r   r   r   test_yaml_linkage7  s   $z"OrderedDictTests.test_yaml_linkagec                 C   sj   | j }g d}||}| |jt | | d  d|_| |jd d | | d ddi d S )Nrc   r   rm   x)r4   r^   __dict__r9   assertIsNoner   r   r7   rf   r   r   r   test_reduce_not_too_fatA  s   z(OrderedDictTests.test_reduce_not_too_fatc                 C   s   | j }| }||d< td| j6 tdtjd D ]$}tt||}| || | 	t
| dg | |d | qW d    d S 1 sIw   Y  d S )Nr   r   r   )r4   r   r   r   r   r   r   r   r   r7   r;   rH   assertIs)r'   r4   rE   r   r   r   r   r   test_pickle_recursiveL  s   "z&OrderedDictTests.test_pickle_recursivec                 C   sL   | j }|g d}| t|d | tt|| | t| d d S )Nrc   zIOrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])zOrderedDict())r4   r7   r   r   r\   r   r   r   	test_reprY  s   
zOrderedDictTests.test_reprc                 C   s,   | j }|d}||d< | t|d d S )NrR   r   z@OrderedDict([('a', None), ('b', None), ('c', None), ('x', ...)]))r4   r[   r7   r   r\   r   r   r   test_repr_recursivea  s   

z$OrderedDictTests.test_repr_recursivec                 C   sP   | j }| }| |d< t|}| |t | |d< t|}| |t d S )Nr%   )r4   ru   r   r^   strr:   )r'   r4   rE   rr   r   r   test_repr_recursive_valuesi  s   z+OrderedDictTests.test_repr_recursive_valuesc                 C   s   | j }g d}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 )Nrc   r   rm   r   r   r   )r   rm   r2   r#   r   c                   @   r   )z1OrderedDictTests.test_setdefault.<locals>.Missingc                 S   r   r   r   r   r   r   r   r     r   z=OrderedDictTests.test_setdefault.<locals>.Missing.__missing__Nr   r   r   r   r   r     r   r   r!   )r4   r   r;   r:   r7   
setdefault)r'   r4   r=   rE   Z
pair_orderr   r   r   r   test_setdefaultw  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   ro   r\   r   r   r   test_reinsert  s   zOrderedDictTests.test_reinsertc                 C   s2  | 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    n1 svw   Y  | t |d
d W d    d S 1 sw   Y  d S )Nabcder   ZabdecFZcabder    r   r   Zbcader   )r4   r[   r7   r;   move_to_endr5   ri   r\   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 )
NrR   r   Fr   Zcabr   ZacbZbcaZbac)r4   r[   r   r7   r;   r\   r   r   r   test_move_to_end_issue25406  s   



z,OrderedDictTests.test_move_to_end_issue25406c                 C   s:   | j }tdd}|di |}| t|t| d S )Nr   r   r   )r4   r9   ZassertGreaterr   	getsizeof)r'   r4   r   rE   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)r4   splitr[   r7   rH   r9   r:   )r'   r4   srE   r   r   r   
test_views  s
   
zOrderedDictTests.test_viewsc                 C   s:   | j }G dd d|}g d}| t|| | d S )Nc                   @   r   )z3OrderedDictTests.test_override_update.<locals>.MyODc                 _   s   t  r
   )rz   )r'   argskwdsr   r   r   rD        z:OrderedDictTests.test_override_update.<locals>.MyOD.updateN)rM   rN   rO   rD   r   r   r   r   MyOD  r   r   )r   r   r   ro   )r'   r4   r   r:   r   r   r   test_override_update  s   z%OrderedDictTests.test_override_updatec                 C   s4   | j }d }tdD ]	}|d |fg}q	~t  d S )Ni  )r4   r   r   
gc_collect)r'   r4   r   _r   r   r   test_highly_nested  s   z#OrderedDictTests.test_highly_nestedc                    sj   | j }g  G  fddd|}d }tdD ]}|d |fg}||_q~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 r
   )rJ   r   r&   Zdeletedr   r   __del__  s   zBOrderedDictTests.test_highly_nested_subclass.<locals>.MyOD.__del__N)rM   rN   rO   r   r   r   r   r   r     s    r   d   )r4   r   r   r   r   r7   r;   rv   )r'   r4   r   r   r   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 r
   )_hashr   idrY   )r'   hashr   r   r   r<     s   zBOrderedDictTests.test_delitem_hash_collision.<locals>.Key.__init__c                 S      | j S r
   )r   r&   r   r   r   __hash__  r   zBOrderedDictTests.test_delitem_hash_collision.<locals>.Key.__hash__c                 S   s$   z| j |j kW S  ty   Y dS w )NF)rY   AttributeError)r'   r)   r   r   r   __eq__  s
   z@OrderedDictTests.test_delitem_hash_collision.<locals>.Key.__eq__c                 S   r   r
   rX   r&   r   r   r   __repr__  r   zBOrderedDictTests.test_delitem_hash_collision.<locals>.Key.__repr__N)rM   rN   rO   r<   r   r   r   r   r   r   r   Key  s
    r   c                 S   s$   d}| |d @ }|d> | |  d S )NrA   r   r   r   )r   ZMINSIZEr   r   r   r   blocking_hash  s   zCOrderedDictTests.test_delitem_hash_collision.<locals>.blocking_hashr   .after)r   .ro   )	r'   r4   r   r   Z	COLLIDINGr|   Z	collidingblockingrE   r   r   r   test_delitem_hash_collision  s    z,OrderedDictTests.test_delitem_hash_collisionc                 C   s  | j }G dd d}| }tdD ]	}| }|||< q| t t|  W d    n1 s1w   Y  | t t|  W d    n1 sLw   Y  | t t| W d    n1 sew   Y  | t |  W d    d S 1 sw   Y  d S )Nc                   @   r   )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rM   rN   rO   r   r   r   r   r   r     r   r   r   )	r4   r   r5   ri   r;   ru   r:   r   r   )r'   r4   r   rE   r   r|   r   r   r   test_issue24347  s$   


"z OrderedDictTests.test_issue24347c                 C   s0   | j }G dd d}| }d|| < |  d S )Nc                   @   r   )z-OrderedDictTests.test_issue24348.<locals>.Keyc                 S   r   )Nr   r   r&   r   r   r   r   -  r   z6OrderedDictTests.test_issue24348.<locals>.Key.__hash__Nr   r   r   r   r   r   ,  r   r   r   )r4   r   )r'   r4   r   rE   r   r   r   test_issue24348)  s
   
z OrderedDictTests.test_issue24348c                 C   sL   | j }| }dD ]}dD ]}t|dkr|jdd || }|||< qqdS )a  
        dict resizes after a certain number of insertion operations,
        whether or not there were deletions that freed up slots in the
        hash table.  During fast node lookup, OrderedDict must correctly
        respond to all resizes, even if the current "size" is the same
        as the old one.  We verify that here by forcing a dict resize
        on a sparse odict and then perform an operation that should
        trigger an odict resize (e.g. popitem).  One key aspect here is
        that we will keep the size of the odict the same at each popitem
        call.  This verifies that we handled the dict resize properly.
        Z0123456789ABCDEFr   Fr   N)r4   rd   r   )r'   r4   rE   Zc0c1r|   r   r   r   test_issue246675  s   
z OrderedDictTests.test_issue24667c                 C   .   | j }| }t|dd | dt| d S Nspamr   NULL)r4   r9   __setitem__rh   r   r\   r   r   r   test_dict_setitemN     z"OrderedDictTests.test_dict_setitemc                 C   `   | j }| }d|d< d|d< t|d | t t| W d    d S 1 s)w   Y  d S Nr   r   r   ham)r4   r9   __delitem__r5   ri   r   r\   r   r   r   test_dict_delitemT     
"z"OrderedDictTests.test_dict_delitemc                 C   s:   | j }| }d|d< d|d< t| | dt| d S )Nr   r   r   r   r   )r4   r9   re   rh   r   r\   r   r   r   test_dict_clear]  s   
z OrderedDictTests.test_dict_clearc                 C   r   r   )r4   r9   r   r5   ri   r   r\   r   r   r   test_dict_pope  r   zOrderedDictTests.test_dict_popc                 C   s^   | j }| }d|d< d|d< t| | t t| W d    d S 1 s(w   Y  d S r   )r4   r9   r   r5   ri   r   r\   r   r   r   test_dict_popitemn  s   

"z"OrderedDictTests.test_dict_popitemc                 C   r   r   )r4   r9   r   rh   r   r\   r   r   r   test_dict_setdefaultw  r   z%OrderedDictTests.test_dict_setdefaultc                 C   s.   | j }| }t|dg | dt| d S )N)r   r   r   )r4   r9   rD   rh   r   r\   r   r   r   test_dict_update}  r   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)rM   rN   rO   rE   r   r4   r   r   A  s    
r   )r4   rE   weakrefrefgc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      t |  S r
   )rx   rH   r   r   r   r   <lambda>      z<OrderedDictTests.test_free_after_iterating.<locals>.<lambda>c                 S   r  r
   )rx   ru   r  r   r   r   r    r  c                 S   r  r
   )rx   r:   r  r   r   r   r    r  )r   Zcheck_free_after_iteratingrx   r4   r&   r   r   r   test_free_after_iterating  s   z*OrderedDictTests.test_free_after_iteratingc                 C   sZ  | j }|dddd}|dddd}| }| }||O }|t| O }|ddddd}| |t|B | | ||B | | || | || | }||O }|ddddd}| t||B | | ||B | | || | t||B | | tt||B | | t|t|B | | }|d	O }|d
O }| || | t	 |d B  W d    n1 sw   Y  | t	 |d	B  W d    n1 sw   Y  | t	 |dB  W d    n1 sw   Y  | t	 |d
B  W d    n	1 sw   Y  | t
 |dO }W d    d S 1 s&w   Y  d S )Nr   r   )r   r   r   r   r   )r   r   r   )r   r   r   r   )r   r   r   r   r    ZBAD)r4   r   r;   r:   r7   r9   r   r   r5   r6   
ValueError)r'   r4   r   r   r   r   expectedr   r   r   test_merge_operator  sP   




$z$OrderedDictTests.test_merge_operatorc                 C   s6   t | d g i }t  | tt| d S r
   )rx   r4   r:   r   r  r_   Z
is_trackedry   )r'   r{   r   r   r   !test_ordered_dict_items_result_gc  s   z2OrderedDictTests.test_ordered_dict_items_result_gcN)5rM   rN   rO   r>   r?   rF   rQ   r]   ra   rg   rj   rp   rw   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       sd    .		

	'			+r   c                   @   s   e Zd ZeZejZdS )PurePythonOrderedDictTestsNrM   rN   rO   py_collr   r4   r   r   r   r   r    s    
r  c                   @   s   e Zd ZdZeZeZdS )CPythonBuiltinDictTestszaBuiltin dict preserves insertion order.

    Reuse some of tests in OrderedDict selectively.
    N)rM   rN   rO   __doc__builtinsr   r9   r4   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                   @   sH   e Zd ZeZejZejZejdd Z	dd Z
dd Zejdd Zd	S )
CPythonOrderedDictTestsc                 C   sl  | j }tj}tj}| j}|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Pn2Pr   c                 S   r   r   r   r   r   r   r   rV     rW   z=CPythonOrderedDictTests.test_sizeof_exact.<locals>.<listcomp>r   rA   r!   c                 S   r   r   r   r   r   r   r   rV     rW   rm      ZiP2n2P)r4   structcalcsizer   Zcalcobjsizecheck_sizeofr   rD   r   rH   r:   ru   rx   )r'   r4   r  sizer   Z	basicsizeZkeysizeZ	entrysizepZnodesizerE   Zitersizer   r   r   test_sizeof_exact  s2   

**z)CPythonOrderedDictTests.test_sizeof_exactc                 C   s  | j }|d}| t|td | t t|D ]\}}|| | |d qW d    n1 s6w   Y  | t |D ]}d |d< qCW d    n1 sTw   Y  | t |D ]}|d= qaW d    n1 sqw   Y  | t|td d S )Nr   r!   r.   r   Zbdeaf)	r4   r[   r7   r;   r5   RuntimeError	enumerater   Z
assertLess)r'   r4   rE   r   r   r   r   r    test_key_change_during_iteration  s(   


z8CPythonOrderedDictTests.test_key_change_during_iterationc              
   C   s   | j }g d}||}dD ]U}t||}t| dd  }ttjd D ]=}| j||d, t| }t| t	||}	t
|	}
| t|
| | t|| W d    n1 s\w   Y  q$qd S )Nrc   )rH   ru   r:   r   )method_nameprotocol)r4   getattrr;   r   r   r   r   rx   ry   r   r   r7   )r'   r4   r=   rE   r   methr
  r   r{   r  Z	unpickledr   r   r   test_iterators_pickling  s$   


z/CPythonOrderedDictTests.test_iterators_picklingc                 C   sJ   t   |  }||_g }|| t|}|| ~~~t   d S r
   )r   r  r4   cyclerJ   r   r   )r'   r   r%  Zx_refr   r   r   "test_weakref_list_is_not_traversed.  s   


z:CPythonOrderedDictTests.test_weakref_list_is_not_traversedN)rM   rN   rO   c_collr   r4   r   r  r  r  r  r$  r&  r   r   r   r   r    s    
 r  c                   @   "   e Zd ZeZG dd dejZdS )"PurePythonOrderedDictSubclassTestsc                   @      e Zd ZdS )z.PurePythonOrderedDictSubclassTests.OrderedDictNrM   rN   rO   r   r   r   r   r4   F      r4   Nr  r   r   r   r   r)  C      r)  c                   @   r(  )CPythonOrderedDictSubclassTestsc                   @   r*  )z+CPythonOrderedDictSubclassTests.OrderedDictNr+  r   r   r   r   r4   M  r,  r4   N)rM   rN   rO   r'  r   r4   r   r   r   r   r.  J  r-  r.  c                   @       e Zd Zedd Zdd ZdS )PurePythonGeneralMappingTestsc                 C      t j| _d S r
   r  r4   	type2testclsr   r   r   
setUpClassS     z(PurePythonGeneralMappingTests.setUpClassc                 C      |   }| t|j d S r
   Z_empty_mappingr5   ri   r   r'   r   r   r   r   r   W     z*PurePythonGeneralMappingTests.test_popitemNrM   rN   rO   classmethodr6  r   r   r   r   r   r0  Q  s    
r0  c                   @   r/  )CPythonGeneralMappingTestsc                 C   r1  r
   r'  r4   r3  r4  r   r   r   r6  _  r7  z%CPythonGeneralMappingTests.setUpClassc                 C   r8  r
   r9  r:  r   r   r   r   c  r;  z'CPythonGeneralMappingTests.test_popitemNr<  r   r   r   r   r>  \  s    
r>  c                   @   r/  )PurePythonSubclassMappingTestsc                 C      G dd dt j}|| _d S )Nc                   @   r*  )z@PurePythonSubclassMappingTests.setUpClass.<locals>.MyOrderedDictNr+  r   r   r   r   MyOrderedDictl  r,  rB  r2  r5  rB  r   r   r   r6  j     
z)PurePythonSubclassMappingTests.setUpClassc                 C   r8  r
   r9  r:  r   r   r   r   p  r;  z+PurePythonSubclassMappingTests.test_popitemNr<  r   r   r   r   r@  h  s    
r@  c                   @   r/  )CPythonSubclassMappingTestsc                 C   rA  )Nc                   @   r*  )z=CPythonSubclassMappingTests.setUpClass.<locals>.MyOrderedDictNr+  r   r   r   r   rB  z  r,  rB  r?  rC  r   r   r   r6  x  rD  z&CPythonSubclassMappingTests.setUpClassc                 C   r8  r
   r9  r:  r   r   r   r   ~  r;  z(CPythonSubclassMappingTests.test_popitemNr<  r   r   r   r   rE  u  s    
rE  __main__)+r  
contextlibr   r   r   randomr   r   r  r   Zunittestr   collections.abcr   testr   r   Ztest.supportr   Zimport_fresh_moduler  r'  contextmanagerr   r   ZTestCaser  r  r   methodsetattrr"  Z
skipUnlessr  r)  r.  ZBasicTestMappingProtocolr0  r>  r@  rE  rM   mainr   r   r   r   <module>   s^    
	     0

^

