Ϫf`dZddlmZddlmZmZmZddlZddl m Z ddl m Z ddl mZmZddlmZd d lmZd d lmZd d lmZd d lmZmZd dlmZddlmZddlmZGddej@jBjDZ#Gddej@jBjDZ$y)z0 Tests for L{twisted.application.twist._twist}. )stdout)AnyDictListN) IReactorCore) MemoryReactor)LogLeveljsonFileLogObserver)SignalCapturingMemoryReactor) ExitStatus)Runner) DummyExit)IService MultiService)_twist) TwistOptions)Twistc`eZdZdZd dZd dZd dZd dZd dZd dZ d d Z d d Z d d Z d d Z y) TwistTestsz Tests for L{Twist}. Nc$|jyN)patchInstallReactorselfs K/usr/lib/python3/dist-packages/twisted/application/twist/test/test_twist.pysetUpzTwistTests.setUps   "cdt|_|jtd|jy)zX Patch L{_twist.exit} so we can capture usage and prevent actual exits. exitN)rr!patchrrs r patchExitzTwistTests.patchExit!s!K  66499-rcri_dtdtdtffd }j td|y)zo Patch C{_options.installReactor} so we can capture usage and prevent actual installs. _namereturnc:t}|j|<|Sr)rinstalledReactors)r%r&reactorrs rinstallReactorz6TwistTests.patchInstallReactor..installReactor/s#oG+2D " "4 (Nrr+N)r)rstrrr")rr+s` rrzTwistTests.patchInstallReactor(s: ;= l # ,  Brc^g_dtddffd }jtd|y)zo Patch L{MultiService.startService} so we can capture usage and prevent actual starts. servicer'Nc<jj|yr) serviceStartsappend)r.rs r startServicez2TwistTests.patchStartService..startService=s    % %g .rr2)r0rr"r)rr2s` rpatchStartServicezTwistTests.patchStartService6s2 .0 /( /t / <>rc^tjddg}|j|ty)zI L{Twist.options} given valid arguments returns options. twistwebN)roptionsassertIsInstancer)rr7s rtest_optionsValidArgumentsz%TwistTests.test_optionsValidArgumentsBs'--% 01 g|4rc|jtjddg|j|jj t j|j|jj|j|jjjd|j|jjjdty)z L{Twist.options} given invalid arguments exits with L{ExitStatus.EX_USAGE} and an error/usage message. r5z--bogus-bagelszError: z N)r#rr7assertIdenticalr!statusr EX_USAGEassertIsNotNonemessage assertTrue startswithendswithrrs rtest_optionsInvalidArgumentsz'TwistTests.test_optionsInvalidArgumentsJs  w 012 TYY--z/B/BC TYY../  II   ( ( 3   II   & &|~&'  rctjddg}tj|jd|j}|j t j|y)z: L{Twist.service} returns an L{IService}. r5r6N)rr7r.plugins subOptionsr@r providedBy)rr7r.s r test_servicezTwistTests.test_service^sM--% 01-- 68J8JK ++G45rctjddg}|d}|j}|Jtj|j||j }|j tj|||j|j|g|j|jdd|jdifgy) z L{Twist.startService} starts the service and registers a trigger to stop the service when the reactor shuts down. r5r6r*N)pluginr7beforeshutdown) rr7 subCommandr.rErFr3r2 assertEqualr0triggers stopService)rr7r*rNr.s rtest_startServicezTwistTests.test_startServicefs --% 01)$'' %%%--??:.&&    7G, ++gY7    X &z 2g6I6I2r5R4S rc g|jtdfd|jtddtjgd}tj||j t d|j dt|jdtjtt y ) zi L{Twist.run} runs the runner with arguments corresponding to the given options. __init__c&j|Sr)r1)rargsargsSeens rz%TwistTests.test_run..sHOOD.rr5z--reactor=defaultz--log-format=jsonr6rdefaultr*defaultLogLevellogFilefileLogObserverFactoryN) r"rrr7rYrOlendictr)r inforr )r twistOptionsrWs @rtest_runzTwistTests.test_run~s  6:'QR 65"34}} F   , X*  QK ..y9 ( ':   rc |jgGfdd}|jtd|tjgd|j t |jd|j t d|j djt|jdtjtt|j djdy) zy L{Twist.main} runs the runner with arguments corresponding to the given command line arguments. c*eZdZdeddffd ZddZy)$TwistTests.test_main..Runnerkwargsr'NcD||_d|_j|y)Nr)rVrunsr1)rrkrunnerss rrTz-TwistTests.test_main..Runner.__init__s"  t$rc.|xjdz c_y)Nr])rmrs rrYz(TwistTests.test_main..Runner.runs Q rr'N)__name__ __module__ __qualname__rrTrY)rnsrrrjs % % %  rrr\r]rr^r_N)r3r"rrmainrOrcr0rVrdr)r rerr rm)rrrns @r test_mainzTwistTests.test_mains     68V, MN T//0!4 Wq)  AJOO ..y9 ( ':    !,rrp)rqrrrs__doc__rr#rr3r9rCrHrRrgrurMrrrrs:#. C ?5 (6 0 4!-rrc0eZdZdZddZddZddZddZy)TwistExitTestszr Tests to verify that the Twist script takes the expected actions related to signals and the reactor. Ncd_dtddffd }jtd|dtddfd}jtd|y) NFsigr'cd_y)z Fake to capture whether L{twisted.application._exitWithSignal was called. @param sig: Signal value @type sig: C{int} TN)exitWithSignalCalled)rzrs rfakeExitWithSignalz0TwistExitTests.setUp..fakeExitWithSignals )-D %r_exitWithSignalr%cy)z Prevent Runner from adding new log observers or other tests outside this module will fail. @param _: Unused self param NrM)r%s r startLoggingz*TwistExitTests.setUp..startLoggingr[rr)r|intr"rr)rr}rs` rrzTwistExitTests.setUpsW$)! -C -D - 6,.@A F t  6><8rct}d|_t}||d<t|d<t j ||j |jy)zg _exitWithSignal is not called if the reactor's _exitSignal attribute is zero. Nr*rb)r _exitSignalrr rrY assertFalser|rr*r7s r%test_twistReactorDoesntExitWithSignalz4TwistExitTests.test_twistReactorDoesntExitWithSignalsP /0".$ ,?() ' 223rct}t}||d<t|d<tj||j |j y)z _exitWithSignal is not called if the runner's reactor does not implement L{twisted.internet.interfaces._ISupportsExitSignalCapturing} r*rbN)rrr rrYrr|rs r$test_twistReactorHasNoExitSignalAttrz3TwistExitTests.test_twistReactorHasNoExitSignalAttrsG  /.$ ,?() ' 223rct}d|_t}||d<t|d<t j ||j |jy)zb _exitWithSignal is called if the runner's reactor exits due to a signal. rr*rbN)r rrr rrYr@r|rs r test_twistReactorExitsWithSignalz/TwistExitTests.test_twistReactorExitsWithSignalsN /0.$ ,?() ' 112rrp)rqrrrsrvrrrrrMrrrxrxs 92 4 4 3rrx)%rvsysrtypingrrrtwisted.trial.unittesttwistedtwisted.internet.interfacesrtwisted.internet.testingrtwisted.loggerr r twisted.test.test_twistdr runner._exitr runner._runnerrrunner.test.test_runnerrr.rrr5r_optionsrrtrialunittestTestCaserrxrMrrrsv""428A&$0-#`-''00`-FD3W]]++44D3r