B
    u9ab                 @   s  d dl Z d dlmZ d dlmZ d dlmZ dZG dd dZG dd	 d	e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	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e j
ZG d d! d!ee j
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
Zed*kre   dS )+    N)repeat)deque)length_hint
   c               @   s   e Zd Zdd ZdS )TestInvariantWithoutMutationsc             C   sl   | j }x2ttdtd D ]}| t|| t| qW | t|d | tt| | t|d d S )N   r   )	itreversedrangenassertEqualr   nextassertRaisesStopIteration)selfr   i r   "/usr/lib/python3.7/test_iterlen.pytest_invariant6   s    z,TestInvariantWithoutMutations.test_invariantN)__name__
__module____qualname__r   r   r   r   r   r   4   s   r   c               @   s   e Zd Zdd ZdS )TestTemporarilyImmutablec             C   s\   | j }| t|t t| | t|td  |   | tt| | t|d d S )Nr   r   )r   r   r   r   r   mutater   RuntimeError)r   r   r   r   r   test_immutable_during_iterationA   s    z8TestTemporarilyImmutable.test_immutable_during_iterationN)r   r   r   r   r   r   r   r   r   ?   s   r   c               @   s   e Zd Zdd ZdS )
TestRepeatc             C   s   t d t| _d S )N)r   r   r   )r   r   r   r   setUpQ   s    zTestRepeat.setUpN)r   r   r   r   r   r   r   r   r   O   s   r   c               @   s   e Zd Zdd ZdS )
TestXrangec             C   s   t tt| _d S )N)iterr
   r   r   )r   r   r   r   r   V   s    zTestXrange.setUpN)r   r   r   r   r   r   r   r   r   T   s   r   c               @   s   e Zd Zdd ZdS )TestXrangeCustomReversedc             C   s   t tt| _d S )N)r	   r
   r   r   )r   r   r   r   r   [   s    zTestXrangeCustomReversed.setUpN)r   r   r   r   r   r   r   r   r    Y   s   r    c               @   s   e Zd Zdd ZdS )	TestTuplec             C   s   t ttt| _d S )N)r   tupler
   r   r   )r   r   r   r   r   `   s    zTestTuple.setUpN)r   r   r   r   r   r   r   r   r!   ^   s   r!   c               @   s   e Zd Zdd ZdS )	TestDequec             C   s"   t tt}t|| _|j| _d S )N)r   r
   r   r   r   popr   )r   dr   r   r   r   g   s    
zTestDeque.setUpN)r   r   r   r   r   r   r   r   r#   e   s   r#   c               @   s   e Zd Zdd ZdS )TestDequeReversedc             C   s"   t tt}t|| _|j| _d S )N)r   r
   r   r	   r   r$   r   )r   r%   r   r   r   r   n   s    
zTestDequeReversed.setUpN)r   r   r   r   r   r   r   r   r&   l   s   r&   c               @   s   e Zd Zdd ZdS )TestDictKeysc             C   s$   t tt}t|| _|j| _d S )N)dictfromkeysr
   r   r   r   popitemr   )r   r%   r   r   r   r   u   s    
zTestDictKeys.setUpN)r   r   r   r   r   r   r   r   r'   s   s   r'   c               @   s   e Zd Zdd ZdS )TestDictItemsc             C   s(   t tt}t| | _|j| _d S )N)	r(   r)   r
   r   r   itemsr   r*   r   )r   r%   r   r   r   r   |   s    zTestDictItems.setUpN)r   r   r   r   r   r   r   r   r+   z   s   r+   c               @   s   e Zd Zdd ZdS )TestDictValuesc             C   s(   t tt}t| | _|j| _d S )N)	r(   r)   r
   r   r   valuesr   r*   r   )r   r%   r   r   r   r      s    zTestDictValues.setUpN)r   r   r   r   r   r   r   r   r-      s   r-   c               @   s   e Zd Zdd ZdS )TestSetc             C   s"   t tt}t|| _|j| _d S )N)setr
   r   r   r   r$   r   )r   r%   r   r   r   r      s    
zTestSet.setUpN)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 )TestListc             C   s   t tt| _d S )N)r   r
   r   r   )r   r   r   r   r      s    zTestList.setUpc             C   s   t tt}t|}t| t| | t|td  |t | t|td  g |dd < | t|d | t |g  |td | t|d d S )N   r   r      )	listr
   r   r   r   r   r   appendextend)r   r%   r   r   r   r   test_mutation   s    
zTestList.test_mutationN)r   r   r   r   r7   r   r   r   r   r1      s   r1   c               @   s   e Zd Zdd Zdd ZdS )TestListReversedc             C   s   t tt| _d S )N)r	   r
   r   r   )r   r   r   r   r      s    zTestListReversed.setUpc             C   s   t tt}t|}t| t| | t|td  |t | t|td  g |dd < | t|d | t |g  |td | t|d d S )Nr2   r   r   r3   )	r4   r
   r   r	   r   r   r   r5   r6   )r   r%   r   r   r   r   r7      s    
zTestListReversed.test_mutationN)r   r   r   r   r7   r   r   r   r   r8      s   r8   c               @   s   e Zd Zdd Zdd ZdS )BadLenc             C   s   t tdS )Nr   )r   r
   )r   r   r   r   __iter__   s    zBadLen.__iter__c             C   s   t dd S )Nhello)r   )r   r   r   r   __len__   s    zBadLen.__len__N)r   r   r   r:   r<   r   r   r   r   r9      s   r9   c               @   s   e Zd Zdd Zdd ZdS )BadLengthHintc             C   s   t tdS )Nr   )r   r
   )r   r   r   r   r:      s    zBadLengthHint.__iter__c             C   s   t dd S )Nr;   )r   )r   r   r   r   __length_hint__   s    zBadLengthHint.__length_hint__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 )NoneLengthHintc             C   s   t tdS )Nr   )r   r
   )r   r   r   r   r:      s    zNoneLengthHint.__iter__c             C   s   t S )N)NotImplemented)r   r   r   r   r>      s    zNoneLengthHint.__length_hint__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 )TestLengthHintExceptionsc             C   sx   |  ttt  |  ttt  |  tg jt  |  tg jt  ttd}|  t|jt  |  t|jt  d S )Nr   )r   r   r4   r9   r=   r6   	bytearrayr
   )r   br   r   r   test_issue1242657   s    z*TestLengthHintExceptions.test_issue1242657c             C   s   |  tt ttd d S )Nr   )r   r4   r?   r
   )r   r   r   r   test_invalid_hint   s    z*TestLengthHintExceptions.test_invalid_hintN)r   r   r   rD   rE   r   r   r   r   rA      s   	rA   __main__)Zunittest	itertoolsr   collectionsr   operatorr   r   r   r   ZTestCaser   r   r    r!   r#   r&   r'   r+   r-   r/   r1   r8   objectr9   r=   r?   rA   r   mainr   r   r   r   <module>,   s0   	
