ϪfdZddlmZddlmZddlmZejsddlm Z GddeZ e je jy) z& Tests for L{twisted.internet.stdio}. )Protocol)ReactorBuilder)platform) StandardIOcheZdZdZdZdZdZdZdZdZ dZ d Z e jrd Zy y ) StdioFilesTestszI L{StandardIO} supports reading and writing to filesystem files. c|j}t|djt|d|_|j |jjy)Nwbzrb+)mktempopenclose extraFile addCleanup)selfpaths B/usr/lib/python3/dist-packages/twisted/internet/test/test_stdio.pysetUpzStdioFilesTests.setUpsD{{} T4 dE* ,,-c|jGfddt}|j}t|d5}|j ddddt|d5}|}t ||j |jj |jddd|jjdy#1swYxYw#1swY2xYw)zc Adding a filesystem file reader to a reactor will make sure it is polled. ceZdZdZfdZy)4StdioFilesTests.test_addReader..DataProtocolrcp|xj|z c_|jdk(rjyy)Nhello!)datastop)rrreactors r dataReceivedzAStdioFilesTests.test_addReader..DataProtocol.dataReceived&s- T! 99 )LLN*rN)__name__ __module__ __qualname__rrrsr DataProtocolr#s D #rr"r rNrbstdinstdoutr) buildReactorrr r writerfilenor runReactor assertEqualr)rr"rfprotocolrs @rtest_addReaderzStdioFilesTests.test_addReaders ##% #8 #{{} $   GGI  $  %#~H hhj~~,,.   OOG $ %  2   % %sC%AC$C!$C-cf|jGfddt}|j}t|d5}|}t ||j |j j |jjd|jjd|jj|jdddt|d5}|j|jd dddy#1swY?xYw#1swYyxYw) zc Adding a filesystem file writer to a reactor will make sure it is polled. ceZdZfdZy):StdioFilesTests.test_addWriter..DisconnectProtocolc&jy)N)r)rreasonrs rconnectionLostzIStdioFilesTests.test_addWriter..DisconnectProtocol.connectionLostHs  rN)rrr r4r!srDisconnectProtocolr1Gs rr5r r&r%rhellos, worldNr#s hello, world) r'rr r rr)r transportr(loseConnectionr*r+read)rr5rr,r-rs @rtest_addWriterzStdioFilesTests.test_addWriter@s ##%  {{} $  %*+H xxznn++-      $ $X .    $ $Z 0    - - / OOG $ % $  8   QVVX 7 8 8! % %  8 8sBD1!D'D$'D0c|j}|j}t|djt|d5}t t |j |jj |}|j|j|j|jj|j|j|jdddy#1swYyxYw)zq Removing a filesystem file reader from a reactor will make sure it is no longer polled. r r#r$N) r'r r r rrr)rassertIn_reader getReaders stopReading assertNotInrrrr,stdios rtest_removeReaderz!StdioFilesTests.test_removeReader`s ##%{{} T4 $  B hhj~~,,. E MM%--););)= > MM % % '   U]]G,>,>,@ A B B Bs B,C<<Dc|j}t|jdx|_}t }t ||j |jj |}|jjd|j|j|j|jj|j|j|jy)zq Removing a filesystem file writer from a reactor will make sure it is no longer polled. r r6r7N)r'r r r,rrr)rr8r(r=_writer getWriters stopWritingrA)rrr,r-rCs rtest_removeWriterz!StdioFilesTests.test_removeWritervs ##%$++-..: QXXZt~~/D/D/FPW    * emmW%7%7%9: !!# (:(:(<=rc|j}|j}t|djt|dx|_}t t |j|jj|}|j}|j|j||j|j|jy)zk Calling C{removeAll} on a reactor includes descriptors that are filesystem files. r r#r$N)r'r r r r,rrr)r removeAllr=r>rAr?)rrrr,rCremoveds rtest_removeAllzStdioFilesTests.test_removeAlls ##%{{} T4 $%% J((*>>((*  ##% emmW- (:(:(<=rc|j}|j}t|djt|d5}t t |j |jj |}|j|j|jdddy#1swYyxYw)zW C{reactor.getReaders} includes descriptors that are filesystem files. r r#r$N) r'r r r rrr)rr=r>r?rBs rtest_getReaderszStdioFilesTests.test_getReaderss##%{{} T4 $  ? hhj~~,,. E MM%--););)= > ? ? ?s A(B88Cc|j}t|jdx|_}t t |j |jj |}|j|j|j|jj|j|j|jy)zW C{reactor.getWriters} includes descriptors that are filesystem files. r r6N) r'r r r,rrr)rrArFrG startWritingr=)rrr,rCs rtest_getWriterszStdioFilesTests.test_getWriterss##%$++-.. J88:..'')   (:(:(<= ""$ emmW%7%7%9:rzoStandardIO does not accept stdout as an argument to Windows. Testing redirection to a file is therefore harder.N)rrr __doc__rr.r;rDrIrMrOrRr isWindowsskiprrrrsR. "3H8@B,>(>2?(;(x A rrN)rStwisted.internet.protocolr#twisted.internet.test.reactormixinsrtwisted.python.runtimerrTtwisted.internet.stdiorrglobalsupdatemakeTestCaseClassesrVrrr^sP />+x1~ n~ B 4467r