ó
[³XMc           @   s   d  d l  Z  d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l Z e j Z	 d d d     Ya
 d t
 f d     YZ d e f d	     YZ d
 e e f d     Ya d d d     YZ d a d e j f d     YZ d e j f d     YZ d S(   i’’’’N(   t   unittest(   t   rebuildt   Fooc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR      s    t   Barc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR      s    t   Bazc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR      s    t   Buzc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR      s    t   HashRaisesRuntimeErrorc           B   s    e  Z d  Z d   Z d   Z RS(   s”   
    Things that don't hash (raise an Exception) should be ignored by the
    rebuilder.

    @ivar hashCalled: C{bool} set to True when __hash__ is called.
    c         C   s   t  |  _ d  S(   N(   t   Falset
   hashCalled(   t   self(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   __init__   s    c         C   s   t  |  _ t d   d  S(   Ns   not a TypeError!(   t   TrueR
   t   RuntimeError(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   __hash__   s    	(   R   R   t   __doc__R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR      s   	t   RebuildTestCasec           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   sH   
    Simple testcase for rebuilding, to at least exercise the code.
    c         C   s   |  j    |  _ t j |  j  t j j |  j d  |  _ t j |  j  t t j j |  j d  d  j   t	 j j
 d |  j  d  S(   Nt   twisted_rebuild_fakelibs   __init__.pyt   wi    (   t   mktempt   libPatht   ost   mkdirt   patht   joint   fakelibPatht   filet   closet   syst   insert(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   setUp+   s    %c         C   s   t  j j |  j  d  S(   N(   R   R   t   removeR   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   tearDown3   s    c         C   s½  d d l  m } d d  l } d d  l } | j | t d  t j j |  j	 d   d d l
 m } | j   } y t Wn t k
 r nH Xd d l m } | j   } d | j f d     Y} | | _ |   }	 | j   }
 |  j | j   d	  | j d
  | j | t d  t j j |  j	 d   t j |  y t Wn t k
 rTn9 X| j   } |  j | j   d  |  j | j   d  |  j |
 j   d  |  j | j   d  d  S(   Ni’’’’(   t   sibpaths   myrebuilder1.pys   myrebuilder.py(   t   myrebuilder(   t   test_rebuildt   Cc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR%   D   s   t   agń?s   myrebuilder2.pyt   ct   dt   b(   t   twisted.python.utilR"   t   shutilt   timet   copyfilet   __file__R   R   R   R   R   R#   t   At   objectt	   NameErrort   twisted.testR$   t   BR%   t   Inheritt   assertEqualsR&   t   sleepR   R)   (   R   R"   R+   R,   R#   R&   R$   R)   R%   R'   t   it   b2(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   testFileRebuild6   s<    		c         C   sY   t  j d  } t j t  d t | j   |  j | j t  j  |  j t t  j  d S(   s1   
        Rebuilding an unchanged module.
        R&   t   doLogN(	   t   crash_test_dummyt   XR   R	   t   dot   failUnlessIdenticalt	   __class__t   ft   foo(   R   t   x(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   testRebuild^   s
    
c         C   sÆ   t  j   } | j t  j t  j  | j t  j  } t j t  d  | j t  j  } | j   |  j | j	 t  j  d d l
 m } |  j t | j t  j t  j t  j  d  S(   Ni    i’’’’(   t
   components(   R;   t
   XComponentt
   setAdaptert   IXt   XAt   getComponentR   t   methodR5   R?   t   twisted.pythonRD   t   failUnlessRaisest
   ValueErrort   registerAdapterR<   (   R   RB   t   oldComponentt   newComponentRD   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   testComponentInteractiono   s    
c         C   sv   t    } d d	 d     Ya d t t f d     Ya  t j |  t | d  sZ t d  t | d  sr t d  d  S(
   NR   c           B   s   e  Z d    Z RS(   c         S   s   d  S(   N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyRA      s    (   R   R   RA   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR      s   R   c           B   s   e  Z d  Z RS(   i
   (   R   R   RB   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR      s   RA   s"   Missing method on rebuilt instanceRB   s+   Missing class attribute on rebuilt instance(    (   R   R   R   R   R   t   updateInstancet   hasattrt   AssertionError(   R   R)   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   testUpdateInstance   s    	c         C   s4   d d l  m } d d l m } | j | j  d  S(   Ni’’’’(   R   (   t   banana(   RK   R   t   twisted.spreadRV   t   latestClasst   Banana(   R   R   RV   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   testBananaInteraction   s    c         C   sC   t    a d   } |  j |  t j t  |  j t j t  d S(   s~   
        Rebuilding something that has a __hash__ that raises a non-TypeError
        shouldn't cause rebuild to die.
        c           S   s
   d  a d  S(   N(   t   Nonet   unhashableObject(    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   _cleanup   s    N(   R   R\   t
   addCleanupR   R5   R
   R   (   R   R]   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   test_hashException   s
    		(   R   R   R   R   R!   R9   RC   RQ   RU   RZ   R_   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR   '   s   			(				t   NewStyleTestCasec           B   sz   e  Z d  Z d   Z d   Z d   Z e j d k  rB d e _ n  d   Z	 e j d k rf d e	 _ n  d	   Z
 d
   Z RS(   sB   
    Tests for rebuilding new-style classes of various sorts.
    c         C   s&   t  j d  |  _ |  j t j d <d  S(   Nt   whipping(   t   newt   modulet   mR   t   modules(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR   ©   s    c         C   s   t  j d =|  ` d  S(   NRa   (   R   Re   Rd   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR!   ®   s    
c         B   sz   d } | |  j  j U|  j  j   } d | _ | |  j  j Ue j |  |  j | j d  |  j e |  |  j  j  d S(   sF   
        Try to rebuild a new style class with slots defined.
        s2   class SlottedClass(object):
    __slots__ = ['a']
i   N(	   Rd   t   __dict__t   SlottedClassR&   R   RR   t   assertEqualt   assertIdenticalt   type(   R   t   classDefinitiont   inst(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt
   test_slots³   s    	i   i   sO   __class__ assignment for class with slots is only available starting Python 2.6c         B   sW   d } | |  j  j U|  j  j   } d | _ | |  j  j U|  j e j e j |  d S(   sX   
        Try to rebuild a new style class with slots defined: this should fail.
        s2   class SlottedClass(object):
    __slots__ = ['a']
i   N(   Rd   Rf   Rg   R&   t   assertRaisesR   t   RebuildErrorRR   (   R   Rk   Rl   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   test_errorSlotsĒ   s    	sI   __class__ assignment for class with slots should work starting Python 2.6c         B   s   d } | |  j  j U|  j  j   } | j d  | |  j  j Ue j |  |  j | d d  |  j e |  |  j  j  d S(   s6   
        Try to rebuild a base type subclass.
        s#   class ListSubclass(list):
    pass
i   i    N(	   Rd   Rf   t   ListSubclasst   appendR   RR   Rh   Ri   Rj   (   R   Rk   Rl   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   test_typeSubclassŁ   s    c         B   s]   d } | |  j  j U|  j  j   } d g | _ d } | |  j  j U|  j e e j |  d S(   s   
        Test that when rebuilding an instance with a __slots__ attribute, it
        fails accurately instead of giving a L{rebuild.RebuildError}.
        s(   class NotSlottedClass(object):
    pass
R&   s    class NotSlottedClass:
    pass
N(   Rd   Rf   t   NotSlottedClasst	   __slots__Rn   t	   TypeErrorR   RR   (   R   Rk   Rl   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   test_instanceSlotsź   s    (   i   i   (   i   i   (   R   R   R   R   R!   Rm   R   t   version_infot   skipRp   Rs   Rw   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyR`   „   s   					(    (    (   R   R   Rb   t   twisted.trialR    RK   R   R;   RA   R@   R   R   R0   R   R   R   R[   R\   t   TestCaseR   R`   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_rebuild.pyt   <module>   s   	~