o
    ¯b#  ã                   @   sD   d Z ddlmZ ddlmZ ddlmZmZmZ G dd„ deƒZ	dS )	z(
Tests for L{twisted._threads._memory}.
é    )ÚverifyObject)ÚSynchronousTestCaseé   )ÚAlreadyQuitÚIWorkerÚcreateMemoryWorkerc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚMemoryWorkerTestsz$
    Tests for L{MemoryWorker}.
    c                    s†   t ƒ \}}tt|ƒ g ‰ | ‡ fdd„¡ | ‡ fdd„¡ |  ˆ g ¡ |  |ƒ d¡ |  ˆ dg¡ |  |ƒ d¡ |  ˆ ddg¡ dS )z¸
        L{createMemoryWorker} creates an L{IWorker} and a callable that can
        perform work on it.  The performer returns C{True} if it accomplished
        useful work.
        c                      ó
   ˆ   d¡S )Né   ©Úappend© ©Údoner   úC/usr/lib/python3/dist-packages/twisted/_threads/test/test_memory.pyÚ<lambda>   ó   
 z?MemoryWorkerTests.test_createWorkerAndPerform.<locals>.<lambda>c                      r	   )Né   r   r   r   r   r   r      r   Tr
   r   N)r   r   r   ÚdoÚassertEqual©ÚselfÚworkerÚ	performerr   r   r   Útest_createWorkerAndPerform   s   

z-MemoryWorkerTests.test_createWorkerAndPerformc                    sp   t ƒ \}}g ‰ ‡ fdd„}| |¡ | ¡  |  t|j|¡ |  t|j¡ |ƒ  |  ˆ dg¡ |  |ƒ d¡ dS )a  
        Calling C{quit} on the worker returned by L{createMemoryWorker} causes
        its C{do} and C{quit} methods to raise L{AlreadyQuit}; its C{perform}
        callable will start raising L{AlreadyQuit} when the work already
        provided to C{do} has been exhausted.
        c                      s   ˆ   d¡ d S )Né   r   r   r   r   r   ÚmoreWork.   s   z2MemoryWorkerTests.test_quitQuits.<locals>.moreWorkr   FN)r   r   ÚquitÚassertRaisesr   r   )r   r   r   r   r   r   r   Útest_quitQuits$   s   

z MemoryWorkerTests.test_quitQuitsc                 C   s   t ƒ \}}|  |ƒ d¡ dS )zÐ
        The C{perform} callable returned by L{createMemoryWorker} will return
        no result when there's no work to do yet.  Since there is no work to
        do, the performer returns C{False}.
        FN)r   r   r   r   r   r   Útest_performWhenNothingToDoYet9   s   
z0MemoryWorkerTests.test_performWhenNothingToDoYetN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r   r   r   r   r      s
    r   N)
r$   Úzope.interface.verifyr   Útwisted.trial.unittestr   Ú r   r   r   r   r   r   r   r   Ú<module>   s
   