o
    b
                     @   sh   d Z ddlmZ ddlmZ ddlmZ ddlmZ G dd deZ	G dd	 d	eZ
G d
d deZdS )zA
Whitebox tests for L{twisted.internet.abstract.FileDescriptor}.
    )verifyClass)FileDescriptor)IPushProducer)SynchronousTestCasec                   @   s4   e Zd ZdZdZdd Zdd Zdd Zd	d
 ZdS )
MemoryFilea-  
    A L{FileDescriptor} customization which writes to a Python list in memory
    with certain limitations.

    @ivar _written: A C{list} of C{bytes} which have been accepted as written.

    @ivar _freeSpace: A C{int} giving the number of bytes which will be accepted
        by future writes.
    Tc                 C   s    t j| t d g | _d| _d S )Nreactorr   )r   __init__object_written
_freeSpaceself r   K/usr/lib/python3/dist-packages/twisted/internet/test/test_filedescriptor.pyr	      s   
zMemoryFile.__init__c                 C      d S Nr   r   r   r   r   startWriting"      zMemoryFile.startWritingc                 C   r   r   r   r   r   r   r   stopWriting%   r   zMemoryFile.stopWritingc                 C   s:   t | jt|}|r|  j|8  _| j|d|  |S )z
        Copy at most C{self._freeSpace} bytes from C{data} into C{self._written}.

        @return: A C{int} indicating how many bytes were copied from C{data}.
        N)minr   lenr   append)r   dataacceptLengthr   r   r   writeSomeData(   s
   zMemoryFile.writeSomeDataN)	__name__
__module____qualname____doc__	connectedr	   r   r   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 )	FileDescriptorTestsz&
    Tests for L{FileDescriptor}.
    c                 C   s    t t d}| t|jd dS )zF
        L{FileDescriptor.write} doesn't accept unicode data.
        r   fooN)r   r
   assertRaises	TypeErrorwriter   fileDescriptorr   r   r   $test_writeWithUnicodeRaisesException:   s   z8FileDescriptorTests.test_writeWithUnicodeRaisesExceptionc                 C   s$   t t d}| t|jg d dS )zN
        L{FileDescriptor.writeSequence} doesn't accept unicode data.
        r   )s   foobars   bazN)r   r
   r#   r$   writeSequencer&   r   r   r   ,test_writeSequenceWithUnicodeRaisesExceptionA   s   z@FileDescriptorTests.test_writeSequenceWithUnicodeRaisesExceptionc                 C   s   |  ttt dS )zF
        L{FileDescriptor} should implement L{IPushProducer}.
        N)
assertTruer   r   r   r   r   r   r   $test_implementInterfaceIPushProducerJ   s   z8FileDescriptorTests.test_implementInterfaceIPushProducerN)r   r   r   r   r(   r+   r-   r   r   r   r   r!   5   s
    	r!   c                   @   s   e Zd ZdZdd ZdS )WriteDescriptorTestszN
    Tests for L{FileDescriptor}'s implementation of L{IWriteDescriptor}.
    c                 C   s"   t  }|d | |  dS )z
        When L{FileDescriptor.writeSomeData} returns C{0} to indicate no more
        data can be written immediately, L{FileDescriptor.doWrite} returns
        L{None}.
        s   hello, worldN)r   r%   assertIsNonedoWrite)r   
descriptorr   r   r   test_kernelBufferFullV   s   
z*WriteDescriptorTests.test_kernelBufferFullN)r   r   r   r   r2   r   r   r   r   r.   Q   s    r.   N)r   zope.interface.verifyr   twisted.internet.abstractr   twisted.internet.interfacesr   twisted.trial.unittestr   r   r!   r.   r   r   r   r   <module>   s   %