Your IP : 172.28.240.42


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


ZOc@sdZeZddlZddlmZddlmZmZddl	m
Z
ddlmZm
Z
ddlmZddlmZe
jrdZndd	lmZd
ddYZd
gZdS(
s/
Tests for implementations of L{IReactorTime}.
iN(tTimeoutError(tTestCasetSkipTest(tplatform(tnamedAnytfullyQualifiedName(tlog(tFailure(tprocesstReactorBuildercBseZdZdgZejr@ejdddddgnKejddd	d
gejruejdnejdd
dgdZ
dZdZiZ
dZdZdZdZddZdZeeZRS(s
    L{TestCase} mixin which provides a reactor-creation API.  This mixin
    defines C{setUp} and C{tearDown}, so mix it in before L{TestCase} or call
    its methods from the overridden ones in the subclass.

    @cvar skippedReactors: A dict mapping FQPN strings of reactors for
        which the tests defined by this class will be skipped to strings
        giving the skip message.
    @cvar requiredInterfaces: A C{list} of interfaces which the reactor must
        provide or these tests will be skipped.  The default, C{None}, means
        that no interfaces are required.
    @ivar reactorFactory: A no-argument callable which returns the reactor to
        use for testing.
    @ivar originalHandler: The SIGCHLD handler which was installed when setUp
        ran and which will be re-installed when tearDown runs.
    @ivar _reactors: A list of FQPN strings giving the reactors for which
        TestCases will be created.
    s,twisted.internet.selectreactor.SelectReactors,twisted.internet.gireactor.PortableGIReactors0twisted.internet.gtk3reactor.PortableGtk3Reactors/twisted.internet.gtk2reactor.PortableGtkReactors/twisted.internet.win32eventreactor.Win32Reactors0twisted.internet.iocpreactor.reactor.IOCPReactors$twisted.internet.gireactor.GIReactors(twisted.internet.gtk3reactor.Gtk3Reactors*twisted.internet.glib2reactor.Glib2Reactors(twisted.internet.gtk2reactor.Gtk2Reactors$twisted.internet.cfreactor.CFReactors(twisted.internet.pollreactor.PollReactors*twisted.internet.epollreactor.EPollReactors(twisted.internet.kqreactor.KQueueReactorcCs.tjs*tjtjtj|_ndS(s
        Clear the SIGCHLD handler, if there is one, to ensure an environment
        like the one which exists prior to a call to L{reactor.run}.
        N(Rt	isWindowstsignaltSIGCHLDtSIG_DFLtoriginalHandler(tself((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pytsetUpUscCsl|jdk	r(tjtj|jntdk	rhx1tjrdtjdtjftjq7WndS(s|
        Restore the original SIGCHLD handler and reap processes as long as
        there seem to be any remaining.
        s1ReactorBuilder.tearDown reaping some processes %rN(	RtNoneRRRtreapProcessHandlersRtmsgtreapAllProcesses(R((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pyttearDown^scCs|jt|dddk	r`x+|jD] }|j||jdq,W|jjn|j|j}x|D]}|j	q}WdS(s
        Clean up any resources which may have been allocated for the given
        reactor by its creation or by a test which used it.
        t_internalReadersN(
t_uninstallHandlertgetattrRRtremoveReadertconnectionLosttcleart
disconnectAlltgetDelayedCallstcancel(Rtreactortreadertcallstc((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pytunbuildReactorms



c	sIy$ddlm}ddlm}Wntk
r7n.Xt||re|j|kretdny|jWn6tj	d	d|jttj
nX|jd	k	r2tfd|j}|r2|jtdtjdjg|D]}t|^q
fq2n|j|jS(
sK
        Create and return a reactor using C{self.reactorFactory}.
        i(t	CFReactor(RsuCFReactor uses APIs which manipulate global state, so it's not safe to run its own reactor-builder tests under itselfsFailed to install reactorcs|jS(N(t
providedBy(trequired(R(sG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pyt<lambda>ss%s does not provide %st,N(ttwisted.internet.cfreactorR$ttwisted.internetRtImportErrort
isinstancetreactorFactoryRRterrRtflushLoggedErrorsRtgetErrorMessagetrequiredInterfacestfilterR#Rt	__class__tjoint
addCleanup(RR$t
globalReactortmissingtx((RsG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pytbuildReactors4


5csm|dkr|j}ngfd}j||jritd|fndS(s
        Run the reactor for at most the given amount of time.

        @param reactor: The reactor to run.

        @type timeout: C{int} or C{float}
        @param timeout: The maximum amount of time, specified in seconds, to
            allow the reactor to run.  If the reactor is still running after
            this much time has elapsed, it will be stopped and an exception
            raised.  If C{None}, the default test method timeout imposed by
            Trial will be used.  This depends on the L{IReactorTime}
            implementation of C{reactor} for correct operation.

        @raise TimeoutError: If the reactor is still running after C{timeout}
            seconds.
        csjdjdS(N(tappendRtstop((ttimedOutR(sG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pyR;s
s&reactor still running after %s secondsN(Rt
getTimeoutt	callLatertrunR(RRttimeoutR;((RR<sG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pyt
runReactors
csi}xyjD]njdd}jd|jdd}dtffdY}||_|||j<qW|S(s
        Create a L{TestCase} subclass which mixes in C{cls} for each known
        reactor and return a dict mapping their names to them.
        t.it_ttestcasecsYeZjZjkr.jZnyeZWnejZnXRS((t__name__t
__module__tskippedReactorstskipRR-RR0((Rtcls(sG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pyRDs	(t	_reactorstsplitREtreplaceR(RItclassestshortReactorNametnameRD((RIRsG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pytmakeTestCaseClassess"	N(RERFt__doc__RJRR
textendtisMacOSXR:RR-RR1RGRRR#R9RARPtclassmethod(((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pyR	s>	


				 	* 	((RQttypet
__metaclass__Rttwisted.internet.deferRttwisted.trial.unittestRRttwisted.python.runtimeRttwisted.python.reflectRRttwisted.pythonRttwisted.python.failureRR
RRR*R	t__all__(((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/reactormixins.pyt<module>s