B
    u9a»8  ã               @   sØ   d dl Z d dlZd dlZd dlmZ 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ƒZd dlmZ dd„ ZG dd„ deƒZG dd„ deƒZG dd„ de jƒZdS )é    N)Úsupportc             c   s   x| D ]
}|V  qW d S )N© )ÚseqnÚir   r   ú/usr/lib/python3.7/seq_tests.pyÚiterfunc   s    
r   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚSequencec             C   s
   || _ d S )N)r   )Úselfr   r   r   r   Ú__init__   s    zSequence.__init__c             C   s
   | j | S )N)r   )r	   r   r   r   r   Ú__getitem__   s    zSequence.__getitem__N)Ú__name__Ú
__module__Ú__qualname__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S )ÚIterFuncc             C   s   || _ d| _d S )Nr   )r   r   )r	   r   r   r   r   r
      s    zIterFunc.__init__c             C   s   | S )Nr   )r	   r   r   r   Ú__iter__   s    zIterFunc.__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IterFunc.__next__N)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S )ÚIterGenc             C   s   || _ d| _d S )Nr   )r   r   )r	   r   r   r   r   r
   '   s    zIterGen.__init__c             c   s   x| j D ]
}|V  qW d S )N)r   )r	   Úvalr   r   r   r   *   s    zIterGen.__iter__N)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S )ÚIterNextOnlyc             C   s   || _ d| _d S )Nr   )r   r   )r	   r   r   r   r   r
   0   s    zIterNextOnly.__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   3   s
     zIterNextOnly.__next__N)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S )Ú
IterNoNextc             C   s   || _ d| _d S )Nr   )r   r   )r	   r   r   r   r   r
   ;   s    zIterNoNext.__init__c             C   s   | S )Nr   )r	   r   r   r   r   >   s    zIterNoNext.__iter__N)r   r   r   r
   r   r   r   r   r   r   9   s   r   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú
IterGenExcc             C   s   || _ d| _d S )Nr   )r   r   )r	   r   r   r   r   r
   C   s    zIterGenExc.__init__c             C   s   | S )Nr   )r	   r   r   r   r   F   s    zIterGenExc.__iter__c             C   s   dd  d S )Né   r   r   )r	   r   r   r   r   H   s    zIterGenExc.__next__N)r   r   r   r
   r   r   r   r   r   r   r   A   s   r   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚIterFuncStopc             C   s   d S )Nr   )r	   r   r   r   r   r
   M   s    zIterFuncStop.__init__c             C   s   | S )Nr   )r	   r   r   r   r   O   s    zIterFuncStop.__iter__c             C   s   t ‚d S )N)r   )r	   r   r   r   r   Q   s    zIterFuncStop.__next__N)r   r   r   r
   r   r   r   r   r   r   r   K   s   r   )Úchainc             C   s   t tdd„ ttt| ƒƒƒƒƒS )Nc             S   s   | S )Nr   )Úxr   r   r   Ú<lambda>W   ó    zitermulti.<locals>.<lambda>)r   Úmapr   r   r   )r   r   r   r   Ú	itermultiU   s    r"   c               @   s   e Zd Zdd„ ZdS )Ú
LyingTuplec             c   s
   dV  d S )Nr   r   )r	   r   r   r   r   Z   s    zLyingTuple.__iter__N)r   r   r   r   r   r   r   r   r#   Y   s   r#   c               @   s   e Zd Zdd„ ZdS )Ú	LyingListc             c   s
   dV  d S )Nr   r   )r	   r   r   r   r   ^   s    zLyingList.__iter__N)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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S )*Ú
CommonTestNc             C   sÔ  g }dg}ddg}|   ¡ }|   |¡}|   |¡}|   |¡}|   |¡}|   |¡}	|   |¡}
|   |¡}|   t|ƒ¡}G dd„ dƒ}||ƒ}|   |¡}|  t|ƒt|ƒ¡ d}|   |¡}|  t|ƒt|ƒ¡ xÎddtdƒd	td
ddƒfD ]°}x2ttttt	fD ] }|  |   ||ƒ¡|   |¡¡ qôW |  |   t
|ƒ¡|   ¡ ¡ |  |   dd„ dD ƒ¡|   d¡¡ |  t| j t|ƒ¡ |  t| j t|ƒ¡ |  t| j t|ƒ¡ qàW |  |   tdƒ¡|   d¡¡ |  |   tdgƒ¡|   dg¡¡ d S )Nr   r   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )z.CommonTest.test_constructors.<locals>.OtherSeqc             S   s
   || _ d S )N)Ú_OtherSeq__data)r	   Zinitseqr   r   r   r
   v   s    z7CommonTest.test_constructors.<locals>.OtherSeq.__init__c             S   s
   t | jƒS )N)r   r&   )r	   r   r   r   Ú__len__x   s    z6CommonTest.test_constructors.<locals>.OtherSeq.__len__c             S   s
   | j | S )N)r&   )r	   r   r   r   r   r   z   s    z:CommonTest.test_constructors.<locals>.OtherSeq.__getitem__N)r   r   r   r
   r'   r   r   r   r   r   ÚOtherSequ   s   r(   zthis is also a sequenceZ123Ú iè  )Zdog333333ó?iÐ  i˜  é   c             s   s   | ]
}|V  qd S )Nr   )Ú.0Úcr   r   r   ú	<genexpr>Š   s    z/CommonTest.test_constructors.<locals>.<genexpr>)é   )r   r.   )Ú	type2testÚtupleÚassertEqualr   Úranger   r   r   r"   r   r   ÚassertRaisesÚ	TypeErrorr   r   ÚZeroDivisionErrorr   r#   r$   )r	   Zl0Úl1Úl2ÚuZu0Úu1Úu2ÚuuZuu0Zuu1Zuu2r   r(   ÚsZv0ZvvÚgr   r   r   Útest_constructorse   s<    








  "zCommonTest.test_constructorsc             C   s$   |   |  ¡ ¡ |  |  dg¡¡ d S )Né*   )ZassertFalser/   Z
assertTrue)r	   r   r   r   Ú
test_truth“   s    zCommonTest.test_truthc             C   sŠ  |   dddddg¡}x8tt|ƒƒD ](}|  || |¡ |  |t|ƒ |¡ q"W xLtt|ƒ dƒD ]8}|  || t|ƒ| ¡ |  |t|ƒ t|ƒ| ¡ q`W |  t|jt|ƒ d ¡ |  t|jt|ƒ¡ |  t|jt	dddƒ¡ |   ¡ }|  t|jd¡ |  t|jd¡ |  t
|j¡ |   ddg¡}|  |d d¡ |  |d d¡ |  |d	 d¡ |  |d d¡ |  t|jd
¡ |  t|jd¡ d S )Nr   r   r.   r   é   éÿÿÿÿé
   é   éþÿÿÿéýÿÿÿ)r/   r2   r   r1   Úintr3   Ú
IndexErrorr   Ú
ValueErrorÚslicer4   )r	   r8   r   Úar   r   r   Útest_getitem—   s*     zCommonTest.test_getitemc          
   C   sP  dddddg}|   |¡}|  |dd… |   ¡ ¡ |  |dd… |   dg¡¡ |  |dd… |   dg¡¡ |  |dd	… |¡ |  |d	d… |   g ¡¡ |  |d d … |¡ |  |dd … |   ddddg¡¡ |  |d d… |   dddg¡¡ |  |d d … |¡ |  |d d d… |   dddg¡¡ |  |dd d… |   ddg¡¡ |  |d d d… |   dddddg¡¡ |  |d d d… |   dddg¡¡ |  |dd d… |   ddg¡¡ |  |ddd… |   g ¡¡ |  |ddd… |   dg¡¡ |  |ddd… |   dg¡¡ |  |ddd… |   ddg¡¡ |  |d d d
… |   dg¡¡ |  |dd
… |   g ¡¡ |  |d
d… |¡ |  |dd
d… |d d d… ¡ |  |d
dd… |   g ¡¡ |  |d
dd… |   dddg¡¡ |   dddddg¡}|  |tddƒ d… |   dddg¡¡ |  |dtddƒ… |   ddg¡¡ |  |dd tj… |   dg¡¡ d S )Nr   r   r.   r   rA   rE   rB   iüÿÿiè  iœÿÿÿéd   é€   é‘   )r/   r1   ÚpowÚsysÚmaxsize)r	   Úlr8   rK   r   r   r   Útest_getslice±   s<    
" " &"   "($zCommonTest.test_getslicec             C   sj   |   dddg¡}x|D ]}|  ||¡ qW x,t|ƒd t|ƒd fD ]}|  ||¡ qDW |  t|j¡ d S )Nr   r   r.   )r/   ÚassertInÚminÚmaxÚassertNotInr3   r4   Ú__contains__)r	   r8   r   r   r   r   Útest_containsÖ   s    
zCommonTest.test_containsc             C   s<   G dd„ dƒ}|   |ƒ |  g ¡¡ |  |ƒ |  dg¡¡ d S )Nc               @   s   e Zd Zdd„ ZdZdS )z,CommonTest.test_contains_fake.<locals>.AllEqc             S   s   dS )NTr   )r	   Úotherr   r   r   Ú__eq__ä   s    z3CommonTest.test_contains_fake.<locals>.AllEq.__eq__N)r   r   r   r\   Ú__hash__r   r   r   r   ÚAllEqà   s   r^   r   )rX   r/   rU   )r	   r^   r   r   r   Útest_contains_fakeß   s    zCommonTest.test_contains_fakec                sb   G dd„ dt ƒ‰ G ‡ fdd„dƒ}|  d|ƒ g¡}|  d|¡ |  |ƒ dg¡}|  ˆ |jd¡ d S )Nc               @   s   e Zd ZdS )z3CommonTest.test_contains_order.<locals>.DoNotTestEqN)r   r   r   r   r   r   r   ÚDoNotTestEqî   s   r`   c                   s   e Zd Z‡ fdd„ZdS )z4CommonTest.test_contains_order.<locals>.StopComparesc                s   ˆ ‚d S )Nr   )r	   r[   )r`   r   r   r\   ñ   s    z;CommonTest.test_contains_order.<locals>.StopCompares.__eq__N)r   r   r   r\   r   )r`   r   r   ÚStopComparesð   s   ra   r   )Ú	Exceptionr/   rU   r3   rY   )r	   ra   Z
checkfirstZ	checklastr   )r`   r   Útest_contains_orderê   s    zCommonTest.test_contains_orderc             C   sb   |   t|  ¡ ƒd¡ |   t|  g ¡ƒd¡ |   t|  dg¡ƒd¡ |   t|  dddg¡ƒd¡ d S )Nr   r   r.   r   )r1   r   r/   )r	   r   r   r   Útest_lenù   s    zCommonTest.test_lenc             C   s4   |   dddg¡}|  t|ƒd¡ |  t|ƒd¡ d S )Nr   r   r.   )r/   r1   rV   rW   )r	   r8   r   r   r   Útest_minmaxÿ   s    zCommonTest.test_minmaxc             C   sÎ  |   dg¡}|   ddg¡}|  |||   ¡  ¡ |  ||   ¡ | ¡ |  ||   dg¡ |¡ |  |   dg¡| |   ddg¡¡ |  |   ¡ |d ¡ |  |   ¡ d| ¡ |  |   ¡ |d ¡ |  |   ¡ d| ¡ |  ||d ¡ |  |d| ¡ |  ||d ¡ |  |d| ¡ |  || |d ¡ |  || d| ¡ |  || |d ¡ |  || d| ¡ |  || | |d ¡ |  || | d| ¡ G dd„ d| j ƒ}|ddgƒ}|  ||d ¡ |  ||d ¡ d S )Nr   r   rB   r.   r   c               @   s   e Zd ZdS )z(CommonTest.test_addmul.<locals>.subclassN)r   r   r   r   r   r   r   Úsubclass  s   rf   )r/   r1   ZassertIsNot)r	   r9   r:   rf   Zu3r   r   r   Útest_addmul  s0    "zCommonTest.test_addmulc             C   sº   |   ddg¡}||   ¡ 7 }|  ||   ddg¡¡ ||   ddg¡7 }|  ||   ddddg¡¡ ||   ddg¡7 }|  ||   ddddddg¡¡ |   d¡}||   d¡7 }|  ||   d	¡¡ d S )
Nr   r   r.   r   rA   r*   ZspamZeggsZspameggs)r/   r1   )r	   r8   r   r   r   Ú	test_iadd   s    
zCommonTest.test_iaddc             C   sR   |   ddg¡}|d9 }|  ||   ddddddg¡¡ |d9 }|  ||   g ¡¡ d S )Nr   r   r   )r/   r1   )r	   r8   r   r   r   Ú	test_imul-  s
    zCommonTest.test_imulc             C   s.   G dd„ d| j ƒ}|  tt|dƒƒƒd¡ d S )Nc               @   s   e Zd Zdd„ ZdS )z/CommonTest.test_getitemoverwriteiter.<locals>.Tc             S   s   t |ƒd S )Nz!!!)Ústr)r	   Úkeyr   r   r   r   7  s    z;CommonTest.test_getitemoverwriteiter.<locals>.T.__getitem__N)r   r   r   r   r   r   r   r   ÚT6  s   rl   )r   r.   r   )r/   r1   ÚnextÚiter)r	   rl   r   r   r   Útest_getitemoverwriteiter4  s    z$CommonTest.test_getitemoverwriteiterc             C   sŠ   x„t dƒD ]x}tt |ƒƒ}x2t ddƒD ]$}|  |  || ¡|  |¡| ¡ q&W |  |  |¡d |  g ¡¡ |  t|ƒt|d ƒ¡ q
W d S )NrA   rF   r*   éüÿÿÿr   )r2   r0   r1   r/   Úid)r	   Úmr<   Únr   r   r   Útest_repeat;  s    $zCommonTest.test_repeatc             C   sL   t jdkrH|  dg¡}|d9 }|  t|jd¡ t|dƒrH|  t|jd¡ d S )Niÿÿÿr   i   Ú__imul__)rQ   rR   r/   r3   ÚMemoryErrorÚ__mul__Úhasattrru   )r	   r   r   r   r   Útest_bigrepeatC  s    

zCommonTest.test_bigrepeatc             C   sD  |   ddg¡}|  | d¡d¡ |  | d¡d¡ |  | d¡d¡ |  | d¡d¡ |  t|jd¡ |  t|jd¡ |  | tddƒ¡|   dg¡¡ |  | tdd	ƒ¡|   dg¡¡ |  | tdd	ƒ¡|   ddg¡¡ |  | tddƒ¡|   ddg¡¡ |  | tdd
ƒ¡|   g ¡¡ |  t|jtdddƒ¡ |  t|jd¡ d S )NrC   rD   r   r   rE   rB   rF   r   r.   r*   r   )r/   r1   r   r3   rH   rJ   rI   r4   )r	   rK   r   r   r   Útest_subscriptK  s      ""zCommonTest.test_subscriptc                s   |   dddg¡d }|  | d¡d¡ |  | d¡d¡ |  | d¡d¡ |  t|j¡ G dd„ dtƒ‰ G ‡ fdd„dƒ}|  ˆ |j|ƒ ¡ d S )	Nr   r   r.   r   c               @   s   e Zd ZdS )z%CommonTest.test_count.<locals>.BadExcN)r   r   r   r   r   r   r   ÚBadExcc  s   r{   c                   s   e Zd Z‡ fdd„ZdS )z%CommonTest.test_count.<locals>.BadCmpc                s   |dkrˆ ƒ ‚dS )Nr.   Fr   )r	   r[   )r{   r   r   r\   g  s    z,CommonTest.test_count.<locals>.BadCmp.__eq__N)r   r   r   r\   r   )r{   r   r   ÚBadCmpf  s   r|   )r/   r1   Úcountr3   r4   rb   )r	   rK   r|   r   )r{   r   Ú
test_count[  s    zCommonTest.test_countc                sH  |   ddg¡}|  | d¡d¡ |  | d¡d¡ |  t|jd¡ |   ddddddg¡}|  | d¡d¡ |  | d¡d¡ |  | dd¡d¡ |  | dd¡d¡ |  | dd¡d¡ |  | ddd¡d¡ |  t|jddd¡ |  t|j¡ G d	d
„ d
tƒ‰ G ‡ fdd„dƒ}|   ddddg¡}|  ˆ |j|ƒ ¡ |   ddddddg¡}|  | 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tj	 dtj	 ¡d¡ |  t|jddtj	 dtj	 ¡ |  t|jddd¡ d S )Nr   r   r.   rE   rB   iöÿÿÿr   rA   c               @   s   e Zd ZdS )z%CommonTest.test_index.<locals>.BadExcN)r   r   r   r   r   r   r   r{     s   r{   c                   s   e Zd Z‡ fdd„ZdS )z%CommonTest.test_index.<locals>.BadCmpc                s   |dkrˆ ƒ ‚dS )Nr.   Fr   )r	   r[   )r{   r   r   r\   ƒ  s    z,CommonTest.test_index.<locals>.BadCmp.__eq__N)r   r   r   r\   r   )r{   r   r   r|   ‚  s   r|   rp   rF   )
r/   r1   Úindexr3   rI   r}   r4   rb   rQ   rR   )r	   r8   r|   rK   r   )r{   r   Ú
test_indexn  s:    " zCommonTest.test_indexc             C   s`   |   ddddg¡}xHttjd ƒD ]6}t t ||¡¡}|  ||¡ |  t|ƒt|ƒ¡ q"W d S )NrA   r*   é   é   r   )	r/   r2   ÚpickleZHIGHEST_PROTOCOLÚloadsÚdumpsr1   ZassertNotEqualrq   )r	   ZlstÚprotoZlst2r   r   r   Útest_pickle˜  s
    zCommonTest.test_picklec             C   s$   t  | t| j¡ t  | t| j¡ d S )N)r   Zcheck_free_after_iteratingrn   r/   Úreversed)r	   r   r   r   Útest_free_after_iteratingŸ  s    z$CommonTest.test_free_after_iterating)r   r   r   r/   r>   r@   rL   rT   rZ   r_   rc   rd   re   rg   rh   ri   ro   rt   ry   rz   r~   r€   r‡   r‰   r   r   r   r   r%   a   s*   .%	*r%   )ZunittestrQ   rƒ   Ztestr   r   r   r   r   r   r   r   r   Ú	itertoolsr   r"   r0   r#   Úlistr$   ZTestCaser%   r   r   r   r   Ú<module>   s    	
	