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/test_base.pyc


=Nc@sdZddlZddlmZddlmZddlmZddlmZddl	m
Z
mZddlm
Z
dd	lmZmZdd
lmZddlmZdefd
YZdefdYZdefdYZdS(s%
Tests for L{twisted.internet.base}.
iN(tQueue(t
implements(t
ThreadPool(t
setIDFunction(tIReactorTimetIReactorThreads(tDNSLookupError(tThreadedResolvertDelayedCall(tClock(tTestCasetFakeReactorcBs?eZdZeeedZdZdZdZ	RS(sl
    A fake reactor implementation which just supports enough reactor APIs for
    L{ThreadedResolver}.
    csVt_jj_t_jjfd_t_dS(NcsjS(N(t_threadpool((tself(sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyt<lambda>#s(	R	t_clockt	callLaterRRtstartt
getThreadPoolRt_threadCalls(R
((R
sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyt__init__s
cOs|jj|||fdS(N(Rtput(R
tftargstkwargs((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pytcallFromThread(scCs)|jj\}}}|||dS(N(Rtget(R
RRR((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyt_runThreadCalls,scCs|jjdS(N(Rtstop(R
((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyt_stop1s(
t__name__t
__module__t__doc__RRRRRRR(((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyRs
			tThreadedResolverTestscBs)eZdZdZdZdZRS(s(
    Tests for L{ThreadedResolver}.
    csdd}d}t}|j|jgg}fd}|jtd|t|}|j||f}|j|j|j	|j
|g|j
|g|jj|d|j
|jj
gdS(s
        L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires
        with the value returned by the call to L{socket.gethostbyname} in the
        threadpool of the reactor passed to L{ThreadedResolver.__init__}.
        s	10.0.0.17sfoo.bar.example.comicsj|S(N(tappend(tname(tiptlookedUp(sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pytfakeGetHostByNameIs
t
gethostbynameiN(Rt
addCleanupRtpatchtsocketRt
getHostByNametaddCallbackR"RtassertEqualRtadvancetcalls(R
R#ttimeouttreactort
resolvedToR&tresolvertd((R$R%sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyttest_success:s"	
cCsd}t}|j|jd}|jtd|g}t|}|jd|f}|j|t|j	|j
|j|jt
|d|jj|d|j|jjgdS(s
        L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires a
        L{Failure} if the call to L{socket.gethostbyname} raises an exception.
        icSstddS(NsENOBUFS (this is a funny joke)(tIOError(R#((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyR&gsR's	some.nameiN(RR(RR)R*RR+t
assertFailureRR,R"RR-tlenRR.R/(R
R0R1R&t
failedWithR3R4((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyttest_failure]s		
csd}t}|j|jtfd}|jtd|g}t|}|jd|f}|j|t	|j
|j|jj
|d|j|g|jj
d|jt|djtddS(s
        If L{socket.gethostbyname} does not complete before the specified
        timeout elapsed, the L{Deferred} returned by
        L{ThreadedResolver.getHostByBame} fails with L{DNSLookupError}.
        i
csjdS(N(R(R#(tresult(sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyR&sR's	some.nameisThe I/O was errorfulN(RR(RRR)R*RR+R7RR,R"RR.R-R8RR6(R
R0R1R&R9R3R4((R;sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyttest_timeout{s 		(RRR R5R:R<(((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyR!6s	#	tDelayedCallTestscBs_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
s#
    Tests for L{DelayedCall}.
    cCs(d}t|ddi||dS(s
        Get a L{DelayedCall} instance at a given C{time}.
        
        @param time: The absolute time at which the returned L{DelayedCall}
            will be scheduled.
        cSsdS(N((tcall((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pytnoopscSsdS(N(tNone(((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyRs(N(RR@(R
ttimeR?((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyt_getDelayedCallAts	cCs(|jd|_|jd|_dS(sb
        Create two L{DelayedCall} instanced scheduled to run at different
        times.
        iiN(RBtzerotone(R
((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pytsetUpscs}d}td|didd6d
d
d}id|6fd}|jtt||jt|d	d
S(s
        The string representation of a L{DelayedCall} instance, as returned by
        C{str}, includes the unsigned id of the instance, as well as its state,
        the function to be called, and the function arguments.
        cSsdS(N((((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pytnothingsiiitAcSsdS(Ng?((((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyRsics1y|SWnttfk
r,t|SXdS(N(t	TypeErrortKeyErrortid(tobj(tids(sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pytfakeIDss?<DelayedCall 0xc8 [10.5s] called=0 cancelled=0 nothing(3, A=5)>N(i(RR@R(RR-tstr(R
RFtdcRM((RLsC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyttest_strs	(
	cCsc|j|j}}|j||k|j||k|j||k|j||kdS(s
        For two instances of L{DelayedCall} C{a} and C{b}, C{a < b} is true
        if and only if C{a} is scheduled to run before C{b}.
        N(RCRDt
assertTruetassertFalse(R
RCRD((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyttest_lts
cCsc|j|j}}|j||k|j||k|j||k|j||kdS(s
        For two instances of L{DelayedCall} C{a} and C{b}, C{a <= b} is true
        if and only if C{a} is scheduled to run before C{b} or at the same
        time as C{b}.
        N(RCRDRQRR(R
RCRD((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyttest_les
cCsc|j|j}}|j||k|j||k|j||k|j||kdS(s
        For two instances of L{DelayedCall} C{a} and C{b}, C{a > b} is true
        if and only if C{a} is scheduled to run after C{b}.
        N(RCRDRQRR(R
RCRD((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyttest_gts
cCsc|j|j}}|j||k|j||k|j||k|j||kdS(s
        For two instances of L{DelayedCall} C{a} and C{b}, C{a > b} is true
        if and only if C{a} is scheduled to run after C{b} or at the same
        time as C{b}.
        N(RCRDRQRR(R
RCRD((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyttest_ges
cCsO|j|j|jk|j|j|jk|j|j|jkdS(sD
        A L{DelayedCall} instance is only equal to itself.
        N(RRRCRDRQ(R
((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyttest_eqscCsO|j|j|jk|j|j|jk|j|j|jkdS(sM
        A L{DelayedCall} instance is not equal to any other object.
        N(RQRCRDRR(R
((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyttest_nes(RRR RBRERPRSRTRURVRWRX(((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyR=s						
		
	(R R*Rtzope.interfaceRttwisted.python.threadpoolRttwisted.python.utilRttwisted.internet.interfacesRRttwisted.internet.errorRttwisted.internet.baseRRttwisted.internet.taskR	ttwisted.trial.unittestR
tobjectRR!R=(((sC/usr/lib/python2.7/dist-packages/twisted/internet/test/test_base.pyt<module>s g