
    ;e;                     j   d 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 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ddlmZ d Z G d de          Z G d de          Z G d dej                  ZdS )z3
Tests common to tuple, list and UserList.UserList
    N)support)	ALWAYS_EQNEVER_EQc              #      K   | D ]}|V  dS )zRegular generatorN seqnis     %/usr/lib/python3.11/test/seq_tests.pyiterfuncr      s*             c                       e Zd ZdZd Zd ZdS )SequencezSequence using __getitem__c                     || _         d S Nr	   selfr	   s     r   __init__zSequence.__init__   s    			r   c                     | j         |         S r   r   r   r
   s     r   __getitem__zSequence.__getitem__   s    y|r   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s8                r   r   c                   $    e Zd ZdZd Zd Zd ZdS )IterFuncz Sequence using iterator protocolc                 "    || _         d| _        d S Nr   r   r   s     r   r   zIterFunc.__init__       	r   c                     | S r   r   r   s    r   __iter__zIterFunc.__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IterFunc.__next__    >    6S^^##=%8Idf!r   Nr   r   r   r   r   r$   r.   r   r   r   r   r      sG        &&        r   r   c                       e Zd ZdZd Zd ZdS )IterGenz9Sequence using iterator protocol defined with a generatorc                 "    || _         d| _        d S r    r   r   s     r   r   zIterGen.__init__(   r!   r   c              #   &   K   | j         D ]}|V  d S r   r   )r   vals     r   r$   zIterGen.__iter__+   s,      9 	 	CIIII	 	r   Nr   r   r   r   r   r$   r   r   r   r2   r2   &   s8        ??      r   r2   c                       e Zd ZdZd Zd ZdS )IterNextOnlyz Missing __getitem__ and __iter__c                 "    || _         d| _        d S r    r   r   s     r   r   zIterNextOnly.__init__1   r!   r   c                     | j         t          | j                  k    rt          | j        | j                  }| xj         dz  c_         |S r'   r)   r,   s     r   r.   zIterNextOnly.__next__4   r/   r   N)r   r   r   r   r   r.   r   r   r   r8   r8   /   s8        &&      r   r8   c                       e Zd ZdZd Zd ZdS )
IterNoNextzIterator missing __next__()c                 "    || _         d| _        d S r    r   r   s     r   r   zIterNoNext.__init__<   r!   r   c                     | S r   r   r#   s    r   r$   zIterNoNext.__iter__?   r%   r   Nr6   r   r   r   r<   r<   :   s8        !!      r   r<   c                   $    e Zd ZdZd Zd Zd ZdS )
IterGenExczTest propagation of exceptionsc                 "    || _         d| _        d S r    r   r   s     r   r   zIterGenExc.__init__D   r!   r   c                     | S r   r   r#   s    r   r$   zIterGenExc.__iter__G   r%   r   c                     ddz   d S )N   r   r   r#   s    r   r.   zIterGenExc.__next__I   s    	Qr   Nr0   r   r   r   r@   r@   B   sG        $$        r   r@   c                   $    e Zd ZdZd Zd Zd ZdS )IterFuncStopzTest immediate stopc                     d S r   r   r   s     r   r   zIterFuncStop.__init__N   s    r   c                     | S r   r   r#   s    r   r$   zIterFuncStop.__iter__P   r%   r   c                     t           r   )r+   r#   s    r   r.   zIterFuncStop.__next__R   s    r   Nr0   r   r   r   rF   rF   L   sG                r   rF   )chainc                     t          t          d t          t          t	          |                                                   S )z Test multiple tiers of iteratorsc                     | S r   r   )xs    r   <lambda>zitermulti.<locals>.<lambda>X   s    a r   )rJ   mapr   r2   r   r   s    r   	itermultirP   V   s2    ZZ'(4..*A*A!B!BCCDDDr   c                       e Zd Zd ZdS )
LyingTuplec              #      K   dV  d S r'   r   r#   s    r   r$   zLyingTuple.__iter__[         r   Nr   r   r   r$   r   r   r   rR   rR   Z   #            r   rR   c                       e Zd Zd ZdS )	LyingListc              #      K   dV  d S r'   r   r#   s    r   r$   zLyingList.__iter___   rT   r   NrU   r   r   r   rX   rX   ^   rV   r   rX   c                       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S )
CommonTestNc           	         g }dg}ddg}|                                  }|                      |          }|                      |          }|                      |          }|                      |          }|                      |          }	|                      |          }
|                      |          }|                      t          |                    } G d d          } ||          }|                      |          }|                     t          |          t          |                     d}|                      |          }|                     t          |          t          |                     ddt	          d          d	t	          d
dd          fD ]}t
          t          t          t          t          fD ]G}|                     |                       ||                    |                      |                     H|                     |                      t          |                    |                                             |                     |                      d dD                       |                      d                     |                     t          | j         t          |                     |                     t          | j         t          |                     |                     t          | j         t!          |                     |                     |                      t#          d                    |                      d                     |                     |                      t%          dg                    |                      dg                     |                     t                    5  |                      g            d d d            d S # 1 swxY w Y   d S )Nr   r(   c                        e Zd Zd Zd Zd ZdS ).CommonTest.test_constructors.<locals>.OtherSeqc                     || _         d S r   _OtherSeq__data)r   initseqs     r   r   z7CommonTest.test_constructors.<locals>.OtherSeq.__init__w   s    %r   c                 *    t          | j                  S r   )r*   ra   r#   s    r   __len__z6CommonTest.test_constructors.<locals>.OtherSeq.__len__y   s    4;'''r   c                     | j         |         S r   r`   r   s     r   r   z:CommonTest.test_constructors.<locals>.OtherSeq.__getitem__{   s    {1~%r   N)r   r   r   r   rd   r   r   r   r   OtherSeqr^   v   sA        & & &( ( (& & & & &r   rf   zthis is also a sequence123   )dog333333?i  i     c              3      K   | ]}|V  d S r   r   ).0cs     r   	<genexpr>z/CommonTest.test_constructors.<locals>.<genexpr>   s"      +=+=!A+=+=+=+=+=+=r   )   )r(   rp   )unsupported_arg)	type2testtupleassertEqualr*   ranger   r   r2   rP   r   rF   assertRaises	TypeErrorr8   r<   ZeroDivisionErrorr@   rR   rX   )r   l0l1l2uu0u1u2uuuu0uu1uu2r-   rf   sv0vvgs                     r   test_constructorszCommonTest.test_constructorsf   s   SVNN^^B^^B^^B^^AnnR  nnR  nnR  NN588$$	& 	& 	& 	& 	& 	& 	& 	& HRLL^^AR#a&&)))%^^AR#a&&))) U4[[+uT$q7I7IJ 	P 	PA'+ J J  !!5!5t~~a7H7HIIIIT^^LOO<<dnn>N>NOOOT^^+=+=u+=+=+===t~~e?T?TUUUiaIIIiAGGG/AOOOO 	
4(8(8994>>$;O;OPPP	1#779L9LMMMy)) 	/ 	/NN2N...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   O11O58O5c                     |                      |                                            |                     |                     dg                     d S )N*   )assertFalserr   
assertTruer#   s    r   
test_truthzCommonTest.test_truth   sF    ))***t,,-----r   c           	         |                      g d          }t          t          |                    D ]G}|                     ||         |           |                     |t	          |                   |           Ht          t          |           d          D ]g}|                     ||         t          |          |z              |                     |t	          |                   t          |          |z              h|                     t          |j        t          |           dz
             |                     t          |j        t          |                     |                     t          |j        t          ddd                     |                                  }|                     t          |j        d           |                     t          |j        d           |                     t          |j                   |                      ddg          }|                     |d         d           |                     |d         d           |                     |d         d           |                     |d         d           |                     t          |j        d           |                     t          |j        d	           d S )
Nr   r(   rp   rD      r(   r   
      rD   )rr   ru   r*   rt   intrv   
IndexErrorr   
ValueErrorslicerw   )r   r|   r
   as       r   test_getitemzCommonTest.test_getitem   s]   NN???++s1vv 	+ 	+AQqT1%%%Qs1vvY****Aw## 	2 	2AQqT3q66!8,,,Qs1vvYAq1111*amc!ffWQY???*amSVV<<<*amU1R]]CCCNN*amQ777*amR888)Q]333NNB8$$1r"""1r"""2###2###*amR888*amQ77777r   c                 
   g d}|                      |          }|                     |dd         |                                             |                     |dd         |                      dg                     |                     |dd         |                      dg                     |                     |dd	         |           |                     |d	d         |                      g                      |                     |d d          |           |                     |dd          |                      g d
                     |                     |d d         |                      g d                     |                     |d d          |           |                     |d d d         |                      g d                     |                     |dd d         |                      ddg                     |                     |d d d         |                      g d                     |                     |d d d         |                      g d                     |                     |dd d         |                      ddg                     |                     |ddd         |                      g                      |                     |ddd         |                      dg                     |                     |ddd         |                      dg                     |                     |ddd         |                      ddg                     |                     |d d d         |                      dg                     |                     |dd         |                      g                      |                     |dd         |           |                     |ddd         |d d d                    |                     |ddd         |                      g                      |                     |ddd         |                      g d                     |                      g d          }|                     |t          dd           d         |                      g d                     |                     |dt          dd                   |                      ddg                     |                     |dd t          j                 |                      dg                     d S )Nr   r   r(   rp   r   r   rD   iri   )r(   rp   rD   r   r   r(   rp   )r   rp   r   )r   rD   rp   r(   r   )r   rp   r   ir   d         )rr   rt   powsysmaxsize)r   lr|   r   s       r   test_getslicezCommonTest.test_getslice   s   OONN11Q3!1!12221Q3!4!45552b54>>1##6#67775:***4:r(:(:;;;111q!!!1T6DNN<<<$@$@AAA46DNN999$=$=>>> 	222"""33Q3			!:!:;;;14a4$..!Q"8"899944R4$.."A"ABBB44R4$..";";<<<15b54>>1a&#9#9:::1Qr6DNN2$6$67771Qr6DNNA3$7$78881Qr6DNNA3$7$78881Qr6DNNAq6$:$:;;;66T6DNNA3$7$78883t9t~~b'9'9:::49q)))3tB;44R41114B;););<<<4A:yyy(A(ABBB NN;;;''S3ZZKN,dnnWWW.E.EFFFAs1SzzM+T^^QqE-B-BCCC1>ck>*DNNA3,?,?@@@@@r   c                 $   |                      g d          }|D ]}|                     ||           t          |          dz
  t          |          dz   fD ]}|                     ||           |                     t          |j                   d S )Nr   r(   )rr   assertInminmaxassertNotInrv   rw   __contains__)r   r|   r
   s      r   test_containszCommonTest.test_contains   s    NN999%% 	  	 AMM!QQ3q66!8# 	# 	#AQ"""")Q^44444r   c                 J   |                      t          |                     g                      |                     t          |                     dg                     |                     d|                     t          g                     |                      t          |                     g                      |                      t          |                     t          g                     |                     t          |                     t          g                     d S r'   )r   r   rr   r   r   r#   s    r   test_contains_fakezCommonTest.test_contains_fake   s     	DNN2$6$6777i!4!4555a445554>>"#5#5666DNNH:$>$>???h	{ ; ;<<<<<r   c                 ,    G d dt                      G fdd          }|                     d |            g          }|                     d|           |                      |            dg          }|                     |j        d           d S )Nc                       e Zd ZdS )3CommonTest.test_contains_order.<locals>.DoNotTestEqNr   r   r   r   r   r   DoNotTestEqr              Dr   r   c                       e Zd Z fdZdS )4CommonTest.test_contains_order.<locals>.StopComparesc                     r   r   )r   otherr   s     r   __eq__z;CommonTest.test_contains_order.<locals>.StopCompares.__eq__   s	    !!r   Nr   r   r   r   )r   s   r   StopComparesr      s.        " " " " " " "r   r   r(   )	Exceptionrr   r   rv   r   )r   r   
checkfirst	checklastr   s       @r   test_contains_orderzCommonTest.test_contains_order   s    	 	 	 	 	) 	 	 		" 	" 	" 	" 	" 	" 	" 	" 	" 	" ^^Q$788
a$$$NNLLNNA#677	+y'=qAAAAAr   c                    |                      t          |                                           d           |                      t          |                     g                     d           |                      t          |                     dg                    d           |                      t          |                     g d                    d           d S )Nr   r(   r   rD   )rt   r*   rr   r#   s    r   test_lenzCommonTest.test_len   s    T^^--..222T^^B//00!444T^^QC00111555T^^III6677;;;;;r   c                     |                      g d          }|                     t          |          d           |                     t          |          d           d S )Nr   r   rp   )rr   rt   r   r   r   r|   s     r   test_minmaxzCommonTest.test_minmax  sU    NN999%%Q###Q#####r   c                 
   |                      dg          }|                      ddg          }|                     |||                                  z              |                     ||                                  |z              |                     ||                      dg          z   |           |                     |                      dg          |z   |                      ddg                     |                     |                                  |dz             |                     |                                  d|z             |                     |                                  |dz             |                     |                                  d|z             |                     ||dz             |                     |d|z             |                     ||dz             |                     |d|z             |                     ||z   |dz             |                     ||z   d|z             |                     ||z   |dz             |                     ||z   d|z             |                     ||z   |z   |dz             |                     ||z   |z   d|z              G d d| j                   } |ddg          }|                     ||dz             |                     ||dz             d S )Nr   r(   r   rp   rD   c                       e Zd ZdS )(CommonTest.test_addmul.<locals>.subclassNr   r   r   r   subclassr     r   r   r   )rr   rt   assertIsNot)r   r~   r   r   u3s        r   test_addmulzCommonTest.test_addmul  s   ^^QC  ^^QF##R$.."2"22333T^^--2333dnnaS1112666--2DNNB74K4KLLL))2a4000))1R4000))2a4000))1R4000RT"""QrT"""RT"""QrT"""B1%%%B"%%%B1%%%B"%%%Br2a4(((Br1R4(((	 	 	 	 	t~ 	 	 	Xq!fRT"""RT"""""r   c                 x   |                      ddg          }||                                  z  }|                     ||                      ddg                     ||                      ddg          z  }|                     ||                      g d                     ||                      ddg          z  }|                     ||                      g d                     |                      d	          }||                      d
          z  }|                     ||                      d                     d S )Nr   r(   rp   rD   r   r(   rp   rD   r   rk   )r   r(   rp   rD   r   rk   spameggsspameggsrr   rt   r   s     r   	test_iaddzCommonTest.test_iadd$  s#   NNAq6""	T^^DNNAq622333	T^^QF###DNN<<<88999	T^^QF###DNN+=+=+=>>???NN6""	T^^F###DNN:6677777r   c                     |                      ddg          }|dz  }|                     ||                      g d                     |dz  }|                     ||                      g                      d S )Nr   r(   rD   )r   r(   r   r(   r   r(   r   r   s     r   	test_imulzCommonTest.test_imul1  sz    NNAq6""	QDNN+=+=+=>>???	QDNN2../////r   c           	           G d d| j                   }|                     t          t           |d                              d           d S )Nc                       e Zd Zd ZdS )/CommonTest.test_getitemoverwriteiter.<locals>.Tc                 &    t          |          dz   S )Nz!!!)str)r   keys     r   r   z;CommonTest.test_getitemoverwriteiter.<locals>.T.__getitem__;  s    3xx%''r   N)r   r   r   r   r   r   r   Tr   :  s#        ( ( ( ( (r   r   )r(   rp   r(   )rr   rt   nextiter)r   r   s     r   test_getitemoverwriteiterz$CommonTest.test_getitemoverwriteiter8  sb    	( 	( 	( 	( 	( 	( 	( 	( 	d11U88nn--q11111r   c                    t          d          D ]}t          t          |                    }t          dd          D ]D}|                     |                     ||z            |                     |          |z             E|                     |                     |          dz  |                     g                      |                     t	          |          t	          |dz                       d S )Nr   r   rk   r(   )ru   rs   rt   rr   id)r   mr   ns       r   test_repeatzCommonTest.test_repeat?  s    q 	- 	-AeAhhA2q\\ K K  !!4!4dnnQ6G6G6IJJJJT^^A..3T^^B5G5GHHHRUUBqsGG,,,,	- 	-r   c                    t           j        dk    ro|                     dg          }|dz  }|                     t          |j        d           t          |d          r%|                     t          |j        d           d S d S d S )Nir   i   __imul__)r   r   rr   rv   MemoryError__mul__hasattrr   )r   rM   s     r   test_bigrepeatzCommonTest.test_bigrepeatG  s    ;*$$s##AJAk19e<<<q*%% B!!+qz5AAAAA %$B Br   c           	         |                      ddg          }|                     |                    d          d           |                     |                    d          d           |                     |                    d          d           |                     |                    d          d           |                     t          |j        d           |                     t          |j        d           |                     |                    t          dd                    |                      dg                     |                     |                    t          dd	                    |                      dg                     |                     |                    t          dd	                    |                      ddg                     |                     |                    t          dd                    |                      ddg                     |                     |                    t          dd
                    |                      g                      |                     t          |j        t          ddd                     |                     t          |j        d           d S )Nr   r   r   r(   r   r   r   rD   rp   rk   rM   )rr   rt   r   rv   r   r   r   rw   )r   r   s     r   test_subscriptzCommonTest.test_subscriptO  s1   NNB8$$q))2...q))2...r**B///r**B///*amR888*amQ777uQqzz22DNNB44H4HIIIuQqzz22DNNB44H4HIIIuQqzz22DNNB84L4LMMMuQqzz22DNNB84L4LMMMuQqzz22DNN24F4FGGG*amU1b!__EEE)Q]C88888r   c                    |                      g d          dz  }|                     |                    d          d           |                     |                    d          d           |                     |                    d          d           |                     |                    t                    d           |                     |                      t          t          g                              d          d           |                     |                      t          t          g                              t                    d           |                     |                      t          t          g                              t                    d           |                     t          |j                    G d dt                     G fd	d
          }|                     |j         |                       d S )Nr   rD   r   r(   	   rp   c                       e Zd ZdS )%CommonTest.test_count.<locals>.BadExcNr   r   r   r   BadExcr   l  r   r   r   c                       e Zd Z fdZdS )%CommonTest.test_count.<locals>.BadCmpc                 (    |dk    r
             dS Nrp   Fr   r   r   r   s     r   r   z,CommonTest.test_count.<locals>.BadCmp.__eq__p      A:: &((Nur   Nr   r   s   r   BadCmpr   o  .              r   r   )rr   rt   countr   r   rv   rw   r   )r   r   r   r   s      @r   
test_countzCommonTest.test_count_  s   NN999%%a'Q'''Q'''Q'''++Q///I(>??EEaHH!LLLI(>??EEhOOQRSSS8(<==CCINNPQRRR)QW---	 	 	 	 	Y 	 	 		 	 	 	 	 	 	 	 	 	 	&!'668844444r   c                 
   |                      ddg          }|                     |                    d          d           |                     |                    d          d           |                     t          |j        d           |                      g d          }|                     |                    d          d           |                     |                    d          d           |                     |                    dd          d           |                     |                    dd          d           |                     |                    dd          d           |                     |                    ddd          d           |                     t          |j        ddd           |                     |                    t                    d           |                     |                      t          t          g                              d          d           |                     |                      t          t          g                              t                    d           |                     t          |                      t          t          g          j        t                     |                     t          |j                    G d	 d
t                     G fdd          }|                      g d          }|                     |j         |                       |                      g d          }|                     |                    d          d           |                     |                    dd          d           |                     |                    dd          d           |                     |                    dd          d           |                     |                    dd          d           |                     |                    dd          d           |                     |                    ddd          d           |                     |                    ddd          d           |                     |                    ddt          j        z  dt          j        z            d           |                     t          |j        ddt          j        z  dt          j        z             |                     t          |j        ddd           d S )Nr   r(   rp   )r   r   r   r   r(   rp   r   irD   r   c                       e Zd ZdS )%CommonTest.test_index.<locals>.BadExcNr   r   r   r   r   r     r   r   r   c                       e Zd Z fdZdS )%CommonTest.test_index.<locals>.BadCmpc                 (    |dk    r
             dS r   r   r   s     r   r   z,CommonTest.test_index.<locals>.BadCmp.__eq__  r   r   Nr   r   s   r   r   r    r   r   r   r   r   r   )rr   rt   indexrv   r   r   r   r   rw   r   r   r   )r   r|   r   r   r   s       @r   
test_indexzCommonTest.test_indexw  s   NNAq6""Q'''Q'''*agq111NN///00Q'''Q'''A***S))1---A***Aq))1---*agq!S999++Q///I(>??EEaHH!LLLI(>??EEhOOQRSSS*dnnh5I&J&J&PR[\\\)QW---	 	 	 	 	Y 	 	 		 	 	 	 	 	 	 	 	 	 NN<<<((&!'6688444NN///00Q'''A***B+++S))1---A***B+++Aq))1---B++Q///Bs{NAckMBBAFFF*agq!CK-3;OOO*agq!S99999r   c                 L   |                      g d          }t          t          j        dz             D ]o}t          j        t          j        ||                    }|                     ||           |                     t          |          t          |                     pd S )N)r   rk         r(   )	rr   ru   pickleHIGHEST_PROTOCOLloadsdumpsrt   assertNotEqualr   )r   lstprotolst2s       r   test_picklezCommonTest.test_pickle  s    nn\\\**62Q677 	3 	3E<S% 8 899DT3'''4"S''2222	3 	3r   c                     t          j        | t          | j                   t          j        | t          | j                   d S r   )r   check_free_after_iteratingr   rr   reversedr#   s    r   test_free_after_iteratingz$CommonTest.test_free_after_iterating  s6    *4t~FFF*44>JJJJJr   )r   r   r   rr   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[   b   sV       I// // //b. . .8 8 84#A #A #AJ5 5 5	= 	= 	=B B B< < <$ $ $
# # #88 8 80 0 02 2 2- - -B B B9 9 9 5 5 50-: -: -:^3 3 3K K K K Kr   r[   )r   unittestr   r  testr   test.supportr   r   r   r   r   r2   r8   r<   r@   rF   	itertoolsrJ   rP   rs   rR   listrX   TestCaser[   r   r   r   <module>r     sB     



        , , , , , , , ,  
                     	 	 	 	 	 	 	 	                           E E E              MK MK MK MK MK" MK MK MK MK MKr   