ϪfJdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z dejvZ ddlZdd lmZe*Gd d ej(ZGd d ej,ZGddeZGdde j2Zy#e$r erdZdZY[wxYw)z+ Tests for L{twisted.internet.serialport}. N)Protocol) DoNothing)Failure)platform)unittestTWISTED_FORCE_SERIAL_TESTS) serialportc*eZdZfdZdZdZxZS)RegularFileSerialc@t||i|||_||_yN)super__init__ captured_argscaptured_kwargs)selfargskwargs __class__s L/usr/lib/python3/dist-packages/twisted/internet/test/test_win32serialport.pyrzRegularFileSerial.__init__$s% G d -f -!%D #)D cyr rs r_reconfigurePortz"RegularFileSerial._reconfigurePort) rcyr rrs r_reconfigure_portz#RegularFileSerial._reconfigure_port,rr)__name__ __module__ __qualname__rrr __classcell__rs@rr r #s *   rr c(eZdZeZfdZdZxZS)RegularFileSerialPortc|jd}d|vr|d=tjj|_||j_t ||i|y)NcbInQue)getserialwin32COMSTATcomstatr'rr)rrrr'rs rrzRegularFileSerialPort.__init__2sPjj+GF"9%!<<//DL#*DLL G d -f -rcd|jfS)NT)r,rs r_clearCommErrorz%RegularFileSerialPort._clearCommError=s% %r)rr r!r _serialFactoryrr.r"r#s@rr%r%/s* . &rr%ceZdZdZdZy)CollectReceivedProtocolcg|_yr ) received_datars rrz CollectReceivedProtocol.__init__Bs rc:|jj|yr )r3append)rdatas r dataReceivedz$CollectReceivedProtocol.dataReceivedEs !!$'rN)rr r!rr7rrrr1r1As  (rr1ceZdZdZesej sdZnesdZdZ dZ dZ dZ dZ d Zd Zd Zd Zd Zy)Win32SerialPortTestszB Minimal testing for Twisted's Win32 serial port support. zThis test must run on Windows.z-Windows serial port support is not available.cLt|_t|_t j |_tjj|j d|_d}t|jd5}|j|dddy#1swYyxYw)N fake_serials1234wb) rprotocolrreactortempfilemkdtemp directoryospathjoinopenwrite)rr6fs rsetUpzWin32SerialPortTests.setUpUss   { !))+GGLL?  $))T " a GGDM   s ?BB#cBtj|jyr )shutilrmtreerArs rtearDownzWin32SerialPortTests.tearDownas dnn%rct|j|j|j}|j |jf|j j |j j}|j d|d|j tj|d|j tj|d|j tj|d|j d|d|j d|d|j d |d |jttd y ) zx Test correct positional and keyword arguments have been passed to the C{serial.Serial} object. i%baudratebytesizeparitystopbitsrxonxoffrtsctsNtimeoutCleanup)r%r=rCr> assertEqual_serialrrr) EIGHTBITS PARITY_NONE STOPBITS_ONEconnectionLostr Exception)rportrs rtest_serialPortDefaultArgsz/Win32SerialPortTests.test_serialPortDefaultArgsds  %T]]DIIt||L $))t||'A'AB-- vj12 ))6*+=> ++VH-=> ,,fZ.@A F9-. F8,- vi01 GIi$89:rc|jd|jjt|j|j|j }|jd|j|jd|jj|j||jj |jttdy)z Test the port is connected at initialization time, and C{Protocol.makeConnection} has been called on the desired protocol. rrUN) rVr= connectedr%rCr> transportr[rr\)rr]s r!test_serialPortInitiallyConnectedz6Win32SerialPortTests.test_serialPortInitiallyConnectedws DMM334$T]]DIIt||L DNN+ DMM334 t}}667 GIi$89:rcjt|j|j|j|}|j |j d|j d|j d|j |j |jttdy)Nr=deviceNameOrPortNumberr>r'rsabcdsABCDrU) r%r=rCr>serialReadEventrFserialWriteEventr[rr\)rr'r]s rcommon_exerciseHandleAccessz0Win32SerialPortTests.common_exerciseHandleAccesss$]]#'99LL    3 7 7   GIi$89:rc(|jdyNFr'rirs rtest_exerciseHandleAccess_1z0Win32SerialPortTests.test_exerciseHandleAccess_1s (((7rc(|jdyNTrlrmrs rtest_exerciseHandleAccess_2z0Win32SerialPortTests.test_exerciseHandleAccess_2s (((6rct}t||j|j|}|j |j t d|jD|jttdy)Nrec3<K|]}t|tywr ) isinstancebytes).0ds r zEWin32SerialPortTests.common_serialPortReturnsBytes..sQQJq%0QsrU) r1r%rCr>rg assertTrueallr3r[rr\)rr'r=r]s rcommon_serialPortReturnsBytesz2Win32SerialPortTests.common_serialPortReturnsBytessk*,$#'99LL    Q(:P:PQQR GIi$89:rc(|jdyrkr{rs rtest_serialPortReturnsBytes_1z2Win32SerialPortTests.test_serialPortReturnsBytes_1s **5*9rc(|jdyrpr}rs rtest_serialPortReturnsBytes_2z2Win32SerialPortTests.test_serialPortReturnsBytes_2s **4*8rN)rr r!__doc__ testingForcedr isWindowsskipr rHrLr^rcrirnrqr{r~rrrrr9r9IsY !x!!#3DBD &;& ; ;$87 ;:9rr9)rrBrJr?twisted.internet.protocolr%twisted.internet.test.test_serialportrtwisted.python.failurertwisted.python.runtimer twisted.trialrenvironrr)twisted.internetr ImportErrorSerialr SerialPortr%r1TestCaser9rrrrs .;*+", :  + FMM & 5 5&$(h(d98,,d9a J F s B B"!B"