
    ;e$                     2   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  G d d          Z G d d          Z G d d          Z	 G d	 d
          Z
 G d d          Z G d d          Z G d d          Z G d de j        e          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de j        e          Z G d de          Z G d d e          Z G d! d"e          Zed#k    r e j                     dS dS )$    N)supportc                       e Zd Z	 d Zd ZdS )Gc                     || _         d S Nseqnselfr	   s     */usr/lib/python3.11/test/test_enumerate.py__init__z
G.__init__   s    			    c                     | j         |         S r   r   r   is     r   __getitem__zG.__getitem__   s    y|r   N)__name__
__module____qualname__r   r    r   r   r   r   	   s5               r   r   c                   "    e Zd Z	 d Zd Zd ZdS )Ic                 "    || _         d| _        d S Nr   r	   r   r
   s     r   r   z
I.__init__       	r   c                     | S r   r   r   s    r   __iter__z
I.__iter__       r   c                     | j         t          | j                  k    rt          | j        | j                  }| xj         dz  c_         |S N   r   lenr	   StopIterationr   vs     r   __next__z
I.__next__   >    6S^^##=%8Idf!r   Nr   r   r   r   r   r)   r   r   r   r   r      sD        &        r   r   c                       e Zd Z	 d Zd ZdS )Igc                 "    || _         d| _        d S r   r   r
   s     r   r   zIg.__init__   r   r   c              #   &   K   | j         D ]}|V  d S r   r   )r   vals     r   r   zIg.__iter__"   s,      9 	 	CIIII	 	r   Nr   r   r   r   r   r   r   r   r-   r-      s5        ?      r   r-   c                       e Zd Z	 d Zd ZdS )Xc                 "    || _         d| _        d S r   r   r
   s     r   r   z
X.__init__(   r   r   c                     | j         t          | j                  k    rt          | j        | j                  }| xj         dz  c_         |S r"   r$   r'   s     r   r)   z
X.__next__+   r*   r   N)r   r   r   r   r)   r   r   r   r3   r3   &   s5        &      r   r3   c                   "    e Zd Z	 d Zd Zd ZdS )Ec                 "    || _         d| _        d S r   r   r
   s     r   r   z
E.__init__3   r   r   c                     | S r   r   r   s    r   r   z
E.__iter__6   r    r   c                     ddz   d S )N   r   r   r   s    r   r)   z
E.__next__8   s    	Qr   Nr+   r   r   r   r7   r7   1   sD        $        r   r7   c                       e Zd Z	 d Zd ZdS )Nc                 "    || _         d| _        d S r   r   r
   s     r   r   z
N.__init__=   r   r   c                     | S r   r   r   s    r   r   z
N.__iter__@   r    r   Nr1   r   r   r   r=   r=   ;   s5        !      r   r=   c                       e Zd Zd ZdS )
PickleTestc                    t          t          j        dz             D ]%}t          j        ||          }t          j        |          }|                     t          |          t          |                     |                     t          |          |           t          j        |          }	 t          |           n-# t          $ r  | 
                    |dd                     Y w xY wt          j        ||          }t          j        |          }|                     t          |          |dd                     'd S r"   )rangepickleHIGHEST_PROTOCOLdumpsloadsassertEqualtypelistnextr&   assertFalse)r   itorgseqprotodits         r   check_picklezPickleTest.check_pickleE   s)   62Q677 	0 	0EUE**AaBT%[[$r((333T"XXs+++aBR      QRR))) R''AaBT"XXs122w////	0 	0s   1C'C+*C+N)r   r   r   rR   r   r   r   rA   rA   C   s#        0 0 0 0 0r   rA   c                       e Zd ZeZdg dcZZd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zej        d             Zej        d             ZdS )EnumerateTestCaseabc))r   a)r#   b)   cc                    |                      t          |                     | j                            | j                   |                     | j                  }|                      t	          |          |           |                      t          |                     | j                            | j                   | j        j         d S r   )rH   rI   enumrN   iterrJ   res__doc__r   es     r   test_basicfunctionz$EnumerateTestCase.test_basicfunction[   s    dii1122DI>>>IIdha!$$$dii1122DH===	r   c                 l    |                      |                     | j                  | j                   d S r   )rR   r[   rN   r]   r   s    r   test_picklezEnumerateTestCase.test_pickleb   s.    $))DH--tx88888r   c           	      &   |                      t          |                     t          | j                                      | j                   |                     t          d                    }|                     t          t          |           d S N )	rH   rJ   r[   r   rN   r]   assertRaisesr&   rK   r_   s     r   test_getitemseqnz"EnumerateTestCase.test_getitemseqne   k    dii$(4455tx@@@IIaee-q11111r   c           	      &   |                      t          |                     t          | j                                      | j                   |                     t          d                    }|                     t          t          |           d S re   )	rH   rJ   r[   r   rN   r]   rg   r&   rK   r_   s     r   test_iteratorseqnz#EnumerateTestCase.test_iteratorseqnj   ri   r   c           	      &   |                      t          |                     t          | j                                      | j                   |                     t          d                    }|                     t          t          |           d S re   )	rH   rJ   r[   r-   rN   r]   rg   r&   rK   r_   s     r   test_iteratorgeneratorz(EnumerateTestCase.test_iteratorgeneratoro   sk    dii485566AAAIIbff-q11111r   c                 l    |                      t          | j        t          | j                             d S r   )rg   	TypeErrorr[   r3   rN   r   s    r   test_noniterablez"EnumerateTestCase.test_noniterablet   *    )TY$(<<<<<r   c                 l    |                      t          | j        t          | j                             d S r   )rg   ro   r[   r=   rN   r   s    r   test_illformediterablez(EnumerateTestCase.test_illformediterablew   rq   r   c           	          |                      t          t          |                     t	          | j                                       d S r   )rg   ZeroDivisionErrorrJ   r[   r7   rN   r   s    r   test_exception_propagationz,EnumerateTestCase.test_exception_propagationz   s5    +T499Qtx[[3I3IJJJJJr   c                    |                      t          | j                   |                      t          | j        d           |                      t          | j        dd           |                      t          | j        ddd           d S )Nr#   rU   rV   rX   r;   )rg   ro   r[   r   s    r   test_argumentcheckz$EnumerateTestCase.test_argumentcheck}   st    )TY///)TY222)TYs;;;)TYq!<<<<<r   c           
      J   |                      t          |                     t          | j                                      | j                   t          |                     t          | j                  d                    }|                      t          |                     t          | j                  d                    |           |                      t          |                     dt          | j                                      |           |                     t          | j        g d           |                     t          | j        dd           |                     t          | j        dd           |                     t          | j        d	           d S )
N)iterabler   )rz   start)r{   rz   r;   )rz   x)r{   r|   )r|   y)r|   )rH   rJ   r[   r-   rN   r]   rg   ro   )r   expecteds     r   test_kwargszEnumerateTestCase.test_kwargs   sU   diiDHi>>??JJJ		"TX,,2233diiDHQiGGHH!	# 	# 	#diia"TX,,iGGHH!	# 	# 	#)TYqAAA)TYa1===)TY!q999)TY!44444r   c                    |                      t          t          t          t          t          t          | j                                                          t          | j                             |                      t          t          t          t          t          | j                                                t          dt          | j                                       d S r"   )	rH   r%   setmapidrJ   	enumeraterN   minr   s    r   test_tuple_reusez"EnumerateTestCase.test_tuple_reuse   s     	SRi.A.A)B)B!C!CDDEEs48}}UUUSR48)<)<!=!=>>??Qs48}}AUAUVVVVVr   c                     |                      g g          }t          j                     |                     t          j        t          |                               d S r   )r[   gccollect
assertTrue
is_trackedrK   )r   rQ   s     r   test_enumerate_result_gcz*EnumerateTestCase.test_enumerate_result_gc   sJ    
 YYt__

 	d2hh//00000r   N)r   r   r   r   r[   rN   r]   ra   rc   rh   rk   rm   rp   rs   rv   rx   r   r   cpython_onlyr   r   r   r   r   rT   rT   V   s       D111HC  9 9 92 2 2
2 2 2
2 2 2
= = == = =K K K= = =
5 
5 
5 W W W 	1 	1 	1 	1 	1r   rT   c                       e Zd ZdS )MyEnumN)r   r   r   r   r   r   r   r      s        Dr   r   c                       e Zd ZeZdS )SubclassTestCaseN)r   r   r   r   r[   r   r   r   r   r      s        DDDr   r   c                       e Zd Zdg cZZdS )	TestEmptyrf   N)r   r   r   rN   r]   r   r   r   r   r      s        2HCr   r   c                   d    e Zd Z eddd          Z e e ed          e                    ZdS )TestBig
   i N  rX   N)r   r   r   rC   rN   rJ   zipr]   r   r   r   r   r      sD        
%5

C
$ss55<<%%
&
&CCCr   r   c                       e Zd Zd Zd Zd Zd Zd Z ej	         e
ed          d          d             Zd	 Zd
 ZdS )TestReversedc           	          G d d          }dt          d          t          t          d                     |            t          ddd          t                              d          fD ]H}|                     t          |          d d d         t          t          |                               I|                     t          t          g d	           d S )
Nc                       e Zd Zd Zd ZdS )#TestReversed.test_simple.<locals>.Ac                 :    |dk     rt          |          S t          N   )strr&   r   s     r   r   z/TestReversed.test_simple.<locals>.A.__getitem__   s    q55q66M##r   c                     dS r   r   r   s    r   __len__z+TestReversed.test_simple.<locals>.A.__len__   s    qr   N)r   r   r   r   r   r   r   r   Ar      s2        $ $ $    r   r   rU   r   r#      abcde)rV   )
rC   tupler   dictfromkeysrH   rJ   reversedrg   ro   )r   r   datas      r   test_simplezTestReversed.test_simple   s    	 	 	 	 	 	 	 	 E!HHeIe,<,<&=&=qqss!BqMM4==#9#9; 	E 	EDT$ZZ"-tHTNN/C/CDDDD)XrQ77777r   c                     t          d          }|                     t          t          |                    t          t	          |                               d S r"   )rC   rH   rI   r   r\   )r   r|   s     r   test_range_optimizationz$TestReversed.test_range_optimization   sC    !HHhqkk**DaMM:::::r   c                 
   dt          d          t          d          t          d          fD ]}|                     t	          j        t          |                    t          |                     t          |          }t          |           |                     t	          j        |          d            G d d          }t           |                      }|                     t          t          j        |           d S )Nhellor   r   c                       e Zd ZdZd Zd ZdS ).TestReversed.test_len.<locals>.SeqWithWeirdLenFc                 0    | j         s	d| _         dS t          )NTr   )calledru   r   s    r   r   z6TestReversed.test_len.<locals>.SeqWithWeirdLen.__len__   s    { "&DK2''r   c                     |S r   r   r   indexs     r   r   z:TestReversed.test_len.<locals>.SeqWithWeirdLen.__getitem__       r   N)r   r   r   r   r   r   r   r   r   SeqWithWeirdLenr      s7        F( ( (
    r   r   )
r   rJ   rC   rH   operatorlength_hintr   r%   rg   ru   )r   srr   s       r   test_lenzTestReversed.test_len   s    5>>4==%((C 	9 	9AX1(1++>>AGGGAGGGX1!44a8888	 	 	 	 	 	 	 	 __&&''+X-A1EEEEEr   c                 `     G d d          } |            }t          |          }||_        d S )Nc                       e Zd Zd Zd ZdS )!TestReversed.test_gc.<locals>.Seqc                     dS )Nr   r   r   s    r   r   z)TestReversed.test_gc.<locals>.Seq.__len__   s    rr   c                     |S r   r   r   s     r   r   z-TestReversed.test_gc.<locals>.Seq.__getitem__   r   r   N)r   r   r   r   r   r   r   r   Seqr      s2              r   r   )r   r   )r   r   r   r   s       r   test_gczTestReversed.test_gc   sM    	 	 	 	 	 	 	 	
 CEEQKKr   c                     |                      t          t                     |                      t          t          g d           d S )Nextra)rg   ro   r   r   s    r   	test_argszTestReversed.test_args   s8    )X...)Xr7;;;;;r   getrefcountztest needs sys.getrefcount()c                 <   d }t                      x}|_        t          j        |          }t	          d          D ]7}	 t          |           |                     d           (# t          $ r Y 4w xY w|                     |t          j        |                     d S )Nc                      d S r   r   r   r   r   fz'TestReversed.test_bug1229429.<locals>.f   s    Dr   r   z'non-callable __reversed__ didn't raise!)	object__reversed__sysr   rC   r   failro   rH   )r   r   r   rcr   s        r   test_bug1229429zTestReversed.test_bug1229429   s    	 	 	#XX%AN_Qr 	E 	EAE 		CDDDD     	S_Q//00000s   A$$
A10A1c                 z    G d dt                     } |            }|                     t          t          |            G d dt                     } |            }|                     t          t          |            G d dt                     } |            }|                     t          t          |           d S )Nc                       e Zd Zd ZdS )+TestReversed.test_objmethods.<locals>.NoLenc                     dS r"   r   r   s     r   r   z7TestReversed.test_objmethods.<locals>.NoLen.__getitem__       QQr   N)r   r   r   r   r   r   r   NoLenr      s        .....r   r   c                       e Zd Zd ZdS )/TestReversed.test_objmethods.<locals>.NoGetItemc                     dS NrX   r   r   s    r   r   z7TestReversed.test_objmethods.<locals>.NoGetItem.__len__       aar   N)r   r   r   r   r   r   r   	NoGetItemr      s        '''''r   r   c                       e Zd Zd Zd ZdZdS )-TestReversed.test_objmethods.<locals>.Blockedc                     dS r"   r   r   s     r   r   z9TestReversed.test_objmethods.<locals>.Blocked.__getitem__  r   r   c                     dS r   r   r   s    r   r   z5TestReversed.test_objmethods.<locals>.Blocked.__len__  r   r   N)r   r   r   r   r   r   r   r   r   Blockedr     s%        ...'''LLLr   r   )r   rg   ro   r   )r   r   nlr   ngir   rW   s          r   test_objmethodszTestReversed.test_objmethods   s    	/ 	/ 	/ 	/ 	/F 	/ 	/ 	/UWW)Xr222	( 	( 	( 	( 	( 	( 	( 	(ikk)Xs333	  	  	  	  	 f 	  	  	  GII)Xq11111r   c                     dt          d          t          t          d                    t          ddd          fD ];}|                     t	          |          t          |          d d d                    <d S )NrU   r   r#   r   r   )rC   r   r   rR   r   rJ   )r   r   s     r   rc   zTestReversed.test_pickle  sx    588U9U+;+;%<%<eAbmmK 	@ 	@Dhtnnd4jj2.>????	@ 	@r   N)r   r   r   r   r   r   r   r   unittest
skipUnlesshasattrr   r   r   rc   r   r   r   r   r      s        8 8 8; ; ;F F F&  < < < Xm446TUU1 1 VU1 2 2 2&@ @ @ @ @r   r   c                       e Zd Zd ZdS )EnumerateStartTestCasec                     |                      | j                  }|                     t          |          |           |                     t	          |                      | j                            | j                   d S r   )r[   rN   rH   r\   rJ   r]   r_   s     r   ra   z)EnumerateStartTestCase.test_basicfunction  se    IIdha!$$$dii1122DH=====r   N)r   r   r   ra   r   r   r   r   r     s#        > > > > >r   r   c                   $    e Zd ZddZdg dcZZdS )	TestStart   c                 $    t          ||          S N)r{   r   r   rz   r{   s      r   r[   zTestStart.enum      ////r   rU   ))r   rV   )   rW   )   rY   N)r   )r   r   r   r[   rN   r]   r   r   r   r   r     s6        0 0 0 0 777HCr   r   c                   t    e Zd Zej        dz   fdZdej        dz   dfej        dz   dfej        dz   dfgcZZd	S )
TestLongStartr#   c                 $    t          ||          S r   r   r   s      r   r[   zTestLongStart.enum   r   r   rU   rV   rX   rW   r;   rY   N)r   r   r   r   maxsizer[   rN   r]   r   r   r   r   r     sc        #&;? 0 0 0 0 Ac*S[]3,?Ac*,HCr   r   __main__)r   r   r   rD   r   testr   r   r   r-   r3   r7   r=   rA   TestCaserT   r   r   r   r   r   r   r   r   r   r   mainr   r   r   <module>r      s&     



  				                           	 	 	 	 	 	 	 	              0 0 0 0 0 0 0 0&J1 J1 J1 J1 J1): J1 J1 J1X	 	 	 	 	Y 	 	 	    (       !   ' ' ' ' ' ' ' '
[@ [@ [@ [@ [@8$j [@ [@ [@|> > > > >. > > >8 8 8 8 8& 8 8 8, , , , ,* , , , zHMOOOOO r   