ó
[³XMc           @   sV   d  Z  d d l m Z d d l m Z d d	 d „  ƒ  YZ d e j f d „  ƒ  YZ d S(
   s%   
Tests for L{twisted.python.monkey}.
iÿÿÿÿ(   t   unittest(   t   MonkeyPatchert   TestObjc           B   s   e  Z d  „  Z RS(   c         C   s   d |  _  d |  _ d |  _ d  S(   Ns	   foo values	   bar values	   baz value(   t   foot   bart   baz(   t   self(    (    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.pyR      s   t   MonkeyPatcherTestc           B   sq   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z RS(   s;   
    Tests for L{MonkeyPatcher} monkey-patching class.
    c         C   s(   t  ƒ  |  _ t  ƒ  |  _ t ƒ  |  _ d  S(   N(   R   t
   testObjectt   originalObjectR   t   monkeyPatcher(   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   setUp   s    c         C   se   |  j  j ƒ  |  j |  j j |  j j ƒ |  j |  j j |  j j ƒ |  j |  j j |  j j ƒ d S(   sL   
        A monkey patcher without patches shouldn't change a thing.
        N(   R   t   patcht   assertEqualsR   R   R   R   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt
   test_empty   s    c         C   s}   t  |  j d d f |  j d d f ƒ } | j ƒ  |  j d |  j j ƒ |  j d |  j j ƒ |  j |  j j |  j j ƒ d S(   s}   
        Constructing a L{MonkeyPatcher} with patches should add all of the
        given patches to the patch list.
        R   t   hahaR   t   heheN(   R   R   R   R   R   R   R   R   (   R   t   patcher(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   test_constructWithPatches+   s    
c         C   s@   |  j  j |  j d d ƒ |  j  j ƒ  |  j |  j j d ƒ d S(   sf   
        Patching an attribute that exists sets it to the value defined in the
        patch.
        R   R   N(   R   t   addPatchR   R   R   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   test_patchExisting8   s    c         C   s3   |  j  j |  j d d ƒ |  j t |  j  j ƒ d S(   sT   
        Patching a non-existing attribute fails with an C{AttributeError}.
        t   nowheres   blow up pleaseN(   R   R   R   t   assertRaisest   AttributeErrorR   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   test_patchNonExistingB   s    c         C   s‚   |  j  j |  j d d ƒ |  j  j |  j d d ƒ |  j  j ƒ  |  j |  j j d ƒ |  j  j ƒ  |  j |  j j |  j j ƒ d S(   s|   
        Adding a patch for an object and attribute that already have a patch
        overrides the existing patch.
        R   t   blaht   BLAHN(   R   R   R   R   R   R   t   restoreR   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   test_patchAlreadyPatchedK   s    c         C   s|   |  j  j |  j d d ƒ |  j  j ƒ  |  j  j ƒ  |  j |  j j |  j j ƒ |  j  j ƒ  |  j |  j j |  j j ƒ d S(   sH   
        Restoring an already-restored monkey patch is a no-op.
        R   R   N(   R   R   R   R   R   R   R   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   test_restoreTwiceIsANoOpX   s    c            s]   g  ‰  d ‡  f d † } |  j j | d d d d ƒ} |  j d | ƒ |  j d g ˆ  ƒ d S(	   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 ƒ d S(   NR   (   t   append(   t   at   bt   c(   t   log(    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   fk   s    i   i   R$   i
   R   N(   i   i   i
   (   t   NoneR   t   runWithPatchesR   (   R   R&   t   result(    (   R%   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   test_runWithPatchesDecorationd   s
    c            sš   ‡  f d †  } ˆ  j  j ˆ  j d d ƒ ˆ  j  j | ƒ } ˆ  j d ˆ  j j ˆ  j j f | ƒ ˆ  j  j | ƒ } ˆ  j d ˆ  j j ˆ  j j f | ƒ d S(   s‘   
        We should be able to call the same function with runWithPatches more
        than once. All patches should apply for each call.
        c              s   ˆ  j  j ˆ  j  j ˆ  j  j f S(   N(   R   R   R   R   (    (   R   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyR&   y   s    R   R   N(   R   R   R   R(   R   R   R   R   (   R   R&   R)   (    (   R   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   test_repeatedRunWithPatchest   s    c         C   sh   |  j  j |  j d d ƒ |  j |  j j |  j j ƒ |  j  j d „  ƒ |  j |  j j |  j j ƒ d S(   so   
        C{runWithPatches} should restore the original values after the function
        has executed.
        R   R   c           S   s   d  S(   N(   R'   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   <lambda>Ž   s    N(   R   R   R   R   R   R   R(   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   test_runWithPatchesRestores‡   s    c            s–   ‡  f d †  } ˆ  j  j ˆ  j d d ƒ ˆ  j  j ˆ  j d d ƒ ˆ  j t ˆ  j  j | ƒ ˆ  j ˆ  j j ˆ  j j ƒ ˆ  j ˆ  j j	 ˆ  j j	 ƒ d S(   sv   
        Test runWithPatches restores the original values even when the function
        raises an exception.
        c              s9   ˆ  j  ˆ  j j d ƒ ˆ  j  ˆ  j j d ƒ t d ‚ d  S(   NR   t   blahblahs   Something went wrong!(   R   R   R   R   t   RuntimeError(    (   R   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   _—   s    R   R   R   R.   N(
   R   R   R   R   R/   R(   R   R   R   R   (   R   R0   (    (   R   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt&   test_runWithPatchesRestoresOnException’   s    (   R   R	   t   __doc__R   R   R   R   R   R   R    R*   R+   R-   R1   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyR
      s   				
							N(    (   R2   t   twisted.trialR    t   twisted.python.monkeyR   R   t   TestCaseR
   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_monkey.pyt   <module>   s   