a
    zeb                     @   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   sh   | j }ttdtd D ]}| t|| t| q| t|d | tt| | t|d d S N   r   )	itreversedrangenassertEqualr   nextassertRaisesStopIteration)selfr	   i r   '/usr/lib/python3.9/test/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 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 r   iterr   r   r	   r   r   r   r   r    V   s    zTestXrange.setUpNr!   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 r   r
   r   r   r	   r   r   r   r   r    [   s    zTestXrangeCustomReversed.setUpNr!   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 r   )r$   tupler   r   r	   r   r   r   r   r    `   s    zTestTuple.setUpNr!   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 r   )r   r   r   r$   r	   popr   r   dr   r   r   r    g   s    
zTestDeque.setUpNr!   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 r   )r   r   r   r
   r	   r*   r   r+   r   r   r   r    n   s    
zTestDequeReversed.setUpNr!   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 r   )dictfromkeysr   r   r$   r	   popitemr   r+   r   r   r   r    u   s    
zTestDictKeys.setUpNr!   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 r   )	r/   r0   r   r   r$   itemsr	   r1   r   r+   r   r   r   r    |   s    zTestDictItems.setUpNr!   r   r   r   r   r2   z   s   r2   c                   @   s   e Zd Zdd ZdS )TestDictValuesc                 C   s(   t tt}t| | _|j| _d S r   )	r/   r0   r   r   r$   valuesr	   r1   r   r+   r   r   r   r       s    zTestDictValues.setUpNr!   r   r   r   r   r4      s   r4   c                   @   s   e Zd Zdd ZdS )TestSetc                 C   s"   t tt}t|| _|j| _d S r   )setr   r   r$   r	   r*   r   r+   r   r   r   r       s    
zTestSet.setUpNr!   r   r   r   r   r6      s   r6   c                   @   s   e Zd Zdd Zdd ZdS )TestListc                 C   s   t tt| _d S 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    r@   r   r   r   r   r8      s   r8   c                   @   s   e Zd Zdd Zdd ZdS )TestListReversedc                 C   s   t tt| _d S 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 r9   )	r<   r   r   r
   r   r   r   r=   r>   r?   r   r   r   r@      s    
zTestListReversed.test_mutationNrA   r   r   r   r   rB      s   rB   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 NZhellor   r   r   r   r   __len__   s    zBadLen.__len__N)r   r   r   rF   rI   r   r   r   r   rC      s   rC   c                   @   s   e Zd Zdd Zdd ZdS )BadLengthHintc                 C   s   t tdS rD   rE   r   r   r   r   rF      s    zBadLengthHint.__iter__c                 C   s   t dd S rG   rH   r   r   r   r   __length_hint__   s    zBadLengthHint.__length_hint__Nr   r   r   rF   rK   r   r   r   r   rJ      s   rJ   c                   @   s   e Zd Zdd Zdd ZdS )NoneLengthHintc                 C   s   t tdS rD   rE   r   r   r   r   rF      s    zNoneLengthHint.__iter__c                 C   s   t S r   )NotImplementedr   r   r   r   rK      s    zNoneLengthHint.__length_hint__NrL   r   r   r   r   rM      s   rM   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 rD   )r   r   r<   rC   rJ   r>   	bytearrayr   )r   br   r   r   test_issue1242657   s    z*TestLengthHintExceptions.test_issue1242657c                 C   s   |  tt ttd d S rD   )r   r<   rM   r   r   r   r   r   test_invalid_hint   s    z*TestLengthHintExceptions.test_invalid_hintN)r   r   r   rR   rS   r   r   r   r   rO      s   	rO   __main__)Zunittest	itertoolsr   collectionsr   operatorr   r   r   r   ZTestCaser   r"   r%   r'   r)   r-   r.   r2   r4   r6   r8   rB   objectrC   rJ   rM   rO   r   mainr   r   r   r   <module>,   s0   	
