
    VhA                    2   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZmZmZmZmZmZmZ ddlmZmZ dd	lmZmZmZmZ dd
lmZ ddlm Z   G d de       Z! G d de       Z" G d d      Z# G d de       Z$ G d de      Z% G d de       Z&y)z(
Tests for L{twisted.internet.testing}.
    )annotations)Callable)verifyObject)Protocol)IPv4Address)	IAddress
IConnector	IConsumerIListeningPortIPushProducerIReactorSSLIReactorTCPIReactorUNIX
ITransport)ClientFactoryFactory)MemoryReactorNonStreamingProducerRaisingMemoryReactorStringTransport)namedAny)TestCasec                      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dZy)StringTransportTestsz@
    Tests for L{twisted.internet.testing.StringTransport}.
    c                "    t               | _        y N)r   	transportselfs    R/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/test/test_testing.pysetUpzStringTransportTests.setUp+   s    (*    c                    | j                  t        t        | j                               | j                  t        t        | j                               | j                  t        t
        | j                               y)zq
        L{StringTransport} instances provide L{ITransport}, L{IPushProducer},
        and L{IConsumer}.
        N)
assertTruer   r   r   r   r
   r   s    r    test_interfacesz$StringTransportTests.test_interfaces.   sI    
 	Z@A]DNNCDY?@r"   c                    t               }t               }| j                  j                  ||       | j                  | j                  j                  |       | j                  | j                  j
                  |       y)zz
        L{StringTransport.registerProducer} records the arguments supplied to
        it as instance attributes.
        N)objectr   registerProducerassertIsproducer	streamingr   r*   r+   s      r    test_registerProducerz*StringTransportTests.test_registerProducer7   sV    
 8H	'')<dnn--x8dnn..	:r"   c                N   t               }| j                  j                  |d       | j                  t        | j                  j                  t               d       | j                  | j                  j                  |       | j                  | j                  j                         y)zy
        L{StringTransport.registerProducer} raises L{RuntimeError} if a
        producer is already registered.
        TFN)	r'   r   r(   assertRaisesRuntimeErrorr)   r*   r$   r+   )r   r*   s     r    test_disallowedRegisterProducerz4StringTransportTests.test_disallowedRegisterProducerB   sr    
 8''$7$..9968U	
 	dnn--x8001r"   c                   t               }t               }| j                  j                  |d       | j                  j                          | j	                  | j                  j
                         | j                  j                  |d       | j                  | j                  j
                  |       | j                  | j                  j                         y)z
        L{StringTransport.unregisterProducer} causes the transport to forget
        about the registered producer and makes it possible to register a new
        one.
        FTN)	r'   r   r(   unregisterProducerassertIsNoner*   r)   r$   r+   )r   oldProducernewProducers      r    test_unregisterProducerz,StringTransportTests.test_unregisterProducerO   s     hh''U;))+$..112''T:dnn--{;001r"   c                X    | j                  t        | j                  j                         y)z
        L{StringTransport.unregisterProducer} raises L{RuntimeError} if called
        when no producer is registered.
        N)r/   r0   r   r3   r   s    r    test_invalidUnregisterProducerz3StringTransportTests.test_invalidUnregisterProducer^   s    
 	,(I(IJr"   c                P    | j                  | j                  j                  d       y)zO
        L{StringTransport.producerState} is initially C{'producing'}.
        	producingN)assertEqualr   producerStater   s    r    test_initialProducerStatez.StringTransportTests.test_initialProducerStatee   s     	55{Cr"   c                    | j                   j                          | j                  | j                   j                  d       y)zy
        L{StringTransport.pauseProducing} changes the C{producerState} of the
        transport to C{'paused'}.
        pausedN)r   pauseProducingr<   r=   r   s    r    test_pauseProducingz(StringTransportTests.test_pauseProducingk   s.    
 	%%'55x@r"   c                    | j                   j                          | j                   j                          | j                  | j                   j                  d       y)z}
        L{StringTransport.resumeProducing} changes the C{producerState} of the
        transport to C{'producing'}.
        r;   N)r   rA   resumeProducingr<   r=   r   s    r    test_resumeProducingz)StringTransportTests.test_resumeProducings   s>    
 	%%'&&(55{Cr"   c                    | j                   j                          | j                  | j                   j                  d       y)z{
        L{StringTransport.stopProducing} changes the C{'producerState'} of the
        transport to C{'stopped'}.
        stoppedN)r   stopProducingr<   r=   r   s    r    test_stopProducingz'StringTransportTests.test_stopProducing|   s.    
 	$$&55yAr"   c                    | j                   j                          | j                  t        | j                   j                         y)zu
        L{StringTransport.pauseProducing} raises L{RuntimeError} if the
        transport has been stopped.
        N)r   rH   r/   r0   rA   r   s    r     test_stoppedTransportCannotPausez5StringTransportTests.test_stoppedTransportCannotPause   s.    
 	$$&,(E(EFr"   c                    | j                   j                          | j                  t        | j                   j                         y)zv
        L{StringTransport.resumeProducing} raises L{RuntimeError} if the
        transport has been stopped.
        N)r   rH   r/   r0   rD   r   s    r    !test_stoppedTransportCannotResumez6StringTransportTests.test_stoppedTransportCannotResume   s.    
 	$$&,(F(FGr"   c                    | j                   j                          | j                  t        | j                   j                         y)zz
        L{StringTransport.pauseProducing} raises L{RuntimeError} if the
        transport is being disconnected.
        N)r   loseConnectionr/   r0   rA   r   s    r    &test_disconnectingTransportCannotPausez;StringTransportTests.test_disconnectingTransportCannotPause   s.    
 	%%',(E(EFr"   c                    | j                   j                          | j                  t        | j                   j                         y)z{
        L{StringTransport.resumeProducing} raises L{RuntimeError} if the
        transport is being disconnected.
        N)r   rO   r/   r0   rD   r   s    r    'test_disconnectingTransportCannotResumez<StringTransportTests.test_disconnectingTransportCannotResume   s.    
 	%%',(F(FGr"   c                    | j                  | j                  j                         | j                  j                          | j	                  | j                  j                         y)zv
        L{StringTransport.loseConnection} toggles the C{disconnecting} instance
        variable to C{True}.
        N)assertFalser   disconnectingrO   r$   r   s    r    $test_loseConnectionSetsDisconnectingz9StringTransportTests.test_loseConnectionSetsDisconnecting   sB    
 	556%%'445r"   c                j    t               }| j                  t        |      j                         |       y)z
        If a host address is passed to L{StringTransport.__init__}, that
        value is returned from L{StringTransport.getHost}.
        N)r'   r)   r   getHostr   addresss     r    test_specifiedHostAddressz.StringTransportTests.test_specifiedHostAddress   s'    
 (og.668'Br"   c                l    t               }| j                  t        |      j                         |       y)z
        If a peer address is passed to L{StringTransport.__init__}, that
        value is returned from L{StringTransport.getPeer}.
        )peerAddressN)r'   r)   r   getPeerrY   s     r    test_specifiedPeerAddressz.StringTransportTests.test_specifiedPeerAddress   s'    
 (o':BBDgNr"   c                `    t               j                         }| j                  |t               y)z
        If no host address is passed to L{StringTransport.__init__}, an
        L{IPv4Address} is returned from L{StringTransport.getHost}.
        N)r   rX   assertIsInstancer   rY   s     r    test_defaultHostAddressz,StringTransportTests.test_defaultHostAddress   %    
 "#++-g{3r"   c                `    t               j                         }| j                  |t               y)z
        If no peer address is passed to L{StringTransport.__init__}, an
        L{IPv4Address} is returned from L{StringTransport.getPeer}.
        N)r   r^   ra   r   rY   s     r    test_defaultPeerAddressz,StringTransportTests.test_defaultPeerAddress   rc   r"   NreturnNone)__name__
__module____qualname____doc__r!   r%   r-   r1   r7   r9   r>   rB   rE   rI   rK   rM   rP   rR   rV   r[   r_   rb   re    r"   r    r   r   &   sr    +A	;22KDADBGHGH6CO44r"   r   c                  @    e Zd ZdZd	dZd	dZd	dZd	dZd	dZd	dZ	y)
ReactorTestszA
    Tests for L{MemoryReactor} and L{RaisingMemoryReactor}.
    c                x    t               }t        t        |       t        t        |       t        t        |       y)zt
        L{MemoryReactor} provides all of the attributes described by the
        interfaces it advertises.
        N)r   r   r   r   r   )r   memoryReactors     r    test_memoryReactorProvidesz'ReactorTests.test_memoryReactorProvides   s)    
 &[-0[-0\=1r"   c                x    t               }t        t        |       t        t        |       t        t        |       y)z{
        L{RaisingMemoryReactor} provides all of the attributes described by the
        interfaces it advertises.
        N)r   r   r   r   r   )r   raisingReactors     r    test_raisingReactorProvidesz(ReactorTests.test_raisingReactorProvides   s*    
 ./[.1[.1\>2r"   c                ,   t               }|j                  ddt                     |j                  ddt               d      fD ]j  }t	        t
        |       |j                         }t	        t        |       | j                  |j                  d       | j                  |j                  d       l |j                  dt                     }t	        t
        |       |j                         }t	        t        |       | j                  |j                  d       y)a  
        L{MemoryReactor.connectTCP}, L{MemoryReactor.connectSSL}, and
        L{MemoryReactor.connectUNIX} will return an L{IConnector} whose
        C{getDestination} method returns an L{IAddress} with attributes which
        reflect the values passed.
        ztest.example.comi   Ns
   /fake/path)r   
connectTCPr   
connectSSLr   r	   getDestinationr   r<   hostportconnectUNIXname)r   rq   	connectorrZ   s       r    test_connectDestinationz$ReactorTests.test_connectDestination   s     &$$%7}O$$%7}PTU
 	1I Y/..0G7+W\\+=>W\\40	1 "--m]_M	Z+**,Xw'}5r"   c                (   t               }|j                  dt                     |j                  dt               d      fD ]j  }t	        t
        |       |j                         }t	        t        |       | j                  |j                  d       | j                  |j                  d       l |j                  dt                     }t	        t
        |       |j                         }t	        t        |       | j                  |j                  d       y)a  
        L{MemoryReactor.listenTCP}, L{MemoryReactor.listenSSL} and
        L{MemoryReactor.listenUNIX} will return an L{IListeningPort} whose
        C{getHost} method returns an L{IAddress}; C{listenTCP} and C{listenSSL}
        will have a default host of C{'0.0.0.0'}, and a port that reflects the
        value passed, and C{listenUNIX} will have a name that reflects the path
        passed.
        i2   Nz0.0.0.0s   /path/to/socket)r   	listenTCPr   	listenSSLr   r   rX   r   r<   rz   r{   
listenUNIXr}   )r   rq   r{   rZ   s       r    test_listenDefaultHostz#ReactorTests.test_listenDefaultHost   s     &##D')4##D')T:
 	1D .llnG7+W\\95W\\40	1 ''(:GIF^T*,,.Xw''9:r"   c                   t               }t               }|j                  |       |j                  |       | j                  |j	                         |g       |j                  |       | j                  |j	                         g        y)z>
        Adding, removing, and listing readers works.
        N)r'   r   	addReaderr<   
getReadersremoveReader)r   readerreactors      r    test_readerszReactorTests.test_readers  p     /&!&!++-x8V$++-r2r"   c                   t               }t               }|j                  |       |j                  |       | j                  |j	                         |g       |j                  |       | j                  |j	                         g        y)z>
        Adding, removing, and listing writers works.
        N)r'   r   	addWriterr<   
getWritersremoveWriter)r   writerr   s      r    test_writerszReactorTests.test_writers'  r   r"   Nrf   )
ri   rj   rk   rl   rr   ru   r   r   r   r   rm   r"   r    ro   ro      s%    236.;23 3r"   ro   c                  0    e Zd ZdZddZddZddZd	dZy)
TestConsumerzP
    A very basic test consumer for use with the NonStreamingProducerTests.
    c                .    g | _         d | _        d | _        y r   )writesr*   producerStreamingr   s    r    __init__zTestConsumer.__init__=  s    #% $.2r"   c                     || _         || _        y)z
        Registers a single producer with this consumer. Just keeps track of it.

        @param producer: The producer to register.
        @param streaming: Whether the producer is a streaming one or not.
        Nr*   r   r,   s      r    r(   zTestConsumer.registerProducerB  s     !!*r"   c                     d| _         d| _        y)zC
        Forget the producer we had previously registered.
        Nr   r   s    r    r3   zTestConsumer.unregisterProducerL  s     !%r"   c                :    | j                   j                  |       y)zz
        Some data was written to the consumer: stores it for later use.

        @param data: The data to write.
        N)r   append)r   datas     r    writezTestConsumer.writeS  s     	4 r"   Nrf   )r*   r'   r+   boolrg   rh   )r   bytesrg   rh   )ri   rj   rk   rl   r   r(   r3   r   rm   r"   r    r   r   8  s    3
+&!r"   r   c                       e Zd ZdZddZddZy)NonStreamingProducerTestszF
    Tests for the L{NonStreamingProducer} to validate behaviour.
    c                Z   t               }t        |      }|j                  |d       | j                  |j                  |       | j                  |j
                  |       | j                  |j                         t        d      D ]  }|j                           g d}| j                  |j                         | j                  |j                         | j                  |j
                         | j                  |j                  |       | j                  t        |j                         y)z
        When the L{NonStreamingProducer} has resumeProducing called 10 times,
        it writes the counter each time and then fails.
        F
   )
   0   1   2   3   4   5   6   7   8   9N)r   r   r(   r)   r*   consumerrT   r   rangerD   r4   r<   r   r/   r0   )r   r   r*   _expectedWritess        r    test_producesOnly10Timesz2NonStreamingProducerTests.test_producesOnly10Timesa  s    
  >'1!!(E2h''2h''2334r 	'A$$&	' V(++,(445(++,.9 	,(@(@Ar"   c                    t               }t        |      }|j                  |d       |j                          | j	                  t
        |j                         y)zb
        When the L{NonStreamingProducer} is paused, it raises a
        L{RuntimeError}.
        FN)r   r   r(   rD   r/   r0   rA   )r   r   r*   s      r    test_cannotPauseProductionz4NonStreamingProducerTests.test_cannotPauseProduction{  sI    
  >'1!!(E2 	  ",(?(?@r"   Nrf   )ri   rj   rk   rl   r   r   rm   r"   r    r   r   \  s    B4Ar"   r   c                      e Zd Zedd       Z y)_SupportsNamec                     y r   rm   r   s    r    ri   z_SupportsName.__name__  s    r"   N)rg   str)ri   rj   rk   propertyrm   r"   r    r   r     s     r"   r   c                      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y)DeprecationTestsz8
    Deprecations in L{twisted.test.proto_helpers}.
    c                   d|j                    }| j                  |g      }| j                  t        |d   d          | j                  dt	        |             | j                  ||d   d          | j                  |t        |             y )Nztwisted.internet.testing.r   category   message)ri   flushWarningsr<   DeprecationWarninglenassertInr)   r   )r   testobjnew_pathwarningss        r    helperzDeprecationTests.helper  s|    .s||n=%%tf-+Xa[-DECM*hI 67c8H-.r"   c                H    ddl m} | j                  | j                  |       y )Nr   )AccumulatingProtocol)twisted.test.proto_helpersr   r   test_accumulatingProtocol)r   r   s     r    r   z*DeprecationTests.test_accumulatingProtocol      CD224HIr"   c                H    ddl m} | j                  | j                  |       y )Nr   )LineSendingProtocol)r   r   r   test_lineSendingProtocol)r   r   s     r    r   z)DeprecationTests.test_lineSendingProtocol  s    BD113FGr"   c                H    ddl m} | j                  | j                  |       y )Nr   )FakeDatagramTransport)r   r   r   test_fakeDatagramTransport)r   r   s     r    r   z+DeprecationTests.test_fakeDatagramTransport  s    DD335JKr"   c                H    ddl m} | j                  | j                  |       y )Nr   )r   )r   r   r   test_stringTransport)r   r   s     r    r   z%DeprecationTests.test_stringTransport  s    >D--?r"   c                H    ddl m} | j                  | j                  |       y )Nr   ) StringTransportWithDisconnection)r   r   r   %test_stringTransportWithDisconnection)r   r   s     r    r   z6DeprecationTests.test_stringTransportWithDisconnection  s    O668X	
r"   c                H    ddl m} | j                  | j                  |       y )Nr   )StringIOWithoutClosing)r   r   r   test_stringIOWithoutClosing)r   r   s     r    r   z,DeprecationTests.test_stringIOWithoutClosing  s    ED446LMr"   c                H    ddl m} | j                  | j                  |       y )Nr   )_FakeConnector)r   r   r   test__fakeConnector)r   r   s     r    r   z$DeprecationTests.test__fakeConnector  s    =D,,n=r"   c                H    ddl m} | j                  | j                  |       y )Nr   )	_FakePort)r   r   r   test__fakePort)r   r   s     r    r   zDeprecationTests.test__fakePort  s    8D''3r"   c                H    ddl m} | j                  | j                  |       y )Nr   )r   )r   r   r   test_memoryReactor)r   r   s     r    r   z#DeprecationTests.test_memoryReactor  s    <D++];r"   c                H    ddl m} | j                  | j                  |       y )Nr   )MemoryReactorClock)r   r   r   test_memoryReactorClock)r   r   s     r    r   z(DeprecationTests.test_memoryReactorClock  s    AD002DEr"   c                H    ddl m} | j                  | j                  |       y )Nr   )r   )r   r   r   test_raisingMemoryReactor)r   r   s     r    r   z*DeprecationTests.test_raisingMemoryReactor  r   r"   c                H    ddl m} | j                  | j                  |       y )Nr   )r   )r   r   r   test_nonStreamingProducer)r   r   s     r    r   z*DeprecationTests.test_nonStreamingProducer  r   r"   c                H    ddl m} | j                  | j                  |       y )Nr   )waitUntilAllDisconnected)r   r   r   test_waitUntilAllDisconnected)r   r   s     r    r   z.DeprecationTests.test_waitUntilAllDisconnected  s    GD668PQr"   c                H    ddl m} | j                  | j                  |       y )Nr   )EventLoggingObserver)r   r   r   test_eventLoggingObserver)r   r   s     r    r   z*DeprecationTests.test_eventLoggingObserver  r   r"   N)r   zCallable[..., object]r   r   rg   rh   rf   )ri   rj   rk   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rm   r"   r    r   r     s\    /J
H
L
@

N
>
4
<
F
J
J
R
Jr"   r   N)'rl   
__future__r   typingr   zope.interface.verifyr   typing_extensionsr   twisted.internet.addressr   twisted.internet.interfacesr   r	   r
   r   r   r   r   r   r   twisted.internet.protocolr   r   twisted.internet.testingr   r   r   r   twisted.python.reflectr   twisted.trial.unittestr   r   ro   r   r   r   r   rm   r"   r    <module>r      s    #  . & 0
 
 
 =  , +e48 e4Pg38 g3T!! !!H+A +A\H SJx SJr"   