U
    c6{i¾  ã                   @   s–   d dd… Z ddlmZ ddlmZ ddlmZ G dd	„ d	ƒZG d
d„ dejƒZ	G dd„ dej
ƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )z$Revision: 1.3 $é   éþÿÿÿé    )Úhtb)Úunittesté   )ÚDummyConsumerc                   @   s.   e Zd ZdZeddœdd„Zedœdd„ZdS )	Ú
DummyClockr   N)ÚwhenÚreturnc                 C   s
   || _ d S ©N©Útime)Úselfr	   © r   ú9/tmp/pip-unpacked-wheel-hfbvu0bz/twisted/test/test_htb.pyÚset   s    zDummyClock.set©r
   c                 C   s   | j S r   r   ©r   r   r   r   Ú__call__   s    zDummyClock.__call__)Ú__name__Ú
__module__Ú__qualname__r   Úintr   r   r   r   r   r   r   
   s   r   c                   @   s   e Zd ZdZdZdS )Ú
SomeBucketéd   é   N)r   r   r   ZmaxburstÚrater   r   r   r   r      s   r   c                   @   s(   e Zd Zddœdd„Zddœdd„ZdS )ÚTestBucketBaseNr   c                 C   s   t j| _tƒ | _| jt _d S r   )r   r   Ú_realTimeFuncr   Úclockr   r   r   r   ÚsetUp   s    zTestBucketBase.setUpc                 C   s   | j t_d S r   )r   r   r   r   r   r   r   ÚtearDown   s    zTestBucketBase.tearDown)r   r   r   r    r!   r   r   r   r   r      s   r   c                   @   s6   e Zd Zddœdd„Zddœdd„Zddœdd„ZdS )	ÚBucketTestsNr   c                 C   s    t ƒ }| d¡}|  d|¡ dS )z1
        Testing the size of the bucket.
        éè  r   N)r   ÚaddÚassertEqual©r   ÚbÚfitr   r   r   ÚtestBucketSize$   s    
zBucketTests.testBucketSizec                 C   s6   t ƒ }| d¡}| j d¡ | d¡}|  d|¡ dS )z2
        Testing the bucket's drain rate.
        r#   é
   é   N)r   r$   r   r   r%   r&   r   r   r   ÚtestBucketDrain,   s
    

zBucketTests.testBucketDrainc                 C   sP   t ƒ }| d¡ | j d¡ | ¡ }|  |¡ | j d¡ | ¡ }|  |¡ dS )z\
        L{htb.Bucket.drip} returns C{True} if the bucket is empty after that drip.
        r+   é	   r*   N)r   r$   r   r   ZdripZassertFalseÚ
assertTrue)r   r'   Úemptyr   r   r   Útest_bucketEmpty6   s    

zBucketTests.test_bucketEmpty)r   r   r   r)   r,   r0   r   r   r   r   r"   #   s   
r"   c                   @   s6   e Zd Zddœdd„Zddœdd„Zddœdd„ZdS )	ÚBucketNestingTestsNr   c                 C   s.   t  | ¡ tƒ | _t| jƒ| _t| jƒ| _d S r   )r   r    r   ÚparentÚchild1Úchild2r   r   r   r   r    E   s    
zBucketNestingTests.setUpc                 C   s(   | j  d¡ | j d¡}|  d|¡ d S )NéZ   r*   )r3   r$   r4   r%   ©r   r(   r   r   r   ÚtestBucketParentSizeK   s    z'BucketNestingTests.testBucketParentSizec                 C   s<   d| j _| j d¡ | j d¡ | j d¡}|  d|¡ d S )Nr   r   r*   )r2   r   r3   r$   r   r   r%   r6   r   r   r   ÚtestBucketParentRateQ   s
    z'BucketNestingTests.testBucketParentRate)r   r   r   r    r7   r8   r   r   r   r   r1   D   s   r1   c                   @   s6   e Zd Zddœdd„Zddœdd„Zddœdd„ZdS )	ÚConsumerShaperTestsNr   c                 C   s0   t  | ¡ tƒ | _tƒ | _t | j| j¡| _d S r   )	r   r    r   Ú
underlyingr   Úbucketr   ZShapedConsumerÚshapedr   r   r   r   r    c   s    
zConsumerShaperTests.setUpc                 C   sT   d}| j  d¡ | j d¡ | j |¡ | j ¡  |  t| j	 
¡ ƒ|| j j ¡ d S )Nr*   r   Zdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r;   r$   r<   Úwriter   r   ZresumeProducingr%   Úlenr:   Úgetvaluer   )r   Zdelta_tr   r   r   ÚtestRatei   s    
zConsumerShaperTests.testRatec                 C   s.   |   | jjd¡ | j ¡  |   | jjd¡ d S )Nr   r   )r%   r;   Z	_refcountr<   ZstopProducingr   r   r   r   ÚtestBucketRefss   s    
z"ConsumerShaperTests.testBucketRefs)r   r   r   r    r@   rA   r   r   r   r   r9   b   s   
r9   N)Ú__version__Ztwisted.protocolsr   Ztwisted.trialr   Ztest_pcpr   r   ZBucketr   ZTestCaser   r"   r1   r9   r   r   r   r   Ú<module>   s   

!