U
    ¹êW[ï“ ã                   @   sÎ  d Z ddlmZmZ ddlZddlZddlZddlZddlm	Z	 e	r^ddl
mZmZmZ dZndZddlmZmZ ddlmZmZ dd	lmZ dd
lmZ G dd„ deƒZdd„ Zdd„ ZG dd„ deƒZG dd„ dejƒZ G dd„ dej!eƒZ"G dd„ dej!ƒZ#G dd„ dej!ƒZ$G dd„ dej!ƒZ%G dd„ dej!ƒZ&G dd „ d ej!ƒZ'G d!d"„ d"ej!eƒZ(G d#d$„ d$ejƒZ)d%d&„ Z*G d'd(„ d(ej!ƒZ+G d)d*„ d*ejƒZ,G d+d,„ d,ejeƒZ-d-d.„ Z.G d/d0„ d0ejƒZ/dS )1z+
Test cases for L{twisted.internet.defer}.
é    )ÚdivisionÚabsolute_importN)Ú_PY3)Únew_event_loopÚFutureÚCancelledErrorz'asyncio not available before python 3.4)ÚfailureÚlog)ÚdeferÚreactor)ÚClock)Úunittestc                   @   s   e Zd ZdS )ÚGenericErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú9/usr/lib/python3/dist-packages/twisted/test/test_defer.pyr      s   r   c                  O   s*   zdd  W n   t j| |Ž}Y nX |S )zÊ
    Make a L{failure.Failure} of a divide-by-zero error.

    @param args: Any C{*args} are passed to Failure's constructor.
    @param kwargs: Any C{**kwargs} are passed to Failure's constructor.
    é   r   )r   ÚFailure)ÚargsÚkwargsÚfr   r   r   ÚgetDivisionFailure$   s
    r   c                 C   s   |   d¡ dS )z¿
    A fake L{defer.Deferred} canceller which callbacks the L{defer.Deferred}
    with C{str} "Callback Result" when cancelling it.

    @param deferred: The cancelled L{defer.Deferred}.
    úCallback ResultN©Úcallback©Údeferredr   r   r   ÚfakeCallbackCanceller3   s    r   c                   @   s   e Zd ZdZdd„ ZdS )ÚImmediateFailureMixinz+
    Add additional assertion methods.
    c                 C   s>   g }|  |j¡ |  t|ƒd¡ |  |d  |¡¡ |d jS )z¨
        Assert that the given Deferred current result is a Failure with the
        given exception.

        @return: The exception instance in the Deferred.
        r   r   )Ú
addErrbackÚappendÚassertEqualÚlenÚ
assertTrueÚcheckÚvalue)Úselfr   Ú	exceptionÚfailuresr   r   r   ÚassertImmediateFailureC   s
    z,ImmediateFailureMixin.assertImmediateFailureN)r   r   r   Ú__doc__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 )	Ú	UtilTestsz&
    Tests for utility functions.
    c                 C   s0   t  tƒ ¡}t |¡}|  t¡ |  ||¡ dS )z<
        L{defer.logError} returns the given error.
        N)r   r   ÚRuntimeErrorr
   ÚlogErrorÚflushLoggedErrorsÚassertIs)r(   ÚerrorÚresultr   r   r   Útest_logErrorReturnsErrorW   s    

z#UtilTests.test_logErrorReturnsErrorc                 C   s2   t  tƒ ¡}t |¡ |  t¡}|  ||g¡ dS )z9
        L{defer.logError} logs the given error.
        N)r   r   r.   r
   r/   r0   r#   )r(   r2   Úerrorsr   r   r   Útest_logErrorLogsErrorb   s    

z UtilTests.test_logErrorLogsErrorc                    sR   g ‰ ‡ fdd„}t  |¡ t tƒ ¡}t |¡ |  t¡ |  ˆ d  	d¡¡ dS )zR
        The text logged by L{defer.logError} has no repr of the failure.
        c                    s   ˆ   t | ¡¡ d S ©N)r"   r	   ÚtextFromEventDict)Z	eventDict©Úoutputr   r   Úemits   s    z4UtilTests.test_logErrorLogsErrorNoRepr.<locals>.emitr   úUnhandled Error
Traceback N)
r	   ÚaddObserverr   r   r.   r
   r/   r0   r%   Ú
startswith)r(   r;   r2   r   r9   r   Útest_logErrorLogsErrorNoReprm   s    


z&UtilTests.test_logErrorLogsErrorNoReprN)r   r   r   r,   r4   r6   r?   r   r   r   r   r-   R   s   r-   c                   @   s4  e 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)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$dEdF„ Z%dGdH„ Z&dIdJ„ Z'dKdL„ Z(dMdN„ Z)dOdP„ Z*dQdR„ Z+dSdT„ Z,dUdV„ Z-dWdX„ Z.dYdZ„ Z/d[d\„ Z0d]d^„ Z1d_d`„ Z2dadb„ Z3dcdd„ Z4dedf„ Z5dgdh„ Z6didj„ Z7dkdl„ Z8dmdn„ Z9dodp„ Z:dqdr„ Z;dsdt„ Z<dudv„ Z=dwdx„ Z>dydz„ Z?d{d|„ Z@d}d~„ ZAdd€„ ZBdd‚„ ZCdƒd„„ ZDd…d†„ ZEd‡dˆ„ ZFd‰dŠ„ ZGd‹S )ŒÚDeferredTestsc                 C   s(   d | _ d | _d | _|  tjt ¡ ¡ d S r7   )ÚcallbackResultsÚerrbackResultsÚcallback2ResultsÚ
addCleanupr
   ÚsetDebuggingÚgetDebugging©r(   r   r   r   ÚsetUp‚   s    zDeferredTests.setUpc                 O   s   ||f| _ |d S ©Nr   ©rA   ©r(   r   Úkwr   r   r   Ú	_callback‰   s    
zDeferredTests._callbackc                 O   s   ||f| _ d S r7   ©rC   rK   r   r   r   Ú
_callback2   s    zDeferredTests._callback2c                 O   s   ||f| _ d S r7   ©rB   rK   r   r   r   Ú_errback   s    zDeferredTests._errbackc                 C   s@   t  ¡ }| | j¡ | d¡ |  | j¡ |  | jdi f¡ d S ©NÚhello©rS   ©	r
   ÚDeferredÚaddCallbackrM   r   ÚassertIsNonerB   r#   rA   ©r(   r   r   r   r   ÚtestCallbackWithoutArgs“   s
    
z%DeferredTests.testCallbackWithoutArgsc                 C   sB   t  ¡ }| | jd¡ | d¡ |  | j¡ |  | jdi f¡ d S )NÚworldrS   )rS   r[   rU   rY   r   r   r   ÚtestCallbackWithArgsš   s
    
z"DeferredTests.testCallbackWithArgsc                 C   sH   t  ¡ }|j| jdd | d¡ |  | j¡ |  | jdddif¡ d S )Nr[   )r[   rS   rT   rU   rY   r   r   r   ÚtestCallbackWithKwArgs¡   s    

ÿz$DeferredTests.testCallbackWithKwArgsc                 C   s^   t  ¡ }| | j¡ | | j¡ | d¡ |  | j¡ |  | j	di f¡ |  | j
di f¡ d S rR   )r
   rV   rW   rM   rO   r   rX   rB   r#   rA   rC   rY   r   r   r   ÚtestTwoCallbacks©   s    
ÿÿzDeferredTests.testTwoCallbacksc                 C   sÈ   t  ¡ }t  ¡ }t  ¡ }t  |||g¡}g }|fdd„}dd„ }| ||¡ | d¡ | |¡ | tdƒ¡ | d¡ |  |d |d	 d t	|d	 d	 j
ƒf|d
 gt jdft jdft jdfg¡ d S )Nc                 S   s   |  | ¡ d S r7   )Úextend©Z
resultListr3   r   r   r   Úcbº   s    z*DeferredTests.testDeferredList.<locals>.cbc                 S   s   d S r7   r   ©Úerrr   r   r   Úcatch¼   s    z-DeferredTests.testDeferredList.<locals>.catchÚ1Ú2Ú3r   r   é   )r
   rV   ÚDeferredListÚaddCallbacksr   r!   Úerrbackr   r#   Ústrr'   ÚSUCCESSÚFAILURE)r(   Údefr1Údefr2Údefr3Údlr3   ra   rd   r   r   r   ÚtestDeferredList´   s*    



ýþûzDeferredTests.testDeferredListc                 C   sf   g }|fdd„}t  g ¡}| |¡ |  |g g¡ g |d d …< t jg dd}| |¡ |  |g ¡ d S )Nc                 S   s   |  | ¡ d S r7   ©r"   r`   r   r   r   ra   Ô   s    z/DeferredTests.testEmptyDeferredList.<locals>.cbr   ©ZfireOnOneCallback)r
   ri   rj   r#   )r(   r3   ra   rr   r   r   r   ÚtestEmptyDeferredListÒ   s    


z#DeferredTests.testEmptyDeferredListc           	      C   sâ   t  ¡ }t  ¡ }t  ¡ }t j|||gdd}g }| |j¡ dd„ }| |¡ | d¡ |  |g ¡ | tdƒ¡ |  t	|ƒd¡ |d }|  
t|jt jƒd|jf ¡ |j}|  |jjt¡ |  |jjjd	¡ |  |jd¡ d S )
Nr   ©ZfireOnOneErrbackc                 S   s   d S r7   r   rb   r   r   r   rd   ê   s    z;DeferredTests.testDeferredListFireOnOneError.<locals>.catchre   ú	from def2r   zHissubclass(aFailure.type, defer.FirstError) failed: failure's type is %r)rx   )r
   rV   ri   r!   r"   r   r#   rk   r   r$   r%   Ú
issubclassÚtypeÚ
FirstErrorr'   Ú
subFailurer   Úindex)	r(   ro   rp   rq   rr   r3   rd   ZaFailureÚ
firstErrorr   r   r   ÚtestDeferredListFireOnOneErrorà   s,    

ÿÿz,DeferredTests.testDeferredListFireOnOneErrorc                 C   sŽ   t  ¡ }t  |g¡}g }| |j¡ g }| |j¡ | tdƒ¡ |  d|d j	j
d ¡ |  dt|ƒ¡ |  d|d d d j	j
d ¡ d S )NÚBangr   r   )r
   rV   ri   r!   r"   rW   rk   r   r#   r'   r   r$   ©r(   Úd1rr   Z	errorTrapr3   r   r   r   Ú!testDeferredListDontConsumeErrors  s    z/DeferredTests.testDeferredListDontConsumeErrorsc                 C   s†   t  ¡ }t j|gdd}g }| |j¡ g }| |j¡ | tdƒ¡ |  g |¡ |  dt	|ƒ¡ |  d|d d d j
jd ¡ d S )NT©ZconsumeErrorsr€   r   r   )r
   rV   ri   r!   r"   rW   rk   r   r#   r$   r'   r   r   r   r   r   ÚtestDeferredListConsumeErrors  s    z+DeferredTests.testDeferredListConsumeErrorsc                 C   sb   t  ¡ }t  ¡ }| tdƒ¡ t j||gdd}g }| |j¡ |  dt|ƒ¡ | dd„ ¡ d S )Nr€   Trw   r   c                 S   s   d S r7   r   ©Úer   r   r   Ú<lambda>2  ó    zWDeferredTests.testDeferredListFireOnOneErrorWithAlreadyFiredDeferreds.<locals>.<lambda>)	r
   rV   rk   r   ri   r!   r"   r#   r$   ©r(   r‚   Úd2rr   r3   r   r   r   Ú7testDeferredListFireOnOneErrorWithAlreadyFiredDeferreds&  s    zEDeferredTests.testDeferredListFireOnOneErrorWithAlreadyFiredDeferredsc                 C   sh   t  ¡ }t  ¡ }| tdƒ¡ | d¡ t  ||g¡}g }| |j¡ |  dt	|ƒ¡ | 
dd„ ¡ d S )Nr€   rh   r   c                 S   s   d S r7   r   r†   r   r   r   rˆ   C  r‰   zIDeferredTests.testDeferredListWithAlreadyFiredDeferreds.<locals>.<lambda>)r
   rV   rk   r   r   ri   rW   r"   r#   r$   r!   rŠ   r   r   r   Ú)testDeferredListWithAlreadyFiredDeferreds4  s    
z7DeferredTests.testDeferredListWithAlreadyFiredDeferredsc                 C   sF   t  ¡ }t  ¡ }t  ||g¡}| ¡  |  |t j¡ |  |t j¡ dS )zw
        When cancelling an unfired L{defer.DeferredList}, cancel every
        L{defer.Deferred} in the list.
        N©r
   rV   ri   ÚcancelÚfailureResultOfr   ©r(   ÚdeferredOneÚdeferredTwoÚdeferredListr   r   r   Útest_cancelDeferredListF  s    z%DeferredTests.test_cancelDeferredListc                 C   s–   t  t¡}t  ¡ }t  ||g¡}| ¡  |  |t j¡ |  |¡}|  |d d ¡ |  	|d d d¡ |  
|d d ¡ |  |d d  t j¡¡ dS )zø
        When cancelling an unfired L{defer.DeferredList} without the
        C{fireOnOneCallback} and C{fireOnOneErrback} flags set, the
        L{defer.DeferredList} will be callback with a C{list} of
        (success, result) C{tuple}s.
        r   r   r   N)r
   rV   r   ri   r   r   r   ÚsuccessResultOfr%   r#   ÚassertFalser&   ©r(   r’   r“   r”   r3   r   r   r   Útest_cancelDeferredListCallbackS  s    

z-DeferredTests.test_cancelDeferredListCallbackc                 C   sJ   t  ¡ }t  ¡ }t j||gdd}| ¡  |  |t j¡ |  |t j¡ dS )zž
        When cancelling an unfired L{defer.DeferredList} with the flag
        C{fireOnOneCallback} set, cancel every L{defer.Deferred} in the list.
        Tru   NrŽ   r‘   r   r   r   Ú,test_cancelDeferredListWithFireOnOneCallbackf  s    
ÿz:DeferredTests.test_cancelDeferredListWithFireOnOneCallbackc                 C   sT   t  t¡}t  ¡ }t j||gdd}| ¡  |  |t j¡ |  |¡}|  |d¡ dS )a,  
        When cancelling an unfired L{defer.DeferredList} with the flag
        C{fireOnOneCallback} set, if one of the L{defer.Deferred} callbacks
        in its canceller, the L{defer.DeferredList} will callback with the
        result and the index of the L{defer.Deferred} in a C{tuple}.
        Tru   )r   r   N)	r
   rV   r   ri   r   r   r   r–   r#   r˜   r   r   r   Ú?test_cancelDeferredListWithFireOnOneCallbackAndDeferredCallbackt  s    

ÿ
zMDeferredTests.test_cancelDeferredListWithFireOnOneCallbackAndDeferredCallbackc                 C   sr   t  ¡ }t  ¡ }t j||gdd}| ¡  |  |t j¡ |  |t j¡ |  |t j¡}|j}|  |j	 
t j¡¡ dS )z
        When cancelling an unfired L{defer.DeferredList} with the flag
        C{fireOnOneErrback} set, cancel every L{defer.Deferred} in the list.
        Trw   N)r
   rV   ri   r   r   r   r{   r'   r%   r|   r&   )r(   r’   r“   r”   ZdeferredListFailurer~   r   r   r   Ú+test_cancelDeferredListWithFireOnOneErrback…  s    
ÿÿz9DeferredTests.test_cancelDeferredListWithFireOnOneErrbackc                 C   sˆ   t  t¡}t  t¡}t j||gdd}| ¡  |  |¡}|  |d d ¡ |  |d d d¡ |  |d d ¡ |  |d d d¡ dS )a  
        When cancelling an unfired L{defer.DeferredList} with the flag
        C{fireOnOneErrback} set, if all the L{defer.Deferred} callbacks
        in its canceller, the L{defer.DeferredList} will callback with a
        C{list} of (success, result) C{tuple}s.
        Trw   r   r   r   N)r
   rV   r   ri   r   r–   r%   r#   r˜   r   r   r   Ú?test_cancelDeferredListWithFireOnOneErrbackAllDeferredsCallback—  s    


ÿ
zMDeferredTests.test_cancelDeferredListWithFireOnOneErrbackAllDeferredsCallbackc                 C   sf   t  ¡ }t  ¡ }||g}t  |¡}t  ¡ }| |¡ | ¡  |  |t j¡ |  |t j¡ |  |¡ dS )zs
        Cancelling a L{defer.DeferredList} will cancel the original
        L{defer.Deferred}s passed in.
        N)r
   rV   ri   r"   r   r   r   ÚassertNoResult)r(   r’   r“   ZargumentListr”   ZdeferredThreer   r   r   Ú,test_cancelDeferredListWithOriginalDeferredsª  s    

z:DeferredTests.test_cancelDeferredListWithOriginalDeferredsc                 C   s\   dd„ }t  |¡}t  ¡ }t  ||g¡}| ¡  |  |t j¡ |  t¡}|  t	|ƒd¡ dS )zÀ
        Cancelling a L{defer.DeferredList} will cancel every L{defer.Deferred}
        in the list even exceptions raised from the C{cancel} method of the
        L{defer.Deferred}s.
        c                 S   s   t dƒ‚dS )z
            A L{defer.Deferred} canceller that raises an exception.

            @param deferred: The cancelled L{defer.Deferred}.
            ÚtestN)r.   r   r   r   r   ÚcancellerRaisesExceptionÁ  s    zTDeferredTests.test_cancelDeferredListWithException.<locals>.cancellerRaisesExceptionr   N)
r
   rV   ri   r   r   r   r0   r.   r#   r$   )r(   r¡   r’   r“   r”   r5   r   r   r   Ú$test_cancelDeferredListWithException»  s    

z2DeferredTests.test_cancelDeferredListWithExceptionc                 C   sB   t  ¡ }t  ¡ }t j||gdd}| d¡ | ¡  |  |¡ dS )zî
        When a L{defer.DeferredList} has fired because one L{defer.Deferred} in
        the list fired with a non-failure result, the cancellation will do
        nothing instead of cancelling the rest of the L{defer.Deferred}s.
        Tru   N)r
   rV   ri   r   r   rž   r‘   r   r   r   Ú)test_cancelFiredOnOneCallbackDeferredListÑ  s    
ÿ
z7DeferredTests.test_cancelFiredOnOneCallbackDeferredListc                 C   s`   t  ¡ }t  ¡ }t j||gdd}| tdƒ¡ | ¡  |  |¡ |  |t¡ |  |t j¡ dS )zê
        When a L{defer.DeferredList} has fired because one L{defer.Deferred} in
        the list fired with a failure result, the cancellation will do
        nothing instead of cancelling the rest of the L{defer.Deferred}s.
        Trw   r    N)	r
   rV   ri   rk   r   r   rž   r   r{   r‘   r   r   r   Ú(test_cancelFiredOnOneErrbackDeferredListà  s    
ÿ
z6DeferredTests.test_cancelFiredOnOneErrbackDeferredListc                 C   s,   g }t  d¡}| |j¡ |  |dg¡ d S )NÚsuccess)r
   ÚsucceedrW   r"   r#   ©r(   ÚlÚdr   r   r   ÚtestImmediateSuccessñ  s    
z"DeferredTests.testImmediateSuccessc                 C   s8   g }t  tdƒ¡}| |j¡ |  t|d jƒd¡ d S ©NÚfailr   )r
   r¬   r   r!   r"   r#   rl   r'   r§   r   r   r   ÚtestImmediateFailureø  s    z"DeferredTests.testImmediateFailurec                 C   sT   g }t  tdƒ¡}| ¡  | |j¡ |  |g ¡ | ¡  |  t|d j	ƒd¡ d S r«   )
r
   r¬   r   Úpauser!   r"   r#   Úunpauserl   r'   r§   r   r   r   ÚtestPausedFailureþ  s    zDeferredTests.testPausedFailurec                 C   sx   g }t  ¡  dd„ ¡ |j¡}| d¡ |  |d jt¡ g }t  ¡  dd„ ¡ |j¡}| d¡ |  |d jt¡ d S )Nc                 S   s   dd S ©Nr   r   r   ©Ú_r   r   r   rˆ   	  r‰   z2DeferredTests.testCallbackErrors.<locals>.<lambda>r   r   c                 S   s   t  tƒ ¡S r7   )r   r   ÚZeroDivisionErrorr²   r   r   r   rˆ     r‰   )	r
   rV   rW   r!   r"   r   ÚassertIsInstancer'   r´   r§   r   r   r   ÚtestCallbackErrors  s    
ÿÿ
z DeferredTests.testCallbackErrorsc                 C   s(   t  ¡ }| ¡  | | j¡ | ¡  d S r7   )r
   rV   r®   rW   rM   r¯   ©r(   r©   r   r   r   ÚtestUnpauseBeforeCallback  s    z'DeferredTests.testUnpauseBeforeCallbackc                 C   sœ   t  ¡ }t  ¡ }| ¡  | |fdd„¡ | | j¡ | d¡ | jd ksRtdƒ‚| d¡ | jd ksntdƒ‚| ¡  | jd d dks˜td| jf ƒ‚d S )	Nc                 S   s   |S r7   r   )Úrr‹   r   r   r   rˆ     r‰   z2DeferredTests.testReturnDeferred.<locals>.<lambda>r   z Should not have been called yet.rh   z&Still should not have been called yet.r   z/Result should have been from second deferred:%s)	r
   rV   r®   rW   rM   r   rA   ÚAssertionErrorr¯   ©r(   r©   r‹   r   r   r   ÚtestReturnDeferred  s    

z DeferredTests.testReturnDeferredc                    sz   t ƒ }t ¡ ‰ ˆ  |¡ ˆ  ¡  t ¡ }| ‡ fdd„¡ | d¡ g }| |j¡ |  |g ¡ ˆ  ¡  |  ||g¡ dS )zÃ
        When a paused Deferred with a result is returned from a callback on
        another Deferred, the other Deferred is chained to the first and waits
        for it to be unpaused.
        c                    s   ˆ S r7   r   ©Úignored©Zpausedr   r   rˆ   1  r‰   zDDeferredTests.test_chainedPausedDeferredWithResult.<locals>.<lambda>N)	Úobjectr
   rV   r   r®   rW   r"   r#   r¯   )r(   ÚexpectedZchainedr3   r   r¿   r   Ú$test_chainedPausedDeferredWithResult&  s    

z2DeferredTests.test_chainedPausedDeferredWithResultc                    s`   t  ¡ }t  ¡ ‰ | ‡ fdd„¡ | d¡ | ¡  ˆ  d¡ g }ˆ  |j¡ |  |dg¡ dS )z½
        A paused Deferred encountered while pushing a result forward through a
        chain does not prevent earlier Deferreds from continuing to execute
        their callbacks.
        c                    s   ˆ S r7   r   r½   ©Úsecondr   r   rˆ   C  r‰   z:DeferredTests.test_pausedDeferredChained.<locals>.<lambda>N)r
   rV   rW   r   r®   r"   r#   )r(   Úfirstr3   r   rÃ   r   Útest_pausedDeferredChained;  s    

z(DeferredTests.test_pausedDeferredChainedc                 C   sœ   g }t  t  d¡t  d¡g¡ |j¡ |  |ddgg¡ g }t  d¡t  tƒ ¡g}t  |¡ |j¡ |  t	|ƒd¡ |  
|d tj¡ |d  dd„ ¡ d S )Nr   rh   r   c                 S   s   dS ©Nr   r   r†   r   r   r   rˆ   X  r‰   z2DeferredTests.test_gatherResults.<locals>.<lambda>)r
   ÚgatherResultsr¦   rW   r"   r#   r¬   Ú
ValueErrorr!   r$   rµ   r   r   )r(   r¨   rr   r   r   r   Útest_gatherResultsL  s    "z DeferredTests.test_gatherResultsc                 C   s”   t  d¡}t  tdƒ¡}t j||gdd}g }| |j¡ g }| |j¡ |  t|ƒt|ƒfd¡ |  	|d j
t j¡ |d j
j}|  	|j
t¡ dS )zÒ
        If a L{Deferred} in the list passed to L{gatherResults} fires with a
        failure and C{consumerErrors} is C{True}, the failure is converted to a
        L{None} result on that L{Deferred}.
        r   zoh noesTr„   ©r   r   r   N)r
   r¦   r¬   r.   rÈ   r!   r"   r#   r$   rµ   r'   r{   r|   )r(   ZdgoodZdbadr©   ZunconsumedErrorsZgatheredErrorsr~   r   r   r   Ú#test_gatherResultsWithConsumeErrors[  s    
ÿz1DeferredTests.test_gatherResultsWithConsumeErrorsc                 C   sn   t  ¡ }t  ¡ }t  ||g¡}| ¡  |  |t j¡ |  |t j¡ |  |t j¡}|j}|  |j	 
t j¡¡ dS )z„
        When cancelling the L{defer.gatherResults} call, all the
        L{defer.Deferred}s in the list will be cancelled.
        N)r
   rV   rÈ   r   r   r   r{   r'   r%   r|   r&   )r(   r’   r“   r3   ZgatherResultsFailurer~   r   r   r   Útest_cancelGatherResultsq  s    z&DeferredTests.test_cancelGatherResultsc                 C   sX   t  t¡}t  t¡}t  ||g¡}| ¡  |  |¡}|  |d d¡ |  |d d¡ dS )a  
        When cancelling the L{defer.gatherResults} call, if all the
        L{defer.Deferred}s callback in their canceller, the L{defer.Deferred}
        returned by L{defer.gatherResults} will be callbacked with the C{list}
        of the results.
        r   r   r   N)r
   rV   r   rÈ   r   r–   r#   )r(   r’   r“   r3   ZcallbackResultr   r   r   Ú0test_cancelGatherResultsWithAllDeferredsCallback  s    


z>DeferredTests.test_cancelGatherResultsWithAllDeferredsCallbackc                 C   sH   g g  }}t  dd„ d¡}| |j|j¡ |  |g ¡ |  |dg¡ dS )z•
        L{defer.maybeDeferred} should retrieve the result of a synchronous
        function and pass it to its resulting L{defer.Deferred}.
        c                 S   s   | d S ©Né   r   ©Úxr   r   r   rˆ   —  r‰   z6DeferredTests.test_maybeDeferredSync.<locals>.<lambda>é
   é   N)r
   ÚmaybeDeferredrj   r"   r#   )r(   ÚSÚEr©   r   r   r   Útest_maybeDeferredSync‘  s
    
z$DeferredTests.test_maybeDeferredSyncc              
   C   s˜   g g  }}zdd  W n* t k
r@ } zt|ƒ}W 5 d}~X Y nX t dd„ d¡}| |j|j¡ |  |g ¡ |  t|ƒd¡ |  t|d jƒ|¡ dS )z
        L{defer.maybeDeferred} should catch exception raised by a synchronous
        function and errback its resulting L{defer.Deferred} with it.
        Z10rÐ   Nc                 S   s   | d S rÏ   r   rÑ   r   r   r   rˆ   §  r‰   z;DeferredTests.test_maybeDeferredSyncError.<locals>.<lambda>r   r   )	Ú	TypeErrorrl   r
   rÕ   rj   r"   r#   r$   r'   )r(   rÖ   r×   r‡   rÁ   r©   r   r   r   Útest_maybeDeferredSyncError  s    
z)DeferredTests.test_maybeDeferredSyncErrorc                    sF   t  ¡ ‰ t  ‡ fdd„¡}ˆ  d¡ g }| |j¡ |  |dg¡ dS )zƒ
        L{defer.maybeDeferred} should let L{defer.Deferred} instance pass by
        so that original result is the same.
        c                      s   ˆ S r7   r   r   ©r©   r   r   rˆ   ´  r‰   z7DeferredTests.test_maybeDeferredAsync.<locals>.<lambda>ZSuccessN)r
   rV   rÕ   r   rW   r"   r#   )r(   r‹   r3   r   rÛ   r   Útest_maybeDeferredAsync®  s    
z%DeferredTests.test_maybeDeferredAsyncc                    s<   t  ¡ ‰ t  ‡ fdd„¡}ˆ  t tƒ ¡¡ |  |t¡ dS )z°
        L{defer.maybeDeferred} should let L{defer.Deferred} instance pass by
        so that L{failure.Failure} returned by the original instance is the
        same.
        c                      s   ˆ S r7   r   r   rÛ   r   r   rˆ   Â  r‰   z<DeferredTests.test_maybeDeferredAsyncError.<locals>.<lambda>N)r
   rV   rÕ   rk   r   r   r.   r+   )r(   r‹   r   rÛ   r   Útest_maybeDeferredAsyncError»  s    z*DeferredTests.test_maybeDeferredAsyncErrorc                    s†   g ‰g ‰ t  ¡ ‰‡ ‡‡fdd„}t  d¡}| |¡ ˆ d¡ | ˆj¡ ˆ ˆ j¡ | ˆ j¡ |  g ˆ ¡ |  ˆddddg¡ d	S )
a  
        When a L{Deferred} encounters a result which is another L{Deferred}
        which is waiting on a third L{Deferred}, the middle L{Deferred}'s
        callbacks are executed after the third L{Deferred} fires and before the
        first receives a result.
        c                    sR   ˆ  d| f¡ t d¡}‡‡fdd„}‡fdd„}| |¡ |¡ | ˆ j ¡ |S )Nústart-of-cbÚinnerc                    s   ˆ  d¡ ˆ S ©N©ÚfirstCallbackrß   rt   ©r3   ©rß   Úresultsr   r   râ   Ô  s    
zMDeferredTests.test_innerCallbacksPreserved.<locals>.cb.<locals>.firstCallbackc                    s   ˆ   d| f¡ | d S ©NÚsecondCallbackrh   rt   rã   ©rå   r   r   rç   ×  s    zNDeferredTests.test_innerCallbacksPreserved.<locals>.cb.<locals>.secondCallback©r"   r
   r¦   rW   r!   ©r3   r©   râ   rç   ©r*   rß   rå   r   r   ra   Ñ  s    
z6DeferredTests.test_innerCallbacksPreserved.<locals>.cbÚouterÚorange©rÞ   rì   rá   ©rç   rí   ÚorangeorangeN)r
   rV   r¦   rW   r   r"   r!   r#   ©r(   ra   rì   r   rë   r   Útest_innerCallbacksPreservedÇ  s&    


ýþz*DeferredTests.test_innerCallbacksPreservedc                    s‚   g ‰g ‰t  ¡ ‰ ‡ ‡‡fdd„}t  d¡}| |¡ | ˆj¡ |  ddgˆ¡ ˆ  d¡ |  g ˆ¡ |  ˆddddgfg¡ dS )	a   
        The continue callback of a L{Deferred} waiting for another L{Deferred}
        is not necessarily the first one. This is somewhat a whitebox test
        checking that we search for that callback among the whole list of
        callbacks.
        c                    s^   ˆ  d| f¡ t ¡ }‡ ‡fdd„}‡fdd„}| |¡ | |¡ | ˆj ¡ | d ¡ |S )Nra   c                    s   ˆ  d| f¡ t ˆ g¡S ©Nrâ   ©r"   r
   rÈ   r½   ©Úarå   r   r   râ   û  s    zNDeferredTests.test_continueCallbackNotFirst.<locals>.cb.<locals>.firstCallbackc                    s   ˆ   d| f¡ d S ©Nrç   rt   rã   rè   r   r   rç   ÿ  s    zODeferredTests.test_continueCallbackNotFirst.<locals>.cb.<locals>.secondCallback©r"   r
   rV   rW   r!   r   rê   ©rö   r*   rå   r   r   ra   ÷  s    


z7DeferredTests.test_continueCallbackNotFirst.<locals>.cbrì   ©ra   rì   ©râ   NÚwithersrç   N)r
   rV   r¦   rW   r!   r"   r#   r   rñ   r   rù   r   Útest_continueCallbackNotFirstì  s"    


þþz+DeferredTests.test_continueCallbackNotFirstc                    sž   g ‰g ‰t  ¡ ‰ ‡ ‡‡fdd„}t  ¡ }| |¡ | ‡fdd„¡ | ˆj¡ | d¡ |  ddgˆ¡ ˆ  d¡ |  g ˆ¡ |  ˆddd	dgfd
g¡ dS )zÃ
        A callback added to a L{Deferred} after a previous callback attached
        another L{Deferred} as a result is run after the callbacks of the other
        L{Deferred} are run.
        c                    s^   ˆ  d| f¡ t ¡ }‡ ‡fdd„}‡fdd„}| |¡ | |¡ | ˆj ¡ | d ¡ |S )Nra   c                    s   ˆ  d| f¡ t ˆ g¡S ró   rô   r½   rõ   r   r   râ   #  s    zLDeferredTests.test_callbackOrderPreserved.<locals>.cb.<locals>.firstCallbackc                    s   ˆ   d| f¡ d S r÷   rt   rã   rè   r   r   rç   '  s    zMDeferredTests.test_callbackOrderPreserved.<locals>.cb.<locals>.secondCallbackrø   rê   rù   r   r   ra     s    


z5DeferredTests.test_callbackOrderPreserved.<locals>.cbc                    s
   ˆ   d¡S )NÚfinalrt   rÑ   rè   r   r   rˆ   2  r‰   z;DeferredTests.test_callbackOrderPreserved.<locals>.<lambda>rì   rú   rû   rü   rç   rþ   N)r
   rV   rW   r!   r"   r   r#   rñ   r   rù   r   Útest_callbackOrderPreserved  s(    


 þþz)DeferredTests.test_callbackOrderPreservedc                    sh   t  ¡ ‰g ‰‡fdd„‰ ‡fdd„}‡ ‡‡fdd„}ˆ |¡ ˆ |¡ ˆ d¡ |  ˆdd	d
g¡ dS )z
        A callback added to a L{Deferred} by a callback on that L{Deferred}
        should be added to the end of the callback chain.
        c                    s   ˆ   d¡ d S )Né   rt   rã   ©Úcalledr   r   Ú	callback3F  s    z;DeferredTests.test_reentrantRunCallbacks.<locals>.callback3c                    s   ˆ   d¡ d S ©Nrh   rt   rã   r  r   r   Ú	callback2H  s    z;DeferredTests.test_reentrantRunCallbacks.<locals>.callback2c                    s   ˆ  d¡ ˆ ˆ ¡ d S rÇ   ©r"   rW   rã   ©r  r  r   r   r   Ú	callback1J  s    
z;DeferredTests.test_reentrantRunCallbacks.<locals>.callback1Nr   rh   r   ©r
   rV   rW   r   r#   )r(   r  r  r   r  r   Útest_reentrantRunCallbacks?  s    


z(DeferredTests.test_reentrantRunCallbacksc                    sR   t  ¡ ‰g ‰‡fdd„‰ ‡ ‡‡‡fdd„}ˆ |¡ ˆ d¡ ˆ ˆddg¡ dS )z˜
        A callback added to a L{Deferred} by a callback on that L{Deferred}
        should not be executed until the running callback returns.
        c                    s   ˆ   d¡ d S r  rt   rã   r  r   r   r  Z  s    z;DeferredTests.test_nonReentrantCallbacks.<locals>.callback2c                    s&   ˆ  d¡ ˆ ˆ ¡ ˆ ˆdg¡ d S rÇ   )r"   rW   r#   rã   ©r  r  r   r(   r   r   r  \  s    

z;DeferredTests.test_nonReentrantCallbacks.<locals>.callback1Nr   rh   r	  )r(   r  r   r  r   Útest_nonReentrantCallbacksS  s    

z(DeferredTests.test_nonReentrantCallbacksc                    sZ   d‰t  ¡ ‰‡fdd„‰ ‡ ‡fdd„}ˆ |¡ ˆ d¡ |  ˆt¡}|  |jˆf¡ dS )zé
        After an exception is raised by a callback which was added to a
        L{Deferred} by a callback on that L{Deferred}, the L{Deferred} should
        call the first errback with a L{Failure} wrapping that exception.
        zcallback raised exceptionc                    s   t ˆ ƒ‚d S r7   )Ú	Exceptionrã   )ÚexceptionMessager   r   r  m  s    zFDeferredTests.test_reentrantRunCallbacksWithFailure.<locals>.callback2c                    s   ˆ  ˆ ¡ d S r7   )rW   rã   )r  r   r   r   r  o  s    zFDeferredTests.test_reentrantRunCallbacksWithFailure.<locals>.callback1N)r
   rV   rW   r   r+   r  r#   r   )r(   r  r)   r   )r  r   r  r   Ú%test_reentrantRunCallbacksWithFailuree  s    

z3DeferredTests.test_reentrantRunCallbacksWithFailurec                    sr   t ƒ }t |¡‰ t ¡ }| ‡ fdd„¡ | d¡ g }ˆ  |j¡ |  |d ¡ | |j¡ |  |d |¡ dS )a  
        If a first L{Deferred} with a result is returned from a callback on a
        second L{Deferred}, the result of the second L{Deferred} becomes the
        result of the first L{Deferred} and the result of the first L{Deferred}
        becomes L{None}.
        c                    s   ˆ S r7   r   ©Úign©rÅ   r   r   rˆ     r‰   z=DeferredTests.test_synchronousImplicitChain.<locals>.<lambda>Nr   r   )	rÀ   r
   r¦   rV   rW   r   r"   rX   r1   )r(   r3   rÄ   rå   r   r  r   Útest_synchronousImplicitChainw  s    

z+DeferredTests.test_synchronousImplicitChainc                    s”   t  ¡ ‰ t  ¡ }| ‡ fdd„¡ | d¡ g }ˆ  |j¡ g }| |j¡ |  |g ¡ |  |g ¡ tƒ }ˆ  |¡ |  |dg¡ |  ||g¡ dS )a9  
        If a first L{Deferred} without a result is returned from a callback on
        a second L{Deferred}, the result of the second L{Deferred} becomes the
        result of the first L{Deferred} as soon as the first L{Deferred} has
        one and the result of the first L{Deferred} becomes L{None}.
        c                    s   ˆ S r7   r   r  r  r   r   rˆ   ”  r‰   z>DeferredTests.test_asynchronousImplicitChain.<locals>.<lambda>N)r
   rV   rW   r   r"   r#   rÀ   )r(   rÄ   ÚfirstResultÚsecondResultr3   r   r  r   Útest_asynchronousImplicitChain‹  s    

z,DeferredTests.test_asynchronousImplicitChainc                 C   s`   t  tdƒ¡}t  ¡ }| |fdd„¡ | d¡ g }| |j¡ |  |d ¡ |  |t¡ dS )a  
        If a first L{Deferred} with a L{Failure} result is returned from a
        callback on a second L{Deferred}, the first L{Deferred}'s result is
        converted to L{None} and no unhandled error is logged when it is
        garbage collected.
        úFirst Deferred's Failurec                 S   s   |S r7   r   )r  rÅ   r   r   r   rˆ   ¯  r‰   zBDeferredTests.test_synchronousImplicitErrorChain.<locals>.<lambda>Nr   )	r
   r¬   r.   rV   rW   r   r"   rX   r+   )r(   rÅ   rÄ   r  r   r   r   Ú"test_synchronousImplicitErrorChain¦  s    
z0DeferredTests.test_synchronousImplicitErrorChainc                    s¸   t  ¡ ‰ t  ¡ }| ‡ fdd„¡ | d¡ g }| |j¡ g }ˆ  |j¡ g }| |j¡ |  |g ¡ |  |g ¡ ˆ  tdƒ¡ |  	|d  
t¡¡ |  |dg¡ |  t|ƒd¡ dS )aP  
        Let C{a} and C{b} be two L{Deferred}s.

        If C{a} has no result and is returned from a callback on C{b} then when
        C{a} fails, C{b}'s result becomes the L{Failure} that was C{a}'s result,
        the result of C{a} becomes L{None} so that no unhandled error is logged
        when it is garbage collected.
        c                    s   ˆ S r7   r   r  r  r   r   rˆ   Â  r‰   zCDeferredTests.test_asynchronousImplicitErrorChain.<locals>.<lambda>Nr  r   r   )r
   rV   rW   r   r!   r"   r#   rk   r.   r%   r&   r$   )r(   rÄ   ZsecondErrorr  r  r   r  r   Ú#test_asynchronousImplicitErrorChain·  s     	
z1DeferredTests.test_asynchronousImplicitErrorChainc                    sŽ   t  ¡ ‰ t  ¡ ‰ˆ ‡ fdd„¡ t  ¡ }| ‡fdd„¡ g }| |j¡ tƒ }ˆ d¡ | d¡ |  |g ¡ ˆ  |¡ |  ||g¡ dS )zæ
        L{Deferred} chaining is transitive.

        In other words, let A, B, and C be Deferreds.  If C is returned from a
        callback on B and B is returned from a callback on A then when C fires,
        A fires.
        c                    s   ˆ S r7   r   r  r  r   r   rˆ   ß  r‰   zGDeferredTests.test_doubleAsynchronousImplicitChaining.<locals>.<lambda>c                    s   ˆ S r7   r   r  rÃ   r   r   rˆ   á  r‰   N)r
   rV   rW   r"   rÀ   r   r#   )r(   ÚthirdZthirdResultr3   r   )rÅ   rÄ   r   Ú'test_doubleAsynchronousImplicitChainingÕ  s    


z5DeferredTests.test_doubleAsynchronousImplicitChainingc                    s˜   g ‰g ‰ t  ¡ ‰‡ ‡‡fdd„}t  d¡}| |¡ | ˆj¡ |  ˆddg¡ ˆ d¡ ˆ ˆ j¡ | ˆ j¡ |  g ˆ d¡ |  ˆdddd	g¡ d
S )zÀ
        L{Deferred}s can have callbacks that themselves return L{Deferred}s.
        When these "inner" L{Deferred}s fire (even asynchronously), the
        callback chain continues.
        c                    sR   ˆ  d| f¡ t d¡}‡‡fdd„}‡fdd„}| |¡ |¡ | ˆ j ¡ |S )NrÞ   rß   c                    s   ˆ  d¡ ˆ S rà   rt   rã   rä   r   r   râ     s    
zXDeferredTests.test_nestedAsynchronousChainedDeferreds.<locals>.cb.<locals>.firstCallbackc                    s   ˆ   d| f¡ | d S ræ   rt   rã   rè   r   r   rç     s    zYDeferredTests.test_nestedAsynchronousChainedDeferreds.<locals>.cb.<locals>.secondCallbackré   rê   rë   r   r   ra     s    
zADeferredTests.test_nestedAsynchronousChainedDeferreds.<locals>.cbrì   rî   rá   rí   ú&Got errbacks but wasn't expecting any.rï   rð   N©r
   rV   r¦   rW   r"   r#   r   r!   rñ   r   rë   r   Ú'test_nestedAsynchronousChainedDeferredsõ  s6    

 ÿ
  ÿýþz5DeferredTests.test_nestedAsynchronousChainedDeferredsc                    s¢   g ‰g ‰ t  ¡ ‰‡ ‡‡fdd„}t  d¡}| |¡ | ˆj¡ |  ˆddg¡ ˆ d¡ | ˆ j¡ ˆ ˆ j¡ |  g ˆ d¡ |  ˆddddgfddgg¡ d	S )
aK  
        L{Deferred}s can have callbacks that themselves return L{Deferred}s.
        These L{Deferred}s can have other callbacks added before they are
        returned, which subtly changes the callback chain. When these "inner"
        L{Deferred}s fire (even asynchronously), the outer callback chain
        continues.
        c                    sV   ˆ  d| f¡ t d¡}‡‡fdd„}‡fdd„}| |¡ | |¡ | ˆ j ¡ |S )NrÞ   rß   c                    s   ˆ  d| f¡ ˆ  dd„ ¡S )Nrâ   c                 S   s   | gS r7   r   rÑ   r   r   r   rˆ   I  r‰   z|DeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.cb.<locals>.firstCallback.<locals>.<lambda>r  r½   rä   r   r   râ   C  s    zjDeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.cb.<locals>.firstCallbackc                    s   ˆ   d| f¡ | d S ræ   rt   rã   rè   r   r   rç   K  s    zkDeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.cb.<locals>.secondCallbackré   rê   rë   r   r   ra   ?  s    


zSDeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.cbrì   rî   rá   rü   r  rç   Nr  rñ   r   rë   r   Ú9test_nestedAsynchronousChainedDeferredsWithExtraCallbacks0  s6    

 ÿ
  ÿýþzGDeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacksc                 C   s,   t  ¡ }t  ¡ }| |¡ |  |j|¡ dS )zT
        When we chain a L{Deferred}, that chaining is recorded explicitly.
        N)r
   rV   ÚchainDeferredr1   Ú
_chainedTo©r(   rö   Úbr   r   r   Ú&test_chainDeferredRecordsExplicitChainq  s    
z4DeferredTests.test_chainDeferredRecordsExplicitChainc                 C   s4   t  ¡ }t  ¡ }| |¡ | d¡ |  |j¡ dS )aR  
        Any recorded chaining is cleared once the chaining is resolved, since
        it no longer exists.

        In other words, if one L{Deferred} is recorded as depending on the
        result of another, and I{that} L{Deferred} has fired, then the
        dependency is resolved and we no longer benefit from recording it.
        N)r
   rV   r   r   rX   r!  r"  r   r   r   Ú%test_explicitChainClearedWhenResolved{  s
    	

z3DeferredTests.test_explicitChainClearedWhenResolvedc                    s>   t  ¡ }t  ¡ ‰ | ‡ fdd„¡ | d¡ |  |jˆ ¡ dS )zÍ
        We can chain L{Deferred}s implicitly by adding callbacks that return
        L{Deferred}s. When this chaining happens, we record it explicitly as
        soon as we can find out about it.
        c                    s   ˆ S r7   r   r½   ©r#  r   r   rˆ   “  r‰   zFDeferredTests.test_chainDeferredRecordsImplicitChain.<locals>.<lambda>N)r
   rV   rW   r   r1   r!  )r(   rö   r   r&  r   Ú&test_chainDeferredRecordsImplicitChain‹  s
    
z4DeferredTests.test_chainDeferredRecordsImplicitChainc                    sˆ   t  ¡ ‰ ‡ fdd„}ˆ  |¡ ˆ  d¡ |  |g¡}|  t|ƒd¡ |d }|  |d t¡ d}|  t	 
||d ¡d	||d f ¡ d
S )z„
        When a Deferred is returned from a callback directly attached to that
        same Deferred, a warning is emitted.
        c                    s   ˆ S r7   r   rã   rÛ   r   r   ÚcircularCallbackž  s    zADeferredTests.test_circularChainWarning.<locals>.circularCallbackÚfoor   r   Úcategoryz1Callback returned the Deferred it was attached toÚmessagez
Expected match: %r
Got: %rN)r
   rV   rW   r   ÚflushWarningsr#   r$   ÚDeprecationWarningr%   ÚreÚsearch)r(   r(  Zcircular_warningsZwarningÚpatternr   rÛ   r   Útest_circularChainWarning˜  s    

þz'DeferredTests.test_circularChainWarningc                    s`   |   ttdtj¡ tjdtd t ¡ ‰ ‡ fdd„}ˆ  |¡ ˆ  	d¡ |  
ˆ ¡}| t¡ dS )z¸
        If the deprecation warning for circular deferred callbacks is
        configured to be an error, the exception will become the failure
        result of the Deferred.
        Úfiltersr2   )r*  c                    s   ˆ S r7   r   rã   rÛ   r   r   r(  ¶  s    zCDeferredTests.test_circularChainException.<locals>.circularCallbackr)  N)rD   ÚsetattrÚwarningsr2  Úfilterwarningsr-  r
   rV   rW   r   r   Útrap)r(   r(  r   r   rÛ   r   Útest_circularChainException­  s    


z)DeferredTests.test_circularChainExceptionc                 C   s*   t  ¡ }t|ƒ}|  t|ƒd|f ¡ dS )z€
        The C{repr()} of a L{Deferred} contains the class name and a
        representation of the internal Python ID.
        z<Deferred at 0x%x>N)r
   rV   Úidr#   Úrepr)r(   r©   Zaddressr   r   r   Ú	test_repr¾  s     ÿzDeferredTests.test_reprc                 C   s0   t  ¡ }| d¡ |  t|ƒdt|ƒf ¡ dS )zb
        If a L{Deferred} has been fired, then its C{repr()} contains its
        result.
        rí   z+<Deferred at 0x%x current result: 'orange'>N)r
   rV   r   r#   r9  r8  r·   r   r   r   Útest_reprWithResultÉ  s    
 ÿÿz!DeferredTests.test_reprWithResultc                 C   s>   t  ¡ }t  ¡ }| |¡ |  t|ƒdt|ƒt|ƒf ¡ dS )zÇ
        If a L{Deferred} C{a} has been fired, but is waiting on another
        L{Deferred} C{b} that appears in its callback chain, then C{repr(a)}
        says that it is waiting on C{b}.
        z.<Deferred at 0x%x waiting on Deferred at 0x%x>N)r
   rV   r   r#   r9  r8  r"  r   r   r   Útest_reprWithChainingÕ  s    
  ÿÿz#DeferredTests.test_reprWithChainingc                    s$   ‡ fdd„}ˆ   |dƒ|dƒ¡ dS )zw
        The depth of the call stack does not grow as more L{Deferred} instances
        are chained together.
        c                    sÔ   g ‰‡fdd„}t  ¡ }dd„ t| ƒD ƒ}|d d … }t  ¡ ‰ | ¡ }| |fdd„¡ | |¡ |r†| ¡ }| |fdd„¡ |}qb| ‡ fdd„¡ | d ¡ |D ]}| d ¡ q¦ˆ ˆg ¡ ˆ  d ¡ ˆd	 S )
Nc                    s   ˆ   tt ¡ ƒ¡ d S r7   )r"   r$   Ú	tracebackÚextract_stackr½   )Ústackr   r   ÚrecordStackDepthê  s    zVDeferredTests.test_boundedStackDepth.<locals>.chainDeferreds.<locals>.recordStackDepthc                 S   s   g | ]}t  ¡ ‘qS r   )r
   rV   )Ú.0r¾   r   r   r   Ú
<listcomp>î  s     zPDeferredTests.test_boundedStackDepth.<locals>.chainDeferreds.<locals>.<listcomp>c                 S   s   |S r7   r   ©r  rß   r   r   r   rˆ   ó  r‰   zNDeferredTests.test_boundedStackDepth.<locals>.chainDeferreds.<locals>.<lambda>c                 S   s   |S r7   r   rC  r   r   r   rˆ   ø  r‰   c                    s   ˆ S r7   r   r  )Úlastr   r   rˆ   ú  r‰   r   )r
   rV   ÚrangeÚpoprW   r   r#   )ZhowManyr@  ÚtopZinnerDeferredsZoriginalInnersrß   ZnewInnerrG   )rD  r?  r   ÚchainDeferredsè  s(    


z<DeferredTests.test_boundedStackDepth.<locals>.chainDeferredsr   rh   N)r#   )r(   rH  r   rG   r   Útest_boundedStackDepthã  s    #z$DeferredTests.test_boundedStackDepthc                    s|   t  ¡ }t  ¡ ‰ t  ¡ ‰| ‡ fdd„¡ ˆ  ‡fdd„¡ ˆ  d¡ | d¡ ˆ d¡ g }ˆ  |j¡ |  |dg¡ dS )a  
        Given three Deferreds, one chained to the next chained to the next,
        callbacks on the middle Deferred which are added after the chain is
        created are called once the last Deferred fires.

        This is more of a regression-style test.  It doesn't exercise any
        particular code path through the current implementation of Deferred, but
        it does exercise a broken codepath through one of the variations of the
        implementation proposed as a resolution to ticket #411.
        c                    s   ˆ S r7   r   r½   rÃ   r   r   rˆ     r‰   zZDeferredTests.test_resultOfDeferredResultOfDeferredOfFiredDeferredCalled.<locals>.<lambda>c                    s   ˆ S r7   r   r½   )r  r   r   rˆ     r‰   N)r
   rV   rW   r   r"   r#   )r(   rÅ   ÚLr   )rÄ   r  r   Ú:test_resultOfDeferredResultOfDeferredOfFiredDeferredCalled  s    


zHDeferredTests.test_resultOfDeferredResultOfDeferredOfFiredDeferredCalledc                 C   s   t  d¡ t  ¡ }g }tdƒ}z|‚W n   | ¡  Y nX | |j¡ |d }|  |j|¡ |j	d dd… \}}|  g |¡ |  g |¡ dS )z¿
        C{Deferred.errback()} creates a failure from the current Python
        exception.  When Deferred.debug is not set no globals or locals are
        captured in that failure.
        Fr€   r   éþÿÿÿN)
r
   rE   rV   r   rk   r!   r"   r#   r'   Úframes©r(   r©   r¨   Úexcr¬   ÚlocalzÚglobalzr   r   r   Útest_errbackWithNoArgsNoDebug&  s    
z+DeferredTests.test_errbackWithNoArgsNoDebugc                 C   s   t  d¡ t  ¡ }g }tdƒ}z|‚W n   | ¡  Y nX | |j¡ |d }|  |j|¡ |j	d dd… \}}|  
g |¡ |  
g |¡ dS )z¹
        C{Deferred.errback()} creates a failure from the current Python
        exception.  When Deferred.debug is set globals and locals are captured
        in that failure.
        Tr€   r   rL  N)r
   rE   rV   r   rk   r!   r"   r#   r'   rM  ÚassertNotEqualrN  r   r   r   Útest_errbackWithNoArgs<  s    
z$DeferredTests.test_errbackWithNoArgsc                 C   sx   t  ¡ }| d¡ t  d¡ dd„ }| |¡ g }| |j¡ |d }|jd dd… \}}|  g |¡ |  g |¡ dS )úœ
        An error raised by a callback creates a Failure.  The Failure captures
        locals and globals if and only if C{Deferred.debug} is set.
        NFc                 S   s   t dƒ‚d S ©Nr€   ©r   r½   r   r   r   Ú
raiseErrorZ  s    zHDeferredTests.test_errorInCallbackDoesNotCaptureVars.<locals>.raiseErrorr   rL  )	r
   rV   r   rE   rW   r!   r"   rM  r#   ©r(   r©   rX  r¨   r¬   rP  rQ  r   r   r   Ú&test_errorInCallbackDoesNotCaptureVarsR  s    


z4DeferredTests.test_errorInCallbackDoesNotCaptureVarsc                 C   sx   t  ¡ }| d¡ t  d¡ dd„ }| |¡ g }| |j¡ |d }|jd dd… \}}|  g |¡ |  g |¡ dS )rU  NTc                 S   s   t dƒ‚d S rV  rW  r½   r   r   r   rX  m  s    zODeferredTests.test_errorInCallbackCapturesVarsWhenDebugging.<locals>.raiseErrorr   rL  )	r
   rV   r   rE   rW   r!   r"   rM  rS  rY  r   r   r   Ú-test_errorInCallbackCapturesVarsWhenDebugginge  s    


z;DeferredTests.test_errorInCallbackCapturesVarsWhenDebuggingc                 C   s8  t ƒ }t ¡ }z| ¡  W n   | ¡  Y nX dd„ }t |¡}|  |¡}t | 	¡ ¡}t
r¬|  t|ƒd¡ |  d|d d ¡ |  d|d d ¡ |  d|d d ¡ nL|  t|ƒd¡ |  d|d	 d ¡ |  d|d	 d ¡ |  d|d	 d ¡ |  d|d d ¡ |  d
|d d ¡ |  d|d d ¡ dS )z
        L{defer.inlineCallbacks} that re-raise tracebacks into their deferred
        should not lose their tracebacks.
        c                 s   s
   | V  d S r7   r   rÛ   r   r   r   Úic„  s    z8DeferredTests.test_inlineCallbacksTracebacks.<locals>.icr   Z
test_deferrh   r   r   z1/0r   Útest_inlineCallbacksTracebackszf.raiseException()N)r   r
   rV   ZraiseExceptionrk   ZinlineCallbacksr   r=  Ú
extract_tbZgetTracebackObjectr   r#   r$   ÚassertIn)r(   r   r©   r\  Z
newFailureÚtbr   r   r   r]  x  s,    

z,DeferredTests.test_inlineCallbacksTracebacksN)Hr   r   r   rH   rM   rO   rQ   rZ   r\   r]   r^   rs   rv   r   rƒ   r…   rŒ   r   r•   r™   rš   r›   rœ   r   rŸ   r¢   r£   r¤   rª   r­   r°   r¶   r¸   r¼   rÂ   rÆ   rÊ   rÌ   rÍ   rÎ   rØ   rÚ   rÜ   rÝ   rò   rý   rÿ   r
  r  r  r  r  r  r  r  r  r  r$  r%  r'  r1  r7  r:  r;  r<  rI  rK  rR  rT  rZ  r[  r]  r   r   r   r   r@   €   sŠ   (	%)* ;A
+r@   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚFirstErrorTestsz"
    Tests for L{FirstError}.
    c                 C   sP   t dƒ}z|‚W n   t ¡ }Y nX t |d¡}|  t|ƒdt|ƒf ¡ dS )z¦
        The repr of a L{FirstError} instance includes the repr of the value of
        the sub-failure and the index which corresponds to the L{FirstError}.
        ú	some textr   zFirstError[#3, %s]N)rÉ   r   r   r
   r{   r#   r9  ©r(   rO  r   r2   r   r   r   r:  ž  s    þzFirstErrorTests.test_reprc                 C   sP   t dƒ}z|‚W n   t ¡ }Y nX t |d¡}|  t|ƒdt|ƒf ¡ dS )z—
        The str of a L{FirstError} instance includes the str of the
        sub-failure and the index which corresponds to the L{FirstError}.
        rb  rÐ   zFirstError[#5, %s]N)rÉ   r   r   r
   r{   r#   rl   rc  r   r   r   Útest_str¯  s    þzFirstErrorTests.test_strc                 C   s²   zdd  W n   t  ¡ }Y nX t |d¡}t |d¡}ztdƒ‚W n   t  ¡ }Y nX t |d¡}|  ||k¡ |  ||k¡ |  ||k¡ |  ||k¡ |  |dk¡ dS )zÖ
        L{FirstError} instances compare equal to each other if and only if
        their failure and index compare equal.  L{FirstError} instances do not
        compare equal to instances of other types.
        r   r   é   Zbaré	   rÓ   N)r   r   r
   r{   rÉ   r%   r—   )r(   ZfirstFailureZoneZ
anotherOneZsecondFailureZanotherr   r   r   Útest_comparisonÀ  s     zFirstErrorTests.test_comparisonN)r   r   r   r,   r:  rd  rg  r   r   r   r   ra  š  s   ra  c                   @   s¬   e 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 )*ÚAlreadyCalledTestsc                 C   s   t  ¡ | _t  d¡ d S ©NT)r
   rF   Ú_deferredWasDebuggingrE   rG   r   r   r   rH   ß  s    
zAlreadyCalledTests.setUpc                 C   s   t  | j¡ d S r7   )r
   rE   rj  rG   r   r   r   ÚtearDownã  s    zAlreadyCalledTests.tearDownc                 O   s   d S r7   r   rK   r   r   r   rM   æ  s    zAlreadyCalledTests._callbackc                 O   s   d S r7   r   rK   r   r   r   rQ   è  s    zAlreadyCalledTests._errbackc                 C   s   |  d¡ d S )NrS   r   r·   r   r   r   Ú_call_1ë  s    zAlreadyCalledTests._call_1c                 C   s   |  d¡ d S )NZtwicer   r·   r   r   r   Ú_call_2í  s    zAlreadyCalledTests._call_2c                 C   s   |  t tƒ ¡¡ d S r7   ©rk   r   r   r.   r·   r   r   r   Ú_err_1ï  s    zAlreadyCalledTests._err_1c                 C   s   |  t tƒ ¡¡ d S r7   rn  r·   r   r   r   Ú_err_2ñ  s    zAlreadyCalledTests._err_2c                 C   s8   t  ¡ }| | j| j¡ |  |¡ |  t j| j|¡ d S r7   )	r
   rV   rj   rM   rQ   rl  ÚassertRaisesÚAlreadyCalledErrorrm  r·   r   r   r   ÚtestAlreadyCalled_CCô  s    
z'AlreadyCalledTests.testAlreadyCalled_CCc                 C   s8   t  ¡ }| | j| j¡ |  |¡ |  t j| j|¡ d S r7   )	r
   rV   rj   rM   rQ   rl  rq  rr  rp  r·   r   r   r   ÚtestAlreadyCalled_CEú  s    
z'AlreadyCalledTests.testAlreadyCalled_CEc                 C   s8   t  ¡ }| | j| j¡ |  |¡ |  t j| j|¡ d S r7   )	r
   rV   rj   rM   rQ   ro  rq  rr  rp  r·   r   r   r   ÚtestAlreadyCalled_EE   s    
z'AlreadyCalledTests.testAlreadyCalled_EEc                 C   s8   t  ¡ }| | j| j¡ |  |¡ |  t j| j|¡ d S r7   )	r
   rV   rj   rM   rQ   ro  rq  rr  rm  r·   r   r   r   ÚtestAlreadyCalled_EC  s    
z'AlreadyCalledTests.testAlreadyCalled_ECc                 C   sD   d}|D ](}|  d| ¡r| d| ¡r|d7 }q|  ||k¡ d S )Nr   z %s:z %sr   )r>   Úendswithr%   )r(   ZlinetypeÚfuncÚlinesrÁ   ÚcountÚliner   r   r   Ú_count  s    ÿ
zAlreadyCalledTests._countc                 C   s„   |j d  d¡}|  d||d¡ |  dd|d¡ |  dd|d¡ |  dd|d¡ |  dd|d¡ |  d	||d¡ |  d	||d¡ d S )
Nr   Ú
ÚCr   rl  rm  ro  rp  ÚI)r   Úsplitr|  )r(   r‡   ZcallerZinvoker1Zinvoker2ry  r   r   r   Ú_check  s    zAlreadyCalledTests._checkc              
   C   st   t  ¡ }| | j| j¡ |  |¡ z|  |¡ W n4 t jk
rd } z|  |ddd¡ W 5 d }~X Y nX |  	d¡ d S )NÚtestAlreadyCalledDebug_CCrl  rm  ú2second callback failed to raise AlreadyCalledError)
r
   rV   rj   rM   rQ   rl  rm  rr  r  r¬   ©r(   r©   r‡   r   r   r   r‚  #  s    
"z,AlreadyCalledTests.testAlreadyCalledDebug_CCc              
   C   st   t  ¡ }| | j| j¡ |  |¡ z|  |¡ W n4 t jk
rd } z|  |ddd¡ W 5 d }~X Y nX |  	d¡ d S )NÚtestAlreadyCalledDebug_CErl  rp  ú1second errback failed to raise AlreadyCalledError)
r
   rV   rj   rM   rQ   rl  rp  rr  r  r¬   r„  r   r   r   r…  .  s    
"z,AlreadyCalledTests.testAlreadyCalledDebug_CEc              
   C   st   t  ¡ }| | j| j¡ |  |¡ z|  |¡ W n4 t jk
rd } z|  |ddd¡ W 5 d }~X Y nX |  	d¡ d S )NÚtestAlreadyCalledDebug_ECro  rm  rƒ  )
r
   rV   rj   rM   rQ   ro  rm  rr  r  r¬   r„  r   r   r   r‡  9  s    
"z,AlreadyCalledTests.testAlreadyCalledDebug_ECc              
   C   st   t  ¡ }| | j| j¡ |  |¡ z|  |¡ W n4 t jk
rd } z|  |ddd¡ W 5 d }~X Y nX |  	d¡ d S )NÚtestAlreadyCalledDebug_EEro  rp  r†  )
r
   rV   rj   rM   rQ   ro  rp  rr  r  r¬   r„  r   r   r   rˆ  D  s    
"z,AlreadyCalledTests.testAlreadyCalledDebug_EEc              
   C   sz   t  d¡ t  ¡ }| | j| j¡ |  |¡ z|  |¡ W n0 t jk
rj } z|  	|j
¡ W 5 d }~X Y nX |  d¡ d S )NFrƒ  )r
   rE   rV   rj   rM   rQ   rl  rm  rr  r—   r   r¬   r„  r   r   r   ÚtestNoDebuggingO  s    

z"AlreadyCalledTests.testNoDebuggingc                 C   sl   t  d¡ t  ¡ }| dd„ ¡ t  d¡ | d ¡ t  d¡ t  ¡ }| d ¡ t  d¡ | dd„ ¡ d S )NFc                 S   s   d S r7   r   r  r   r   r   rˆ   a  r‰   z8AlreadyCalledTests.testSwitchDebugging.<locals>.<lambda>Tc                 S   s   d S r7   r   r  r   r   r   rˆ   i  r‰   )r
   rE   rV   ÚaddBothr   r·   r   r   r   ÚtestSwitchDebugging\  s    





z&AlreadyCalledTests.testSwitchDebuggingN)r   r   r   rH   rk  rM   rQ   rl  rm  ro  rp  rs  rt  ru  rv  r|  r  r‚  r…  r‡  rˆ  r‰  r‹  r   r   r   r   rh  Þ  s(   rh  c                   @   s¤   e 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'S )(ÚDeferredCancellerTestsc                 C   s   d | _ d | _d | _d| _d S rI   )rA   rB   rC   ÚcancellerCallCountrG   r   r   r   rH   n  s    zDeferredCancellerTests.setUpc                 C   s   |   | jd¡ d S )NrË   )r_  r  rG   r   r   r   rk  u  s    zDeferredCancellerTests.tearDownc                 C   s
   || _ |S r7   rJ   ©r(   Údatar   r   r   rM   z  s    z DeferredCancellerTests._callbackc                 C   s
   || _ d S r7   rN   rŽ  r   r   r   rO     s    z!DeferredCancellerTests._callback2c                 C   s
   || _ d S r7   rP   rŽ  r   r   r   rQ   ƒ  s    zDeferredCancellerTests._errbackc                 C   sB   t  ¡ }| | j| j¡ | ¡  |  | jjt j	¡ |  
| j¡ dS )z
        A L{defer.Deferred} without a canceller must errback with a
        L{defer.CancelledError} and not callback.
        N)r
   rV   rj   rM   rQ   r   r#   rB   rz   r   rX   rA   r·   r   r   r   Útest_noCanceller‡  s
    z'DeferredCancellerTests.test_noCancellerc                 C   sT   t  ¡ }| | j| j¡ | ¡  | d¡ |  t j|jd¡ |  t j|j	t
ƒ ¡ dS )zÒ
        A L{defer.Deferred} without a canceller, when cancelled must allow
        a single extra call to callback, and raise
        L{defer.AlreadyCalledError} if callbacked or errbacked thereafter.
        N)r
   rV   rj   rM   rQ   r   r   rq  rr  rk   r  r·   r   r   r   Ú!test_raisesAfterCancelAndCallback“  s    
z8DeferredCancellerTests.test_raisesAfterCancelAndCallbackc                 C   sV   t  ¡ }| | j| j¡ | ¡  | tƒ ¡ |  t j	|j
d¡ |  t j	|jtƒ ¡ dS )zÑ
        A L{defer.Deferred} without a canceller, when cancelled must allow
        a single extra call to errback, and raise
        L{defer.AlreadyCalledError} if callbacked or errbacked thereafter.
        N)r
   rV   rj   rM   rQ   r   rk   r  rq  rr  r   r·   r   r   r   Ú test_raisesAfterCancelAndErrback¥  s    z7DeferredCancellerTests.test_raisesAfterCancelAndErrbackc                 C   sJ   t  ¡ }| | j| j¡ | ¡  | j}| d¡ | ¡  |  || j¡ dS )z…
        A L{Deferred} without a canceller, when cancelled and then
        callbacked, ignores multiple cancels thereafter.
        N)	r
   rV   rj   rM   rQ   r   rB   r   r1   ©r(   r©   ÚcurrentFailurer   r   r   Ú5test_noCancellerMultipleCancelsAfterCancelAndCallback·  s    
zLDeferredCancellerTests.test_noCancellerMultipleCancelsAfterCancelAndCallbackc                 C   sp   t  ¡ }| | j| j¡ | ¡  |  | jjt j	¡ | j}| 
tƒ ¡ |  | jjt j	¡ | ¡  |  || j¡ dS )zŠ
        A L{defer.Deferred} without a canceller, when cancelled and then
        errbacked, ignores multiple cancels thereafter.
        N)r
   rV   rj   rM   rQ   r   r#   rB   rz   r   rk   r   r1   r“  r   r   r   Ú4test_noCancellerMultipleCancelsAfterCancelAndErrbackÇ  s    zKDeferredCancellerTests.test_noCancellerMultipleCancelsAfterCancelAndErrbackc                 C   sR   t  ¡ }| | j| j¡ | ¡  |  | jjt j	¡ | j}| ¡  |  
|| j¡ dS )z·
        Calling cancel multiple times on a deferred with no canceller
        results in a L{defer.CancelledError}. Subsequent calls to cancel
        do not cause an error.
        N)r
   rV   rj   rM   rQ   r   r#   rB   rz   r   r1   r“  r   r   r   Útest_noCancellerMultipleCancelÙ  s    z5DeferredCancellerTests.test_noCancellerMultipleCancelc                    sp   ‡ fdd„}t j|d}| ˆ jˆ j¡ | ¡  ˆ  ˆ jjt j	¡ ˆ j}| ¡  ˆ  
|ˆ j¡ ˆ  ˆ jd¡ dS )a,  
        Verify that calling cancel multiple times on a deferred with a
        canceller that does not errback results in a
        L{defer.CancelledError} and that subsequent calls to cancel do not
        cause an error and that after all that, the canceller was only
        called once.
        c                    s   ˆ  j d7  _ d S rÇ   ©r  rÛ   rG   r   r   r   ð  s    zCDeferredCancellerTests.test_cancellerMultipleCancel.<locals>.cancel©Z	cancellerr   N)r
   rV   rj   rM   rQ   r   r#   rB   rz   r   r1   r  )r(   r   r©   r”  r   rG   r   Útest_cancellerMultipleCancelè  s    z3DeferredCancellerTests.test_cancellerMultipleCancelc                    sz   ‡ fdd„}t j|d}| ˆ jˆ j¡ | ¡  ˆ  ˆ jd¡ ˆ  ˆ jj	t j
¡ ˆ  t j|jd¡ ˆ  t j|jtƒ ¡ dS )z·
        Verify that a L{defer.Deferred} calls its specified canceller when
        it is cancelled, and that further call/errbacks raise
        L{defer.AlreadyCalledError}.
        c                    s   ˆ  j d7  _ d S rÇ   r˜  rÛ   rG   r   r   r     s    z;DeferredCancellerTests.test_simpleCanceller.<locals>.cancelr™  r   N)r
   rV   rj   rM   rQ   r   r#   r  rB   rz   r   rq  rr  r   rk   r  ©r(   r   r©   r   rG   r   Útest_simpleCancellerý  s    z+DeferredCancellerTests.test_simpleCancellerc                    s6   ‡ ‡fdd„}t j|d‰ ˆ  ˆjˆj¡ ˆ  ¡  dS )zQ
        Verify that a canceller is given the correct deferred argument.
        c                    s   ˆ  | ˆ ¡ d S r7   )r1   )r‚   ©r©   r(   r   r   r     s    z8DeferredCancellerTests.test_cancellerArg.<locals>.cancelr™  N)r
   rV   rj   rM   rQ   r   )r(   r   r   r  r   Útest_cancellerArg  s    z(DeferredCancellerTests.test_cancellerArgc                    sf   ‡ fdd„}t j|d}| ˆ jˆ j¡ | d¡ | ¡  ˆ  ˆ jd¡ ˆ  	ˆ j
¡ ˆ  ˆ jd¡ dS )zo
        Test that cancelling a deferred after it has been callbacked does
        not cause an error.
        c                    s   ˆ  j d7  _ |  tƒ ¡ d S rÇ   ©r  rk   r   rÛ   rG   r   r   r   !  s    z?DeferredCancellerTests.test_cancelAfterCallback.<locals>.cancelr™  zbiff!r   N)r
   rV   rj   rM   rQ   r   r   r#   r  rX   rB   rA   r›  r   rG   r   Útest_cancelAfterCallback  s    
z/DeferredCancellerTests.test_cancelAfterCallbackc                    sj   ‡ fdd„}t j|d}| ˆ jˆ j¡ | tƒ ¡ | ¡  ˆ  ˆ j	d¡ ˆ  ˆ j
jt¡ ˆ  ˆ j¡ dS )z†
        Test that cancelling a L{Deferred} after it has been errbacked does
        not result in a L{defer.CancelledError}.
        c                    s   ˆ  j d7  _ |  tƒ ¡ d S rÇ   rŸ  rÛ   rG   r   r   r   2  s    z>DeferredCancellerTests.test_cancelAfterErrback.<locals>.cancelr™  r   N)r
   rV   rj   rM   rQ   rk   r   r   r#   r  rB   rz   rX   rA   r›  r   rG   r   Útest_cancelAfterErrback-  s    z.DeferredCancellerTests.test_cancelAfterErrbackc                    sR   ‡ fdd„}t j|d}| ˆ jˆ j¡ | ¡  ˆ  ˆ jd¡ ˆ  ˆ jj	t
¡ dS )z?
        Test a canceller which errbacks its deferred.
        c                    s   ˆ  j d7  _ |  tƒ ¡ d S rÇ   rŸ  rÛ   rG   r   r   r   B  s    zADeferredCancellerTests.test_cancellerThatErrbacks.<locals>.cancelr™  r   N)r
   rV   rj   rM   rQ   r   r#   r  rB   rz   r   r›  r   rG   r   Útest_cancellerThatErrbacks>  s    z1DeferredCancellerTests.test_cancellerThatErrbacksc                    s\   ‡ fdd„}t j|d}| ˆ jˆ j¡ | ¡  ˆ  ˆ jd¡ ˆ  ˆ jd¡ ˆ  	ˆ j
¡ dS )z<
        Test a canceller which calls its deferred.
        c                    s   ˆ  j d7  _ |  d¡ d S )Nr   úhello!)r  r   rÛ   rG   r   r   r   P  s    zBDeferredCancellerTests.test_cancellerThatCallbacks.<locals>.cancelr™  r   r£  N)r
   rV   rj   rM   rQ   r   r#   r  rA   rX   rB   r›  r   rG   r   Útest_cancellerThatCallbacksL  s    z2DeferredCancellerTests.test_cancellerThatCallbacksc                    sˆ   ‡fdd„}‡fdd„}t j|d‰ t j|d}| d¡ | ‡ fdd„¡ | ¡  | ˆjˆj¡ ˆ ˆj	d	¡ ˆ ˆj
jt j¡ dS )
zÅ
        Verify that a Deferred, a, which is waiting on another Deferred, b,
        returned from one of its callbacks, will propagate
        L{defer.CancelledError} when a is cancelled.
        c                    s   ˆ  j d7  _ d S rÇ   r˜  rÛ   rG   r   r   ÚinnerCancela  s    zEDeferredCancellerTests.test_cancelNestedDeferred.<locals>.innerCancelc                    s   ˆ   d¡ d S ©NF)r%   rÛ   rG   r   r   r   c  s    z@DeferredCancellerTests.test_cancelNestedDeferred.<locals>.cancelr™  Nc                    s   ˆ S r7   r   )r  r&  r   r   rˆ   i  r‰   zBDeferredCancellerTests.test_cancelNestedDeferred.<locals>.<lambda>r   )r
   rV   r   rW   r   rj   rM   rQ   r#   r  rB   rz   r   )r(   r¥  r   rö   r   )r#  r(   r   Útest_cancelNestedDeferred[  s    
z0DeferredCancellerTests.test_cancelNestedDeferredN)r   r   r   rH   rk  rM   rO   rQ   r  r‘  r’  r•  r–  r—  rš  rœ  rž  r   r¡  r¢  r¤  r§  r   r   r   r   rŒ  m  s&   rŒ  c                   @   sh   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S )ÚLogTestsz+
    Test logging of unhandled errors.
    c                 C   s   g | _ t | j j¡ dS )z<
        Add a custom observer to observer logging.
        N)Úcr	   r=   r"   rG   r   r   r   rH   y  s    zLogTests.setUpc                 C   s   t  | jj¡ dS )z&
        Remove the observer.
        N)r	   ZremoveObserverr©  r"   rG   r   r   r   rk  €  s    zLogTests.tearDownc                 C   s   dd„ | j D ƒS )Nc                 S   s   g | ]}|d  r|‘qS )ZisErrorr   )rA  r‡   r   r   r   rB  ˆ  s      z*LogTests._loggedErrors.<locals>.<listcomp>©r©  rG   r   r   r   Ú_loggedErrors‡  s    zLogTests._loggedErrorsc                 C   s8   |   ¡ }|  t|ƒd¡ |d d  t¡ |  t¡ dS )zV
        Check the output of the log observer to see if the error is present.
        rh   r   r   N)r«  r#   r$   r6  r´   r0   )r(   Zc2r   r   r   r  ‹  s    zLogTests._checkc                 C   s,   t  ¡  dd„ ¡ d¡ t ¡  |  ¡  dS )zÚ
        Verify that when a L{Deferred} with no references to it is fired,
        and its final result (the one not handled by any callback) is an
        exception, that exception will be logged immediately.
        c                 S   s   dd S r±   r   rÑ   r   r   r   rˆ   š  r‰   z(LogTests.test_errorLog.<locals>.<lambda>r   N)r
   rV   rW   r   ÚgcÚcollectr  rG   r   r   r   Útest_errorLog”  s    zLogTests.test_errorLogc                 C   s"   dd„ }|ƒ  t  ¡  |  ¡  dS )zD
        Same as L{test_errorLog}, but with an inner frame.
        c                  S   s$   t  ¡ } |  dd„ ¡ |  d¡ d S )Nc                 S   s   dd S r±   r   rÑ   r   r   r   rˆ   ¤  r‰   z`LogTests.test_errorLogWithInnerFrameRef.<locals>._subErrorLogWithInnerFrameRef.<locals>.<lambda>r   )r
   rV   rW   r   rÛ   r   r   r   Ú_subErrorLogWithInnerFrameRef¢  s    zNLogTests.test_errorLogWithInnerFrameRef.<locals>._subErrorLogWithInnerFrameRefN©r¬  r­  r  )r(   r¯  r   r   r   Útest_errorLogWithInnerFrameRefž  s    z'LogTests.test_errorLogWithInnerFrameRefc                 C   s"   dd„ }|ƒ  t  ¡  |  ¡  dS )zQ
        Same as L{test_errorLogWithInnerFrameRef}, plus create a cycle.
        c                  S   s.   t  ¡ } |  | fdd„¡ | | _|  d¡ d S )Nc                 S   s   dd S r±   r   )rÒ   r©   r   r   r   rˆ   ±  r‰   zdLogTests.test_errorLogWithInnerFrameCycle.<locals>._subErrorLogWithInnerFrameCycle.<locals>.<lambda>r   )r
   rV   rW   Z_dr   rÛ   r   r   r   Ú_subErrorLogWithInnerFrameCycle¯  s    zRLogTests.test_errorLogWithInnerFrameCycle.<locals>._subErrorLogWithInnerFrameCycleNr°  )r(   r²  r   r   r   Ú test_errorLogWithInnerFrameCycle«  s    z)LogTests.test_errorLogWithInnerFrameCyclec                 C   sj   t  ¡  dd„ ¡ d¡ t ¡  |  ¡  |  dt| j	ƒ¡ t
 | j	d ¡}d}|  | |¡d |¡¡ dS )	z
        Verify that when a L{Deferred} with no references to it is fired,
        the logged message does not contain a repr of the failure object.
        c                 S   s   dd S r±   r   rÑ   r   r   r   rˆ   ¿  r‰   z.LogTests.test_errorLogNoRepr.<locals>.<lambda>r   rh   éÿÿÿÿr<   ú%Expected message starting with: {0!r}N)r
   rV   rW   r   r¬  r­  r  r#   r$   r©  r	   r8   r%   r>   Úformat)r(   ÚmsgrÁ   r   r   r   Útest_errorLogNoReprº  s    ÿÿzLogTests.test_errorLogNoReprc                 C   s`   dd„ }|ƒ  t  ¡  |  ¡  |  dt| jƒ¡ t | jd ¡}d}|  | 	|¡d 
|¡¡ dS )z³
        Verify that when a L{Deferred} with no references to it is fired,
        the logged message includes debug info if debugging on the deferred
        is enabled.
        c                  S   s*   t  ¡ } d| _|  dd„ ¡ |  d¡ d S )NTc                 S   s   dd S r±   r   rÑ   r   r   r   rˆ   Õ  r‰   z?LogTests.test_errorLogDebugInfo.<locals>.doit.<locals>.<lambda>r   )r
   rV   ÚdebugrW   r   rÛ   r   r   r   ÚdoitÒ  s    z-LogTests.test_errorLogDebugInfo.<locals>.doitrh   r´  z
(debug:  Irµ  N)r¬  r­  r  r#   r$   r©  r	   r8   r%   r>   r¶  )r(   rº  r·  rÁ   r   r   r   Útest_errorLogDebugInfoÌ  s    ÿÿzLogTests.test_errorLogDebugInfoc                 C   s„   t  ¡ }| dd„ ¡ | d¡ g }g }| |j|j¡ |  |g ¡ |  t|ƒd¡ |d  t	¡ ~~~t
 ¡  |  |  ¡ g ¡ dS )z¿
        If one Deferred with an error result is returned from a callback on
        another Deferred, when the first Deferred is garbage collected it does
        not log its error.
        c                 S   s   t  tdƒ¡S )NZzoop)r
   r¬   r.   r  r   r   r   rˆ   ë  r‰   z3LogTests.test_chainedErrorCleanup.<locals>.<lambda>Nr   r   )r
   rV   rW   r   rj   r"   r#   r$   r6  r  r¬  r­  r«  )r(   r©   rå   r5   r   r   r   Útest_chainedErrorCleanupä  s    
z!LogTests.test_chainedErrorCleanupc                    sL   t  tdƒ¡}t  ¡ ‰ | ‡ fdd„¡ d ‰ }t ¡  |  |  ¡ g ¡ dS )z¼
        If a Deferred with a failure result has an errback which chains it to
        another Deferred, the initial failure is cleared by the errback so it is
        not logged.
        zoh noc                    s   ˆ S r7   r   r½   ©Zgoodr   r   rˆ     r‰   z6LogTests.test_errorClearedByChaining.<locals>.<lambda>N)	r
   r¬   r  rV   r!   r¬  r­  r#   r«  )r(   Zbadr   r½  r   Útest_errorClearedByChaining  s    z$LogTests.test_errorClearedByChainingN)r   r   r   r,   rH   rk  r«  r  r®  r±  r³  r¸  r»  r¼  r¾  r   r   r   r   r¨  t  s   	
r¨  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚDeferredListEmptyTestsc                 C   s
   d| _ d S rI   )ÚcallbackRanrG   r   r   r   rH     s    zDeferredListEmptyTests.setUpc                 C   s   t  g ¡}| | j¡ dS )zTesting empty DeferredList.N)r
   ri   rW   Úcb_empty)r(   rr   r   r   r   ÚtestDeferredListEmpty  s    
z,DeferredListEmptyTests.testDeferredListEmptyc                 C   s   d| _ |  g |¡ d S rÇ   )rÀ  r#   )r(   Úresr   r   r   rÁ    s    zDeferredListEmptyTests.cb_emptyc                 C   s   |   | jd¡ d S )NzCallback was never run.)r%   rÀ  rG   r   r   r   rk  !  s    zDeferredListEmptyTests.tearDownN)r   r   r   rH   rÂ  rÁ  rk  r   r   r   r   r¿    s   r¿  c                   @   sl   e 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S )ÚOtherPrimitivesTestsc                 C   s   |  j d7  _ d S rÇ   ©Úcounter)r(   r3   r   r   r   Ú_incr'  s    zOtherPrimitivesTests._incrc                 C   s
   d| _ d S rI   rÅ  rG   r   r   r   rH   *  s    zOtherPrimitivesTests.setUpc                    s®  t  ¡ }| ¡  ˆj¡ ˆ |j¡ ˆ ˆjd¡ | ¡  ˆj¡ ˆ |j¡ ˆ ˆjd¡ | 	¡  ˆ |j¡ ˆ ˆjd¡ | 	¡  ˆ 
|j¡ ˆ ˆjd¡ ˆ t|j¡ tƒ }tƒ }t  ¡ ‰ ‡ fdd„}|j|ˆ|d}ˆ |j¡ ˆ ˆj|¡ | ‡fdd„¡ | ¡  ˆj¡ ˆ |j¡ ˆ ˆjd¡ ˆ  |¡ ˆ ˆj|¡ ˆ |j¡ ˆ ˆjd¡ | ¡  ‡fd	d„¡}| ¡  ˆ ˆjjt j¡ | 	¡  ˆ 
|j¡ d S )
Nr   rh   c                    s
   || _ ˆ S r7   r&  ©r(   r#  ©ÚcontrolDeferredr   r   ÚhelperE  s    z-OtherPrimitivesTests.testLock.<locals>.helperrÈ  c                    s   t ˆ d| ƒS ©Nr3   ©r3  rÑ   rG   r   r   rˆ   M  r‰   z/OtherPrimitivesTests.testLock.<locals>.<lambda>r   c                    s   t ˆ d| ƒS rÌ  rÍ  rÑ   rG   r   r   rˆ   X  r‰   )r
   ÚDeferredLockÚacquirerW   rÇ  r%   Úlockedr#   rÆ  Úreleaser—   rq  rÙ   ÚrunrÀ   rV   r#  r   r3   rŠ  r   rz   r   )r(   ÚlockZfirstUniqueZsecondUniquerË  ÚresultDeferredr©   r   )rÊ  r(   r   ÚtestLock-  sD    
zOtherPrimitivesTests.testLockc                    s2   ‡ fdd„}t  ¡ }| ¡ }| |¡ | ¡  dS )zŠ
        When canceling a L{Deferred} from a L{DeferredLock} that already
        has the lock, the cancel should have no effect.
        c                    s   ˆ   d¡ d S ©NzUnexpected errback call!©r¬   r²   rG   r   r   Ú_failOnErrbacke  s    zIOtherPrimitivesTests.test_cancelLockAfterAcquired.<locals>._failOnErrbackN)r
   rÎ  rÏ  r!   r   )r(   rØ  rÓ  r©   r   rG   r   Útest_cancelLockAfterAcquired`  s
    
z1OtherPrimitivesTests.test_cancelLockAfterAcquiredc                 C   s2   t  ¡ }| ¡  | ¡ }| ¡  |  |t j¡ dS )z×
        When canceling a L{Deferred} from a L{DeferredLock} that does not
        yet have the lock (i.e., the L{Deferred} has not fired), the cancel
        should cause a L{defer.CancelledError} failure.
        N)r
   rÎ  rÏ  r   r+   r   )r(   rÓ  r©   r   r   r   Útest_cancelLockBeforeAcquiredm  s
    z2OtherPrimitivesTests.test_cancelLockBeforeAcquiredc                    sz  d}t  |¡}t  ¡ ‰ ‡ fdd„}g }tƒ }|j|| |d}| |j¡ | | j¡ |  |g ¡ |  | j	|¡ ˆ  
d ¡ |  | ¡ ¡ |  | jd¡ d| _tdd| ƒD ]"}| ¡  | j¡ |  | j|¡ q¨g ‰‡fdd„}‡fd	d
„}	| ¡  ||	¡}
|
 ¡  |  ˆdg¡ | ¡  | j¡ |  | j|¡ | ¡  |  | j|d ¡ tdd| ƒD ] }| ¡  |  | j|d ¡ qTd S )Nre  c                    s
   || _ ˆ S r7   )Úarg©r(   rÛ  rÉ  r   r   rË    s    z2OtherPrimitivesTests.testSemaphore.<locals>.helperrÜ  r   r   c                    s   ˆ   d¡ d S r¦  rt   ©r¹   ©r¥   r   r   r¬   •  s    z0OtherPrimitivesTests.testSemaphore.<locals>.failc                    s   ˆ   d¡ d S ri  rt   rÝ  rÞ  r   r   r¦   —  s    z3OtherPrimitivesTests.testSemaphore.<locals>.succeedT)r
   ÚDeferredSemaphorerV   rÀ   rÒ  rW   r"   rÇ  r#   rÛ  r   rX   rF  rÆ  rE  rÏ  rj   r   rÑ  )r(   ÚNÚsemrË  rå   ZuniqueObjectrÔ  Úir¬   r¦   r©   r   )rÊ  r¥   r   ÚtestSemaphorez  s>    

z"OtherPrimitivesTests.testSemaphorec                 C   s$   |   ttjd¡ |   ttjd¡ dS )zz
        If the token count passed to L{DeferredSemaphore} is less than one
        then L{ValueError} is raised.
        r   r´  N)rq  rÉ   r
   rß  rG   r   r   r   Útest_semaphoreInvalidTokens¨  s    z0OtherPrimitivesTests.test_semaphoreInvalidTokensc                    s4   ‡ fdd„}t  d¡}| ¡ }| |¡ | ¡  dS )z”
        When canceling a L{Deferred} from a L{DeferredSemaphore} that
        already has the semaphore, the cancel should have no effect.
        c                    s   ˆ   d¡ d S rÖ  r×  r²   rG   r   r   rØ  ¶  s    zNOtherPrimitivesTests.test_cancelSemaphoreAfterAcquired.<locals>._failOnErrbackr   N)r
   rß  rÏ  r!   r   )r(   rØ  rá  r©   r   rG   r   Ú!test_cancelSemaphoreAfterAcquired±  s
    

z6OtherPrimitivesTests.test_cancelSemaphoreAfterAcquiredc                 C   s4   t  d¡}| ¡  | ¡ }| ¡  |  |t j¡ dS )zá
        When canceling a L{Deferred} from a L{DeferredSemaphore} that does
        not yet have the semaphore (i.e., the L{Deferred} has not fired),
        the cancel should cause a L{defer.CancelledError} failure.
        r   N)r
   rß  rÏ  r   r+   r   )r(   rá  r©   r   r   r   Ú"test_cancelSemaphoreBeforeAcquired¿  s
    
z7OtherPrimitivesTests.test_cancelSemaphoreBeforeAcquiredc              	   C   s  d\}}t  ||¡}g }t|ƒD ]}| ¡  |j¡ q |  t j|j¡ t|ƒD ]&}| |¡ |  	|t
t|d ƒƒ¡ qNt|ƒD ]&}| || ¡ |  	|t
t|ƒƒ¡ q~|  t j|jd ¡ g }t|ƒD ]2}| ¡  |j¡ |  	|t
t||| d ƒƒ¡ qÄt  ¡ }g }t|ƒD ]}| ¡  |j¡ qt|ƒD ]}| |¡ q,|  	|t
t|ƒƒ¡ t jdd}|  t j|jd ¡ t jdd}|  t j|j¡ d S )N)rh   rh   r   r   )Úsize)Zbacklog)r
   ÚDeferredQueuerE  ÚgetrW   r"   rq  ZQueueUnderflowÚputr#   ÚlistZQueueOverflow)r(   rà  ÚMÚqueueZgottenrâ  r   r   r   Ú	testQueueÌ  s8    
 zOtherPrimitivesTests.testQueuec                    s<   ‡ fdd„}t  ¡ }| ¡ }| |¡ | d¡ | ¡  dS )z‹
        When canceling a L{Deferred} from a L{DeferredQueue} that already has
        a result, the cancel should have no effect.
        c                    s   ˆ   d¡ d S rÖ  r×  r²   rG   r   r   rØ  ÷  s    zPOtherPrimitivesTests.test_cancelQueueAfterSynchronousGet.<locals>._failOnErrbackN)r
   rè  ré  r!   rê  r   )r(   rØ  rí  r©   r   rG   r   Ú#test_cancelQueueAfterSynchronousGetò  s    

z8OtherPrimitivesTests.test_cancelQueueAfterSynchronousGetc                    sb   t  ¡ ‰ ˆ  ¡ }| ¡  ˆ |t j¡ ‡ ‡fdd„}| |¡ g }| |j¡ ˆ t	|ƒd¡ dS )a  
        When canceling a L{Deferred} from a L{DeferredQueue} that does not
        have a result (i.e., the L{Deferred} has not fired), the cancel
        causes a L{defer.CancelledError} failure. If the queue has a result
        later on, it doesn't try to fire the deferred.
        c                    s   ˆ   d ¡ ˆ  ¡  ˆjd ¡S r7   )rê  ré  rW   r1   )Úignore©rí  r(   r   r   ra   	  s    
z9OtherPrimitivesTests.test_cancelQueueAfterGet.<locals>.cbr   N)
r
   rè  ré  r   r+   r   rW   r"   r#   r$   )r(   r©   ra   Údoner   rñ  r   Útest_cancelQueueAfterGet	  s    
z-OtherPrimitivesTests.test_cancelQueueAfterGetN)r   r   r   rÇ  rH   rÕ  rÙ  rÚ  rã  rä  rå  ræ  rî  rï  ró  r   r   r   r   rÄ  &  s   3.	&rÄ  c                   @   sX   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S )ÚDeferredFilesystemLockTestsz8
    Test the behavior of L{DeferredFilesystemLock}
    c                 C   s"   t ƒ | _tj|  ¡ | jd| _d S )N)Z	scheduler)r   Úclockr
   ÚDeferredFilesystemLockÚmktemprÓ  rG   r   r   r   rH   	  s    
ÿz!DeferredFilesystemLockTests.setUpc                 C   s   | j jdd}|S )zI
        Test that the lock can be acquired when no lock is held
        r   ©Útimeout)rÓ  ÚdeferUntilLockedr·   r   r   r   Útest_waitUntilLockedWithNoLock#	  s    z:DeferredFilesystemLockTests.test_waitUntilLockedWithNoLockc                 C   sB   |   | j ¡ ¡ | jjdd}|  |tj¡ | j dgd ¡ |S )zs
        Test that the lock can not be acquired when the lock is held
        for longer than the timeout.
        g      @rø  r   rÓ   )r%   rÓ  rú  ÚassertFailurer
   ÚTimeoutErrorrõ  Úpumpr·   r   r   r   Ú%test_waitUntilLockedWithTimeoutLocked,	  s
    zADeferredFilesystemLockTests.test_waitUntilLockedWithTimeoutLockedc                    s\   ‡ fdd„}ˆ   ˆ j ¡ ¡ ˆ j dˆ jj¡ ˆ jjdd}| |¡ ˆ j dgd ¡ |S )z|
        Test that a lock can be acquired while a lock is held
        but the lock is unlocked before our timeout.
        c                    s   |   tj¡ ˆ  d¡ d S )NzShould not have timed out)r6  r
   rý  r¬   ©r   rG   r   r   Ú	onTimeout@	  s    zVDeferredFilesystemLockTests.test_waitUntilLockedWithTimeoutUnlocked.<locals>.onTimeoutr   rÓ   rø  )r%   rÓ  rõ  Ú	callLaterÚunlockrú  r!   rþ  )r(   r  r©   r   rG   r   Ú'test_waitUntilLockedWithTimeoutUnlocked;	  s    
zCDeferredFilesystemLockTests.test_waitUntilLockedWithTimeoutUnlockedc                 C   s    t  |  ¡ ¡}|  |jt¡ dS )zE
        Test that the default scheduler is set up properly.
        N)r
   rö  r÷  r#   Z
_schedulerr   )r(   rÓ  r   r   r   Útest_defaultSchedulerO	  s    z1DeferredFilesystemLockTests.test_defaultSchedulerc                 C   sN   | j   ¡  | j d| j j¡ | j  ¡ }| j  ¡ }|  |tj¡ | j d¡ |S )z|
        Test that an appropriate exception is raised when attempting
        to use deferUntilLocked concurrently.
        r   )	rÓ  rõ  r  r  rú  rü  r
   ZAlreadyTryingToLockErrorÚadvancer»   r   r   r   Útest_concurrentUsageX	  s    


z0DeferredFilesystemLockTests.test_concurrentUsagec                    sL   ‡ fdd„}ˆ j   ¡  ˆ j dˆ j j¡ ˆ j  ¡ }| |¡ ˆ j d¡ |S )zO
        Test that a DeferredFilesystemLock can be used multiple times
        c                    s   ˆ j  ¡  ˆ j  ¡ }|S r7   )rÓ  r  rú  )r  r©   rG   r   r   ÚlockAquiredn	  s    

zDDeferredFilesystemLockTests.test_multipleUsages.<locals>.lockAquiredr   )rÓ  rõ  r  r  rú  rW   r  )r(   r  r©   r   rG   r   Útest_multipleUsagesj	  s    


z/DeferredFilesystemLockTests.test_multipleUsagesc                 C   sR   | j   ¡  | j  ¡ }| j j}| ¡  |  | ¡ ¡ |  | j j¡ |  |tj	¡ dS )zÂ
        When cancelling a L{defer.Deferred} returned by
        L{defer.DeferredFilesystemLock.deferUntilLocked}, the
        L{defer.DeferredFilesystemLock._tryLockCall} is cancelled.
        N)
rÓ  rú  Z_tryLockCallr   r—   ÚactiverX   r   r
   r   )r(   r   ZtryLockCallr   r   r   Útest_cancelDeferUntilLocked~	  s    

z7DeferredFilesystemLockTests.test_cancelDeferUntilLockedc                 C   sV   | j   ¡  | j jdd}| j j}| ¡  |  | ¡ ¡ |  | j j¡ |  |tj	¡ dS )zº
        When cancel a L{defer.Deferred} returned by
        L{defer.DeferredFilesystemLock.deferUntilLocked}, if the timeout is
        set, the timeout call will be cancelled.
        r   rø  N)
rÓ  rú  Z_timeoutCallr   r—   r
  rX   r   r
   r   )r(   r   ZtimeoutCallr   r   r   Ú&test_cancelDeferUntilLockedWithTimeout	  s    
zBDeferredFilesystemLockTests.test_cancelDeferUntilLockedWithTimeoutN)r   r   r   r,   rH   rû  rÿ  r  r  r  r	  r  r  r   r   r   r   rô  	  s   		rô  c                 C   s   dS )zj
    Private function to be used to pass as an alternate onTimeoutCancel value
    to timeoutDeferred
    Ú
OVERRIDDENr   )ÚvÚtr   r   r   Ú_overrideFunc	  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&S )'ÚDeferredAddTimeoutTestsz7
    Tests for the function L{Deferred.addTimeout}
    c                 C   s<   t  ¡  dtƒ ¡ dd„ ¡}| d¡ |  d|  |¡¡ dS )z
        L{defer.Deferred.addTimeout} returns its own L{defer.Deferred} so it
        can be called in a callback chain.
        rÐ   c                 S   s   dS )Nrò  r   r²   r   r   r   rˆ   ¯	  r‰   z?DeferredAddTimeoutTests.test_timeoutChainable.<locals>.<lambda>Nrò  )r
   rV   Ú
addTimeoutr   rW   r   r#   r–   r·   r   r   r   Útest_timeoutChainableª	  s    
z-DeferredAddTimeoutTests.test_timeoutChainablec                    s‚   t ƒ }t ¡ }| d|¡ t ¡ ‰dg‰ ‡ ‡fdd„}| |¡ | d¡ |  dˆ d ¡ |  ˆ d d¡ | d¡ |  	ˆ¡ dS )zÐ
        The L{defer.Deferred} callbacks with the result if it succeeds before
        the timeout. No cancellation happens after the callback either,
        which could also cancel inner deferreds.
        rÓ   Nc                    s   | ˆ d< ˆS rI   r   rè   ©ÚdCallbackedÚinnerDeferredr   r   Ú
onCallbackÃ	  s    zKDeferredAddTimeoutTests.test_successResultBeforeTimeout.<locals>.onCallbackrå   r   rÔ   )
r   r
   rV   r  rW   r   ÚassertIsNotr#   r  rž   ©r(   rõ  r©   r  r   r  r   Útest_successResultBeforeTimeout´	  s    


z7DeferredAddTimeoutTests.test_successResultBeforeTimeoutc                    s†   t ƒ }t ¡ }|jd|td t ¡ ‰dg‰ ‡ ‡fdd„}| |¡ | d¡ |  dˆ d ¡ |  ˆ d d¡ | 	d¡ |  
ˆ¡ dS )	a  
        The L{defer.Deferred} callbacks with the result if it succeeds before
        the timeout, even if a custom C{onTimeoutCancel} function is provided.
        No cancellation happens after the callback either, which could also
        cancel inner deferreds.
        rÓ   ©ZonTimeoutCancelNc                    s   | ˆ d< ˆS rI   r   rè   r  r   r   r  å	  s    zQDeferredAddTimeoutTests.test_successResultBeforeTimeoutCustom.<locals>.onCallbackrå   r   rÔ   )r   r
   rV   r  r  rW   r   r  r#   r  rž   r  r   r  r   Ú%test_successResultBeforeTimeoutCustomÕ	  s    


z=DeferredAddTimeoutTests.test_successResultBeforeTimeoutCustomc                    sŽ   t ƒ }t ¡ }| d|¡ t ¡ ‰dg‰ tdƒ}‡ ‡fdd„}| |¡ | |¡ |  ˆ d tj	¡ |  
ˆ d j|¡ | d¡ |  ˆ¡ dS )zÌ
        The L{defer.Deferred} errbacks with the failure if it fails before the
        timeout. No cancellation happens after the errback either, which
        could also cancel inner deferreds.
        rÓ   Nr¬   c                    s   | ˆ d< ˆS rI   r   r   ©Ú
dErrbackedr  r   r   Ú	onErrback
  s    zDDeferredAddTimeoutTests.test_failureBeforeTimeout.<locals>.onErrbackr   rÔ   )r   r
   rV   r  rÉ   r!   rk   rµ   r   r   r1   r'   r  rž   ©r(   rõ  r©   r2   r  r   r  r   Útest_failureBeforeTimeout÷	  s    


z1DeferredAddTimeoutTests.test_failureBeforeTimeoutc                    s’   t ƒ }t ¡ }|jd|td t ¡ ‰dg‰ tdƒ}‡ ‡fdd„}| |¡ | |¡ |  ˆ d t	j
¡ |  ˆ d j|¡ | d¡ |  ˆ¡ dS )	a  
        The L{defer.Deferred} errbacks with the failure if it fails before the
        timeout, even if using a custom C{onTimeoutCancel} function.
        No cancellation happens after the errback either, which could also
        cancel inner deferreds.
        rÓ   r  Nr¬   c                    s   | ˆ d< ˆS rI   r   r   r  r   r   r  *
  s    zJDeferredAddTimeoutTests.test_failureBeforeTimeoutCustom.<locals>.onErrbackr   rÔ   )r   r
   rV   r  r  rÉ   r!   rk   rµ   r   r   r1   r'   r  rž   r   r   r  r   Útest_failureBeforeTimeoutCustom
  s    


z7DeferredAddTimeoutTests.test_failureBeforeTimeoutCustomc                 C   s@   t ƒ }t ¡ }| d|¡ |  |¡ | d¡ |  |tj¡ dS )z’
        The L{defer.Deferred} by default errbacks with a L{defer.TimeoutError}
        if it times out before callbacking or errbacking.
        rÓ   rÔ   N)r   r
   rV   r  rž   r  r   rý  ©r(   rõ  r©   r   r   r   Útest_timedOut<
  s    

z%DeferredAddTimeoutTests.test_timedOutc                 C   sH   t ƒ }t ¡ }|jd|td |  |¡ | d¡ |  d|  |¡¡ dS )a=  
        If a custom C{onTimeoutCancel] function is provided, the
        L{defer.Deferred} returns the custom function's return value if the
        L{defer.Deferred} times out before callbacking or errbacking.
        The custom C{onTimeoutCancel} function can return a result instead of
        a failure.
        rÓ   r  rÔ   r  N©	r   r
   rV   r  r  rž   r  r#   r–   r#  r   r   r   Útest_timedOutCustomK
  s    

z+DeferredAddTimeoutTests.test_timedOutCustomc                 C   sJ   t ƒ }t dd„ ¡}| d|¡ |  |¡ | d¡ |  |  |¡d¡ dS )zé
        If a cancellation function is provided when the L{defer.Deferred} is
        initialized, the L{defer.Deferred} returns the cancellation value's
        non-failure return value when the L{defer.Deferred} times out.
        c                 S   s
   |   d¡S )NúI was cancelled!r   rª  r   r   r   rˆ   d
  r‰   zLDeferredAddTimeoutTests.test_timedOutProvidedCancelSuccess.<locals>.<lambda>rÓ   rÔ   r'  N)r   r
   rV   r  rž   r  r#   r–   r#  r   r   r   Ú"test_timedOutProvidedCancelSuccess]
  s    

z:DeferredAddTimeoutTests.test_timedOutProvidedCancelSuccessc                    s^   t ƒ }tdƒ‰ t ‡ fdd„¡}| d|¡ |  |¡ | d¡ |  |t¡}|  |j	ˆ ¡ dS )zí
        If a cancellation function is provided when the L{defer.Deferred} is
        initialized, the L{defer.Deferred} returns the cancellation value's
        non-L{CanceledError} failure when the L{defer.Deferred} times out.
        úwhat!c                    s
   |   ˆ ¡S r7   )rk   rª  ©r2   r   r   rˆ   u
  r‰   zLDeferredAddTimeoutTests.test_timedOutProvidedCancelFailure.<locals>.<lambda>rÓ   rÔ   N)
r   rÉ   r
   rV   r  rž   r  r   r1   r'   )r(   rõ  r©   r   r   r*  r   Ú"test_timedOutProvidedCancelFailurem
  s    

z:DeferredAddTimeoutTests.test_timedOutProvidedCancelFailurec                    s†   t ƒ }t ¡ }| d|¡ t ¡ ‰dg‰ ‡ ‡fdd„}| |¡ | ¡  |  ˆ d tj¡ |  	ˆ d j
tj¡ | d¡ |  ˆ¡ dS )a3  
        If the L{defer.Deferred} is manually cancelled before the timeout, it
        is not re-cancelled (no L{AlreadyCancelled} error, and also no
        canceling of inner deferreds), and the default C{onTimeoutCancel}
        function is not called, preserving the original L{CancelledError}.
        rÓ   Nc                    s   | ˆ d< ˆS rI   r   r   ©Z	dCanceledr  r   r   r  
  s    zCDeferredAddTimeoutTests.test_cancelBeforeTimeout.<locals>.onErrbackr   rÔ   )r   r
   rV   r  r!   r   rµ   r   r   r1   rz   r   r  rž   ©r(   rõ  r©   r  r   r,  r   Útest_cancelBeforeTimeout
  s    

z0DeferredAddTimeoutTests.test_cancelBeforeTimeoutc                    sŠ   t ƒ }t ¡ }|jd|td t ¡ ‰dg‰ ‡ ‡fdd„}| |¡ | ¡  |  ˆ d tj	¡ |  
ˆ d jtj¡ | d¡ |  ˆ¡ dS )a2  
        If the L{defer.Deferred} is manually cancelled before the timeout, it
        is not re-cancelled (no L{AlreadyCancelled} error, and also no
        canceling of inner deferreds), and the custom C{onTimeoutCancel}
        function is not called, preserving the original L{CancelledError}.
        rÓ   r  Nc                    s   | ˆ d< ˆS rI   r   r   r,  r   r   r  ±
  s    zIDeferredAddTimeoutTests.test_cancelBeforeTimeoutCustom.<locals>.onErrbackr   rÔ   )r   r
   rV   r  r  r!   r   rµ   r   r   r1   rz   r   r  rž   r-  r   r,  r   Útest_cancelBeforeTimeoutCustom¡
  s    

z6DeferredAddTimeoutTests.test_cancelBeforeTimeoutCustomc                 C   sN   t ƒ }t dd„ ¡}|jd|td |  |¡ | d¡ |  d|  |¡¡ dS )z{
        A custom translation function can handle a L{defer.Deferred} with a
        custom cancellation function.
        c                 S   s   |   tdƒ¡S )Nr)  )rk   rÉ   rª  r   r   r   rˆ   É
  r‰   zVDeferredAddTimeoutTests.test_providedCancelCalledBeforeTimeoutCustom.<locals>.<lambda>rÓ   r  rÔ   r  Nr%  r#  r   r   r   Ú,test_providedCancelCalledBeforeTimeoutCustomÃ
  s    

zDDeferredAddTimeoutTests.test_providedCancelCalledBeforeTimeoutCustomc                    sx   t ƒ }t ¡ }dg‰ ‡ fdd„}| |¡ | d|¡ | d¡ |  ˆ d tj¡ |  ˆ d j	tj
¡ |  |tj¡ dS )a  
        An errback added before a timeout is added errbacks with a
        L{defer.CancelledError} when the timeout fires.  If the
        errback returns the L{defer.CancelledError}, it is translated
        to a L{defer.TimeoutError} by the timeout implementation.
        Nc                    s   | ˆ d< | S rI   r   r   ©r  r   r   rk   Ý
  s    zGDeferredAddTimeoutTests.test_errbackAddedBeforeTimeout.<locals>.errbackrÓ   rÔ   r   )r   r
   rV   r!   r  r  rµ   r   r   r'   r   r   rý  ©r(   rõ  r©   rk   r   r1  r   Útest_errbackAddedBeforeTimeoutÑ
  s    

z6DeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutc                    st   t ƒ }t ¡ }dg‰ ‡ fdd„}| |¡ | d|¡ | d¡ |  ˆ d tj¡ |  ˆ d j	tj
¡ |  |¡ dS )zñ
        An errback added before a timeout is added errbacks with a
        L{defer.CancelledError} when the timeout fires.  If the
        errback suppresses the L{defer.CancelledError}, the deferred
        successfully completes.
        Nc                    s   | ˆ d< |   tj¡ d S rI   )r6  r
   r   r   r1  r   r   rk   ø
  s    z]DeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutSuppressesCancellation.<locals>.errbackrÓ   rÔ   r   )r   r
   rV   r!   r  r  rµ   r   r   r'   r   r–   r2  r   r1  r   Ú4test_errbackAddedBeforeTimeoutSuppressesCancellationì
  s    

zLDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutSuppressesCancellationc                    s~   t ƒ }t ¡ }dg‰ ‡ fdd„}| |¡ | d|t¡ | d¡ |  ˆ d tj	¡ |  ˆ d j
tj¡ |  d|  |¡¡ dS )a  
        An errback added before a timeout is added with a custom
        timeout function errbacks with a L{defer.CancelledError} when
        the timeout fires.  The timeout function runs if the errback
        returns the L{defer.CancelledError}.
        Nc                    s   | ˆ d< | S rI   r   r   r1  r   r   rk     s    zMDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutCustom.<locals>.errbackrÓ   rÔ   r   r  ©r   r
   rV   r!   r  r  r  rµ   r   r   r'   r   r#   r–   r2  r   r1  r   Ú$test_errbackAddedBeforeTimeoutCustom  s    

z<DeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutCustomc                    s~   t ƒ }t ¡ }dg‰ ‡ fdd„}| |¡ | d|t¡ | d¡ |  ˆ d tj	¡ |  ˆ d j
tj¡ |  d|  |¡¡ dS )a  
        An errback added before a timeout is added with a custom
        timeout function errbacks with a L{defer.CancelledError} when
        the timeout fires.  The timeout function runs if the errback
        suppresses the L{defer.CancelledError}.
        Nc                    s   | ˆ d< d S rI   r   r   r1  r   r   rk   .  s    zcDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutSuppressesCancellationCustom.<locals>.errbackrÓ   rÔ   r   r  r5  r2  r   r1  r   Ú:test_errbackAddedBeforeTimeoutSuppressesCancellationCustom"  s    

zRDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutSuppressesCancellationCustomc                    st   t ƒ }d‰t ‡fdd„¡}dg‰ ‡ fdd„}| |¡ | d|¡ | d¡ |  ˆ d	 ˆ¡ |  ˆ|  |¡¡ dS )
a*  
        Given a deferred with a cancellation function that resumes the
        callback chain, a callback that is added to the deferred
        before a timeout is added to runs when the timeout fires.  The
        deferred completes successfully, without a
        L{defer.TimeoutError}.
        r¥   c                    s
   |   ˆ ¡S r7   r   rÛ   rÞ  r   r   rˆ   F  r‰   zSDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeout.<locals>.<lambda>Nc                    s   | ˆ d< | S rI   r   ©r'   ©r  r   r   r   J  s    zSDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeout.<locals>.callbackrÓ   rÔ   r   )	r   r
   rV   rW   r  r  r#   r1   r–   ©r(   rõ  r©   r   r   ©r  r¥   r   Ú)test_callbackAddedToCancelerBeforeTimeout<  s    

zADeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeoutc                    sx   t ƒ }d‰t ‡fdd„¡}dg‰ ‡ fdd„}| |¡ |jd|td | d	¡ |  ˆ d
 ˆ¡ |  d|  |¡¡ dS )ad  
        Given a deferred with a cancellation function that resumes the
        callback chain, a callback that is added to the deferred
        before a timeout is added to runs when the timeout fires.  The
        deferred completes successfully, without a
        L{defer.TimeoutError}.  The timeout's custom timeout function
        also runs.
        r¥   c                    s
   |   ˆ ¡S r7   r   rÛ   rÞ  r   r   rˆ   c  r‰   zYDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeoutCustom.<locals>.<lambda>Nc                    s   | ˆ d< | S rI   r   r8  r9  r   r   r   g  s    zYDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeoutCustom.<locals>.callbackrÓ   r  rÔ   r   r  )	r   r
   rV   rW   r  r  r  r#   r–   r:  r   r;  r   Ú/test_callbackAddedToCancelerBeforeTimeoutCustomX  s    	

zGDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeoutCustomN)r   r   r   r,   r  r  r  r!  r"  r$  r&  r(  r+  r.  r/  r0  r3  r4  r6  r7  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 )ÚEnsureDeferredTestsz=
    Tests for L{twisted.internet.defer.ensureDeferred}.
    c                 C   s"   t  ¡ }t  |¡}|  ||¡ dS )zQ
        L{defer.ensureDeferred} will pass through a Deferred unchanged.
        N)r
   rV   ÚensureDeferredr1   r»   r   r   r   Útest_passesThroughDeferreds{  s    
z/EnsureDeferredTests.test_passesThroughDeferredsc              	   C   s$   |   t¡ t d¡ W 5 Q R X dS )zx
        Passing L{defer.ensureDeferred} a non-coroutine and a non-Deferred will
        raise a L{ValueError}.
        Z	somethingN)rq  rÉ   r
   r?  rG   r   r   r   Ú'test_willNotAllowNonDeferredOrCoroutine„  s    z;EnsureDeferredTests.test_willNotAllowNonDeferredOrCoroutineN)r   r   r   r,   r@  rA  r   r   r   r   r>  v  s   	r>  c                   @   s   e Zd ZdZdd„ ZdS )ÚTimeoutErrorTestsz1
    L{twisted.internet.defer} timeout code.
    c                 C   sj   t  ¡ }t  |¡ |  |t j¡ |  | jg¡}|  t|ƒd¡ |  	|d d t
¡ |  |d d d¡ dS )zB
        L{twisted.internet.defer.timeout} is deprecated.
        r   r   r*  r+  z~twisted.internet.defer.timeout was deprecated in Twisted 17.1.0; please use twisted.internet.defer.Deferred.addTimeout insteadN)r
   rV   rù  rü  rý  r,  Útest_deprecatedTimeoutr#   r$   r1   r-  )r(   r   ZwarningsShownr   r   r   rC  ’  s    

þz(TimeoutErrorTests.test_deprecatedTimeoutN)r   r   r   r,   rC  r   r   r   r   rB  Ž  s   rB  c                 C   s   |   | j¡ |  ¡  dS )zú
    Tickle an asyncio event loop to call all of the things scheduled with
    call_soon, inasmuch as this can be done via the public API.

    @param loop: The asyncio event loop to flush the previously-called
        C{call_soon} entries from.
    N)Z	call_soonÚstopZrun_forever©Úloopr   r   r   ÚcallAllSoonCalls£  s    rG  c                   @   sH   e Zd ZeZdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ ZdS )ÚDeferredFutureAdapterTestsc                 C   s`   t  ¡ }tƒ }| |¡}|  | ¡ d¡ | d¡ t|ƒ |  |  |¡d¡ |  | 	¡ d¡ dS )zƒ
        L{defer.Deferred.asFuture} returns a L{asyncio.Future} which fires when
        the given L{defer.Deferred} does.
        Fre  N)
r
   rV   r   ÚasFuturer#   rò  r   rG  r–   r3   ©r(   r©   rF  ÚaFuturer   r   r   Útest_asFuture´  s    

z(DeferredFutureAdapterTests.test_asFuturec                    sn   ‡ fdd„‰ dˆ _ t ˆ ¡}tƒ }| |¡}| ¡  t|ƒ |  ˆ j d¡ |  |  |¡d¡ |  	t
|j¡ dS )z“
        L{defer.Deferred.asFuture} returns a L{asyncio.Future} which, when
        cancelled, will cancel the original L{defer.Deferred}.
        c                    s
   dˆ _ d S ri  r  ©Zdprime©Úcancelerr   r   rO  È  s    zFDeferredFutureAdapterTests.test_asFutureCancelFuture.<locals>.cancelerFTN)r  r
   rV   r   rI  r   rG  r#   r–   rq  r   r3   rJ  r   rN  r   Útest_asFutureCancelFutureÃ  s    

z4DeferredFutureAdapterTests.test_asFutureCancelFuturec                 C   sV   dd„ }t  |¡}tƒ }| |¡}| ¡  t|ƒ |  |  |¡d¡ |  t	|j
¡ dS )zÒ
        While Futures don't support succeeding in response to cancellation,
        Deferreds do; if a Deferred is coerced into a success by a Future
        cancellation, that should just be ignored.
        c                 S   s   |   d¡ d S )Nrf  r   rM  r   r   r   rO  Û  s    zGDeferredFutureAdapterTests.test_asFutureSuccessCancel.<locals>.cancelerN)r
   rV   r   rI  r   rG  r#   r–   rq  r   r3   )r(   rO  r©   rF  rK  r   r   r   Útest_asFutureSuccessCancelÕ  s    

z5DeferredFutureAdapterTests.test_asFutureSuccessCancelc                 C   sP   t  ¡ }t tƒ ¡}tƒ }| |¡}t|ƒ | |¡ t|ƒ |  	t|j
¡ dS )zŒ
        L{defer.Deferred.asFuture} makes a L{asyncio.Future} fire with an
        exception when the given L{defer.Deferred} does.
        N)r
   rV   r   r   r´   r   rI  rG  rk   rq  r3   )r(   r©   Z
theFailurerF  Zfuturer   r   r   Útest_asFutureFailureæ  s    

z/DeferredFutureAdapterTests.test_asFutureFailurec                 C   sN   t ƒ }t|d}tj |¡}|  |¡ | d¡ t|ƒ |  |  	|¡d¡ dS )z„
        L{defer.Deferred.fromFuture} returns a L{defer.Deferred} that fires
        when the given L{asyncio.Future} does.
        rE  é   N)
r   r   r
   rV   Ú
fromFuturerž   Z
set_resultrG  r#   r–   )r(   rF  rK  r©   r   r   r   Útest_fromFutureõ  s    


z*DeferredFutureAdapterTests.test_fromFuturec                 C   sN   t ƒ }t|d}tj |¡}| ¡  t|ƒ |  t|j	¡ |  
|¡ t¡ dS )z®
        L{defer.Deferred.fromFuture} makes a L{defer.Deferred} fire with
        an L{asyncio.CancelledError} when the given
        L{asyncio.Future} is cancelled.
        rE  N)r   r   r
   rV   rT  r   rG  rq  r   r3   r   r6  ©r(   rF  Ú	cancelledr©   r   r   r   Útest_fromFutureFutureCancelled  s    
z9DeferredFutureAdapterTests.test_fromFutureFutureCancelledc                 C   s^   t ƒ }t|d}tj |¡}| ¡  t|ƒ |  | ¡ d¡ |  	t
|j¡ |  |¡ t
¡ dS )zš
        L{defer.Deferred.fromFuture} makes a L{defer.Deferred} which, when
        cancelled, cancels the L{asyncio.Future} it was created from.
        rE  TN)r   r   r
   rV   rT  r   rG  r#   rW  rq  r   r3   r   r6  rV  r   r   r   Ú test_fromFutureDeferredCancelled  s    
z;DeferredFutureAdapterTests.test_fromFutureDeferredCancelledN)r   r   r   Ú	asyncSkipÚskiprL  rP  rQ  rR  rU  rX  rY  r   r   r   r   rH  °  s   rH  )0r,   Z
__future__r   r   r4  r¬  r=  r.  Ztwisted.python.compatr   Zasyncior   r   r   rZ  Ztwisted.pythonr   r	   Ztwisted.internetr
   r   Ztwisted.internet.taskr   Ztwisted.trialr   r  r   r   r   rÀ   r    ZTestCaser-   ZSynchronousTestCaser@   ra  rh  rŒ  r¨  r¿  rÄ  rô  r  r  r>  rB  rG  rH  r   r   r   r   Ú<module>   sf   .          $D   	 ! s 	   S