Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyc


=Nc@sdZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZm
Z
mZde	jfdYZde	jfd	YZdS(
sD
Test running processes with the APIs in L{twisted.internet.utils}.
iN(tplatform(tunittest(terrortreactortutilst
interfacestProcessUtilsTestscBseZdZejeddkr-dZndZdZ	e
jZdZ
dZdZdZdZdZdZejrd	e_nd
ZdZdZd
ZdZdZdZdZRS(st
    Test running a process using L{getProcessOutput}, L{getProcessValue}, and
    L{getProcessOutputAndValue}.
    s)reactor doesn't implement IReactorProcesscCsU|j}t|d}|jtjj|tj|jtjj|S(sj
        Write the given list of lines to a text file and return the absolute
        path to it.
        twt(	tmktemptfiletwritetostlineseptjointclosetpathtabspath(tselftsourceLinestscriptt
scriptFile((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pytmakeSourceFiles
 
cCsI|jddddg}tj|jd|g}|j|jdS(s
        L{getProcessOutput} returns a L{Deferred} which fires with the complete
        output of the process it runs after that process exits.
        s
import syssfor s in 'hello world\n':s    sys.stdout.write(s)s    sys.stdout.flush()s-ushello world
(RRtgetProcessOutputtexetaddCallbacktassertEqual(RRtd((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyttest_output(scsbjddg}tjjd|g}j|t}fd}|j||S(s
        The L{Deferred} returned by L{getProcessOutput} is fired with an
        L{IOError} L{Failure} if the child process writes to stderr.
        s
import syss!sys.stderr.write("hello world\n")s-ucsj|jtjS(N(t
assertFailuretprocessEndedRtProcessDone(terr(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pytcbFailedCs(RRRRRtIOErrorR(RRRR ((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyttest_outputWithErrorIgnored6s
cCsR|jdddddg}tj|jd|gdt}|j|jdS(	s
        If a C{True} value is supplied for the C{errortoo} parameter to
        L{getProcessOutput}, the returned L{Deferred} fires with the child's
        stderr output as well as its stdout output.
        s
import sysssys.stdout.write("foo")ssys.stdout.flush()ssys.stderr.write("foo")ssys.stderr.flush()s-uterrortootfoofoo(RRRRtTrueRR(RRR((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyttest_outputWithErrorCollectedIs!cCs@|jdg}tj|jd|g}|j|jdS(s|
        The L{Deferred} returned by L{getProcessValue} is fired with the exit
        status of the child process.
        sraise SystemExit(1)s-ui(RRtgetProcessValueRRR(RRR((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyt
test_value\scs[tj}jddddg}fd}tjjd|g}|j|S(s
        The L{Deferred} returned by L{getProcessOutputAndValue} fires with a
        three-tuple, the elements of which give the data written to the child's
        stdout, the data written to the child's stderr, and the exit status of
        the child.
        s
import syss"sys.stdout.write('hello world!\n')s$sys.stderr.write('goodbye world!\n')ssys.exit(1)csJ|\}}}j|dj|dtjj|ddS(Ns
hello world!
sgoodbye world!i(RRR(t.0toutRtcode(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pytgotOutputAndValuevss-u(tsyst
executableRRtgetProcessOutputAndValueRR(RRRR,R((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyttest_outputAndValuegs	csjjddddddg}fd}tjjd|g}j|t}|j|S(	s
        If the child process exits because of a signal, the L{Deferred}
        returned by L{getProcessOutputAndValue} fires a L{Failure} of a tuple
        containing the the child's stdout, stderr, and the signal which caused
        it to exit.
        simport sys, os, signals"sys.stdout.write('stdout bytes\n')s"sys.stderr.write('stderr bytes\n')ssys.stdout.flush()ssys.stderr.flush()s$os.kill(os.getpid(), signal.SIGKILL)csF|\}}}j|dj|dj|tjdS(Ns
stdout bytes
s
stderr bytes
(RtsignaltSIGKILL(R)R*Rtsig(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyR,ss-u(RRR/RRttupleR(RRR,R((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyttest_outputSignal~s
s"Windows doesn't have real signals.cCsltjj|j}tj||jddg}||jd|gd|}|j|||S(Nsimport os, sysssys.stdout.write(os.getcwd())s-uR(RRRRtmakedirsRRR(RtutilFunctchecktdirRR((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyt	_pathTests
cCs|jtj|jS(s
        L{getProcessOutput} runs the given command with the working directory
        given by the C{path} parameter.
        (R:RRR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyttest_getProcessOutputPathscs"fd}jtj|S(s~
        L{getProcessValue} runs the given command with the working directory
        given by the C{path} parameter.
        csj|ddS(Ni(R(tresulttignored(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyR8s(R:RR'(RR8((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyttest_getProcessValuePathscs"fd}jtj|S(s
        L{getProcessOutputAndValue} runs the given command with the working
        directory given by the C{path} parameter.
        cs3|\}}}j||j|ddS(Ni(R(R)R9R*Rtstatus(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyR8s(R:RR/(RR8((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyt!test_getProcessOutputAndValuePathscCstjj|j}tj||jdd|fdg}|jtjtjtj||jtj	|t
jtj
djtj	|d||j
d|g}|j|||S(Nsimport os, sys, statsos.chmod(%r, stat.S_IXUSR)ssys.stdout.write(os.getcwd())t.is-u(RRRRR6Rt
addCleanuptchdirtgetcwdtchmodtstattS_IMODEtst_modeRR(RR7R8R9RR((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyt_defaultPathTests


%cCs|jtj|jS(s
        If no value is supplied for the C{path} parameter, L{getProcessOutput}
        runs the given command in the same working directory as the parent
        process and succeeds even if the current working directory is not
        accessible.
        (RIRRR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyt test_getProcessOutputDefaultPathscs"fd}jtj|S(s
        If no value is supplied for the C{path} parameter, L{getProcessValue}
        runs the given command in the same working directory as the parent
        process and succeeds even if the current working directory is not
        accessible.
        csj|ddS(Ni(R(R<R=(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyR8s(RIRR'(RR8((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyttest_getProcessValueDefaultPathscs"fd}jtj|S(s	
        If no value is supplied for the C{path} parameter,
        L{getProcessOutputAndValue} runs the given command in the same working
        directory as the parent process and succeeds even if the current
        working directory is not accessible.
        cs3|\}}}j||j|ddS(Ni(R(R)R9R*RR?(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyR8s(RIRR/(RR8((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyt(test_getProcessOutputAndValueDefaultPathsN(t__name__t
__module__t__doc__RtIReactorProcessRtNonetskiptoutputtvalueR-R.RRRR"R&R(R0R5Rt	isWindowsR:R;R>R@RIRJRKRL(((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyRs.												
			
	tWarningSuppressioncBs,eZdZdZdZdZRS(cCs%g|_tj|_|jt_dS(N(twarningstshowwarningtoriginalshow(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pytsetUps	cCs|jt_dS(N(RYRWRX(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyttearDownscOs|jj||fdS(N(RWtappend(Rtatkw((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyRXscCsd}tj|d	tddf}|d|jt|jd|d|jt|jd|d|jt|jddS(
NcSstj|dS(N(RWtwarn(tmsg((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pytfstignoretmessagesThis is messagesSanity check messageisUnignored messagei(signore(RtsuppressWarningstdictRtlenRW(RRatg((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyttestSuppressWarningss	!


(RMRNRZR[RXRh(((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyRVs			(RORWRRFR-R1ttwisted.python.runtimeRt
twisted.trialRttwisted.internetRRRRtTestCaseRRV(((s</usr/lib/python2.7/dist-packages/twisted/test/test_iutils.pyt<module>s<"