o
    HXh0`                     @   sX  d dl Z d dlZd dlZd dlmZ d dlmZ ejddgdZejddgdZ	G dd	 d	Z
G d
d deZG dd dZG dd dZG dd dee jZe e	dG dd dee jZG dd dZG dd dee jZe e	dG dd dee jZe e	dG dd dee jZe e	dG dd dee jZedkre   dS dS )     N)support)import_helperoperator	_operator)Zblocked)Zfreshc                   @   <   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )Seq1c                 C   
   || _ d S Nlstselfr    r   </opt/python-3.10.19/usr/lib/python3.10/test/test_operator.py__init__      
zSeq1.__init__c                 C   
   t | jS r	   lenr   r   r   r   r   __len__   r   zSeq1.__len__c                 C   
   | j | S r	   r
   r   ir   r   r   __getitem__   r   zSeq1.__getitem__c                 C      | j |j  S r	   r
   r   otherr   r   r   __add__      zSeq1.__add__c                 C   
   | j | S r	   r
   r   r   r   r   __mul__   r   zSeq1.__mul__c                 C   
   || j  S r	   r
   r   r   r   r   __rmul__   r   zSeq1.__rmul__N	__name__
__module____qualname__r   r   r   r   r!   r#   r   r   r   r   r          r   c                   @   r   )Seq2c                 C   r   r	   r
   r   r   r   r   r      r   zSeq2.__init__c                 C   r   r	   r   r   r   r   r   r      r   zSeq2.__len__c                 C   r   r	   r
   r   r   r   r   r   !   r   zSeq2.__getitem__c                 C   r   r	   r
   r   r   r   r   r   #   r   zSeq2.__add__c                 C   r    r	   r
   r   r   r   r   r!   %   r   zSeq2.__mul__c                 C   r"   r	   r
   r   r   r   r   r#   '   r   zSeq2.__rmul__Nr$   r   r   r   r   r)      r(   r)   c                   @      e Zd Zdd ZdS )BadIterablec                 C      t r	   )ZeroDivisionErrorr   r   r   r   __iter__+      zBadIterable.__iter__N)r%   r&   r'   r.   r   r   r   r   r+   *       r+   c                   @   sD  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOS )POperatorTestCasec                 C      | j }| t|j | t|jdd | |dd | |dd | |dd | |dd | |dd | |dd d S 	Ny              ?y               @   r                 ?          @)moduleassertRaises	TypeErrorltassertFalse
assertTruer   r   r   r   r   test_lt0      zOperatorTestCase.test_ltc                 C      | j }| t|j | t|jdd | |dd | |dd | |dd | |dd | |dd | |dd d S r3   )r9   r:   r;   ler=   r>   r?   r   r   r   test_le;   rA   zOperatorTestCase.test_lec                 C      | j }G dd dt}| t|j | t|j| |  | |dd | |dd | |dd | |dd | |dd | |dd d S )	Nc                   @   r*   )z#OperatorTestCase.test_eq.<locals>.Cc                 S   r,   r	   SyntaxErrorr   r   r   r   __eq__I   r/   z*OperatorTestCase.test_eq.<locals>.C.__eq__N)r%   r&   r'   rH   r   r   r   r   CH   r0   rI   r4   r   r5   r6   r7   r8   )r9   objectr:   r;   eqrG   r=   r>   r   r   rI   r   r   r   test_eqF      zOperatorTestCase.test_eqc                 C   rE   )	Nc                   @   r*   )z#OperatorTestCase.test_ne.<locals>.Cc                 S   r,   r	   rF   r   r   r   r   __ne__W   r/   z*OperatorTestCase.test_ne.<locals>.C.__ne__N)r%   r&   r'   rO   r   r   r   r   rI   V   r0   rI   r4   r   r5   r6   r7   r8   )r9   rJ   r:   r;   nerG   r>   r=   rL   r   r   r   test_neT   rN   zOperatorTestCase.test_nec                 C   r2   r3   )r9   r:   r;   ger>   r=   r?   r   r   r   test_geb   rA   zOperatorTestCase.test_gec                 C   rB   r3   )r9   r:   r;   gtr>   r=   r?   r   r   r   test_gtm   rA   zOperatorTestCase.test_gtc                 C   sL   | j }| t|j | t|jd  | |dd | |dd d S )Nr4   )r9   r:   r;   absassertEqualr?   r   r   r   test_absx   s
   zOperatorTestCase.test_absc                 C   >   | j }| t|j | t|jd d  | |ddd d S )N         )r9   r:   r;   addrX   r?   r   r   r   test_add      zOperatorTestCase.test_addc                 C   s>   | j }| t|j | t|jd d  | |ddd d S )N   
   )r9   r:   r;   and_rX   r?   r   r   r   test_bitwise_and   r`   z!OperatorTestCase.test_bitwise_andc                 C   s   | j }| t|j | t|jd d  | |ddd | |ddgddgg d | |td	d
gtdgg d | |td	d
gtdgg d | t|jdd d S )NpyZthonZpythonr4   r7   r[   r\   )r4   r7   r[   r\         r]   )rf   rg   r]         )r9   r:   r;   concatrX   r   r)   r?   r   r   r   test_concat   s    &&zOperatorTestCase.test_concatc                 C   s   | j }| t|j | t|jd d  | t|jt d | |g ddd | |g ddd td}| |||dg|d | |i di dgi d d S )	Nr4   )r4   r7   r4   r[   r4   r\   r[   rf   r   nan   r7   )r9   r:   r;   countOfr-   r+   rX   floatr   r   rl   r   r   r   test_countOf   s    zOperatorTestCase.test_countOfc                 C   sV   | j }g d}| t|j| | t|j|d  | ||d | |g d d S )Nr\   r[   r7   r4   r4   )r\   r7   r4   )r9   r:   r;   delitemassertIsNonerX   r   r   ar   r   r   test_delitem   s   zOperatorTestCase.test_delitemc                 C   s@   | j }| t|jd | t|jd d  | |ddd d S )Nrf   r7   )r9   r:   r;   floordivrX   r?   r   r   r   test_floordiv      zOperatorTestCase.test_floordivc                 C   s@   | j }| t|jd | t|jd d  | |ddd d S )Nrf   r7   g      @)r9   r:   r;   truedivrX   r?   r   r   r   test_truediv   rz   zOperatorTestCase.test_truedivc                 C   sF   | j }td}| t|j | t|j|d  | ||dd d S )Nrb   r7   )r9   ranger:   r;   getitemrX   ru   r   r   r   test_getitem   s
   zOperatorTestCase.test_getitemc                 C   s   | j }| t|j | t|jd d  | t|jt d | |g ddd | t|jg dd td}| |||dg|d | |i di dgi d d S )Nr4   rr   r[   r   rl   rm   r7   )	r9   r:   r;   indexOfr-   r+   rX   
ValueErrorro   rp   r   r   r   test_indexOf   s    zOperatorTestCase.test_indexOfc                 C   s:   | j }| t|j | t|jd  | |dd d S )Nr\   )r9   r:   r;   invertrX   invr?   r   r   r   test_invert   s   zOperatorTestCase.test_invertc                 C   sd   | j }| t|j | t|jd d | |ddd | |ddd | t|jdd d S )N*   rf   r4   rb   r   r7   rV   )r9   r:   r;   lshiftrX   r   r?   r   r   r   test_lshift      zOperatorTestCase.test_lshiftc                 C   s>   | j }| t|j | t|jd d | |ddd d S )Nr   rf   r7   r4   )r9   r:   r;   modrX   r?   r   r   r   test_mod   r`   zOperatorTestCase.test_modc                 C   rZ   )Nrf   r7   rb   )r9   r:   r;   mulrX   r?   r   r   r   test_mul   r`   zOperatorTestCase.test_mulc                 C   sJ   | j }| t|j | t|jdd G dd d}| | d d d S )Nr   c                   @   r*   )z'OperatorTestCase.test_matmul.<locals>.Mc                 S   s   |d S )Nr4   r   r   r   r   r   
__matmul__   s   z2OperatorTestCase.test_matmul.<locals>.M.__matmul__N)r%   r&   r'   r   r   r   r   r   M   r0   r   )   )r9   r:   r;   matmulrX   )r   r   r   r   r   r   test_matmul   s
   zOperatorTestCase.test_matmulc                 C   sp   | j }| t|j | t|jd  | |dd | |dd | |dd | |dd d S Nrf   r   r   )r9   r:   r;   negrX   r?   r   r   r   test_neg      zOperatorTestCase.test_negc                 C   rZ   )Nrb   rf   ra   )r9   r:   r;   or_rX   r?   r   r   r   test_bitwise_or   r`   z OperatorTestCase.test_bitwise_orc                 C   sp   | j }| t|j | t|jd  | |dd | |dd | |dd | |dd d S r   )r9   r:   r;   posrX   r?   r   r   r   test_pos   r   zOperatorTestCase.test_posc                 C   sb   | j }| t|j | t|jd d  | |ddd | t|jd | t|jddd d S )Nr[   rf      r4   r7   )r9   r:   r;   powrX   r?   r   r   r   test_pow  s   zOperatorTestCase.test_powc                 C   sd   | j }| t|j | t|jd d | |ddd | |ddd | t|jdd d S )Nr   rf   r4   r7   r   rV   )r9   r:   r;   rshiftrX   r   r?   r   r   r   test_rshift  r   zOperatorTestCase.test_rshiftc                 C   sj   | j }| t|j | t|jd d  | t|jt d | |tdd | |tdd d S )Nr4   r\   r7   rf   )	r9   r:   r;   containsr-   r+   r>   r}   r=   r?   r   r   r   test_contains  s   zOperatorTestCase.test_containsc                 C   sr   | j }ttd}| t|j| | t|j|d d  | ||dd | |g d | t|j|dd d S )Nr[   r   r7   )r7   r4   r7   r\   )	r9   listr}   r:   r;   setitemrt   rX   
IndexErrorru   r   r   r   test_setitem  s   zOperatorTestCase.test_setitemc                 C   rZ   )Nrf   r7   r[   )r9   r:   r;   subrX   r?   r   r   r   test_sub$  r`   zOperatorTestCase.test_subc                 C   s|   | j }G dd dt}| t|j | t|j|  | |d | |dg | |d | |g  d S )Nc                   @   r*   )z&OperatorTestCase.test_truth.<locals>.Cc                 S   r,   r	   rF   r   r   r   r   __bool__-  r/   z/OperatorTestCase.test_truth.<locals>.C.__bool__N)r%   r&   r'   r   r   r   r   r   rI   ,  r0   rI   rf   r   )r9   rJ   r:   r;   truthrG   r>   r=   rL   r   r   r   
test_truth*  s   zOperatorTestCase.test_truthc                 C   rZ   )N      r]   )r9   r:   r;   xorrX   r?   r   r   r   test_bitwise_xor6  r`   z!OperatorTestCase.test_bitwise_xorc                 C   \   | j }d }}|d d |dd   }| t|j | ||| | ||| d S NZxyzpdqr[   )r9   r:   r;   is_r>   r=   r   r   rv   bcr   r   r   test_is<     zOperatorTestCase.test_isc                 C   r   r   )r9   r:   r;   is_notr=   r>   r   r   r   r   test_is_notD  r   zOperatorTestCase.test_is_notc                 C   s  | j }G dd d}| }d|_|d}| ||d | t| | t||d | jt||dd |d}| t|| | t|jd | t|j | }d	|_d
|_d|_	| |ddd|d | t|jd G dd dt
}| t|d|  | }d|_| |_d|j_|d}| ||d | t||j |dd}| ||d |ddd}| t|| |d}| t|| |d}| t|| | |j_d|jj_|d}| ||d |ddd}| ||d d S )Nc                   @      e Zd ZdS )z+OperatorTestCase.test_attrgetter.<locals>.ANr%   r&   r'   r   r   r   r   AN      r   arthurnameZdent)ZsurnameZrankr7   XYZxzy)r   r   r   )r   r   r   c                   @   r*   )z+OperatorTestCase.test_attrgetter.<locals>.Cc                 S   r,   r	   rF   r   r   r   r   r   __getattr__e  r/   z7OperatorTestCase.test_attrgetter.<locals>.C.__getattr__N)r%   r&   r'   r   r   r   r   r   rI   d  r0   rI   foothomasz
child.name)r   r   zchild.child.namezchild.z.childjohnson)r   r   r   )r9   r   
attrgetterrX   r:   r;   AttributeErrorr   r   r   rJ   rG   child)r   r   r   rv   frecordrI   r   r   r   test_attrgetterL  sT   







z OperatorTestCase.test_attrgetterc                 C   s  | j }d}|d}| ||d | t| | t||d | jt||dd |d}| t|| G dd dt}| t|d|  |d	}| t|| | t|j td
d}|d}| ||d
 |d}| t	|| g d}|d}| t
t||g d | t||dg d t
tttd}| |ddd|d | t|ddd| td}	| |d|	d | |tdd|	d G dd dt}
| |d|
dd | |dg d d | |dtd!d"d! d S )#NABCDEr7   rI   r[   )sizerb   c                   @   r*   )z+OperatorTestCase.test_itemgetter.<locals>.Cc                 S   r,   r	   rF   r   r   r   r   r     r/   z7OperatorTestCase.test_itemgetter.<locals>.C.__getitem__N)r%   r&   r'   r   r   r   r   r   rI     r0   r   r   val)keyr   Znonkey)Zappler[   Zbananar7   Zpearrf   Zoranger4   r4   )r[   r7   rf   r4   )r   r   r   r      rf   )2Z105r   ZabcderV   er\   )r   dc                   @   s   e Zd Z	 dS )z+OperatorTestCase.test_itemgetter.<locals>.TNr   r   r   r   r   T  s    r   r   abcrv   )rv   r   r   d      )r9   
itemgetterrX   r:   r;   r   rJ   rG   dictKeyErrorr   mapsortedstrr}   tupleslice)r   r   rv   r   rI   r   Z	inventoryZgetcountdatatr   r   r   r   test_itemgetter  sF   






 z OperatorTestCase.test_itemgetterc                 C   s  | j }| t|j | t|jd G dd d}| }|d}| t|| |ddd}| ||d | t| | t||d | jt||dd |d	}| ||d
 | t||| |jd	dd}| ||d |jdddd}| ||d d S )Nr   c                   @   &   e Zd Zdd Zd	ddZdd ZdS )
z-OperatorTestCase.test_methodcaller.<locals>.Ac                 _      |d |d  S Nr   r4   r   r   argskwdsr   r   r   r        z1OperatorTestCase.test_methodcaller.<locals>.A.foor   c                 S      |S r	   r   r   r   r   r   r   bar  r/   z1OperatorTestCase.test_methodcaller.<locals>.A.barc                  _      |d |d fS Nr   r   r   r   r   r   r   r   baz  r   z1OperatorTestCase.test_methodcaller.<locals>.A.bazNr   r%   r&   r'   r   r   r   r   r   r   r   r         
r   r   r4   r7   r[   )spamr   r   rf   r   r   r   eggs)r   r   )r   r   )r9   r:   r;   methodcallerr   rX   )r   r   r   rv   r   r   r   r   test_methodcaller  s&   

z"OperatorTestCase.test_methodcallerc                 C   s8  | j }G dd dt}| }| ||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 S )Nc                   @   s|   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )z(OperatorTestCase.test_inplace.<locals>.Cc                 S      dS )Niaddr   r   r   r   r   __iadd__      z1OperatorTestCase.test_inplace.<locals>.C.__iadd__c                 S   r  )Niandr   r   r   r   r   __iand__  r  z1OperatorTestCase.test_inplace.<locals>.C.__iand__c                 S   r  )N	ifloordivr   r   r   r   r   __ifloordiv__  r  z6OperatorTestCase.test_inplace.<locals>.C.__ifloordiv__c                 S   r  )Nilshiftr   r   r   r   r   __ilshift__  r  z4OperatorTestCase.test_inplace.<locals>.C.__ilshift__c                 S   r  )Nimodr   r   r   r   r   __imod__  r  z1OperatorTestCase.test_inplace.<locals>.C.__imod__c                 S   r  )Nimulr   r   r   r   r   __imul__  r  z1OperatorTestCase.test_inplace.<locals>.C.__imul__c                 S   r  )Nimatmulr   r   r   r   r   __imatmul__  r  z4OperatorTestCase.test_inplace.<locals>.C.__imatmul__c                 S   r  )Niorr   r   r   r   r   __ior__  r  z0OperatorTestCase.test_inplace.<locals>.C.__ior__c                 S   r  )Nipowr   r   r   r   r   __ipow__  r  z1OperatorTestCase.test_inplace.<locals>.C.__ipow__c                 S   r  )Nirshiftr   r   r   r   r   __irshift__  r  z4OperatorTestCase.test_inplace.<locals>.C.__irshift__c                 S   r  )Nisubr   r   r   r   r   __isub__  r  z1OperatorTestCase.test_inplace.<locals>.C.__isub__c                 S   r  )Nitruedivr   r   r   r   r   __itruediv__  r  z5OperatorTestCase.test_inplace.<locals>.C.__itruediv__c                 S   r  )Nixorr   r   r   r   r   __ixor__  r  z1OperatorTestCase.test_inplace.<locals>.C.__ixor__c                 S   r  )Nrf   r   r   r   r   r   r     r  z4OperatorTestCase.test_inplace.<locals>.C.__getitem__N)r%   r&   r'   r  r  r
  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r   rI     s    rI   rf   r  r  r	  r  r  r  r  r  r  r  r  r  r  )r9   rJ   rX   r  r  r	  r  r  r  r  r  r  r  r  r  r  iconcat)r   r   rI   r   r   r   r   test_inplace  s"   zOperatorTestCase.test_inplacec                 C   s8  | j }G dd dt}| |g dd | |tg dd | ||dd | ||tdd | ||tdd | t ||d	 W d    n1 s\w   Y  | t ||d
 W d    n1 sxw   Y  | t	 ||t	 W d    d S 1 sw   Y  d S )Nc                   @   s   e Zd Zdd Zdd ZdS )z,OperatorTestCase.test_length_hint.<locals>.Xc                 S   r   r	   )value)r   r!  r   r   r   r     r   z5OperatorTestCase.test_length_hint.<locals>.X.__init__c                 S   s   t | jt u r
| j| jS r	   )typer!  r   r   r   r   __length_hint__  s   z<OperatorTestCase.test_length_hint.<locals>.X.__length_hint__N)r%   r&   r'   r   r#  r   r   r   r   r     s    r   r7   r   )r4   r7   r[   r[   r\   r   r   )
r9   rJ   rX   length_hintiterNotImplementedr;   r:   r   LookupError)r   r   r   r   r   r   test_length_hint  s    
"z!OperatorTestCase.test_length_hintc                 C   sZ   | j }dd t|D }|D ]}t||}t|d|d d d }|r*| || qd S )Nc                 S   s   g | ]	}| d s|qS )_)
startswith).0r   r   r   r   
<listcomp>  s    z<OperatorTestCase.test_dunder_is_original.<locals>.<listcomp>__r*  )r9   dirgetattrstripZassertIs)r   r   namesr   ZorigZdunderr   r   r   test_dunder_is_original	  s   
z(OperatorTestCase.test_dunder_is_originalN)*r%   r&   r'   r@   rD   rM   rQ   rS   rU   rY   r_   rd   rk   rq   rw   ry   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)  r3  r   r   r   r   r1   /   sP    
				53!r1   c                   @      e Zd ZeZdS )PyOperatorTestCaseN)r%   r&   r'   py_operatorr9   r   r   r   r   r5    s    r5  zrequires _operatorc                   @   r4  )COperatorTestCaseN)r%   r&   r'   
c_operatorr9   r   r   r   r   r7    s    r7  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
OperatorPickleTestCasec                 C   s~   t tjd| j t||}W d    n1 sw   Y  t tjd| j t|W  d    S 1 s8w   Y  d S )Nr   )	r   Z	swap_itemsysmodulesr9   pickledumpsmodule2loads)r   objprotoZpickledr   r   r   copy  s   $zOperatorPickleTestCase.copyc              	   C   sF  | j j}G dd d}| }d|_d|_d|_| |_| |j_d|jj_tt	j
d D ]t}| j|dd |d	}| ||}| t|t| | |||| |d	d
d}| ||}| t|t| | |||| |d}| ||}| t|t| | |||| W d    n1 sw   Y  q,d S )Nc                   @   r   )z1OperatorPickleTestCase.test_attrgetter.<locals>.ANr   r   r   r   r   r   $  r   r   r   r   r   Vr4   rA  r   r   r   zt.u.v)r9   r   r   r   r   r   uvr}   r<  HIGHEST_PROTOCOLsubTestrB  rX   repr)r   r   r   rv   rA  r   f2r   r   r   r   "  s4   

z&OperatorPickleTestCase.test_attrgetterc              	   C   s   | j j}d}ttjd D ]V}| j|dF |d}| ||}| t|t| | |||| |ddd}| ||}| t|t| | |||| W d    n1 s^w   Y  qd S )Nr   r4   rD  r7   r   r\   )	r9   r   r}   r<  rG  rH  rB  rX   rI  )r   r   rv   rA  r   rJ  r   r   r   r   >  s   z&OperatorPickleTestCase.test_itemgetterc              	   C   sJ  | j j}G dd d}| }ttjd D ]}| j|d} |d}| ||}| t|t| | |||| |ddd}| ||}| t|t| | |||| |ddd	}| ||}| t|t| | |||| |d
ddd}| ||}| |||| W d    n1 sw   Y  qd S )Nc                   @   r   )
z3OperatorPickleTestCase.test_methodcaller.<locals>.Ac                 _   r   r   r   r   r   r   r   r   P  r   z7OperatorPickleTestCase.test_methodcaller.<locals>.A.foor   c                 S   r   r	   r   r   r   r   r   r   R  r/   z7OperatorPickleTestCase.test_methodcaller.<locals>.A.barc                  _   r   r   r   r   r   r   r   r   T  r   z7OperatorPickleTestCase.test_methodcaller.<locals>.A.bazNr   r   r   r   r   r   r   O  r   r   r4   rD  r   r   r7   rf   r   r   r   r   r   )	r9   r  r}   r<  rG  rH  rB  rX   rI  )r   r  r   rv   rA  r   rJ  r   r   r   r  M  s.   z(OperatorPickleTestCase.test_methodcallerN)r%   r&   r'   rB  r   r   r  r   r   r   r   r9    s
    r9  c                   @      e Zd ZeZeZdS )PyPyOperatorPickleTestCaseN)r%   r&   r'   r6  r9   r>  r   r   r   r   rL  l  s    rL  c                   @      e Zd ZeZeZdS )PyCOperatorPickleTestCaseN)r%   r&   r'   r6  r9   r8  r>  r   r   r   r   rN  p      rN  c                   @   rM  )CPyOperatorPickleTestCaseN)r%   r&   r'   r8  r9   r6  r>  r   r   r   r   rP  u  rO  rP  c                   @   rK  )CCOperatorPickleTestCaseN)r%   r&   r'   r8  r9   r>  r   r   r   r   rQ  z  rO  rQ  __main__)Zunittestr<  r:  testr   Ztest.supportr   Zimport_fresh_moduler6  r8  r   rJ   r)   r+   r1   ZTestCaser5  Z
skipUnlessr7  r9  rL  rN  rP  rQ  r%   mainr   r   r   r   <module>   s@       g
Q


