B
    u9aw!                 @   s   d dl Z d dlmZ d dlZejZG dd dZG dd deZG dd de j	Z
G d	d
 d
ZG dd dee j	ZG dd dZG dd dee j	ZG dd dee j	ZG dd dee j	ZG dd dee j	ZG dd dee j	ZG dd de j	ZG dd de j	Zedkre   dS )    N)supportc               @   s   e Zd Zdd ZdS )newstylec             C   s   | j S )N)ind)self r    /usr/lib/python3.7/test_index.py	__index__   s    znewstyle.__index__N)__name__
__module____qualname__r   r   r   r   r   r      s   r   c               @   s   e Zd Zdd ZdS )TrapIntc             C   s   t | S )N)int)r   r   r   r   r      s    zTrapInt.__index__N)r	   r
   r   r   r   r   r   r   r   
   s   r   c               @   sL   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S )BaseTestCasec             C   s   t  | _t  | _d S )N)r   on)r   r   r   r   setUp   s    zBaseTestCase.setUpc             C   s<   d| j _d| j_| t| j d | t| jd d S )N   )r   r   r   assertEqualoperatorindex)r   r   r   r   
test_basic   s    zBaseTestCase.test_basicc             C   s   d| j _d| j_t| j | j | j }tddd}| || j |d t| j| j| j}tddd}| || j|d d S )N   r   )r   r   r   slicer   indices)r   ZslcZ	check_slcr   r   r   
test_slice   s    zBaseTestCase.test_slicec             C   sz   d| j _d| j_| d d | d  d | | j  d | | j d | d d | d d	 d S )
N            iTr   Fr   )r   r   r   r   r   )r   r   r   r   test_wrappers#   s    zBaseTestCase.test_wrappersc             C   sL   t td}| |tdtd |dd  | tt dd d S )N
   r   r   )r   r   r   )listranger   r   r   r   )r   rr   r   r   test_subclasses-   s    $zBaseTestCase.test_subclassesc             C   sd   d| j _d| j_| ttj| j  | ttj| j | tt| j jd | tt| jjd d S )Ndumbbadr   )	r   r   r   assertRaises	TypeErrorr   r   r   r   )r   r   r   r   
test_error2   s    zBaseTestCase.test_errorc             C   sV   G dd dt }|d}| }t|}| |d | |d | t|t  d S )Nc               @   s   e Zd Zdd ZdS )z8BaseTestCase.test_int_subclass_with_index.<locals>.MyIntc             S   s   t | d S )Nr   )r   )r   r   r   r   r   >   s    zBBaseTestCase.test_int_subclass_with_index.<locals>.MyInt.__index__N)r	   r
   r   r   r   r   r   r   MyInt=   s   r+   r      )r   r   r   r   r   assertIstype)r   r+   Zmy_intZdirect_indexZoperator_indexr   r   r   test_int_subclass_with_index:   s    
z)BaseTestCase.test_int_subclass_with_indexc          	   C   sp   G dd d}G dd dt }| }| t t|}W d Q R X | |d | }t|}| |d d S )Nc               @   s   e Zd Zdd ZdS )z<BaseTestCase.test_index_returns_int_subclass.<locals>.BadIntc             S   s   dS )NTr   )r   r   r   r   r   L   s    zFBaseTestCase.test_index_returns_int_subclass.<locals>.BadInt.__index__N)r	   r
   r   r   r   r   r   r   BadIntK   s   r0   c               @   s   e Zd Zdd ZdS )z=BaseTestCase.test_index_returns_int_subclass.<locals>.BadInt2c             S   s   dS )NTr   )r   r   r   r   r   P   s    zGBaseTestCase.test_index_returns_int_subclass.<locals>.BadInt2.__index__N)r	   r
   r   r   r   r   r   r   BadInt2O   s   r1   r   r   )r   ZassertWarnsDeprecationWarningr   r   r   )r   r0   r1   Zbad_intr   r   r   r   test_index_returns_int_subclassJ   s    
z,BaseTestCase.test_index_returns_int_subclassN)r	   r
   r   r   r   r   r    r%   r*   r/   r3   r   r   r   r   r      s   

r   c               @   sL   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S )SeqTestCasec             C   s$   t  | _t  | _t  | _t  | _d S )N)r   r   r   o2n2)r   r   r   r   r   `   s    zSeqTestCase.setUpc             C   sH   d| j _d| j_| | j| j | jd  | | j| j  | jd  d S )Nr   r   )r   r   r   r   seq)r   r   r   r   
test_indexf   s    zSeqTestCase.test_indexc             C   sl   d| j _d| j_d| j_d| j_| | j| j | j | jdd  | | j| j| j | jdd  d S )Nr      r   r   )r   r   r5   r   r6   r   r7   )r   r   r   r   r   l   s    $zSeqTestCase.test_slicec             C   s:  t | j}t|d | j_|d | j_| | j| jd  | jdd  | | jd | j | j | | j| jd  | jdd  | | jd | j | j | d | j_t|d  | j_| | j| jd  | j | | jd | j | jdd  | | j| jd  | j | | jd | j | jdd  d S )Ng      ?r   r   )	lenr7   r   r   r   r   r   r5   r6   )r   Zseqlenr   r   r   test_slice_bug7532t   s    
"""zSeqTestCase.test_slice_bug7532c             C   s|   d| j _d| j_| | j| j  | jd  | | j| j | jd  | | j | j | jd  | | j| j | jd  d S )Nr9   r   )r   r   r   r   r7   )r   r   r   r   test_repeat   s    zSeqTestCase.test_repeatc             C   s   d| j _d| j_| | j| j | jd  | | j| j | jd  | | j| j | jd  | | j| j| jd  | | j| j| jd  | | j| j| jd  d S )Nr   r   )r   r   r   r   r7   __getitem____mul____rmul__)r   r   r   r   r       s    zSeqTestCase.test_wrappersc             C   s   |  | jt  | jd  d S )Nr   )r   r7   r   )r   r   r   r   r%      s    zSeqTestCase.test_subclassesc             C   sl   d| j _d| j_dd }| t|| j |  | t|| j|  dd }| t|| j |  | t|| j|  d S )Nr&   r'   c             S   s
   |j |  S )N)r7   )xobjr   r   r   <lambda>       z(SeqTestCase.test_error.<locals>.<lambda>c             S   s   |j | d  S )N)r7   )r@   rA   r   r   r   rB      rC   )r   r   r   r(   r)   )r   ZindexobjZsliceobjr   r   r   r*      s    zSeqTestCase.test_errorN)r	   r
   r   r   r8   r   r;   r<   r    r%   r*   r   r   r   r   r4   ]   s   
r4   c               @   s,   e Zd ZddddddgZdd Zd	d
 ZdS )ListTestCaser   r!         (   2   c          
   C   s   d| j _d| j_td}|| j = || j= d|| j < d|| j< | |td ddd	d
dddg}|| jd | |dddd
dddg || j | |ddd
dddg d S )Nr   r   zab!cdefghi!jXYZ
abYdefghXjr   r   r   r,   	   r!      here)r   r   r   r"   r   __setitem____delitem__)r   lstr   r   r   test_setdelitem   s    

zListTestCase.test_setdelitemc          	   C   s   d| j _d| j_ddg}|| j 9 }| |ddddg || j9 }| |ddddgd  dddddd	g}|| j}| || | |dddddd	gd  d S )
Nr   r9   r   r   r   r   r,   rK   rL   )r   r   r   r   __imul__r-   )r   rP   l2r   r   r   test_inplace_repeat   s    

z ListTestCase.test_inplace_repeatN)r	   r
   r   r7   rQ   rT   r   r   r   r   rD      s   rD   c               @   s@   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZeZdd Z	dS )NewSeqc             C   s   t || _d S )N)r"   _list)r   iterabler   r   r   __init__   s    zNewSeq.__init__c             C   s
   t | jS )N)reprrV   )r   r   r   r   __repr__   s    zNewSeq.__repr__c             C   s
   | j |kS )N)rV   )r   otherr   r   r   __eq__   s    zNewSeq.__eq__c             C   s
   t | jS )N)r:   rV   )r   r   r   r   __len__   s    zNewSeq.__len__c             C   s   |  | j| S )N)	__class__rV   )r   r   r   r   r   r>      s    zNewSeq.__mul__c             C   s
   | j | S )N)rV   )r   r   r   r   r   r=      s    zNewSeq.__getitem__N)
r	   r
   r   rX   rZ   r\   r]   r>   r?   r=   r   r   r   r   rU      s   rU   c               @   s   e Zd ZdZdS )TupleTestCase)r   r!   rE   rF   rG   rH   N)r	   r
   r   r7   r   r   r   r   r_      s   r_   c               @   s   e Zd ZedZdS )ByteArrayTestCases   this is a testN)r	   r
   r   	bytearrayr7   r   r   r   r   r`      s   r`   c               @   s   e Zd ZdZdS )BytesTestCases   this is a testN)r	   r
   r   r7   r   r   r   r   rb      s   rb   c               @   s   e Zd ZdZdS )StringTestCasezthis is a testN)r	   r
   r   r7   r   r   r   r   rc      s   rc   c               @   s   e Zd ZedZdS )NewSeqTestCase)r   r!   rE   rF   rG   rH   N)r	   r
   r   rU   r7   r   r   r   r   rd      s   rd   c               @   s   e Zd Zdd ZdS )RangeTestCasec             C   s>   t  }d|_| tdd| d | tdd|d d S )Nr   r   rE   r   )r   r   r   r#   r=   )r   r   r   r   r   
test_range   s    zRangeTestCase.test_rangeN)r	   r
   r   rf   r   r   r   r   re      s   re   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
OverflowTestCasec             C   s   dd | _ | j  | _d S )Nr   d   )posneg)r   r   r   r   r      s    
zOverflowTestCase.setUpc             C   s,   |  | j | j |  | j | j d S )N)r   ri   r   rj   )r   r   r   r   test_large_longs   s    z!OverflowTestCase.test_large_longsc             C   s   G dd d}| }|  || j | j |  || j | j |  || j| j tdtdf |  || j| jd tdtdf d S )Nc               @   s   e Zd Zdd Zdd ZdS )z.OverflowTestCase.test_getitem.<locals>.GetItemc             S   s   d S )Nr   )r   r   r   r   r]     s    z6OverflowTestCase.test_getitem.<locals>.GetItem.__len__c             S   s   |S )Nr   )r   keyr   r   r   r=     s    z:OverflowTestCase.test_getitem.<locals>.GetItem.__getitem__N)r	   r
   r   r]   r=   r   r   r   r   GetItem   s   rm   r   r   )r   ri   rj   r   maxsize)r   rm   r@   r   r   r   test_getitem   s    zOverflowTestCase.test_getitemc                s,     t fdd   t fdd d S )Nc                  s
   d j  S )Na)ri   r   )r   r   r   rB     rC   z7OverflowTestCase.test_sequence_repeat.<locals>.<lambda>c                  s
   d j  S )Nrp   )rj   r   )r   r   r   rB     rC   )r(   OverflowError)r   r   )r   r   test_sequence_repeat  s    z%OverflowTestCase.test_sequence_repeatN)r	   r
   r   r   rk   ro   rr   r   r   r   r   rg      s   rg   __main__)ZunittestZtestr   r   ZMAX_Py_ssize_trn   r   r   r   ZTestCaser   r4   rD   rU   r_   r`   rb   rc   rd   re   rg   r	   mainr   r   r   r   <module>   s$   OF"	
