
    9bh9                        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  ej                  d      Z	d dl	m
Z
mZ 	 d dlmZ dZ G d d      Z G d d	      Z G d
 d      Z G d de      Z G d de      Z G d de      Zd Z G d de      Z G d de      Z G d dej4                        Zedk(  r ej:                          yy# e$ r dZY w xY w)    N)cpython_onlyimport_helper	_testcapi)PY_SSIZE_T_MAXPY_SSIZE_T_MIN)ndarrayc                       e Zd ZddZy)BadDescrNc                     t         N)RuntimeError)selfobjobjtypes      D/opt/python-3.12.12/usr/lib/python3.12/test/test_capi/test_number.py__get__zBadDescr.__get__   s        r   )__name__
__module____qualname__r    r   r   r
   r
      s    r   r
   c                   B     e Zd Zd Ze fd       Ze fd       Z xZS )
WithDunderc                 d    | j                   r| j                   S | j                  r| j                  y r   )valexc)r   argss     r   _methzWithDunder._meth   s'    8888O88((N r   c                     t         |   |       }||_        d |_        t	        | | j
                  | j                         |S r   super__new__r   r   setattrmethnamer   )clsr   r   	__class__s      r   with_valzWithDunder.with_val   s8    goc"S\\399-
r   c                     t         |   |       }d |_        ||_        t	        | | j
                  | j                         |S r   r    )r%   r   r   r&   s      r   with_exczWithDunder.with_exc%   s8    goc"S\\399-
r   )r   r   r   r   classmethodr'   r)   __classcell__r&   s   @r   r   r      s0    
    r   r   c                        e Zd Z fdZ xZS )
HasBadAttrc                 d    t         |   |       }t        | | j                  t	                      |S r   )r!   r"   r#   r$   r
   )r%   r   r&   s     r   r"   zHasBadAttr.__new__.   s(    goc"S\\8:.
r   )r   r   r   r"   r+   r,   s   @r   r.   r.   -   s     r   r.   c                       e Zd ZdZy)	IndexLike	__index__Nr   r   r   r$   r   r   r   r1   r1   4       Hr   r1   c                       e Zd ZdZy)IntLike__int__Nr3   r   r   r   r6   r6   7   s    Hr   r6   c                       e Zd ZdZy)	FloatLike	__float__Nr3   r   r   r   r9   r9   :   r4   r   r9   c                 8    t        | j                  dz   | fi       S )NSubclass)typer   )bases    r   
subclassofr?   >   s    
*TGR88r   c                       e Zd Zy)	SomeErrorNr   r   r   r   r   r   rA   rA   B       r   rA   c                       e Zd Zy)
OtherErrorNrB   r   r   r   rE   rE   E   rC   r   rE   c                       e Zd Zd Zd Zd Z ej                  edu d      d        Z	 ej                  edu d      d        Z
d Zed	        Zd
 Zd Zd Zd Zd Zy)CAPITestc                 z   t         j                  }| j                   |d             | j                   |t        j	                  d                   | j                   |t
        j	                  d                   | j                   |d             | j                   |t        j	                  d                   | j                   |d             | j                   |g              | j                   |d             | j                   |t                            | j                   |t                     y )N   c         ?      @      ?       @abc)
r   number_check
assertTruer1   r'   r6   r9   assertFalseobjectNULL)r   checks     r   
test_checkzCAPITest.test_checkJ   s    &&a!i00345g..r234c
#i00678d$r#u&vx)t%r   c                    t         j                  t         j                  t         j                  t         j                  d}|j                         D ]}  \  }}| j                  t        |t                      | j                  t        |t               t        t        |      }dD ])  }	  ||       | j                   ||       ||             +  y # t        $ r | j                  t        ||       Y Qw xY w)N)__neg____pos____abs__
__invert__)r   *   Q	@rM   )r   number_negativenumber_positivenumber_absolutenumber_invertitemsassertRaises	TypeErrorrR   SystemErrorrS   getattroperatorassertEqual)r   methmapnamefuncopxs         r   test_unary_opszCAPITest.test_unary_opsZ   s    '77'77'77!*!8!8:
 "--/JD$ivx8 k46 4(B,5qE $$T!Wbe4 - * ! :%%iq9:s   &C C43C4c                 z   i dt         j                  dt         j                  dt         j                  dt         j                  dt         j
                  dt         j                  dt         j                  dt         j                  d	t         j                  d
t         j                  dt         j                  dt         j                  dt         j                  dt         j                  dt         j                  dt         j                   dt         j"                  t         j$                  t         j&                  t         j(                  t         j*                  t         j,                  t         j.                  t         j0                  t         j2                  t         j4                  t         j6                  d
}|j9                         D ]  \  }}g d}|D ]B  }| j;                  t<        |t?               |       | j;                  t<        ||t?                      D tA        tB        |tD              }tG        jH                  |d      D ]/  \  }}	  |||       | jK                   |||       |||             1  y # t<        tL        tN        f$ r(}| j;                  |jP                  |||       Y d }~ld }~ww xY w)N__add____sub____mul__
__matmul____floordiv____truediv____mod__
__divmod__
__lshift__
__rshift____and____xor____or____pow____iadd____isub____imul__)
__imatmul____ifloordiv____itruediv____imod____ilshift____irshift____iand____ixor____ior____ipow__)r   r[   r]   r\   {   rM      ))r   
number_addnumber_subtractnumber_multiplynumber_matrixmultiplynumber_floordividenumber_truedividenumber_remaindernumber_divmodnumber_lshiftnumber_rshift
number_and
number_xor	number_ornumber_powernumber_inplaceaddnumber_inplacesubtractnumber_inplacemultiplynumber_inplacematrixmultiplynumber_inplacefloordividenumber_inplacetruedividenumber_inplaceremaindernumber_inplacelshiftnumber_inplacershiftnumber_inplaceandnumber_inplacexornumber_inplaceornumber_inplacepowerrb   rc   rd   rR   rf   rg   divmod	itertoolscombinationsrh   
ValueErrorZeroDivisionErrorr&   )	r   ri   rj   rk   casesrm   rl   yr   s	            r   test_binary_opszCAPITest.test_binary_opsq   sv   9i22 i77i77  !@!@ "9#?#?	
 !)"="= i88  !8!8  !8!8  !8!8 i22 i22 Y00 i44 y:: y??  y??!" #,"H"H$-$G$G#,#E#E(@@"+"@"@"+"@"@(::(::'88(<<5: "--/JD$0E !!)T68Q?!!)T1fh? 
 40B!..ua81;q!H $$T!QZAq: 9 * ":/@A A%%cmmT1a@@As   	I>>J:J55J:Nzneeds _testbufferc                    t         j                  }t         j                  }ddgddgg d}}}| j                   |||      |       | j                  |ddg       | j	                  t
        |t        dgd      d       ddgddgg d}}}| j                   |||      |       | j                  ||       | j	                  t
        |t        dgd      d       y )NrI   r         )rI   r   r   r   rI   )r   r   r   rh   rc   rd   r   )r   add
inplaceaddabrs         r   test_misc_addzCAPITest.test_misc_add   s     ""00
 a&1a&,a1QA&QF#)S'1#t*<a@a&1a&,a1Aq)1-A)Z!d1CQGr   c                    t         j                  }t         j                  }dgdddg}}}| j                   |||      |       | j                  ||fdgdf       | j                   |||      |       | j                  ||fdgdf       | j                   |dgd      g        | j	                  t
        |t        dgd      d       | j	                  t
        |dgd       | j	                  t        |dgt        dz          | j	                  t        |ddgt        dz  dz          dgdddg}}}| j                   |||      |       | j                  ||f|df       dg}| j                   |||      |       | j                  ||fdgdf       | j	                  t
        |t        dgd      d       | j	                  t        |dgt        dz          | j	                  t        |ddgt        dz  dz          y )NrI   r   r\   r   rK   )
r   r   r   rh   rc   rd   r   OverflowErrorr   MemoryError)r   multiplyinplacemultiplyr   r   r   s         r   test_misc_multiplyzCAPITest.test_misc_multiply   s    ,,#:: #q1a&a1!Q+!Q1#q*!Q+!Q1#q*1#r*B/)XwsD/A1E)XsC8-A38JK+x!Q9JQ9NO#q1a&a1A.2!Q!Q(CA.2!Q1#q*)_gqc46H!L-1#~PQ?QR+APQ@QTU@UVr   c           	         t         j                  }t         j                  } G d dt              }| j	                   |ddd      t        ddd             | j                  t        |ddd       | j                  t        |dd|j                  t                     | j                  t        |ddt                      | j	                   |ddd      t        ddd             | j                  t        |ddd       | j                  t        |ddt                       G d d      } |       }| j	                   ||d      |df       | j	                   ||d      |df       | j	                   ||dd      |ddf       | j	                   ||dd      |ddf        G d	 d      } |       }| j	                   |d|      |df       | j	                   |d|      |df       | j                  t        |d|d       | j                  t        |d|d        G d
 d      } |       }| j	                   ||d      |df       | j	                   ||dd      |df       y )Nc                       e Zd ZdZy)(CAPITest.test_misc_power.<locals>.HasPowr}   Nr3   r   r   r   HasPowr      s     Hr   r   r               ?c                       e Zd Zd Zy)#CAPITest.test_misc_power.<locals>.Xc                      | S r   r   r   s    r   r}   z+CAPITest.test_misc_power.<locals>.X.__pow__       r   N)r   r   r   r}   r   r   r   Xr          r   r   c                       e Zd Zd Zy)r   c                      | S r   r   r   s    r   __rpow__z,CAPITest.test_misc_power.<locals>.X.__rpow__   r   r   N)r   r   r   r   r   r   r   r   z#CAPITest.test_misc_power.<locals>.X   r   r   c                       e Zd Zd Zy)r   c                      | S r   r   r   s    r   r   z,CAPITest.test_misc_power.<locals>.X.__ipow__   r   r   N)r   r   r   r   r   r   r   r   z#CAPITest.test_misc_power.<locals>.X   r   r   )r   r   r   r   rh   powrc   rd   r'   NotImplementedrR   )r   powerinplacepowerr   r   rm   s         r   test_misc_powerzCAPITest.test_misc_power   s&   && 44	!Z 	! 	q"a#aQ-8)UAr48)UAr6??>3RS)UAr68<aQ/QA?)\1b$?)\1b&(C	 	 Cq"2w/a,q"g6q"a1b!*5aQ/!R<	 	 Cq!q!f-a+aV4)UAq!4)\1a;	 	 Ca,q"g6aQ/!R9r   c                    t         j                  }| j                  t              5 } |t        d       d d d        | j                  dt        j                               | j                  t              5 } |t        t        j                         d d d        | j                  dt        |j                               | j                  t              5 } |dd       d d d        y # 1 sw Y   xY w# 1 sw Y   bxY w# 1 sw Y   y xY w)Nr[   z6Did you mean "print(<message>, file=<output_stream>)"?zDid you mean rI   spam)r   r   rc   rd   printassertInstr	exceptionmaxsysstderrassertNotIn)r   rshiftcontexts      r   test_rshift_printzCAPITest.test_rshift_print   s     ((y)W5" * 014W5F5F1G	Iy)W3

# *#g.?.?*@Ay)W1f *) *) *) *)s#   C'6C3
C?'C03C<?Dc                    t         j                  }| j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |t        d            d       | j                   |t	        d            d       | j                   |t
        j                  d            d       | j                   |t        j                  d            d       | j                  t        |t        j                  d             t        j                         5  t        j                  dt               | j                  t        |t        j                  d	             d d d        | j                  t              5  | j                   |t        j                  d	            d       d d d        | j                  t        |t        j!                  t                     | j                  t        |d
       | j                  t        |t#                      | j                  t$        |t&               y # 1 sw Y   xY w# 1 sw Y   xY w)Nr[   r   rI   42s   42rJ         ?errorT              ?)r   number_longrh   	bytearray
memoryviewr1   r'   r6   rc   rd   warningscatch_warningssimplefilterDeprecationWarningassertWarnsr   r)   rR   re   rS   )r   longs     r   	test_longzCAPITest.test_long  s   $$b2&dQ'dR(eb)i./4j/0"5i0045r:g..r23R8)T7+;+;C+@A$$&!!'+=>0$8H8H8NO ' 01T'"2"24"891= 2,g.>.>|.LM)T2.)T684+tT2 '& 21s   AI),I)I&)I2c                    t         j                  }| j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |t        j	                  d            d       | j                   |t
        j	                  d            d       | j                   |t
        j	                  d            d	       | j                  t        |t        j	                  d
             t        j                         5  t        j                  dt               | j                  t        |t        j	                   t        t              d                   d d d        | j                  t              5  | j                   |t        j	                   t        t              d                  d       d d d        | j                  t        |t        j!                  t                     | j                  t        |t
        j	                  d             | j                  t"        |t
        j	                  ddz               | j                  t        |d       | j                  t        |t%                      | j                  t&        |t(               y # 1 sw Y   =xY w# 1 sw Y   xY w)Nr   r   g     ^@z1.25rL   rJ   g     X@r\   g      i  r   r   i  r   )r   number_floatrh   r9   r'   r1   rc   rd   r   r   r   r   r?   floatr   r   r)   r   rR   re   rS   )r   float_s     r   
test_floatzCAPITest.test_float&  s   ''t,d+.	 2 24 894@	 2 22 67>	 2 22 67>)VY-?-?-DE$$&!!'+=>0&):L:LM^ZX]M^_cMd:ef ' 01VI$6$67Hz%7H7N$OPRVW 2,	0B0B<0PQ)VY-?-?-EF-1C1CAtG1LM)VR0)VVX6+vt4 '& 21s   AJ+?J8+J58Kc                 Z   t         j                  }| j                   |d      d       t        j                         5  t        j
                  dt               | j                  t        |t        j                  d             d d d        | j                  t              5  | j                   |t        j                  d            d       d d d        | j                  t        |t        j                  d             | j                  t        |t        j                  t                     | j                  t        |d       | j                  t        |d       | j                  t        |t                      | j                  t        |t                y # 1 sw Y   xY w# 1 sw Y   xY w)Nr   r   TrI   r   r   r   )r   number_indexrh   r   r   r   r   rc   r1   r'   r   rd   r   r)   rR   re   rS   )r   indexs     r   
test_indexzCAPITest.test_indexA  s-   &&rB'$$&!!'+=>0%9K9KD9QR ' 01U9#5#5d#;<a@ 2)UI,>,>s,CD,y/A/A,/OP)UD1)UD1)UFH5+ud3 '& 21s   AF,F!F!F*c                    t         j                  }| j                   |dd      t        d             | j                   |dd      t	        d             | j                   |dd      t        d             | j                   |dd      t        d             | j                  t        |t        d       | j                  t        |dd       | j                  t        |dd       | j                  t        |d	d       y )
N
   r   r            r   r   r   )r   number_tobaserh   binoctr   hexrc   re   rS   rd   )r   tobases     r   test_tobasezCAPITest.test_tobaseT  s    ((AB0AB0BR1BR1+vtQ7+vq!4)VT15)VT15r   c                    t         j                  }g t        dd      t        t        D ]  }| j                   ||t              |       ! | j                   |t        dz   t              t               | j                   |t        dz
  t              t               | j                  t        |t        dz   t               | j                  t        |t        dz   t               | j                  t        |t        t               y )Ni   r   )r   number_asssizetranger   r   rh   r   rS   rc   r   re   rd   )r   asssizetns      r   test_asssizetzCAPITest.test_asssizetb  s    ,,@5Q<@@@AXa7; A."3T:NK."3T:NK->B3FV,.22E|T+xyAr   )r   r   r   rU   rn   r   unittestskipIfr   r   r   r   r   r   r   r   r   r  r  r   r   r   rG   rG   I   s    & 5..;f X__W_&9:H ;H X__W_&9:W ;W4-:^  32564&6Br   rG   __main__)r   rg   r   r  r   test.supportr   r   import_moduler   r   r   _testbufferr   ImportErrorrS   r
   r   r.   r1   r6   r9   r?   	ExceptionrA   rE   TestCaserG   r   mainr   r   r   <module>r     s      
   4'M''4	 4#   , 
 j 
 9		 		 	dBx   dBN	 zHMMO E  Gs   C CC