
    Vh                     J   d Z ddl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 ddlmZ dej                  v Z	 ddlZdd	lmZ e* G d
 dej(                        Z G d dej,                        Z G d de      Z G d dej2                        Zy# e$ r
 er dZdZY [w xY w)z+
Tests for L{twisted.internet.serialport}.
    N)Protocol)	DoNothing)Failure)platform)unittestTWISTED_FORCE_SERIAL_TESTS)
serialportc                   *     e Zd Z fdZd Zd Z xZS )RegularFileSerialc                 @    t        |   |i | || _        || _        y N)super__init__captured_argscaptured_kwargs)selfargskwargs	__class__s      Z/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/test/test_win32serialport.pyr   zRegularFileSerial.__init__$   s%    Gd-f-!%D#)D     c                      y r    r   s    r   _reconfigurePortz"RegularFileSerial._reconfigurePort)       r   c                      y r   r   r   s    r   _reconfigure_portz#RegularFileSerial._reconfigure_port,   r   r   )__name__
__module____qualname__r   r   r   __classcell__r   s   @r   r   r   #   s    	*
		r   r   c                   (     e Zd ZeZ fdZd Z xZS )RegularFileSerialPortc                     |j                  d      }d|v r|d= t        j                  j                  | _        || j                  _        t        |   |i | y )NcbInQue)getserialwin32COMSTATcomstatr'   r   r   )r   r   r   r'   r   s       r   r   zRegularFileSerialPort.__init__2   sP    jj+GF"9%!<<//DL#*DLL Gd-f-r   c                     d| j                   fS )NT)r,   r   s    r   _clearCommErrorz%RegularFileSerialPort._clearCommError=   s    %%r   )r   r    r!   r   _serialFactoryr   r.   r"   r#   s   @r   r%   r%   /   s    *		.	&r   r%   c                       e Zd Zd Zd Zy)CollectReceivedProtocolc                     g | _         y r   )received_datar   s    r   r   z CollectReceivedProtocol.__init__B   s
    r   c                 :    | j                   j                  |       y r   )r3   append)r   datas     r   dataReceivedz$CollectReceivedProtocol.dataReceivedE   s    !!$'r   N)r   r    r!   r   r7   r   r   r   r1   r1   A   s     (r   r1   c                       e Zd ZdZes ej                         sdZnesdZd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Zy)Win32SerialPortTestszB
    Minimal testing for Twisted's Win32 serial port support.
    zThis test must run on Windows.z-Windows serial port support is not available.c                 L   t               | _        t               | _        t	        j
                         | _        t        j                  j                  | j                  d      | _        d}t        | j                  d      5 }|j                  |       d d d        y # 1 sw Y   y xY w)Nfake_serials   1234wb)r   protocolr   reactortempfilemkdtemp	directoryospathjoinopenwrite)r   r6   fs      r   setUpzWin32SerialPortTests.setUpU   ss     
 {!))+GGLL?	$))T" 	aGGDM	 	 	s   ?BB#c                 B    t        j                  | j                         y r   )shutilrmtreerA   r   s    r   tearDownzWin32SerialPortTests.tearDowna   s    dnn%r   c                    t        | j                  | j                  | j                        }| j	                  | j                  f|j
                  j                         |j
                  j                  }| j	                  d|d          | j	                  t        j                  |d          | j	                  t        j                  |d          | j	                  t        j                  |d          | j	                  d|d          | j	                  d|d          | j	                  d	|d
          |j                  t        t        d                   y	)zx
        Test correct positional and keyword arguments have been
        passed to the C{serial.Serial} object.
        i%  baudratebytesizeparitystopbitsr   xonxoffrtsctsNtimeoutCleanup)r%   r=   rC   r>   assertEqual_serialr   r   r)   	EIGHTBITSPARITY_NONESTOPBITS_ONEconnectionLostr   	Exception)r   portr   s      r   test_serialPortDefaultArgsz/Win32SerialPortTests.test_serialPortDefaultArgsd   s
   
 %T]]DIIt||L$))t||'A'AB--vj12))6*+=>++VH-=>,,fZ.@AF9-.F8,-vi01GIi$89:r   c                    | j                  d| j                  j                         t        | j                  | j                  | j
                        }| j                  d|j                         | j                  d| j                  j                         | j                  || j                  j                         |j                  t        t        d                   y)z
        Test the port is connected at initialization time, and
        C{Protocol.makeConnection} has been called on the desired protocol.
        r      rU   N)
rV   r=   	connectedr%   rC   r>   	transportr[   r   r\   )r   r]   s     r   !test_serialPortInitiallyConnectedz6Win32SerialPortTests.test_serialPortInitiallyConnectedw   s    
 	DMM334$T]]DIIt||LDNN+DMM334t}}667GIi$89:r   c                 j   t        | j                  | j                  | j                  |      }|j	                          |j                  d       |j                  d       |j                  d       |j                          |j                          |j                  t        t        d                   y )Nr=   deviceNameOrPortNumberr>   r'   r   s   abcds   ABCDrU   )
r%   r=   rC   r>   serialReadEventrF   serialWriteEventr[   r   r\   )r   r'   r]   s      r   common_exerciseHandleAccessz0Win32SerialPortTests.common_exerciseHandleAccess   s    $]]#'99LL	
 	

3

7

7GIi$89:r   c                 (    | j                  d       y NFr'   ri   r   s    r   test_exerciseHandleAccess_1z0Win32SerialPortTests.test_exerciseHandleAccess_1   s    (((7r   c                 (    | j                  d       y NTrl   rm   r   s    r   test_exerciseHandleAccess_2z0Win32SerialPortTests.test_exerciseHandleAccess_2   s    (((6r   c                    t               }t        || j                  | j                  |      }|j	                          | j                  t        d |j                  D                     |j                  t        t        d                   y )Nre   c              3   <   K   | ]  }t        |t                y wr   )
isinstancebytes).0ds     r   	<genexpr>zEWin32SerialPortTests.common_serialPortReturnsBytes.<locals>.<genexpr>   s     QQJq%0Qs   rU   )r1   r%   rC   r>   rg   
assertTrueallr3   r[   r   r\   )r   r'   r=   r]   s       r   common_serialPortReturnsBytesz2Win32SerialPortTests.common_serialPortReturnsBytes   sk    *,$#'99LL	
 	Q(:P:PQQRGIi$89:r   c                 (    | j                  d       y rk   r{   r   s    r   test_serialPortReturnsBytes_1z2Win32SerialPortTests.test_serialPortReturnsBytes_1   s    **5*9r   c                 (    | j                  d       y rp   r}   r   s    r   test_serialPortReturnsBytes_2z2Win32SerialPortTests.test_serialPortReturnsBytes_2   s    **4*8r   N)r   r    r!   __doc__testingForcedr   	isWindowsskipr	   rH   rL   r^   rc   ri   rn   rq   r{   r~   r   r   r   r   r9   r9   I   sY     !x!!#3DBD
&;&;;$87;:9r   r9   )r   rB   rJ   r?   twisted.internet.protocolr   %twisted.internet.test.test_serialportr   twisted.python.failurer   twisted.python.runtimer   twisted.trialr   environr   r)   twisted.internetr	   ImportErrorSerialr   
SerialPortr%   r1   TestCaser9   r   r   r   <module>r      s    
   . ; * + ",

:	+ 
FMM 
&
 5 5 &$(h (d98,, d9a  JFs   
B B"!B"