
    dafI                         d dl Z d dlZd dlmZ  ej                  d      ZdZ G d de      Z G d d      Z	 G d d	      Z
 G d
 de j                        Zedk(  r e j                          yy)    N)import_helper	_testcapic                       e Zd Zy)IntSubclassN)__name__
__module____qualname__     3/root/Python-3.12.4/Lib/test/test_capi/test_long.pyr   r      s    r   r   c                       e Zd Zd Zd Zy)Indexc                     || _         y Nvalue)selfr   s     r   __init__zIndex.__init__   s	    
r   c                     | j                   S r   r   r   s    r   	__index__zIndex.__index__   s    zzr   N)r   r   r	   r   r   r
   r   r   r   r      s    r   r   c                       e Zd Zd Zd Zy)MyIndexAndIntc                      y)N
   r
   r   s    r   r   zMyIndexAndInt.__index__       r   c                      y)N   r
   r   s    r   __int__zMyIndexAndInt.__int__   r   r   N)r   r   r	   r   r   r
   r   r   r   r      s    r   r   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y)	LongTestsc                    h d t        d      D        d t        d      D        d t        d      D        d t        d      D        d t        d      D        d t        d      D        D ]I  }| j                  |	      5  t        j                  |      \  }}|r| j	                  ||       d d d        K y # 1 sw Y   VxY w)
Nc              3   &   K   | ]	  }d |z    yw   Nr
   .0ns     r   	<genexpr>z)LongTests.test_compact.<locals>.<genexpr>"   s     &qad&   B   c              3   (   K   | ]
  }d |z     ywr$   r
   r&   s     r   r)   z)LongTests.test_compact.<locals>.<genexpr>#   s     'q!te'   c              3   ,   K   | ]  }d |z  dz
    ywr%      Nr
   r&   s     r   r)   z)LongTests.test_compact.<locals>.<genexpr>$   s     *1adQh*s   c              3   .   K   | ]  }d |z   dz     ywr/   r
   r&   s     r   r)   z)LongTests.test_compact.<locals>.<genexpr>%   s     +Aq!teai+s   c              3   &   K   | ]	  }d |z    yw%   Nr
   r&   s     r   r)   z)LongTests.test_compact.<locals>.<genexpr>'   s     'b!e'r*      c              3   (   K   | ]
  }d |z     ywr3   r
   r&   s     r   r)   z)LongTests.test_compact.<locals>.<genexpr>(   s     (r1uf(r-   )r(   )rangesubTestr   call_long_compact_apiassertEqual)r   r(   
is_compactr   s       r   test_compactzLongTests.test_compact   s    	
&E"I&	
 (U2Y'	
 +b	*		

 ,r+	
 (U2Y'	
 )eBi(	
 	/A " /$-$C$CA$F!
E$$Q./ /	// /s   -B<<C	c                 H   | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  t        j                        d       y )N)Tr>   r   )Tr      )Tr?   )Fr>   )r:   r   r9   sysmaxsizer   s    r   test_compact_knownzLongTests.test_compact_known/   sw     	88<jI88;YG88={K88E$	&r   c                    t         j                  }| j                   |d             | j                   |d             | j                   |d             | j                   |d             | j                   |t        d                   | j	                   |d             | j	                   |t                            y Nr0   l   
~l!]c r>   T      ?)r   pylong_check
assertTruer   assertFalseobjectr   checks     r   test_long_checkzLongTests.test_long_check8   s    &&a!<=>b	"d$k!n-.s$vx)r   c                    t         j                  }| j                   |d             | j                   |d             | j                   |d             | j                   |d             | j                   |t	        d                   | j                   |d             | j                   |t                            y rD   )r   pylong_checkexactrG   rH   r   rI   rJ   s     r   test_long_checkexactzLongTests.test_long_checkexactD   s    ++a!<=>b	"t%{1~./s$vx)r   c           	         t         j                  }t        j                  j                  }ddddddd|| f	D ]>  }| j                  |      5  | j                   ||      t        |             d d d        @ | j                  t        |t        d	             | j                  t        |t        d
             | j                  t        |t        d             y # 1 sw Y   xY w)Ng      @gffffff@g@gffffffgg        g       r   infz-infnan)r   pylong_fromdoubler@   
float_infomaxr8   r:   intassertRaisesOverflowErrorfloat
ValueError)r   
fromdouble	float_maxr   s       r   test_long_fromdoublezLongTests.test_long_fromdoubleP   s    00
NN&&	3T4dI	zR 	@EE* @  E!2CJ?@ @	@ 	-U5\B-U6]C*j%,?	@ @s   "CC"	c                 $   t         j                  }t               } ||      } |t              }| j	                  |t
               | j                  |d       | j	                  |t
               | j                  |d       | j                  ||       y )Nr   )	r   pylong_fromvoidptrrI   NULLassertIsInstancerV   assertGreaterEqualr:   assertNotEqual)r   fromvoidptrobjxys        r   test_long_fromvoidptrzLongTests.test_long_fromvoidptr[   sx    22ha%1%a%AAq!r   c                 4   t         j                  }| j                   |dd      d       | j                   |dd      d       | j                   |dd      d	       | j                   |dd
      d       | j                   |dd
      d       | j                  t        |dd
       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                  t        |dd       | j                  t        |dd       | j                  t        |dd       | j                  t        |dd       | j                  t        |dd       | j                  t        |dj                         d
       | j                  t        |dj                         d       | j                   |dd
      d       | j                   |dd
      d       | j                   |dd      d       | j                   |dd      d       y )Ns   123r   ){      s   cafe   )     s   xyz$   )  rk   r   s   0xcafe)rm      s   -123)rn   s    -123 )rr   rq   s   1_23)rj   rn   s   - 123r   r0   r>   r4      ١٢٣٤٥٦٧٨٩٠s   123 s   123 456)i#  rk   )r   pylong_fromstringr:   rW   rZ   encode)r   
fromstrings     r   test_long_fromstringzLongTests.test_long_fromstringg   s   00
FB/:GR0+>FB/<FA.9Iq1;?*j'1=GR0)<Ir2I>GR0(;*j(B?*j#r:*j&!<*j&"=*j&"=*j2H2O2O2QSTU*j2H2O2O2QSUVJ2H=M15x@J3Z@M26
Cr   c                    t         j                  }| j                   |dd      d       | j                   |dd      d       | j                   |dd      d	       | j                   |dd
      d       | j                   |dd
      d       | j                  t        |dd
       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                  t        |dd       | j                  t        |dd       | j                  t        |dd       | j                  t        |dd       | j                  t        |dd       | j                   |dd
      d       | j                   |dd      d       | j                  t        |dd
       | j                  t        |dd
       | j                  t        |dd       | j                  t        |dd       y )N123r   rj   caferl   rm   xyzro   rp   r   0xcafez-123rr   z -123 1_23z- 123 r0   r>   r4   rs   iIl   xhH z123 z123 456)r   pylong_fromunicodeobjectr:   rW   rZ   )r   fromunicodeobjects     r   test_long_fromunicodeobjectz%LongTests.test_long_fromunicodeobject   s   %>>*5"5s;*626?*5"5u=*5!4c:*8Q7@*&7C*626=*8R8$?*626<*&7"E*&7R@*&7B*&7C*&7C*+A1EzR*+A2FU*&7AF*&7qI*&7BG*&7rJr   c                    t         j                  }ddl m}m} ||ddddfD ]5  }| j	                  |      5  | j                   ||      |       d d d        7 | j                   |t        d            d       | j                   |t        d            d       | j                   |t                     d       | j                  t        ||dz
         | j                  t        ||dz          | j                  t        |d	       | j                  t        |d
       | j                  t        |d       | j                  t        |t               y # 1 sw Y   9xY w)Nr   LONG_MINLONG_MAXr>   r0     r   *   r   rE      23)r   pylong_aslongr   r   r8   r:   r   r   r   rW   rX   	TypeErrorSystemErrorr`   )r   aslongr   r   r   s        r   test_long_aslongzLongTests.test_long_aslong   s'   ((0"aD9 	7EE* 7  67 7	7 	B0"5b	*B/0"5-A>-A>)VS1)VT2)VS1+vt47 7   EE	c                     t         j                  }ddl m}m} ||ddddfD ]7  }| j	                  |      5  | j                   ||      |df       d d d        9 | j                   |t        d            d       | j                   |t        d            d       | j                   |t                     d	       | j                   ||dz
        d
       | j                   ||dz         d       y # 1 sw Y   xY w)Nr   r   r>   r0   r   r   r   r   r   r   r   r>   r>   r>   r0   )	r   pylong_aslongandoverflowr   r   r8   r:   r   r   r   )r   aslongandoverflowr   r   r   s        r   test_long_aslongandoverflowz%LongTests.test_long_aslongandoverflow   s    %>>0"aD9 	GEE* G  !25!9E1:FG G	G 	*;r?;WE*595w?*=?;WE*8a<8(C*8a<8'BG G   C44C=	c                    t         j                  }ddl m} |dddfD ]5  }| j                  |      5  | j	                   ||      |       d d d        7 | j	                   |t        d            d       | j                  t        |t        d             | j                  t        |t                      | j                  t        |d       | j                  t        ||dz          | j                  t        |d       | j                  t        |d	       | j                  t        |d
       | j                  t        |t               y # 1 sw Y   4xY w)Nr   	ULONG_MAXr0   r   r   r   r>   rE   r   r   )r   pylong_asunsignedlongr   r8   r:   r   rW   r   r   r   rX   r   r`   )r   asunsignedlongr   r   s       r   test_long_asunsignedlongz"LongTests.test_long_asunsignedlong   s   "88'At, 	?EE* ?  !6>? ?	? 	B8"=)^U2Y?)^]_E-<-QG)^S9)^T:)^S9+~t<? ?   EE	c                    t         j                  }ddl m} |dddfD ]5  }| j                  |      5  | j	                   ||      |       d d d        7 | j	                   |t        d            d       | j	                   |t        d            d       | j	                   |t                     d       | j	                   |d      |       | j	                   ||dz         d       | j                  t        |d	       | j                  t        |d
       | j                  t        |d       | j                  t        |t               y # 1 sw Y   8xY w)Nr   r   r0   r   r   r   r   r>   rE   r   r   )r   pylong_asunsignedlongmaskr   r8   r:   r   r   r   rW   r   r   r`   )r   asunsignedlongmaskr   r   s       r   test_long_asunsignedlongmaskz&LongTests.test_long_asunsignedlongmask   s8   &@@'At, 	CEE* C  !3E!:EBC C	C 	+KO<bA+E"I6;+MO<bA+B/;+IM:A>)%7=)%7>)%7=+'94@C C   EE	c                    t         j                  }ddl m}m} ||ddddfD ]5  }| j	                  |      5  | j                   ||      |       d d d        7 | j                   |t        d            d       | j                   |t        d            d       | j                   |t                     d       | j                  t        ||dz
         | j                  t        ||dz          | j                  t        |d	       | j                  t        |d
       | j                  t        |d       | j                  t        |t               y # 1 sw Y   9xY w)Nr   	LLONG_MIN	LLONG_MAXr>   r0   r   r   r   r   rE   r   r   )r   pylong_aslonglongr   r   r8   r:   r   r   r   rW   rX   r   r   r`   )r   
aslonglongr   r   r   s        r   test_long_aslonglongzLongTests.test_long_aslonglong   s(   00
2B1d; 	;EE* ;  E!2E:; ;	; 	KO4b9E"I.3MO4b9-Y]C-Y]C)Z5)Z6)Z5+z48; ;r   c                     t         j                  }ddl m}m} ||ddddfD ]7  }| j	                  |      5  | j                   ||      |df       d d d        9 | j                   |t        d            d       | j                   |t        d            d       | j                   |t                     d	       | j                   ||dz
        d
       | j                   ||dz         d       y # 1 sw Y   xY w)Nr   r   r>   r0   r   r   r   r   r   r   r   )	r   pylong_aslonglongandoverflowr   r   r8   r:   r   r   r   )r   aslonglongandoverflowr   r   r   s        r   test_long_aslonglongandoverflowz)LongTests.test_long_aslonglongandoverflow  s     ) F F2B1d; 	KEE* K  !6u!=qzJK K	K 	.{2?I.uRy97C.}?I.y1}=xH.y1}=wGK Kr   c                    t         j                  }ddl m} |dddfD ]5  }| j                  |      5  | j	                   ||      |       d d d        7 | j	                   |t        d            d       | j                  t        |t        d             | j                  t        |t                      | j                  t        |d       | j                  t        ||dz          | j                  t        |d       | j                  t        |d	       | j                  t        |d
       | j                  t        |t               y # 1 sw Y   4xY w)Nr   
ULLONG_MAXr0   r   r   r   r>   rE   r   r   )r   pylong_asunsignedlonglongr   r8   r:   r   rW   r   r   r   rX   r   r`   )r   asunsignedlonglongr   r   s       r   test_long_asunsignedlonglongz&LongTests.test_long_asunsignedlonglong  s,   &@@( !Q- 	CEE* C  !3E!:EBC C	C 	+KO<bA)%7rC)%7I-);R@-);Z!^L)%7=)%7>)%7=+'94@C Cr   c                    t         j                  }ddl m} |dddfD ]5  }| j                  |      5  | j	                   ||      |       d d d        7 | j	                   |t        d            d       | j	                   |t        d            d       | j	                   |t                     d       | j	                   |d      |       | j	                   ||dz         d       | j                  t        |d	       | j                  t        |d
       | j                  t        |d       | j                  t        |t               y # 1 sw Y   8xY w)Nr   r   r0   r   r   r   r   r>   rE   r   r   )r   pylong_asunsignedlonglongmaskr   r8   r:   r   r   r   rW   r   r   r`   )r   asunsignedlonglongmaskr   r   s       r    test_long_asunsignedlonglongmaskz*LongTests.test_long_asunsignedlonglongmask+  s8   !*!H!H( !Q- 	GEE* G  !7!>FG G	G 	/B@"E/b	:B?/@"E/3Z@/
Q?C)%;SA)%;TB)%;SA+'=tDG Gr   c                    t         j                  }ddl m}m} ||ddddfD ]5  }| j	                  |      5  | j                   ||      |       d d d        7 | j                   |t        d            d       | j                  t        |t        d             | j                  t        |t                      | j                  t        ||dz
         | j                  t        ||dz          | j                  t        |d       | j                  t        |d	       | j                  t        |d
       | j                  t        |t               y # 1 sw Y   7xY w)Nr   )PY_SSIZE_T_MINPY_SSIZE_T_MAXr>   r0   r   r   r   rE   r   r   )r   pylong_as_ssize_tr   r   r8   r:   r   rW   r   r   r   rX   r   r`   )r   
as_ssize_tr   r   r   s        r   test_long_as_ssize_tzLongTests.test_long_as_ssize_t?  s$   00
<$nb!QE 	;EE* ;  E!2E:; ;	; 	KO4b9)Zr;)ZA-^a5GH-^a5GH)Z5)Z6)Z5+z48; ;s   EE	c                    t         j                  }ddl m} |dddfD ]5  }| j                  |      5  | j	                   ||      |       d d d        7 | j	                   |t        d            d       | j                  t        |t        d             | j                  t        |t                      | j                  t        |d       | j                  t        ||dz          | j                  t        |d       | j                  t        |d	       | j                  t        |d
       | j                  t        |t               y # 1 sw Y   4xY w)Nr   )SIZE_MAXr0   r   r   r   r>   rE   r   r   )r   pylong_as_size_tr   r8   r:   r   rW   r   r   r   rX   r   r`   )r   	as_size_tr   r   s       r   test_long_as_size_tzLongTests.test_long_as_size_tS  s   ..	&1d+ 	:EE* :  5!159: :	: 	;r?3R8)Yb	:)Y@-B7-HqLA)Y4)Y5)Y4+y$7: :r   c                 8   t         j                  }t        t        j                  j
                        }| |ddddfD ]Z  }| j                  |      5  | j                   ||      t        |             | j                   ||      t               d d d        \ | j                   |t        d            d       | j                  t        |t        d             | j                  t        |t                      | j                  t        |d|z         | j                  t        |d	|z         | j                  t        |d
       | j                  t        |d       | j                  t        |d       | j                  t         |t"               y # 1 sw Y   \xY w)Nr>   r   r0   r   r   r   g      E@r%   rE   r   r   )r   pylong_asdoublerV   r@   rT   rU   r8   r:   rY   ra   r   rW   r   r   r   rX   r   r`   )r   asdoubleMAXr   s       r   test_long_asdoublezLongTests.test_long_asdoubleg  sL   ,,#..$$%dCQ40 	>EE* >  %%,?%%huou=> >	>
 	+b/2D9)XuRy9)X}?-1s7;-28<)Xs3)Xt4)Xs3+x6> >s   >FF	c                    t         j                  }t         j                  }t               } ||      } |t              }| j                   ||      |       | j                   ||      t               | j                   |t        |            |       dt         j                  dz  z  }||dz  k\  r| j                   |||z
        |       ||dz  k\  r| j                   |||z
        t               | j                  t        |t        |             | j                  t        |t                      | j                  t        |ddz         | j                  t        |ddz          y )Nr0      r%   i  )r   r_   pylong_asvoidptrrI   r`   assertIsr   SIZEOF_VOID_PrW   r   r   rX   )r   rd   	asvoidptrre   rf   rg   Ms          r   test_long_asvoidptrzLongTests.test_long_asvoidptr{  s!   22..	hilC(ilD)iA/5 )))A--19MM)AE*C019MM)AE*D1)Ya9)Y9-AtG<-QWH=r   c                    t         j                  }ddl m} d|z  }d|dz
  z   }d|dz
  z  dz
  }||ddddfD ]5  }| j                  |      5  | j	                   ||      |       d d d        7 | j	                   |t        d	            d	       | j	                   |t        d	            d	       | j	                   |t                     d
       | j                  t        ||dz
         | j                  t        ||dz          | j                  t        |d       | j                  t        |d       | j                  t        |d       | j                  t        |t               y # 1 sw Y   9xY w)Nr   )SIZEOF_PID_Tr   r%   r0   r>   r   r   r   r   rE   r   r   )r   pylong_aspidr   r8   r:   r   r   r   rW   rX   r   r   r`   )r   aspidr   bits	PID_T_MIN	PID_T_MAXr   s          r   test_long_aspidzLongTests.test_long_aspid  sQ   &&*<a[L	QK!O	B1d; 	6EE* 6  uu56 6	6 	{2/4uRy)2.}/4-	A>-	A>)UC0)UD1)UC0+ud36 6s   E''E1	N)r   r   r	   r<   rB   rL   rO   r]   rh   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r   r!   r!      ss    / &	*	*	@
"D<K<5(C$=(A(9(H$A(E(9(8(7(>04r   r!   __main__)unittestr@   test.supportr   import_moduler   r`   rV   r   r   r   TestCaser!   r   mainr
   r   r   <module>r      sv     
 & (M''4		# 	  K4!! K4\ zHMMO r   