B
    u9a                 @   s<  d dl Z d dlZd dlZd dlZd dlmZ G dd dZG dd dZG dd dZG d	d
 d
Z	G dd dZ
G dd dZG dd dZG dd de jeZG dd deZG dd deZG dd deZG dd deZG dd de jeZG dd deZG dd  d eZG d!d" d"eZed#kr8e   dS )$    N)supportc               @   s    e Zd ZdZdd Zdd ZdS )GzSequence using __getitem__c             C   s
   || _ d S )N)seqn)selfr    r   $/usr/lib/python3.7/test_enumerate.py__init__
   s    z
G.__init__c             C   s
   | j | S )N)r   )r   ir   r   r   __getitem__   s    zG.__getitem__N)__name__
__module____qualname____doc__r   r
   r   r   r   r   r      s   r   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	Iz Sequence using iterator protocolc             C   s   || _ d| _d S )Nr   )r   r	   )r   r   r   r   r   r      s    z
I.__init__c             C   s   | S )Nr   )r   r   r   r   __iter__   s    z
I.__iter__c             C   s2   | j t| jkrt| j| j  }|  j d7  _ |S )N   )r	   lenr   StopIteration)r   vr   r   r   __next__   s
     z
I.__next__N)r   r   r   r   r   r   r   r   r   r   r   r      s   r   c               @   s    e Zd ZdZdd Zdd ZdS )Igz9Sequence using iterator protocol defined with a generatorc             C   s   || _ d| _d S )Nr   )r   r	   )r   r   r   r   r   r      s    zIg.__init__c             c   s   x| j D ]
}|V  qW d S )N)r   )r   valr   r   r   r   !   s    zIg.__iter__N)r   r   r   r   r   r   r   r   r   r   r      s   r   c               @   s    e Zd ZdZdd Zdd ZdS )Xz Missing __getitem__ and __iter__c             C   s   || _ d| _d S )Nr   )r   r	   )r   r   r   r   r   r   '   s    z
X.__init__c             C   s2   | j t| jkrt| j| j  }|  j d7  _ |S )Nr   )r	   r   r   r   )r   r   r   r   r   r   *   s
     z
X.__next__N)r   r   r   r   r   r   r   r   r   r   r   %   s   r   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	EzTest propagation of exceptionsc             C   s   || _ d| _d S )Nr   )r   r	   )r   r   r   r   r   r   2   s    z
E.__init__c             C   s   | S )Nr   )r   r   r   r   r   5   s    z
E.__iter__c             C   s   dd  d S )N   r   r   )r   r   r   r   r   7   s    z
E.__next__N)r   r   r   r   r   r   r   r   r   r   r   r   0   s   r   c               @   s    e Zd ZdZdd Zdd ZdS )NzIterator missing __next__()c             C   s   || _ d| _d S )Nr   )r   r	   )r   r   r   r   r   r   <   s    z
N.__init__c             C   s   | S )Nr   )r   r   r   r   r   ?   s    z
N.__iter__N)r   r   r   r   r   r   r   r   r   r   r   :   s   r   c               @   s   e Zd Zdd ZdS )
PickleTestc          	   C   s   xt tjd D ]}t||}t|}| t|t| | t|| t|}yt| W n( t	k
r   | 
|dd   wY nX t||}t|}| t||dd   qW d S )Nr   )rangepickleZHIGHEST_PROTOCOLdumpsloadsassertEqualtypelistnextr   ZassertFalse)r   Zitorgseqprotoditr   r   r   check_pickleD   s    


zPickleTest.check_pickleN)r   r   r   r)   r   r   r   r   r   B   s   r   c               @   sv   e Zd ZeZddddg Z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ejdd ZdS )EnumerateTestCaseabc)r   a)r   b)   cc             C   s\   |  t| | j| j | | j}|  t|| |  t| | j| j | jj d S )N)r!   r"   enumr%   iterr#   resr   )r   er   r   r   test_basicfunctionZ   s
    z$EnumerateTestCase.test_basicfunctionc             C   s   |  | | j| j d S )N)r)   r0   r%   r2   )r   r   r   r   test_picklea   s    zEnumerateTestCase.test_picklec             C   s>   |  t| t| j| j | td}| tt| d S )N )	r!   r#   r0   r   r%   r2   assertRaisesr   r$   )r   r3   r   r   r   test_getitemseqnd   s    z"EnumerateTestCase.test_getitemseqnc             C   s>   |  t| t| j| j | td}| tt| d S )Nr6   )	r!   r#   r0   r   r%   r2   r7   r   r$   )r   r3   r   r   r   test_iteratorseqni   s    z#EnumerateTestCase.test_iteratorseqnc             C   s>   |  t| t| j| j | td}| tt| d S )Nr6   )	r!   r#   r0   r   r%   r2   r7   r   r$   )r   r3   r   r   r   test_iteratorgeneratorn   s    z(EnumerateTestCase.test_iteratorgeneratorc             C   s   |  t| jt| j d S )N)r7   	TypeErrorr0   r   r%   )r   r   r   r   test_noniterables   s    z"EnumerateTestCase.test_noniterablec             C   s   |  t| jt| j d S )N)r7   r;   r0   r   r%   )r   r   r   r   test_illformediterablev   s    z(EnumerateTestCase.test_illformediterablec             C   s   |  tt| t| j d S )N)r7   ZeroDivisionErrorr#   r0   r   r%   )r   r   r   r   test_exception_propagationy   s    z,EnumerateTestCase.test_exception_propagationc             C   sH   |  t| j |  t| jd |  t| jdd |  t| jddd d S )Nr   r+   r,   r.   r   )r7   r;   r0   )r   r   r   r   test_argumentcheck|   s    z$EnumerateTestCase.test_argumentcheckc          	   C   sZ   |  tttttt| jt| j |  ttttt| jtdt| j d S )Nr   )	r!   r   setmapidr#   	enumerater%   min)r   r   r   r   test_tuple_reuse   s    *z"EnumerateTestCase.test_tuple_reuseN)r   r   r   rD   r0   r%   r2   r4   r5   r8   r9   r:   r<   r=   r?   r@   r   Zcpython_onlyrF   r   r   r   r   r*   U   s   r*   c               @   s   e Zd ZdS )MyEnumN)r   r   r   r   r   r   r   rG      s   rG   c               @   s   e Zd ZeZdS )SubclassTestCaseN)r   r   r   rG   r0   r   r   r   r   rH      s   rH   c               @   s   e Zd Zdg  ZZdS )	TestEmptyr6   N)r   r   r   r%   r2   r   r   r   r   rI      s   rI   c               @   s*   e Zd ZedddZeeedeZdS )TestBig
   i N  r.   N)r   r   r   r   r%   r#   zipr2   r   r   r   r   rJ      s   rJ   c               @   s^   e Zd Zdd Zdd Zdd Zdd Zd	d
 Ze	e
edddd Zdd Zdd ZdS )TestReversedc             C   s   G dd d}xNdt dttd| t dddfD ]&}| t|d d d tt| q4W | tti  | jttg dd d S )	Nc               @   s   e Zd Zdd Zdd ZdS )z#TestReversed.test_simple.<locals>.Ac             S   s   |dk rt |S td S )N   )strr   )r   r	   r   r   r   r
      s    z/TestReversed.test_simple.<locals>.A.__getitem__c             S   s   dS )NrN   r   )r   r   r   r   __len__   s    z+TestReversed.test_simple.<locals>.A.__len__N)r   r   r   r
   rP   r   r   r   r   A   s   rQ   r+   rN   r      )r,   )r   tuplerD   r!   r#   reversedr7   r;   )r   rQ   datar   r   r   test_simple   s
    *&zTestReversed.test_simplec             C   s(   t d}| tt|tt| d S )Nr   )r   r!   r"   rU   r1   )r   xr   r   r   test_range_optimization   s    z$TestReversed.test_range_optimizationc             C   s   x\dt dtdtdfD ]@}| tt|t| t|}t| | t|d qW G dd d}t| }| t	tj| d S )NZhellorN   r   c               @   s    e Zd ZdZdd Zdd ZdS )z.TestReversed.test_len.<locals>.SeqWithWeirdLenFc             S   s   | j sd| _ dS td S )NTrK   )calledr>   )r   r   r   r   rP      s    z6TestReversed.test_len.<locals>.SeqWithWeirdLen.__len__c             S   s   |S )Nr   )r   indexr   r   r   r
      s    z:TestReversed.test_len.<locals>.SeqWithWeirdLen.__getitem__N)r   r   r   rZ   rP   r
   r   r   r   r   SeqWithWeirdLen   s   r\   )
rT   r#   r   r!   operatorlength_hintrU   r   r7   r>   )r   srr\   r   r   r   test_len   s    	
zTestReversed.test_lenc             C   s&   G dd d}| }t |}||_d S )Nc               @   s   e Zd Zdd Zdd ZdS )z!TestReversed.test_gc.<locals>.Seqc             S   s   dS )NrK   r   )r   r   r   r   rP      s    z)TestReversed.test_gc.<locals>.Seq.__len__c             S   s   |S )Nr   )r   r[   r   r   r   r
      s    z-TestReversed.test_gc.<locals>.Seq.__getitem__N)r   r   r   rP   r
   r   r   r   r   Seq   s   rb   )rU   r`   )r   rb   r_   r`   r   r   r   test_gc   s    zTestReversed.test_gcc             C   s    |  tt |  ttg d d S )NZextra)r7   r;   rU   )r   r   r   r   	test_args   s    zTestReversed.test_argsgetrefcountztest needs sys.getrefcount()c          	   C   sr   dd }t   }|_t|}x<tdD ]0}yt| W n tk
rL   Y q(X | d q(W | |t| d S )Nc               S   s   d S )Nr   r   r   r   r   f   s    z'TestReversed.test_bug1229429.<locals>.frK   z'non-callable __reversed__ didn't raise!)	object__reversed__sysre   r   rU   r;   Zfailr!   )r   rf   r`   Zrcr	   r   r   r   test_bug1229429   s    
zTestReversed.test_bug1229429c             C   sp   G dd dt }| }| tt| G dd dt }| }| tt| G dd dt }| }| tt| d S )Nc               @   s   e Zd Zdd ZdS )z+TestReversed.test_objmethods.<locals>.NoLenc             S   s   dS )Nr   r   )r   r	   r   r   r   r
          z7TestReversed.test_objmethods.<locals>.NoLen.__getitem__N)r   r   r   r
   r   r   r   r   NoLen   s   rl   c               @   s   e Zd Zdd ZdS )z/TestReversed.test_objmethods.<locals>.NoGetItemc             S   s   dS )Nr.   r   )r   r   r   r   rP      rk   z7TestReversed.test_objmethods.<locals>.NoGetItem.__len__N)r   r   r   rP   r   r   r   r   	NoGetItem   s   rm   c               @   s    e Zd Zdd Zdd ZdZdS )z-TestReversed.test_objmethods.<locals>.Blockedc             S   s   dS )Nr   r   )r   r	   r   r   r   r
      rk   z9TestReversed.test_objmethods.<locals>.Blocked.__getitem__c             S   s   dS )Nr.   r   )r   r   r   r   rP      rk   z5TestReversed.test_objmethods.<locals>.Blocked.__len__N)r   r   r   r
   rP   rh   r   r   r   r   Blocked   s   rn   )rg   r7   r;   rU   )r   rl   nlrm   Zngirn   r-   r   r   r   test_objmethods   s    zTestReversed.test_objmethodsc             C   sL   xFdt dttdt dddfD ]"}| t|t|d d d  q"W d S )Nr+   rN   r   rR   rS   )r   rT   rD   r)   rU   r#   )r   rV   r   r   r   r5      s    &zTestReversed.test_pickleN)r   r   r   rW   rY   ra   rc   rd   unittestZ
skipUnlesshasattrri   rj   rp   r5   r   r   r   r   rM      s   
rM   c               @   s   e Zd Zdd ZdS )EnumerateStartTestCasec             C   s:   |  | j}| t|| | t|  | j| j d S )N)r0   r%   r!   r1   r#   r2   )r   r3   r   r   r   r4      s    z)EnumerateStartTestCase.test_basicfunctionN)r   r   r   r4   r   r   r   r   rs      s   rs   c               @   s$   e Zd Zdd Zddddg ZZdS )	TestStartc             C   s   t |ddS )N   )start)rD   )r   r	   r   r   r   <lambda>  rk   zTestStart.<lambda>r+   )ru   r,   )   r-   )   r/   N)r   r   r   r0   r%   r2   r   r   r   r   rt      s   rt   c               @   sB   e Zd Zdd Zdejd dfejd dfejd d	fg ZZd
S )TestLongStartc             C   s   t |tjd dS )Nr   )rv   )rD   ri   maxsize)r   r	   r   r   r   rw     rk   zTestLongStart.<lambda>r+   r   r,   r.   r-   r   r/   N)r   r   r   r0   ri   r{   r%   r2   r   r   r   r   rz     s   rz   __main__)rq   r]   ri   r   Ztestr   r   r   r   r   r   r   r   ZTestCaser*   rD   rG   rH   rI   rJ   rM   rs   rt   rz   r   mainr   r   r   r   <module>   s,   	
4^
