B
    u9aZ                 @   s<  d dl Z d dlZd dl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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r8e   dS )    N)supportoperator	_operator)Zblocked)Zfreshc               @   s<   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   s
   || _ d S )N)lst)selfr    r   #/usr/lib/python3.7/test_operator.py__init__   s    zSeq1.__init__c             C   s
   t | jS )N)lenr   )r   r   r   r	   __len__   s    zSeq1.__len__c             C   s
   | j | S )N)r   )r   ir   r   r	   __getitem__   s    zSeq1.__getitem__c             C   s   | j |j  S )N)r   )r   otherr   r   r	   __add__   s    zSeq1.__add__c             C   s
   | j | S )N)r   )r   r   r   r   r	   __mul__   s    zSeq1.__mul__c             C   s
   || j  S )N)r   )r   r   r   r   r	   __rmul__   s    zSeq1.__rmul__N)	__name__
__module____qualname__r
   r   r   r   r   r   r   r   r   r	   r   
   s   r   c               @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )Seq2c             C   s
   || _ d S )N)r   )r   r   r   r   r	   r
      s    zSeq2.__init__c             C   s
   t | jS )N)r   r   )r   r   r   r	   r      s    zSeq2.__len__c             C   s
   | j | S )N)r   )r   r   r   r   r	   r      s    zSeq2.__getitem__c             C   s   | j |j  S )N)r   )r   r   r   r   r	   r      s    zSeq2.__add__c             C   s
   | j | S )N)r   )r   r   r   r   r	   r   !   s    zSeq2.__mul__c             C   s
   || j  S )N)r   )r   r   r   r   r	   r   #   s    zSeq2.__rmul__N)	r   r   r   r
   r   r   r   r   r   r   r   r   r	   r      s   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   s   | j }| t|j | t|jdd | |dd | |dd | |dd | |dd | |dd | |dd d S )	Ny              ?y               @   r   g        g      ?   g       @)moduleassertRaises	TypeErrorltassertFalse
assertTrue)r   r   r   r   r	   test_lt(   s    zOperatorTestCase.test_ltc             C   s   | j }| t|j | t|jdd | |dd | |dd | |dd | |dd | |dd | |dd d S )	Ny              ?y               @r   r   g        g      ?r   g       @)r   r   r   ler   r   )r   r   r   r   r	   test_le3   s    zOperatorTestCase.test_lec             C   s   | 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               @   s   e Zd Zdd ZdS )z#OperatorTestCase.test_eq.<locals>.Cc             S   s   t d S )N)SyntaxError)r   r   r   r   r	   __eq__A   s    z*OperatorTestCase.test_eq.<locals>.C.__eq__N)r   r   r   r$   r   r   r   r	   C@   s   r%   r   r   g        g      ?r   g       @)r   objectr   r   eqr#   r   r   )r   r   r%   r   r   r	   test_eq>   s    zOperatorTestCase.test_eqc             C   s   | 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               @   s   e Zd Zdd ZdS )z#OperatorTestCase.test_ne.<locals>.Cc             S   s   t d S )N)r#   )r   r   r   r   r	   __ne__O   s    z*OperatorTestCase.test_ne.<locals>.C.__ne__N)r   r   r   r)   r   r   r   r	   r%   N   s   r%   r   r   g        g      ?r   g       @)r   r&   r   r   ner#   r   r   )r   r   r%   r   r   r	   test_neL   s    zOperatorTestCase.test_nec             C   s   | j }| t|j | t|jdd | |dd | |dd | |dd | |dd | |dd | |dd d S )	Ny              ?y               @r   r   g        g      ?r   g       @)r   r   r   ger   r   )r   r   r   r   r	   test_geZ   s    zOperatorTestCase.test_gec             C   s   | j }| t|j | t|jdd | |dd | |dd | |dd | |dd | |dd | |dd d S )	Ny              ?y               @r   r   g        g      ?r   g       @)r   r   r   gtr   r   )r   r   r   r   r	   test_gte   s    zOperatorTestCase.test_gtc             C   sL   | j }| t|j | t|jd  | |dd | |dd d S )Nr   )r   r   r   absassertEqual)r   r   r   r   r	   test_absp   s
    zOperatorTestCase.test_absc             C   s>   | j }| t|j | t|jd d  | |ddd d S )N         )r   r   r   addr2   )r   r   r   r   r	   test_addw   s    zOperatorTestCase.test_addc             C   s>   | j }| t|j | t|jd d  | |ddd d S )N   
   )r   r   r   and_r2   )r   r   r   r   r	   test_bitwise_and}   s    z!OperatorTestCase.test_bitwise_andc             C   s   | j }| t|j | t|jd d  | |ddd | |ddgddgddddg | |tdd	gtd
gdd	d
g | |tdd	gtd
gdd	d
g | t|jdd d S )NpyZthonZpythonr   r   r4   r5         r6         )r   r   r   concatr2   r   r   )r   r   r   r   r	   test_concat   s    $((zOperatorTestCase.test_concatc          
   C   sj   | j }| t|j | t|jd d  | |ddddddgdd | |ddddddgdd d S )Nr   r   r4   r5   r>   r   )r   r   r   countOfr2   )r   r   r   r   r	   test_countOf   s
     zOperatorTestCase.test_countOfc             C   s\   | j }ddddg}| t|j| | t|j|d  | ||d | |dddg d S )Nr5   r4   r   r   )r   r   r   delitemassertIsNoner2   )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 )Nr>   r   )r   r   r   floordivr2   )r   r   r   r   r	   test_floordiv   s    zOperatorTestCase.test_floordivc             C   s@   | j }| t|jd | t|jd d  | |ddd d S )Nr>   r   g      @)r   r   r   truedivr2   )r   r   r   r   r	   test_truediv   s    zOperatorTestCase.test_truedivc             C   sF   | j }td}| t|j | t|j|d  | ||dd d S )Nr:   r   )r   ranger   r   getitemr2   )r   r   rH   r   r   r	   test_getitem   s
    zOperatorTestCase.test_getitemc             C   s`   | j }| t|j | t|jd d  | |ddddgdd | t|jddddgd d S )Nr5   r4   r   r   r   )r   r   r   indexOfr2   
ValueError)r   r   r   r   r	   test_indexOf   s
    zOperatorTestCase.test_indexOfc             C   s:   | j }| t|j | t|jd  | |dd d S )Nr5   )r   r   r   invertr2   inv)r   r   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*   r>   r   r:   r   r   r0   )r   r   r   lshiftr2   rR   )r   r   r   r   r	   test_lshift   s    zOperatorTestCase.test_lshiftc             C   s>   | j }| t|j | t|jd d | |ddd d S )NrX   r>   r   r   )r   r   r   modr2   )r   r   r   r   r	   test_mod   s    zOperatorTestCase.test_modc             C   s>   | j }| t|j | t|jd d  | |ddd d S )Nr>   r   r:   )r   r   r   mulr2   )r   r   r   r   r	   test_mul   s    zOperatorTestCase.test_mulc             C   sJ   | j }| t|j | t|jdd G dd d}| | d d d S )NrX   c               @   s   e Zd Zdd ZdS )z'OperatorTestCase.test_matmul.<locals>.Mc             S   s   |d S )Nr   r   )r   r   r   r   r	   
__matmul__   s    z2OperatorTestCase.test_matmul.<locals>.M.__matmul__N)r   r   r   r_   r   r   r   r	   M   s   r`   )   )r   r   r   matmulr2   )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 )Nr>   rT   r   )r   r   r   negr2   )r   r   r   r   r	   test_neg   s    zOperatorTestCase.test_negc             C   s>   | j }| t|j | t|jd d  | |ddd d S )Nr:   r>   r9   )r   r   r   or_r2   )r   r   r   r   r	   test_bitwise_or   s    z OperatorTestCase.test_bitwise_orc             C   sp   | j }| t|j | t|jd  | |dd | |dd | |dd | |dd d S )Nr>   rT   r   )r   r   r   posr2   )r   r   r   r   r	   test_pos   s    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 )Nr4   r>      r   r   )r   r   r   powr2   )r   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 )NrX   r>   r   r   r   r0   )r   r   r   rshiftr2   rR   )r   r   r   r   r	   test_rshift   s    zOperatorTestCase.test_rshiftc             C   sV   | j }| t|j | t|jd d  | |tdd | |tdd d S )Nr5   r   r>   )r   r   r   containsr   rN   r   )r   r   r   r   r	   test_contains  s
    zOperatorTestCase.test_containsc             C   st   | j }ttd}| t|j| | t|j|d d  | ||dd | |dddg | t|j|dd d S )Nr4   r   r   r   r5   )	r   listrN   r   r   setitemrG   r2   
IndexError)r   r   rH   r   r   r	   test_setitem  s    zOperatorTestCase.test_setitemc             C   s>   | j }| t|j | t|jd d  | |ddd d S )Nr>   r   r4   )r   r   r   subr2   )r   r   r   r   r	   test_sub  s    zOperatorTestCase.test_subc             C   s|   | j }G dd dt}| t|j | t|j|  | |d | |dg | |d | |g  d S )Nc               @   s   e Zd Zdd ZdS )z&OperatorTestCase.test_truth.<locals>.Cc             S   s   t d S )N)r#   )r   r   r   r	   __bool__  s    z/OperatorTestCase.test_truth.<locals>.C.__bool__N)r   r   r   rw   r   r   r   r	   r%     s   r%   r>   r   )r   r&   r   r   truthr#   r   r   )r   r   r%   r   r   r	   
test_truth  s    zOperatorTestCase.test_truthc             C   s>   | j }| t|j | t|jd d  | |ddd d S )N      r6   )r   r   r   xorr2   )r   r   r   r   r	   test_bitwise_xor#  s    z!OperatorTestCase.test_bitwise_xorc             C   s\   | j }d }}|d d |dd   }| t|j | ||| | ||| d S )Nxyzpdqr4   )r   r   r   is_r   r   )r   r   rH   bcr   r   r	   test_is)  s    zOperatorTestCase.test_isc             C   s\   | j }d }}|d d |dd   }| t|j | ||| | ||| d S )Nr~   r4   )r   r   r   is_notr   r   )r   r   rH   r   r   r   r   r	   test_is_not1  s    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               @   s   e Zd ZdS )z+OperatorTestCase.test_attrgetter.<locals>.AN)r   r   r   r   r   r   r	   A;  s   r   arthurnameZdent)ZsurnameZrankr   XYZxzy)r   r   r   )r   r   r   c               @   s   e Zd Zdd ZdS )z+OperatorTestCase.test_attrgetter.<locals>.Cc             S   s   t d S )N)r#   )r   r   r   r   r	   __getattr__R  s    z7OperatorTestCase.test_attrgetter.<locals>.C.__getattr__N)r   r   r   r   r   r   r   r	   r%   Q  s   r%   foothomasz
child.name)r   r   zchild.child.namezchild.z.childjohnson)r   r   r   )r   r   
attrgetterr2   r   r   AttributeErrorr   r   r   r&   r#   Zchild)r   r   r   rH   frecordr%   r   r   r	   test_attrgetter9  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	|| ddddg}|d}| t
t||ddddg | t||dddddg t
tttd}| |ddd|d | t|ddd| d S )NABCDEr   r%   r4   )sizer:   c               @   s   e Zd Zdd ZdS )z+OperatorTestCase.test_itemgetter.<locals>.Cc             S   s   t d S )N)r#   )r   r   r   r   r	   r   z  s    z7OperatorTestCase.test_itemgetter.<locals>.C.__getitem__N)r   r   r   r   r   r   r   r	   r%   y  s   rX   r   val)keyr   Znonkey)Zappler4   )Zbananar   )Zpearr>   )Zoranger   r   r>      )2Z105r   )r   
itemgetterr2   r   r   rs   r&   r#   dictKeyErrorrq   mapsortedstrrN   )	r   r   rH   r   r%   dZ	inventoryZgetcountdatar   r   r	   test_itemgettern  s6    






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               @   s&   e Zd Zdd Zd	ddZdd ZdS )
z-OperatorTestCase.test_methodcaller.<locals>.Ac             _   s   |d |d  S )Nr   r   r   )r   argskwdsr   r   r	   r     s    z1OperatorTestCase.test_methodcaller.<locals>.A.foorX   c             S   s   |S )Nr   )r   r   r   r   r	   bar  s    z1OperatorTestCase.test_methodcaller.<locals>.A.barc              _   s   |d |d fS )Nr   r   r   )r   r   r   r   r	   baz  s    z1OperatorTestCase.test_methodcaller.<locals>.A.bazN)rX   )r   r   r   r   r   r   r   r   r   r	   r     s   
r   r   r   r   r4   )spamr   rX   r>   )r   r   r   eggs)r   r   )r   r   )r   r   r   methodcallerrs   r2   )r   r   r   rH   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   s   dS )Niaddr   )r   r   r   r   r	   __iadd__      z1OperatorTestCase.test_inplace.<locals>.C.__iadd__c             S   s   dS )Niandr   )r   r   r   r   r	   __iand__  r   z1OperatorTestCase.test_inplace.<locals>.C.__iand__c             S   s   dS )N	ifloordivr   )r   r   r   r   r	   __ifloordiv__  r   z6OperatorTestCase.test_inplace.<locals>.C.__ifloordiv__c             S   s   dS )Nilshiftr   )r   r   r   r   r	   __ilshift__  r   z4OperatorTestCase.test_inplace.<locals>.C.__ilshift__c             S   s   dS )Nimodr   )r   r   r   r   r	   __imod__  r   z1OperatorTestCase.test_inplace.<locals>.C.__imod__c             S   s   dS )Nimulr   )r   r   r   r   r	   __imul__  r   z1OperatorTestCase.test_inplace.<locals>.C.__imul__c             S   s   dS )Nimatmulr   )r   r   r   r   r	   __imatmul__  r   z4OperatorTestCase.test_inplace.<locals>.C.__imatmul__c             S   s   dS )Niorr   )r   r   r   r   r	   __ior__  r   z0OperatorTestCase.test_inplace.<locals>.C.__ior__c             S   s   dS )Nipowr   )r   r   r   r   r	   __ipow__  r   z1OperatorTestCase.test_inplace.<locals>.C.__ipow__c             S   s   dS )Nirshiftr   )r   r   r   r   r	   __irshift__  r   z4OperatorTestCase.test_inplace.<locals>.C.__irshift__c             S   s   dS )Nisubr   )r   r   r   r   r	   __isub__  r   z1OperatorTestCase.test_inplace.<locals>.C.__isub__c             S   s   dS )Nitruedivr   )r   r   r   r   r	   __itruediv__  r   z5OperatorTestCase.test_inplace.<locals>.C.__itruediv__c             S   s   dS )Nixorr   )r   r   r   r   r	   __ixor__  r   z1OperatorTestCase.test_inplace.<locals>.C.__ixor__c             S   s   dS )Nr>   r   )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	   r%     s   r%   r>   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r&   r2   r   r   r   r   r   r   r   r   r   r   r   r   r   iconcat)r   r   r%   r   r   r   r	   test_inplace  s"    zOperatorTestCase.test_inplacec          	   C   s   | j }G dd dt}| |g dd | |tdddgd | ||dd | ||tdd | ||tdd | t ||d	 W d Q R X | t ||d
 W d Q R X | t	 ||t	 W d Q R X d S )Nc               @   s   e Zd Zdd Zdd ZdS )z,OperatorTestCase.test_length_hint.<locals>.Xc             S   s
   || _ d S )N)value)r   r   r   r   r	   r
     s    z5OperatorTestCase.test_length_hint.<locals>.X.__init__c             S   s    t | jt kr| jn| jS d S )N)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   r   r   r   r4   r5   r{   abc)
r   r&   r2   length_hintiterNotImplementedr   r   rR   LookupError)r   r   r   r   r   r	   test_length_hint  s    
z!OperatorTestCase.test_length_hintc             C   s^   | j }dd t|D }x@|D ]8}t||}t|d|d d d }|r| || qW 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   )r   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    r"   r(   r+   r-   r/   r3   r8   r<   rC   rE   rI   rK   rM   rP   rS   rW   rZ   r\   r^   rc   re   rg   ri   rl   rn   rp   rt   rv   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r	   r   '   sN   
				5&!r   c               @   s   e Zd ZeZdS )PyOperatorTestCaseN)r   r   r   py_operatorr   r   r   r   r	   r     s   r   zrequires _operatorc               @   s   e Zd ZeZdS )COperatorTestCaseN)r   r   r   
c_operatorr   r   r   r   r	   r     s   r   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
OperatorPickleTestCasec          	   C   sR   t tjd| j t||}W d Q R X t tjd| j t|S Q R X d S )Nr   )	r   Z	swap_itemsysmodulesr   pickledumpsmodule2loads)r   objprotoZpickledr   r   r	   copy  s    zOperatorPickleTestCase.copyc          
   C   s6  | j j}G dd d}| }d|_d|_d|_| |_| |j_d|jj_xtt	j
d D ]}| j|d |d	}| ||}| t|t| | |||| |d	d
d}| ||}| t|t| | |||| |d}| ||}| t|t| | |||| W d Q R X qZW d S )Nc               @   s   e Zd ZdS )z1OperatorPickleTestCase.test_attrgetter.<locals>.AN)r   r   r   r   r   r   r	   r     s   r   r   r   r   Vr   )r   r   r   r   zt.u.v)r   r   r   r   r   tuvrN   r   HIGHEST_PROTOCOLsubTestr   r2   repr)r   r   r   rH   r   r   f2r   r   r	   r     s.    

z&OperatorPickleTestCase.test_attrgetterc          
   C   s   | j j}d}xttjd D ]}| j|d |d}| ||}| t|t| | |||| |ddd}| ||}| t|t| | |||| W d Q R X qW d S )Nr   r   )r   r   r   r5   )	r   r   rN   r   r   r   r   r2   r   )r   r   rH   r   r   r   r   r   r	   r     s    z&OperatorPickleTestCase.test_itemgetterc          
   C   s>  | j j}G dd d}| }x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 Q R X q.W d S )Nc               @   s&   e Zd Zdd Zd	ddZdd ZdS )
z3OperatorPickleTestCase.test_methodcaller.<locals>.Ac             _   s   |d |d  S )Nr   r   r   )r   r   r   r   r   r	   r   0  s    z7OperatorPickleTestCase.test_methodcaller.<locals>.A.foorX   c             S   s   |S )Nr   )r   r   r   r   r	   r   2  s    z7OperatorPickleTestCase.test_methodcaller.<locals>.A.barc              _   s   |d |d fS )Nr   r   r   )r   r   r   r   r	   r   4  s    z7OperatorPickleTestCase.test_methodcaller.<locals>.A.bazN)rX   )r   r   r   r   r   r   r   r   r   r	   r   /  s   
r   r   )r   r   r   r   r>   )r   r   r   r   )r   r   )	r   r   rN   r   r   r   r   r2   r   )r   r   r   rH   r   r   r   r   r   r	   r   -  s(    z(OperatorPickleTestCase.test_methodcallerN)r   r   r   r   r   r   r   r   r   r   r	   r     s   r   c               @   s   e Zd ZeZeZdS )PyPyOperatorPickleTestCaseN)r   r   r   r   r   r   r   r   r   r	   r   L  s   r   c               @   s   e Zd ZeZeZdS )PyCOperatorPickleTestCaseN)r   r   r   r   r   r   r   r   r   r   r	   r   P  s   r   c               @   s   e Zd ZeZeZdS )CPyOperatorPickleTestCaseN)r   r   r   r   r   r   r   r   r   r   r	   r   U  s   r   c               @   s   e Zd ZeZeZdS )CCOperatorPickleTestCaseN)r   r   r   r   r   r   r   r   r   r	   r   Z  s   r   __main__)Zunittestr   r   Ztestr   Zimport_fresh_moduler   r   r   r&   r   r   ZTestCaser   Z
skipUnlessr   r   r   r   r   r   r   mainr   r   r   r	   <module>   s0      OQ
