
    Vh                         d Z ddlZddl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 ddlmZmZ ddlmZ  G d	 d
e      Z G d de      Z G d de      Zy)z/
Tests for L{twisted.trial._dist.workertrial}.
    N)BytesIO)StringTransport)AMP)_WORKER_AMP_STDIN_WORKER_AMP_STDOUTmanagercommandsworkercommandsworkertrial)WorkerLogObservermain)TestCasec                       e Zd ZdZy)FakeAMPz
    A fake amp protocol.
    N)__name__
__module____qualname____doc__     Y/home/dcms/DCMS/lib/python3.12/site-packages/twisted/trial/_dist/test/test_workertrial.pyr   r      s    r   r   c                       e Zd ZdZd Zy)WorkerLogObserverTestsz)
    Tests for L{WorkerLogObserver}.
    c                     g  G fdd      }t         |             }|j                  ddgi       | j                  t        j                  ddifg       y)zU
        L{WorkerLogObserver} forwards data to L{managercommands.TestWrite}.
        c                       e Zd Z fdZy)4WorkerLogObserverTests.test_emit.<locals>.FakeClientc                 ,    j                  ||f       y N)append)selfmethodkwargscallss      r   
callRemotez?WorkerLogObserverTests.test_emit.<locals>.FakeClient.callRemote+   s    ff-.r   N)r   r   r   r#   )r"   s   r   
FakeClientr   *   s    /r   r$   messagezSome logoutN)r   emitassertEqualr   	TestWrite)r   r$   observerr"   s      @r   	test_emitz WorkerLogObserverTests.test_emit$   sX     	/ 	/ %Z\2y:,/0/";";eZ=P!Q RSr   N)r   r   r   r   r+   r   r   r   r   r      s    Tr   r   c                   <    e Zd ZdZd Zd
dZd Zd Zd Zd Z	d	 Z
y)	MainTestsz
    Tests for L{main}.
    c                     t               | _        t               | _        | j                  t        d| j
                         | j                  t        t        dt        j                         dgt        _	        y )NstartLoggingWithObserverargvtrial)
r   
readStreamwriteStreampatchr
   r/   
addCleanupsetattrsysr0   r   s    r   setUpzMainTests.setUp8   sP    !)"9

3T5R5R	
 	fchh79r   Nc                     |t         k(  r| j                  d|       | j                  S |t        k(  r| j                  d|       | j                  S t        d|      )z
        Fake C{os.fdopen} implementation which returns C{self.readStream} for
        the stdin fd and C{self.writeStream} for the stdout fd.
        rbwbzUnexpected fd )r   r(   r2   r   r3   AssertionError)r   fdmodes      r   fdopenzMainTests.fdopenA   s^    
 ""T4(??"%%T4(### >"!899r   c                 &    | j                  |       y)zP
        Override C{startLoggingWithObserver} for not starting logging.
        N)assertFalse)r   r'   	setStdouts      r   r/   z"MainTests.startLoggingWithObserverO   s     	#r   c                     t        | j                         | j                  d| j                  j	                                y)zU
        If no data is ever written, L{main} exits without writing data out.
        r   N)r   r@   r(   r3   getvaluer8   s    r   
test_emptyzMainTests.test_emptyU   s/     	T[[d..779:r   c                 h   t               }t               }|j                  |       |j                  t        j
                  d       |j                  | _        | j                  j                  dd       t        | j                         | j                  d| j                  j                                y)z
        L{main} forwards data from its input stream to a L{WorkerProtocol}
        instance which writes data to the output stream.
        doesntexist)testCaser   s
   StreamOpenN)r   r   makeConnectionr#   r	   Runior2   seekr   r@   assertInr3   rE   )r   clientclientTransports      r   test_forwardCommandzMainTests.test_forwardCommand\   s    
 )+o..,,}E),,Q"T[[ 	mT%5%5%>%>%@Ar   c                     g  G fdd      } |       | _         t        | j                         | j                  d| j                  j                                | j                  dg       y)z
        If reading the input stream fails with a C{IOError} with errno
        C{EINTR}, L{main} ignores it and continues reading.
        c                       e Zd ZdZ fdZy)2MainTests.test_readInterrupted.<locals>.FakeStreamr   c                     | xj                   dz  c_         | j                   dk(  rt        t        j                        j	                  t        j                                y)N   r   )countOSErrorerrnoEINTRr   r7   exc_info)oselfsizeexcInfoss     r   readz7MainTests.test_readInterrupted.<locals>.FakeStream.readv   sA    q ;;!#!%++..OOCLLN3r   Nr   r   r   rW   r_   )r^   s   r   
FakeStreamrT   s   s    Er   ra   r   )NNNN)r2   r   r@   r(   r3   rE   )r   ra   r^   s     @r   test_readInterruptedzMainTests.test_readInterruptedl   s^    
 		 		 %,T[[d..779:,-x8r   c                 z     G d d      } |       | _         | j                  t        t        | j                         y)zm
        L{main} only ignores C{IOError} with C{EINTR} errno: otherwise, the
        error pops out.
        c                       e Zd ZdZd Zy)1MainTests.test_otherReadError.<locals>.FakeStreamr   c                 b    | xj                   dz  c_         | j                   dk(  rt        d      y)NrV   zSomething else )rW   rX   )r\   r]   s     r   r_   z6MainTests.test_otherReadError.<locals>.FakeStream.read   s+    q ;;!#!"233r   Nr`   r   r   r   ra   re      s    Er   ra   N)r2   assertRaisesIOErrorr   r@   )r   ra   s     r   test_otherReadErrorzMainTests.test_otherReadError   s-    	 	 %,'45r   r   )r   r   r   r   r9   r@   r/   rF   rQ   rb   rj   r   r   r   r-   r-   3   s+    :$;B 9.6r   r-   )r   rY   r7   rL   r   twisted.internet.testingr   twisted.protocols.ampr   twisted.trial._distr   r   r   r	   r
   twisted.trial._dist.workertrialr   r   twisted.trial.unittestr   r   r   r-   r   r   r   <module>rp      sV     
  4 %  D +c TX T(`6 `6r   