
    dafv              	          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      Z ej&                  ddg	      Zej,                  d
        Z G d d      Z G d dee
j2                        Z G d de
j2                        Zdj9                         D ]  Z eee eee              [ e
j@                  ed       G d dee
j2                               Z! G d de      Z" G d de!      Z# G d de
j2                        Z$ e
j@                  ed       G d de
j2                               Z% G d dejL                        Z' e
j@                  ed       G d d ejL                               Z( G d! d"ejL                        Z) e
j@                  ed       G d# d$ejL                               Z* G d% d&      Z+ G d' d(      Z, G d) d*e,e
j2                        Z- e
j@                  ed       G d+ d,e,e
j2                               Z.e/d-k(  r e
j`                          yy).    N)	randrangeshuffle)MutableMapping)mapping_testssupport)import_helpercollections_collections)blocked)freshc              #      K   t         j                  |    }|t         j                  | <   	 d  |t         j                  | <   y # |t         j                  | <   w xY wwN)sysmodules)namereplacementoriginal_modules      1/root/Python-3.12.4/Lib/test/test_ordered_dict.pyreplaced_moduler      sF     kk$'O#CKK,+DODs   'AA AAAc                   P   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2e3jh                  d1        Z5y2)3OrderedDictTestsc                 .   | j                   }| j                  t              5   |ddgd        d d d        g d}| j                  t	         |t        |            j                               |       | j                  t	         |di t        |      j                               |       | j                  t         ||      j                               |       | j                  t         |g ddd      j                               |       | j                  t         |d	      j                               d
g       | j                  t         |d      j                               dg       | j                  t        |d       | j                  t        |dd       | j                  t        |j                          |g d      }|j                  ddgdd       | j                  t        |j                               g d       y # 1 sw Y   xY w)Na   b   r   r   c   d   e   r   r   )r!   	   r#   r"   r(   r!   r'   *   self)r.   r,   other)r0   r,    r   r   r    )r$   ,   )r'   7   r&   f      r%   gr$   r   r   r    r#   r&   r5   )r:   r8   )	OrderedDictassertRaises	TypeErrorassertEqualsorteddictitemslist__init__)r.   r<   pairsr$   s       r   	test_initzOrderedDictTests.test_init"   s   &&y) 	48,d3	4BDK 8 > > @A5I :d5k : @ @ BCUKk%066895Ak*R,-449EG=>C	E 	kr288:;l^Lk399;<}oN)["5)["b9)[%9%9: LM	

Hh'1
2aggiR	T'	4 	4s   H

Hc                     | j                   }g d}t        |        ||      } |di |}| j                  t        |j	                               |       y )Nr;   r1   )r<   r   r?   rC   rB   )r.   r<   rB   argdictr$   s        r   test_468zOrderedDictTests.test_468:   sJ    &&Ve$"'"aggi%0    c                    | j                   }| j                  t              5   |       j                  ddgd        d d d        g d} |       }|j                  t	        |             | j                  t        |j                               |        |       } |j                  di t	        |       | j                  t        |j                               |        |       }|j                  |       | j                  t        |j                               |        |       }|j                  g ddd       | j                  t        |j                               |        |       }|j                  d	       | j                  t        |j                               d
g        |       }|j                  i        | j                  t        |j                               di fg        |       }|j                  dddd       | j                  t        t        |j                                     g d        |g d      }|j                  ddgdd       | j                  t        |j                               g d       | j                  t         |       j                  d       | j                  t         |       j                  dd       | j                  t        |j                         | j                  t         |       j                  d       | j                  t         |       j                  dd       | j                  t        |j                         y # 1 sw Y   (xY w)Nr   r   r   r)   r"   r(   r+      r-   )r.   rL   r/   r0   r7   r8      )redbluer0   r.   ))rO   r7   )r0   r8   )rN   r(   )r.   rM   r2   r&   r5   r%   r9   r;   r,   r1   )	r<   r=   r>   updaterA   r?   r@   rB   rC   )r.   r<   rE   odr$   s        r   test_updatezOrderedDictTests.test_updateB   s   &&y) 	=M  (H!5t<	=B]
		$u+
+U3]		 DK 
+U3]
		%bhhj)51]
		:a1	Ebhhj)51 ]
		r	bhhj)L>:]
			bhhj)WbM?;]
		aaqq	1RXXZ 01M	O
 LM	(H%a0aggiR	T 	)[]%9%92>)[]%9%92rB)[%7%78)[]%9%92>)[]%9%92rB)[%7%78U	= 	=s   M""M,c                 t    g  G fdd      }| j                   |              | j                  dg       y )Nc                   "    e Zd Z fdZ fdZy).OrderedDictTests.test_init_calls.<locals>.Spamc                 (    j                  d       y)Nkeysr1   appendr.   callss    r   rW   z3OrderedDictTests.test_init_calls.<locals>.Spam.keyss   s    V$rJ   c                 (    j                  d       y)NrB   r1   rX   rZ   s    r   rB   z4OrderedDictTests.test_init_calls.<locals>.Spam.itemsv   s    W%rJ   N)__name__
__module____qualname__rW   rB   )r[   s   r   SpamrU   r   s    rJ   r`   rW   )r<   r?   )r.   r`   r[   s     @r   test_init_callsz OrderedDictTests.test_init_callsp   s6    	 	 	 )rJ   c                 J    | j                   } G d d|      } |       }d|d<   y )Nc                       e Zd Zd Zy)3OrderedDictTests.test_overridden_init.<locals>.ODNIc                       y r   r1   )argskwargss     r   rD   z<OrderedDictTests.test_overridden_init.<locals>.ODNI.__init__   s    rJ   N)r]   r^   r_   rD   r1   rJ   r   ODNIrd      s    rJ   rh   r   r   r<   )r.   r<   rh   rQ   s       r   test_overridden_initz%OrderedDictTests.test_overridden_init}   s-     &&	; 	 V3rJ   c                    | j                   }|j                  d      }| j                  t        |j	                               dD cg c]  }|d f c}       |j                  dd       }| j                  t        |j	                               dD cg c]  }|d f c}       |j                  dd      }| j                  t        |j	                               dD cg c]  }|df c}       y c c}w c c}w c c}w )Nabcvaluer   )r<   fromkeysr?   rC   rB   )r.   r<   rQ   r!   s       r   test_fromkeyszOrderedDictTests.test_fromkeys   s    &&!!%(bhhj)u+E!QI+EF!!%t!4bhhj)u+E!QI+EF!!%q!1bhhj)E+BqQF+BC	 ,F+E+Bs   C0
C5
C:
c                     | j                   }| j                   |       t               | j                  t	        |t                     y r   )r<   assertIsInstancer   
assertTrue
issubclass)r.   r<   s     r   test_abczOrderedDictTests.test_abc   s2    &&km^<
;?@rJ   c                     | j                   }g d}t        |        ||      }| j                  t        |      t        |             |j	                          | j                  t        |      d       y N)r!   r   r   )r   r"   r#   r&   r5   r   )r<   r   r?   lenclearr.   r<   rE   rQ   s       r   
test_clearzOrderedDictTests.test_clear   sX    &&LR#e*-

R!$rJ   c                    | j                   }g d} ||      }|d= | j                  d|       | j                  t              5  |d= d d d        | j	                  t        |j                               |d d |dd  z          y # 1 sw Y   <xY w)Nrx   r   r   r"   )r<   assertNotInr=   KeyErrorr?   rC   rB   r{   s       r   test_delitemzOrderedDictTests.test_delitem   s    &&LsGb!x( 	3	bhhj)5!9uQRy+@A	 	s   BBc                     | j                   } |g d      }d|d<   d|d<   | j                  t        |j                               g d       y )N)r$   r   r   r    r   r%   r&   
   r!      r6   )r   r   )r!   r   r   r&   )r6   r   r<   r?   rC   rB   r.   r<   rQ   s      r   test_setitemzOrderedDictTests.test_setitem   sI    &&KL33bhhj)W	YrJ   c                 L   | j                   }g d}t        |        ||      }| j                  t        |      |D cg c]  }|d   	 c}       | j                  t        |j	                               |D cg c]  }|d   	 c}       | j                  t        |j                               |D cg c]  }|d   	 c}       | j                  t        |j                               |       | j                  t        t        |            t        |      D cg c]  }|d   	 c}       | j                  t        t        |j	                                     t        |      D cg c]  }|d   	 c}       | j                  t        t        |j                                     t        |      D cg c]  }|d   	 c}       | j                  t        t        |j                                     t        t        |                   y c c}w c c}w c c}w c c}w c c}w c c}w )Nrx   r   r   )r<   r   r?   rC   rW   valuesrB   reversedr.   r<   rE   rQ   ts        r   test_iteratorszOrderedDictTests.test_iterators   s   &&Lb%#8QAaD#89bggi*?A1Q4*?@biik*5,AaQqT,ABbhhj)51hrl+(081!A$8	:hrwwy12(081!A$8	:hryy{34(081!A$8	:hrxxz23T(5/5JK $9*?,A 988s#   H
7H
1H
H
$H
0H!
c                     | j                   }|j                  d      }t        |      }t        |      }||= | j	                  t
              5  t        |       d d d        y # 1 sw Y   y xY w)Nrl   )r<   ro   iternextr=   	Exception)r.   r<   rQ   itkeys        r   %test_detect_deletion_during_iterationz6OrderedDictTests.test_detect_deletion_during_iteration   sb    &&!!%("X2hsGy) 	 H	 	 	s   A!!A*c           
         | j                   }| j                  t              5   |ddgd        d d d        g d} ||      }| j                  t	        |      |D cg c]  }|d   	 c}       | j                  t	        |j                               |D cg c]  }|d   	 c}       | j                  t	        |j                               |D cg c]  }|d   	 c}       | j                  t	        |j                               |       | j                  t	        t        |            t	        t        |      D cg c]  }|d   	 c}             y # 1 sw Y   'xY wc c}w c c}w c c}w c c}w )Nr   r   r   r   r   )	r<   r=   r>   r?   r@   rW   r   rB   r   r   s        r   test_sorted_iteratorsz&OrderedDictTests.test_sorted_iterators   s%   &&y) 	48,d3	4BE%:qad%:;	*5,AaQqT,AB		,U.Cqt.CD
+U3-x ?!1 ?@	B	4 	4 &;,A.C !@s#   EE 
E%
E*
;E/Ec                    | j                   } |       }g }| j                  t        |      |       | j                  t        |j                               |       | j                  t        |j	                               |       | j                  t        |j                               |       | j                  t        t        |            |       | j                  t        t        |j                                     |       | j                  t        t        |j	                                     |       | j                  t        t        |j                                     |       y r   )r<   r?   rC   rW   r   rB   r   )r.   r<   rQ   emptys       r   test_iterators_emptyz%OrderedDictTests.test_iterators_empty   s    &&]b5)bggi%0biik*E2bhhj)51hrl+U3hrwwy12E:hryy{34e<hrxxz23U;rJ   c                 Z   | j                   }g d}t        |        ||      }|r1| j                  |j                         |j	                                |r1| j                  t              5  |j                          d d d        | j                  t        |      d       y # 1 sw Y   %xY wrw   )r<   r   r?   popitempopr=   r   ry   r{   s       r   test_popitemzOrderedDictTests.test_popitem   s    &&LRZZ\599;7 x( 	JJL	R!$	 	s   ,B!!B*c                 (   | j                   }t        d      D cg c]  }||f }} ||      }t        d      D ]  }|j                  d        |j                  d       |j                  d       | j                  t	        |      d       y c c}w )N   rM   Tlastr   )r<   ranger   r?   ry   )r.   r<   irE   objs        r   test_popitem_lastz"OrderedDictTests.test_popitem_last   s    &&!&r+A!Q++% q 	AKK	DS2& ,s   Bc                 t   | j                   }g d}t        |        ||      }t        |       |r7|j                         \  }}| j                  |j                  |      |       |r7| j	                  t
              5  |j                  d       d d d        | j                  t        |      d       | j                  |j                  d      d        G d d|      } |d      }| j                  |j                  d	d
      d
       | j                  |j                  dd      d       | j                  |j                  dd      d       | j                  |j                  dd      d       | j	                  t
              5  |j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nrx   xyzr   i90  c                       e Zd Zd Zy)*OrderedDictTests.test_pop.<locals>.Missingc                      yNr   r1   r.   r   s     r   __missing__z6OrderedDictTests.test_pop.<locals>.Missing.__missing__      rJ   Nr]   r^   r_   r   r1   rJ   r   Missingr         rJ   r   r   r   r   r(   r   r7   default)r<   r   r   r?   r=   r   ry   )r.   r<   rE   rQ   kvr   ms           r   test_popzOrderedDictTests.test_pop   sm   &&L99;DAqRVVAY*  x( 	FF5M	R!$5)51	k 	 aLsA*sA*sA*sA.2x( 	EE#J	 		 		 	s   =F!F.!F+.F7c                 j   | j                   }g d}t        |        ||      } ||      }| j                  ||       |dd  |d d z   } ||      }| j                  ||       | j                  |t	        |             | j                  t	        |      |       | j                  | ||d d              y )Nrx   r   )r<   r   r?   assertNotEqualrA   )r.   r<   rE   od1od2s        r   test_equalityzOrderedDictTests.test_equality  s    &&L% % c"ab	E"1I%% C%d3i(cC(CU3BZ!89rJ   c           	           j                   }g d} ||      dg_        dg_         fd} |j                                t        j                        } ||        j	                  |j                  j                          j	                  |j                  j                          j                  t        |d             t        j                        } ||        j                  |j                  j                          j                  |j                  j                          j                  |j                  j                          j                  |j                  j                          j                  t        |d             t        d j                        5  t        t        j                  dz         D ]  } j                  |      5  t        j                   t        j"                  |            } ||        j                  |j                  j                          j                  |j                  j                          j                  t        |d             d d d         	 d d d         |t%        t'                            |       }|j)                          ||        | |             y # 1 sw Y   xY w# 1 sw Y   _xY w)	Nrx   xzc                 p   d| d}j                  | |       j                  |        j                  t        | j                               t        j                                      j                  t	        |       t	                     j                  t        |       t                     y )Nz
copy: z
od: )assertIsNotr?   rC   rB   ry   type)dupmsgrQ   r.   s     r   checkz,OrderedDictTests.test_copying.<locals>.check/  s    *-r2CS"c*S"%T#))+.RXXZ0@ASXs2w/T#YR1rJ   yr	   r   )proto)r<   r   r   copyassertIsassertFalsehasattrdeepcopyr?   r   r   moduler   pickleHIGHEST_PROTOCOLsubTestloadsdumpsevalreprrP   )r.   r<   rE   r   r   r   update_testrQ   s   `      @r   test_copyingzOrderedDictTests.test_copying'  s0   && Muu	2 	bggiiimc
ceeRTT"ceeRTT"c*+mmBc
%%%%c*+]DKK8 	8v66:; 8\\\. 8 ,,v||B'>?C#J$$SUUBDD1$$SUUBDD1$$WS#%678 88	8 	d48n!m2kk"o8 8	8 	8s%   12K%#BK<
K%K"K%%K.c                     | j                   }g d} ||      }| j                  t        d |j                         d   D                     y )Nrx   c              3   @   K   | ]  }t        |      t        k(    y wr   )r   rC   ).0pairs     r   	<genexpr>z5OrderedDictTests.test_yaml_linkage.<locals>.<genexpr>Z  s     LDJ,Ls   r   )r<   rs   all
__reduce__r{   s       r   test_yaml_linkagez"OrderedDictTests.test_yaml_linkageR  sC    && M 	L9KLLMrJ   c                 N   | j                   }g d} ||      }| j                  |j                  t               | j	                  |j                         d          d|_        | j                  |j                  d   d       | j                  |j                         d   ddi       y )Nrx   r   r   r   )r<   rr   __dict__rA   assertIsNoner   r   r?   r{   s       r   test_reduce_not_too_fatz(OrderedDictTests.test_reduce_not_too_fat\  s    &&Lbkk40"--/!,-S)2.+c2Y7rJ   c                    | j                   } |       }||d<   t        d| j                        5  t        dt        j
                  dz         D ]|  }t	        j                  t	        j                  ||            }| j                  ||       | j                  t        |j                               dg       | j                  |d   |       ~ 	 d d d        y # 1 sw Y   y xY w)Nr   r	   r   )r<   r   r   r   r   r   r   r   r   r?   rC   rW   r   )r.   r<   rQ   r   r   s        r   test_pickle_recursivez&OrderedDictTests.test_pickle_recursiveg  s    &&]1 ]DKK8 	+r6#:#:Q#>? +ll6<<E#:;  b)  chhj!1A37c!fc*	+	+ 	+ 	+s   BCCc                     | j                   } |g d      }| j                  t        |      d       | j                  t        t        |            |       | j                  t         |             d       y )Nrx   z=OrderedDict({'c': 1, 'b': 2, 'a': 3, 'd': 4, 'e': 5, 'f': 6})zOrderedDict())r<   r?   r   r   r   s      r   	test_reprzOrderedDictTests.test_reprt  s_    &&UVbK	Md2h,km,o>rJ   c                 ~    | j                   }|j                  d      }||d<   | j                  t        |      d       y )Nrl   r   z8OrderedDict({'a': None, 'b': None, 'c': None, 'x': ...}))r<   ro   r?   r   r   s      r   test_repr_recursivez$OrderedDictTests.test_repr_recursive|  s>    &&!!%(3bF	HrJ   c                     | j                   } |       }|j                         |d<   t        |      }| j                  |t               |j                         |d<   t        |      }| j                  |t               y )Nr,   )r<   r   r   rr   strrB   )r.   r<   rQ   rs       r   test_repr_recursive_valuesz+OrderedDictTests.test_repr_recursive_values  sf    &&]2H 	a%2Ha%rJ   c                 X   | j                   }g d}t        |        ||      }t        |j                               }| j	                  |j                  dd      d       | j	                  t        |j                               |       | j	                  |j                  dd      d       | j	                  t        |j                               d   d       | j	                  |j                  dd	
      d	        G d d|      }| j	                   |       j                  dd	      d	       y )Nrx   r   r   r"   r   r   )r   r   r:   r*   r   c                       e Zd Zd Zy)1OrderedDictTests.test_setdefault.<locals>.Missingc                      yr   r1   r   s     r   r   z=OrderedDictTests.test_setdefault.<locals>.Missing.__missing__  r   rJ   Nr   r1   rJ   r   r   r     r   rJ   r   r(   )r<   r   rC   rB   r?   
setdefault)r.   r<   rE   rQ   
pair_orderr   s         r   test_setdefaultz OrderedDictTests.test_setdefault  s    &&L"((*%
sB/3bhhj):6sB/4bhhj)"-y9sA6:	k 	 	--a3Q7rJ   c                     | j                   } |       }d|d<   d|d<   |d= | j                  t        |j                               dg       d|d<   | j                  t        |j                               ddg       y )Nr   r   r   r   r   r   r   r   s      r   test_reinsertzOrderedDictTests.test_reinsert  su    && ]33sGbhhj)H:63bhhj)Hh+?@rJ   c                    | j                   }|j                  d      }| j                  t        |      t        d             |j	                  d       | j                  t        |      t        d             |j	                  dd       | j                  t        |      t        d             |j	                  dd       | j                  t        |      t        d             |j	                  d       | j                  t        |      t        d             |j	                  dd       | j                  t        |      t        d	             | j                  t              5  |j	                  d
       d d d        | j                  t              5  |j	                  d
d       d d d        y # 1 sw Y   :xY w# 1 sw Y   y xY w)Nabcder!   abdecFcabder'   r   r   bcader   )r<   ro   r?   rC   move_to_endr=   r   r   s      r   test_move_to_endz!OrderedDictTests.test_move_to_end  sV   &&!!'*b4=1
sb4=1
sE"b4=1
sE"b4=1
sb4=1
s'b4=1x( 	 NN3	 x( 	'NN3&	' 	'	  	 	' 	's   $F/F;/F8;Gc                    | j                   }|j                  d      }|j                  dd       | j                  t	        |      t	        d             |j                  dd       | j                  t	        |      t	        d             |j                  d      }|j                  d       | j                  t	        |      t	        d             |j                  d       | j                  t	        |      t	        d	             y )
Nrl   r!   Fr   cabr   acbbcabac)r<   ro   r   r?   rC   r   s      r   test_move_to_end_issue25406z,OrderedDictTests.test_move_to_end_issue25406  s    &&!!%(
s'b4;/
s'b4;/!!%(
sb4;/
sb4;/rJ   c                     | j                   }t        d      } |di |}| j                  t        j                  |      t        j                  |             y )Nr   r   r1   )r<   rA   assertGreaterr   	getsizeof)r.   r<   r$   rQ   s       r   test_sizeofzOrderedDictTests.test_sizeof  sE    &&1I13==,cmmA.>?rJ   c                 :   | j                   }dj                         }|j                  |      }| j                  |j	                         t        |      j	                                | j                  |j                         t        |      j                                y )Nz@the quick brown fox jumped over a lazy dog yesterday before dawn)r<   splitro   r?   rW   rA   rB   )r.   r<   srQ   s       r   
test_viewszOrderedDictTests.test_views  sl    &&NTTV!!!$DHMMO4T"X^^%56rJ   c                     | j                   } G d d|      }g d}| j                  t         ||      j                               |       y )Nc                       e Zd Zd Zy)3OrderedDictTests.test_override_update.<locals>.MyODc                     t               r   )r   )r.   rf   kwdss      r   rP   z:OrderedDictTests.test_override_update.<locals>.MyOD.update  s
    k!rJ   N)r]   r^   r_   rP   r1   rJ   r   MyODr    s    "rJ   r  )r   r    r   r   )r.   r<   r  rB   s       r   test_override_updatez%OrderedDictTests.test_override_update  sB    &&	"; 	" /d5k//12E:rJ   c                     | j                   }d }t        d      D ]  } |d |fg      } ~t        j                          y )Ni  )r<   r   r   
gc_collect)r.   r<   r   _s       r   test_highly_nestedz#OrderedDictTests.test_highly_nested  sF     &&t 	-Ac{m,C	-rJ   c           
         | j                   }g  G fdd|      }d }t        d      D ]  } |d |fg      }||_         ~t        j                          | j                  t        t        t        d                         y )Nc                       e Zd Z fdZy):OrderedDictTests.test_highly_nested_subclass.<locals>.MyODc                 <    j                  | j                         y r   )rY   r   )r.   deleteds    r   __del__zBOrderedDictTests.test_highly_nested_subclass.<locals>.MyOD.__del__  s    tvv&rJ   N)r]   r^   r_   r  )r  s   r   r  r    s    'rJ   r  d   )r<   r   r   r   r  r?   rC   r   )r.   r<   r  r   r   r  s        @r   test_highly_nested_subclassz,OrderedDictTests.test_highly_nested_subclass  s     &&	'; 	' s 	As}%CCE	 $xc
';"<=rJ   c                    | j                   } G d d      }d }d} ||      } ||      } | ||            } |       }d||<   d||<   d||<   d|d<   ||= ||= | j                  t        |j                               |dfdg       y )Nc                   $    e Zd Zd Zd Zd Zd Zy)9OrderedDictTests.test_delitem_hash_collision.<locals>.Keyc                 D    || _         t        t        |             | _        y r   )_hashr   idrn   )r.   hashs     r   rD   zBOrderedDictTests.test_delitem_hash_collision.<locals>.Key.__init__  s    !
 D]
rJ   c                     | j                   S r   )r%  r-   s    r   __hash__zBOrderedDictTests.test_delitem_hash_collision.<locals>.Key.__hash__      zz!rJ   c                 T    	 | j                   |j                   k(  S # t        $ r Y yw xY w)NF)rn   AttributeError)r.   r0   s     r   __eq__z@OrderedDictTests.test_delitem_hash_collision.<locals>.Key.__eq__  s,    !::44% ! !s    	''c                     | j                   S r   rm   r-   s    r   __repr__zBOrderedDictTests.test_delitem_hash_collision.<locals>.Key.__repr__  r*  rJ   N)r]   r^   r_   rD   r)  r-  r/  r1   rJ   r   Keyr#  
  s    +"!
"rJ   r0  c                 2    d}| |dz
  z  }|dz  |z   | z   dz   S )NrM   r   r   r1   )r'  MINSIZEr   s      r   blocking_hashzCOrderedDictTests.test_delitem_hash_collision.<locals>.blocking_hash  s-    G	!AFa<$&**rJ   r   .after)r4  .r   )	r.   r<   r0  r3  	COLLIDINGr   	collidingblockingrQ   s	            r   test_delitem_hash_collisionz,OrderedDictTests.test_delitem_hash_collision  s    &&	" 	"	+ 	)n	N	}Y/0]3897xLyMbhhj)S#J+GHrJ   c                 `   | j                   } G d d      } |       }t        d      D ]  } |       }|||<    | j                  t              5  t	        |j                                d d d        | j                  t              5  t	        |j                                d d d        | j                  t              5  t        |       d d d        | j                  t              5  |j                          d d d        y # 1 sw Y   xY w# 1 sw Y   mxY w# 1 sw Y   PxY w# 1 sw Y   y xY w)Nc                       e Zd Zd Zy)-OrderedDictTests.test_issue24347.<locals>.Keyc                     t        d      S )Ni )r   r-   s    r   r)  z6OrderedDictTests.test_issue24347.<locals>.Key.__hash__2  s     ((rJ   Nr]   r^   r_   r)  r1   rJ   r   r0  r;  1  s    )rJ   r0  r  )	r<   r   r=   r   rC   r   rB   r   r   )r.   r<   r0  rQ   r   r   s         r   test_issue24347z OrderedDictTests.test_issue24347.  s   &&	) 	) ]s 	A%CBsG	
 x( 		x( 		x( 	H	x( 	GGI	 		 		 		 		 	s0   D D=D&D$ D	DD!$D-c                 r    | j                   } G d d      } |       }d| |       <   |j                          y )Nc                       e Zd Zd Zy)-OrderedDictTests.test_issue24348.<locals>.Keyc                      y)Nr   r1   r-   s    r   r)  z6OrderedDictTests.test_issue24348.<locals>.Key.__hash__H  r   rJ   Nr=  r1   rJ   r   r0  rA  G  r   rJ   r0  r   )r<   r   )r.   r<   r0  rQ   s       r   test_issue24348z OrderedDictTests.test_issue24348D  s4    &&	 	 ]35	


rJ   c                     | j                   } |       }dD ]3  }dD ],  }t        |      dk(  r|j                  d       ||z   }|||<   . 5 y)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.
        0123456789ABCDEFr%   Fr   N)r<   ry   r   )r.   r<   rQ   c0c1r   s         r   test_issue24667z OrderedDictTests.test_issue24667P  s_     &&]$ 	B( r7a<JJEJ*2g3	rJ   c                     | j                   } |       }t        j                  |dd       | j                  dt	        |             y Nspamr   NULL)r<   rA   __setitem__r~   r   r   s      r   test_dict_setitemz"OrderedDictTests.test_dict_setitemi  s:    &&]VQ'b*rJ   c                     | j                   } |       }d|d<   d|d<   t        j                  |d       | j                  t              5  t        |       d d d        y # 1 sw Y   y xY wNr   rK  r   ham)r<   rA   __delitem__r=   r   r   r   s      r   test_dict_delitemz"OrderedDictTests.test_dict_delitemo  s`    &&]6
5	V$x( 	H	 	 	   	AA'c                     | j                   } |       }d|d<   d|d<   t        j                  |       | j                  dt	        |             y )Nr   rK  r   rQ  rL  )r<   rA   rz   r~   r   r   s      r   test_dict_clearz OrderedDictTests.test_dict_clearx  sE    &&]6
5	

2b*rJ   c                     | j                   } |       }d|d<   d|d<   t        j                  |d       | j                  t              5  t        |       d d d        y # 1 sw Y   y xY wrP  )r<   rA   r   r=   r   r   r   s      r   test_dict_popzOrderedDictTests.test_dict_pop  s^    &&]6
5	Vx( 	H	 	 	rT  c                     | j                   } |       }d|d<   d|d<   t        j                  |       | j                  t              5  t        |       d d d        y # 1 sw Y   y xY wrP  )r<   rA   r   r=   r   r   r   s      r   test_dict_popitemz"OrderedDictTests.test_dict_popitem  s\    &&]6
5	Rx( 	H	 	 	s   AA&c                     | j                   } |       }t        j                  |dd       | j                  dt	        |             y rJ  )r<   rA   r   r~   r   r   s      r   test_dict_setdefaultz%OrderedDictTests.test_dict_setdefault  s8    &&]FA&b*rJ   c                     | j                   } |       }t        j                  |dg       | j                  dt	        |             y )N)rK  r   rL  )r<   rA   rP   r~   r   r   s      r   test_dict_updatez!OrderedDictTests.test_dict_update  s8    &&]B&b*rJ   c                     | j                    G fdd      }d |j                  |<   t        j                  |      }~t	        j
                          | j                   |              y )Nc                       e Zd Z W         Zy)/OrderedDictTests.test_reference_loop.<locals>.AN)r]   r^   r_   rQ   ri   s   r   Ara    s
    BrJ   rb  )r<   rQ   weakrefrefgccollectr   )r.   rb  r   r<   s      @r   test_reference_loopz$OrderedDictTests.test_reference_loop  sN    &&	 	QKKN


!#rJ   c                    t        j                  | t        | j                         t        j                  | d | j                         t        j                  | d | j                         t        j                  | d | j                         y )Nc                 4    t        | j                               S r   )r   rW   r$   s    r   <lambda>z<OrderedDictTests.test_free_after_iterating.<locals>.<lambda>  s    4> rJ   c                 4    t        | j                               S r   )r   r   rj  s    r   rk  z<OrderedDictTests.test_free_after_iterating.<locals>.<lambda>  s    4
;K rJ   c                 4    t        | j                               S r   )r   rB   rj  s    r   rk  z<OrderedDictTests.test_free_after_iterating.<locals>.<lambda>  s    4	? rJ   )r   check_free_after_iteratingr   r<   r-   s    r   test_free_after_iteratingz*OrderedDictTests.test_free_after_iterating  se    **4t7G7GH**41I4K[K[\**41KTM]M]^**41JDL\L\]rJ   c                 j   | j                   } |dddd      } |dddd      }|j                         }|j                         }||z  }|t        |j                               z  } |ddddd      }| j	                  |t        |      z  |       | j	                  ||z  |       | j	                  ||       | j	                  ||       |j                         }||z  } |ddddd      }| j	                  t        |      |z  |       | j	                  ||z  |       | j	                  ||       | j                  t        ||z        |       | j                  t        t        |      |z        |       | j                  t        |t        |      z        |       |j                         }|d	z  }|d
z  }| j	                  ||       | j                  t              5  |d z   d d d        | j                  t              5  |d	z   d d d        | j                  t              5  |dz   d d d        | j                  t              5  |d
z   d d d        | j                  t              5  |dz  }d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   hxY w# 1 sw Y   QxY w# 1 sw Y   y xY w)Nr   r   )r   r   r   r   r"   )r   r   r"   )r   r   r   r"   )r   r   r"   r   r1    BAD)r<   r   rC   rB   r?   rA   r   r   r=   r>   
ValueError)r.   r<   r   r   r!   r$   expecteds          r   test_merge_operatorz$OrderedDictTests.test_merge_operator  sv   &&A!*+A!*+FFHFFH	Q	T!'')_1qQ78T!Wh/Q)H%H%FFH	Q1qQ78a1h/Q)H%d1q5k;/d47Q;'5d1tAw;'5668	R	RH%y) 	H	y) 	F	y) 	I	y) 	F	z* 	JA	 		 		 		 		 		 	s<   I9J$JJ*J)9JJJJ&)J2c                     t        | j                  d g i      j                               }t        j                          | j                  t        j                  t        |                   y r   )r   r<   rB   re  rf  rs   
is_trackedr   )r.   r   s     r   !test_ordered_dict_items_result_gcz2OrderedDictTests.test_ordered_dict_items_result_gc  sJ    
 $""D":.4467


 	d2h/0rJ   N)6r]   r^   r_   rF   rI   rR   ra   rj   rp   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   r8  r>  rC  rH  rN  rS  rV  rX  rZ  r\  r^  rg  ro  ru  r   cpython_onlyrx  r1   rJ   r   r   r       s   T01,9\*	DA
%BYL"	B<	%	'4: )VN	8+?H&8(
A'&0@7;	>"%IN,
2++++	^)V 	1 	1rJ   r   c                   (    e Zd ZeZej
                  Zy)PurePythonOrderedDictTestsNr]   r^   r_   py_collr   r<   r1   rJ   r   r{  r{    s    F%%KrJ   r{  c                       e Zd ZdZeZeZy)CPythonBuiltinDictTestszaBuiltin dict preserves insertion order.

    Reuse some of tests in OrderedDict selectively.
    N)r]   r^   r_   __doc__builtinsr   rA   r<   r1   rJ   r   r  r    s    
 FKrJ   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                       e Zd ZeZej
                  Zej                  Zej                  d        Z	d Z
d Zej                  d        Zy)CPythonOrderedDictTestsc                    | j                   }t        j                  }t        j                  }| j
                  } |d      } |d      } |d      } |d      } |d      }	 |       }
 ||
|       d|
_         ||
|       |
j                  t        d      D cg c]  }||f c}        ||
||z   d|z  z   dz   d	|z  z   d|	z  z          |
j                  t        dd
      D cg c]  }||f c}        ||
||z   d|z  z   dz   d
|z  z   d
|	z  z           ||
j                          |d              ||
j                          |d              ||
j                          |d              |d      } |t        |
      |        |t        |
j                               |        |t        |
j                               |        |t        |
j                               |       y c c}w c c}w )NnQ2P3PnPn2Pn2BI2nn2PPPn2Pr   r"   rM   r(   r      iP2n2P)r<   structcalcsizer   calcobjsizecheck_sizeofr   rP   r   rW   rB   r   r   )r.   r<   r  sizer   	basicsizekeysize	entrysizepnodesizerQ   r   itersizes                r   test_sizeof_exactz)CPythonOrderedDictTests.test_sizeof_exact  s   &&??""!!+,	8$UO	SMF#]b)b)
		58,aAq6,-b)g%!+a/!I+=(
JK
		5B<0aAq601b)g%1,r1ByL@2h;NObggic#bhhj$s)$biik49%>d2h!d2779ox(d288:)d299;* -0s   G*%G/c                 h   | j                   }|j                  d      }| j                  t        |      t        d             | j	                  t
              5  t        |      D ](  \  }}|j                  |       | j                  |d       * 	 d d d        | j	                  t
              5  |D ]  }d |d<   	 	 d d d        | j	                  t
              5  |D ]  }|d=  	 d d d        | j                  t        |      t        d             y # 1 sw Y   xY w# 1 sw Y   cxY w# 1 sw Y   FxY w)Nr   r(   r6   r!   bdeaf)	r<   ro   r?   rC   r=   RuntimeError	enumerater   
assertLess)r.   r<   rQ   r   r   s        r    test_key_change_during_iterationz8CPythonOrderedDictTests.test_key_change_during_iteration'  s   &&!!'*b4=1|, 	&!" &1q!1%&	& |, 	 3	 |, 	 sG	 	b4=1	& 	&	 		 	s$   7D,DD(DD%(D1c                 
   | j                   }g d} ||      }dD ]  }t        ||      }t         |             dd  }t        t        j
                  dz         D ]  }| j                  ||      5  t         |             }t        |       t	        j                  ||      }	t	        j                  |	      }
| j                  t        |
      |       | j                  t        |      |       d d d          y # 1 sw Y   xY w)Nrx   )rW   r   rB   r   )method_nameprotocol)r<   getattrrC   r   r   r   r   r   r   r   r   r?   )r.   r<   rE   rQ   r  methrt  r   r   r  	unpickleds              r   test_iterators_picklingz/CPythonOrderedDictTests.test_iterators_pickling8  s    &&L6 
	9K2{+DDF|AB'H622Q67 9\\kA\F 9dfBHR+A &QI$$T)_h?$$T"Xx89 99
	99 9s   /A=C99Dc                     t        j                          | j                         }||_        g }|j	                  |       t        j                  |      }|j	                  |       ~~~t        j                          y r   )re  rf  r<   cyclerY   rc  rd  )r.   r   r  x_refs       r   "test_weakref_list_is_not_traversedz:CPythonOrderedDictTests.test_weakref_list_is_not_traversedI  s\    
 	

UAUue


rJ   N)r]   r^   r_   c_collr   r<   r   r  ry  r  r  r  r  r1   rJ   r   r  r    s\     F$$K''L+ +@2"9"  rJ   r  c                   :    e Zd ZeZ G d dej
                        Zy)"PurePythonOrderedDictSubclassTestsc                       e Zd Zy).PurePythonOrderedDictSubclassTests.OrderedDictNr]   r^   r_   r1   rJ   r   r<   r  a      rJ   r<   Nr|  r1   rJ   r   r  r  ^  s    Fg)) rJ   r  c                   :    e Zd ZeZ G d dej
                        Zy)CPythonOrderedDictSubclassTestsc                       e Zd Zy)+CPythonOrderedDictSubclassTests.OrderedDictNr  r1   rJ   r   r<   r  h  r  rJ   r<   N)r]   r^   r_   r  r   r<   r1   rJ   r   r  r  e  s    Ff(( rJ   r  c                   R    e Zd ZeZ G d dej
                        Zej                  Zy)*PurePythonOrderedDictWithSlotsCopyingTestsc                       e Zd ZdZy)6PurePythonOrderedDictWithSlotsCopyingTests.OrderedDictr   r   Nr]   r^   r_   	__slots__r1   rJ   r   r<   r  o      	rJ   r<   N)r]   r^   r_   r}  r   r<   r   r   r1   rJ   r   r  r  l  s$    Fg)) #00LrJ   r  c                   R    e Zd ZeZ G d dej
                        Zej                  Zy)'CPythonOrderedDictWithSlotsCopyingTestsc                       e Zd ZdZy)3CPythonOrderedDictWithSlotsCopyingTests.OrderedDictr  Nr  r1   rJ   r   r<   r  x  r  rJ   r<   N)r]   r^   r_   r  r   r<   r   r   r1   rJ   r   r  r  t  s&     Ff(( #00LrJ   r  c                   "    e Zd Zed        Zd Zy)PurePythonGeneralMappingTestsc                 .    t         j                  | _        y r   r}  r<   	type2testclss    r   
setUpClassz(PurePythonGeneralMappingTests.setUpClass  s    ++rJ   c                 d    | j                         }| j                  t        |j                         y r   _empty_mappingr=   r   r   r.   r$   s     r   r   z*PurePythonGeneralMappingTests.test_popitem  $    !(AII.rJ   Nr]   r^   r_   classmethodr  r   r1   rJ   r   r  r  }  s    , ,/rJ   r  c                   "    e Zd Zed        Zd Zy)CPythonGeneralMappingTestsc                 .    t         j                  | _        y r   r  r<   r  r  s    r   r  z%CPythonGeneralMappingTests.setUpClass  s    **rJ   c                 d    | j                         }| j                  t        |j                         y r   r  r  s     r   r   z'CPythonGeneralMappingTests.test_popitem  r  rJ   Nr  r1   rJ   r   r  r    s     + +/rJ   r  c                   "    e Zd Zed        Zd Zy)PurePythonSubclassMappingTestsc                 D     G d dt         j                        }|| _        y )Nc                       e Zd Zy)@PurePythonSubclassMappingTests.setUpClass.<locals>.MyOrderedDictNr  r1   rJ   r   MyOrderedDictr        rJ   r  r  r  r  s     r   r  z)PurePythonSubclassMappingTests.setUpClass  s    	G// 	%rJ   c                 d    | j                         }| j                  t        |j                         y r   r  r  s     r   r   z+PurePythonSubclassMappingTests.test_popitem  r  rJ   Nr  r1   rJ   r   r  r    s    & &
/rJ   r  c                   "    e Zd Zed        Zd Zy)CPythonSubclassMappingTestsc                 D     G d dt         j                        }|| _        y )Nc                       e Zd Zy)=CPythonSubclassMappingTests.setUpClass.<locals>.MyOrderedDictNr  r1   rJ   r   r  r    r  rJ   r  r  r  s     r   r  z&CPythonSubclassMappingTests.setUpClass  s    	F.. 	%rJ   c                 d    | j                         }| j                  t        |j                         y r   r  r  s     r   r   z(CPythonSubclassMappingTests.test_popitem  r  rJ   Nr  r1   rJ   r   r  r    s     & &
/rJ   r  c                   <     e Zd Z fdZ fdZ fdZ fdZ xZS )SimpleLRUCachec                 f    t         |           || _        t        j	                  dd      | _        y )Ngetsetdelr   )superrD   r  rA   ro   counts)r.   r  	__class__s     r   rD   zSimpleLRUCache.__init__  s(    	mm$91=rJ   c                 v    | j                   dxx   dz  cc<   t        | 	  |      }| j                  |       |S )Nr  r   )r  r  __getitem__r   )r.   itemrn   r  s      r   r  zSimpleLRUCache.__getitem__  s9    Ea#D)rJ   c                    | j                   dxx   dz  cc<   || vrGt        |       | j                  k\  r/| j                  d       || vrt        |       | j                  k\  r/t        |   ||       | j                  |       y )Nr  r   Fr   )r  ry   r  r   r  rM  r   )r.   r   rn   r  s      r   rM  zSimpleLRUCache.__setitem__  sp    Eao#d)tyy"8LLeL$ o#d)tyy"8C'rJ   c                 R    | j                   dxx   dz  cc<   t        | 	  |       y )Nr  r   )r  r  rR  )r.   r   r  s     r   rR  zSimpleLRUCache.__delitem__  s$    EaC rJ   )r]   r^   r_   rD   r  rM  rR  __classcell__)r  s   @r   r  r    s    >
! !rJ   r  c                   $    e Zd Zd Zd Zd Zd Zy)SimpleLRUCacheTestsc                     | j                  d      }d|d<   d|d<   d|d<   | j                  |j                  dddd       | j                  t        |      ddg       | j                  |j                  dddd       y )	Nr   r   t1t2r"   t3r   r  )r  r?   r  rC   )r.   r!   s     r   test_add_after_fullz'SimpleLRUCacheTests.test_add_after_full  sy    NN1$$$1Qq#ABa4,/1Qq#ABrJ   c                    | j                  d      }t        dd      D ]  }|||<   	 | j                  |j                  d      d       | j                  |j                  d      d       | j                  |j                  d	dd	d
       y )Nr"   r   r%   Fr   )r   r   T)r"   r"   r   r  )r  r   r?   r   r  r.   r!   r   s      r   r   z SimpleLRUCacheTests.test_popitem  s    NN1q! 	AAaD	.7-v61Qq#ABrJ   c                    | j                  d      }t        dd      D ]  }|||<   	 | j                  |j                  dddd       | j                  |j	                  d      d       | j                  |j                  dddd       | j                  |j	                  dd      d       | j                  |j                  dddd       | j                  t        |j                  d       | j                  |j                  dddd       y )Nr"   r   r%   r   r  r   )r  r   r?   r  r   r=   r   r  s      r   r   zSimpleLRUCacheTests.test_pop  s    NN1q! 	AAaD	1Qq#ABq1%1Qq#ABq!a(1Qq#AB(AEE1-1Qq#ABrJ   c           	         | j                  d      }t        dd      D ]  }|||<   	 | j                  t        |      t        t        dd                   | j                  |j                  dddd       | j                  |d   d       | j                  |j                  dddd       | j                  t        |      g d       y )Nr"   r   r%   r   r  r   )r   r"   r   )r  r   r?   rC   r  r  s      r   test_change_order_on_getz,SimpleLRUCacheTests.test_change_order_on_get  s    NN1q! 	AAaD	a$uQ{"341Qq#AB1q!1Qq#ABa),rJ   N)r]   r^   r_   r  r   r   r  r1   rJ   r   r  r    s    CC
C-rJ   r  c                   8    e Zd Z G d deej
                        Zy)PySimpleLRUCacheTestsc                       e Zd Zy)PySimpleLRUCacheTests.type2testNr  r1   rJ   r   r  r    r  rJ   r  N)r]   r^   r_   r  r}  r<   r  r1   rJ   r   r   r     s    NG$7$7 rJ   r   c                       e Zd Zed        Zy)CSimpleLRUCacheTestsc                 N     G d dt         t        j                        }|| _        y )Nc                       e Zd Zy)2CSimpleLRUCacheTests.setUpClass.<locals>.type2testNr  r1   rJ   r   r  r    r  rJ   r  )r  r  r<   r  )r  r  s     r   r  zCSimpleLRUCacheTests.setUpClass  s    	(:(: 	!rJ   N)r]   r^   r_   r  r  r1   rJ   r   r  r    s     " "rJ   r  __main__)1r  
contextlibr   re  r   randomr   r   r  r   unittestrc  collections.abcr   testr   r   test.supportr   import_fresh_moduler}  r  contextmanagerr   r   TestCaser{  r  r  methodsetattrr  
skipUnlessr  r  r  r  r  BasicTestMappingProtocolr  r  r  r  r  r  r   r  r]   mainr1   rJ   r   <module>r     s      	  %  
   * ' & ,-
+
+M5C4DF	*	*	*=2@1A
C , ,D1 D1L&!183D3D &h// # %*EGPF #VW5Ev-NOP  VOP[.0A0A [ Q[|)C &= 11B1B 1 VOP1h.?.? 1 Q1/M$J$J / VOP/!G!G / Q/
/]%K%K 
/ VOP
/-"H"H 
/ Q
/! !2'- '-T/1B1B  VOP".0A0A " Q" zHMMO rJ   