σ @r`Pc@`sldZddlmZmZddlmZddlmZdd d„ƒYZdej fd„ƒYZ d S( s% Tests for L{twisted.python.monkey}. i(tdivisiontabsolute_import(tunittest(t MonkeyPatchertTestObjcB`seZd„ZRS(cC`sd|_d|_d|_dS(Ns foo values bar values baz value(tfootbartbaz(tself((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt__init__s  (t__name__t __module__R (((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyRstMonkeyPatcherTestcB`sqeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z RS( s; Tests for L{MonkeyPatcher} monkey-patching class. cC`s(tƒ|_tƒ|_tƒ|_dS(N(Rt testObjecttoriginalObjectRt monkeyPatcher(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pytsetUps  cC`se|jjƒ|j|jj|jjƒ|j|jj|jjƒ|j|jj|jjƒdS(sL A monkey patcher without patches shouldn't change a thing. N(Rtpatcht assertEqualRRR RR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt test_empty!s cC`s}t|jddf|jddfƒ}|jƒ|jd|jjƒ|jd|jjƒ|j|jj|jjƒdS(s} Constructing a L{MonkeyPatcher} with patches should add all of the given patches to the patch list. RthahaRtheheN(RR RRRRRR(Rtpatcher((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyttest_constructWithPatches.s  cC`s@|jj|jddƒ|jjƒ|j|jjdƒdS(sf Patching an attribute that exists sets it to the value defined in the patch. RRN(RtaddPatchR RRR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyttest_patchExisting;s cC`s3|jj|jddƒ|jt|jjƒdS(sT Patching a non-existing attribute fails with an C{AttributeError}. tnowheresblow up pleaseN(RRR t assertRaisestAttributeErrorR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyttest_patchNonExistingEscC`s‚|jj|jddƒ|jj|jddƒ|jjƒ|j|jjdƒ|jjƒ|j|jj|jjƒdS(s| Adding a patch for an object and attribute that already have a patch overrides the existing patch. RtblahtBLAHN(RRR RRRtrestoreR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyttest_patchAlreadyPatchedNs   cC`s||jj|jddƒ|jjƒ|jjƒ|j|jj|jjƒ|jjƒ|j|jj|jjƒdS(sH Restoring an already-restored monkey patch is a no-op. RRN(RRR RR RRR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyttest_restoreTwiceIsANoOp[s    c`s]g‰d‡fd†}|jj|ddddƒ}|jd|ƒ|jdgˆƒdS( s€ runWithPatches should run the given callable, passing in all arguments and keyword arguments, and return the return value of the callable. c`sˆj|||fƒdS(NR(tappend(tatbtc(tlog(s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pytfnsiiR&i RN(iii (tNoneRtrunWithPatchesR(RR(tresult((R's</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyttest_runWithPatchesDecorationgs c`sš‡fd†}ˆjjˆjddƒˆjj|ƒ}ˆjdˆjjˆjjf|ƒˆjj|ƒ}ˆjdˆjjˆjjf|ƒdS(s‘ We should be able to call the same function with runWithPatches more than once. All patches should apply for each call. c`sˆjjˆjjˆjjfS(N(R RRR((R(s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyR(|sRRN(RRR R*RRRR(RR(R+((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyttest_repeatedRunWithPatcheswscC`sh|jj|jddƒ|j|jj|jjƒ|jjd„ƒ|j|jj|jjƒdS(so C{runWithPatches} should restore the original values after the function has executed. RRcS`sdS(N(R)(((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt‘sN(RRR RRRR*(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyttest_runWithPatchesRestoresŠsc`s–‡fd†}ˆjjˆjddƒˆjjˆjddƒˆjtˆjj|ƒˆjˆjjˆjjƒˆjˆjj ˆjj ƒdS(sv Test runWithPatches restores the original values even when the function raises an exception. c`s<ˆjˆjjdƒˆjˆjjdƒtdƒ‚dS(NRtblahblahsSomething went wrong!(RR RRt RuntimeError((R(s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt_šsRRRR0N( RRR RR1R*RRRR(RR2((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt&test_runWithPatchesRestoresOnException•s (R R t__doc__RRRRRR!R"R,R-R/R3(((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyR s    N(( R4t __future__RRt twisted.trialRttwisted.python.monkeyRRtSynchronousTestCaseR (((s</usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyts