
7ec        	   @   s0  d  d l  Z  d  d l Z d  d l Z 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
 m Z m Z m Z d  d l m Z m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d	 l m Z d  d
 l m Z d  d l m Z d  d l m Z m  Z  m! Z! d  d l" m# Z# d  d l$ m% Z% d  d l& m' Z' m( Z( d  d l) m* Z* m+ Z+ d  d l, m- Z- d  d l. m/ Z/ d  d l0 m1 Z1 d  d l2 m3 Z3 e- j4 rd  d l5 m6 Z6 n d e7 f d     YZ6 y d  d l8 Z8 Wn e9 k
 rd Z8 n XdN Z; e< e d!  Z= d e7 f d"     YZ> d e? f d#     YZ@ d$   ZA d% e7 f d&     YZB d d'  ZC d(   ZD eE eE d) d*  ZF d+   ZG d,   ZH d) eE d-  ZI d d.  ZJ d/ e7 f d0     YZK d eK f d1     YZL d eL f d2     YZM d3 eK f d4     YZN d5   ZO d6   ZP d7   ZQ d8 e7 f d9     YZR d: eK f d;     YZS e eE d<   ZT e e= d=  ZU e d>    ZV e d?    ZW e d@    ZX dA   ZY dB   ZZ dC   Z[ dD   Z\ e dE    Z] dF   Z^ dG eK f dH     YZ_ dI e7 f dJ     YZ` dK eK f dL     YZa dM   Zb d S(O   iN(   t   contextmanager(   t   wraps(   t   TestCaset   skipIft
   skipUnless(   t   Nodet   parseString(   t   apps(   t   Apps(   t   UserSettingsHoldert   settings(   t   mail(   t   ImproperlyConfigured(   t   request_started(   t   DEFAULT_DB_ALIASt   connectionst   reset_queries(   t   Options(   t   Template(   t   setting_changedt   template_rendered(   t   get_script_prefixt   set_script_prefix(   t   six(   t   available_attrs(   t	   force_str(   t
   deactivate(   t   SimpleNamespaceR   c           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR      s   t   Approximatet   ContextListt   isolate_lru_cachet
   get_runnert   modify_settingst   override_settingst   requires_tz_supportt   setup_test_environmentt   teardown_test_environmentt   tzsetc           B   s&   e  Z d  d  Z d   Z d   Z RS(   i   c         C   s   | |  _  | |  _ d  S(   N(   t   valt   places(   t   selfR(   R)   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   __init__3   s    	c         C   s   t  |  j  S(   N(   t   reprR(   (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   __repr__7   s    c         C   s6   |  j  | k r t St t |  j  |  |  j  d k S(   Ni    (   R(   t   Truet   roundt   absR)   (   R*   t   other(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   __eq__:   s    (   R   R   R+   R-   R2   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR   2   s   	c           B   s5   e  Z d  Z d   Z d d  Z d   Z d   Z RS(   sk   A wrapper that provides direct key access to context items contained
    in a list of context objects.
    c         C   s`   t  | t j  rF x" |  D] } | | k r | | Sq Wt |   n t t |   j |  Sd  S(   N(   t
   isinstanceR   t   string_typest   KeyErrort   superR   t   __getitem__(   R*   t   keyt
   subcontext(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR7   D   s    c         C   s*   y |  j  |  SWn t k
 r% | SXd  S(   N(   R7   R5   (   R*   R8   t   default(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   getM   s    c         C   s%   y |  | Wn t  k
 r  t SXt S(   N(   R5   t   FalseR.   (   R*   R8   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   __contains__S   s
    c         C   sE   t    } x5 |  D]- } x$ | D] } | t  | j    O} q Wq W| S(   s0   
        Flattened keys of subcontexts.
        (   t   sett   keys(   R*   R?   R9   t   dict(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR?   Z   s
    	N(   R   R   t   __doc__R7   t   NoneR;   R=   R?   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR   @   s
   			c         C   s,   t  j d |  d |  d |  |  j j |  S(   sz   
    An instrumented Template render method, providing a signal
    that can be intercepted by the test system Client
    t   sendert   templatet   context(   R   t   sendt   nodelistt   render(   R*   RE   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   instrumented_test_rendere   s    t
   _TestStatec           B   s   e  Z RS(    (   R   R   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyRJ   n   s   c         C   s   t  t d  r t d   n  |  d k r6 t j }  n  t   } | t _ t j | _	 t
 t j  d g t _ t j | _ |  t _ t j | _ d t _ t j | _ t t _ g  t _ t   d S(   s   
    Perform global pre-test setup, such as installing the instrumented template
    renderer and setting the email backend to the locmem email backend.
    t
   saved_datasx   setup_test_environment() was already called and can't be called again without first calling teardown_test_environment().t
   testservers-   django.core.mail.backends.locmem.EmailBackendN(   t   hasattrRJ   t   RuntimeErrorRB   R
   t   DEBUGR   RK   t   ALLOWED_HOSTSt   allowed_hostst   listt   debugt   EMAIL_BACKENDt   email_backendR   t   _rendert   template_renderRI   R   t   outboxR   (   RS   RK   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR%   r   s"    						c          C   sI   t  j }  |  j t _ |  j t _ |  j t _ |  j	 t
 _ t  ` t ` d S(   s   
    Perform any global post-test teardown, such as restoring the original
    template renderer and restoring the email sending functions.
    N(   RJ   RK   RQ   R
   RP   RS   RO   RU   RT   RW   R   RV   R   RX   (   RK   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR&      s    	i    c         K   s  t    \ } } g  } x| j   D]	\ }	 \ }
 } d	 } x | D] } t | } | j | |
 | d	 k f  | d	 k r| } | j j d |  d | d | d | j j d i   j d t	   | d k r'x: t
 |  D]) } | j j d | d d |  d |  q Wq'qA t | j j t | j  qA Wq" Wx5 | j   D]' \ } } t | j j t | j  q<W| rx t D] } t	 t | _ qtWn  | S(
   s$   
    Create the test databases.
    t	   verbosityt   autoclobbert   keepdbt	   serializet   TESTt	   SERIALIZEi   t   numberN(   t    get_unique_databases_and_mirrorst   itemsRB   R   t   appendt   creationt   create_test_dbt   settings_dictR;   R.   t   ranget   clone_test_dbt   set_as_test_mirrort   force_debug_cursor(   RY   t   interactiveR[   t	   debug_sqlt   parallelt   kwargst   test_databasest   mirrored_aliasest	   old_namest	   signaturet   db_namet   aliasest   first_aliast   aliast
   connectiont   indext   mirror_alias(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   setup_databases   s8    
"
#c         C   sA  g  } t    } i  } xy |  D]q \ } \ } } t    } x' | D] }	 | j | j |	 g    q> W| j |  s t d |   n  | | | <q Wx |  r<t }
 g  } xu |  D]m \ } \ } } | | j |  r| j |  | j | | | f f  t }
 q | j | | | f f  q W|
 s3t d   n  | }  q W| S(   sp   
    Reorder test_databases into an order that honors the dependencies
    described in TEST[DEPENDENCIES].
    sH   Circular dependency: databases %r depend on each other, but are aliases.s)   Circular dependency in TEST[DEPENDENCIES](	   R>   t   updateR;   t
   isdisjointR   R<   t   issubsetRb   R.   (   Rn   t   dependenciest   ordered_test_databasest   resolved_databasest   dependencies_mapt   sigt   _Rs   t   all_depsRu   t   changedt   deferredRq   Rr   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   dependency_ordered   s2    				
c          C   s,  i  }  i  } i  } t  t j j   } x t  D] } t  | } | j d } | d rd | d |  | <q, | j | j j   | j d t   f  } | d j |  d | k r | d | | <q, | t k r, | j j   | k r, | j d t g  | | <q, q, Wt	 | j
   |  } t j |  } | |  f S(   s  
    Figure out which databases actually need to be created.

    Deduplicate entries in DATABASES that correspond the same database or are
    configured as test mirrors.

    Return two values:
    - test_databases: ordered mapping of signatures to (name, list of aliases)
                      where all aliases share the same underlying database.
    - mirrored_aliases: mapping of mirror aliases to original aliases.
    R]   t   MIRRORt   NAMEi   t   DEPENDENCIES(   R   R   Rc   t   test_db_signatureRe   t
   setdefaultR>   t   addR;   R   Ra   t   collectionst   OrderedDict(   Ro   Rn   R}   t   default_sigRu   Rv   t   test_settingst   item(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR`      s(    

! c      	   C   s   x |  D]w \ } } } | r | d k re x: t  |  D]) } | j j d | d d | d |  q5 Wn  | j j | | |  q q Wd S(   s/   
    Destroy all the non-mirror databases.
    i   R_   RY   R[   N(   Rf   Rc   t   destroy_test_db(   t
   old_configRY   Rl   R[   Rv   t   old_namet   destroyRw   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   teardown_databases+  s    
c         C   s   | s |  j  } n  | j d  } t |  d k rI d j | d   } n d } t | i  i  t | d   } t | | d  } | S(   Nt   .i   i(   t   TEST_RUNNERt   splitt   lent   joint
   __import__R   t   getattr(   R
   t   test_runner_classt	   test_patht   test_module_namet   test_modulet   test_runner(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR!   ;  s    t   TestContextDecoratorc           B   s\   e  Z d  Z d	 d	 d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z RS(
   s  
    A base class that can either be used as a context manager during tests
    or as a test function or unittest.TestCase subclass decorator to perform
    temporary alterations.

    `attr_name`: attribute assigned the return value of enable() if used as
                 a class decorator.

    `kwarg_name`: keyword argument passing the return value of enable() if
                  used as a function decorator.
    c         C   s   | |  _  | |  _ d  S(   N(   t	   attr_namet
   kwarg_name(   R*   R   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR+   V  s    	c         C   s
   t   d  S(   N(   t   NotImplementedError(   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   enableZ  s    c         C   s
   t   d  S(   N(   R   (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   disable]  s    c         C   s
   |  j    S(   N(   R   (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt	   __enter__`  s    c         C   s   |  j    d  S(   N(   R   (   R*   t   exc_typet	   exc_valuet	   traceback(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   __exit__c  s    c            sk   t  | t  r[ | j   | j     f d   }   f d   } | | _ | | _ | St d   d  S(   Nc            s9    j    }  j r+ t |   j |  n    |   d  S(   N(   R   R   t   setattr(   t
   inner_selfRE   (   t   decorated_setUpR*   (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   setUpk  s    	c            s     |    j    d  S(   N(   R   (   R   (   t   decorated_tearDownR*   (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   tearDownq  s    
s1   Can only decorate subclasses of unittest.TestCase(   t
   issubclassR   R   R   t	   TypeError(   R*   t   clsR   R   (    (   R   R   R*   s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   decorate_classf  s    				c            s.   t    d t       f d    } | S(   Nt   assignedc             s9    - }  j  r" | |  j  <n    |  |   SWd  QXd  S(   N(   R   (   t   argsRm   RE   (   t   funcR*   (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   inner{  s    		(   R   R   (   R*   R   R   (    (   R   R*   s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   decorate_callablez  s    *c         C   sO   t  | t  r |  j |  St |  r5 |  j |  St d t |    d  S(   Ns!   Cannot decorate object of type %s(   R3   t   typeR   t   callableR   R   (   R*   t	   decorated(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   __call__  s
    N(   R   R   RA   RB   R+   R   R   R   R   R   R   R   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR   J  s   							c           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s:  
    Acts as either a decorator or a context manager. If it's a decorator it
    takes a function and returns a wrapped function. If it's a contextmanager
    it's used with the ``with`` statement. In either event entering/exiting
    are called before and after, respectively, the function/block is executed.
    c         K   s    | |  _  t t |   j   d  S(   N(   t   optionsR6   R#   R+   (   R*   Rm   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR+     s    	c      
   C   s   d |  j  k rK y t j |  j  d  WqK t k
 rG t j     qK Xn  t t j  } x- |  j  j   D] \ } } t	 | | |  qj Wt j |  _
 | t _ xE |  j  j   D]4 \ } } t j d t j j d | d | d t  q Wd  S(   Nt   INSTALLED_APPSRC   t   settingt   valuet   enter(   R   R   t   set_installed_appst	   Exceptiont   unset_installed_appsR	   R
   t   _wrappedRa   R   t   wrappedR   RF   t	   __class__R.   (   R*   t   overrideR8   t	   new_value(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s    

	c      
   C   s   d |  j  k r t j   n  |  j t _ |  ` xK |  j  D]@ } t t | d   } t j	 d t j j
 d | d | d t  q8 Wd  S(   NR   RC   R   R   R   (   R   R   R   R   R
   R   R   RB   R   RF   R   R<   (   R*   R8   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s    c         C   s:   | j  d  k r |  j | _  n t | j  |  j  | _  d  S(   N(   t   _overridden_settingsRB   R   R@   (   R*   t	   test_func(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   save_options  s    c         C   s?   d d l  m } t | |  s. t d   n  |  j |  | S(   Ni(   t   SimpleTestCasesP   Only subclasses of Django SimpleTestCase can be decorated with override_settings(   t   django.testR   R   t
   ValueErrorR   (   R*   R   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s    (   R   R   RA   R+   R   R   R   R   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR#     s   			
	c           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   
    Like override_settings, but makes it possible to append, prepend or remove
    items instead of redefining the entire list.
    c         O   s\   | r# | s t   | d |  _ n" | s0 t   t | j    |  _ t t |   j   d  S(   Ni    (   t   AssertionErrort
   operationsRR   Ra   R6   R#   R+   (   R*   R   Rm   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR+     s    c         C   s;   | j  d  k r |  j | _  n t | j   |  j | _  d  S(   N(   t   _modified_settingsRB   R   RR   (   R*   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s    c         C   ss  i  |  _  xP|  j D]E\ } } y |  j  | } Wn) t k
 r[ t t t | g    } n Xx | j   D] \ } } t | t j	  r | g } n  | d k r | g  | D] } | | k r | ^ q } qi | d k rg  | D] } | | k r | ^ q | } qi | d k r7g  | D] } | | k r| ^ q} qi t
 d |   qi W| |  j  | <q Wt t |   j   d  S(   NRb   t   prependt   removes   Unsupported action: %s(   R   R   R5   RR   R   R
   Ra   R3   R   R4   R   R6   R"   R   (   R*   t   nameR   R   t   actionRa   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s$    	,,((   R   R   RA   R+   R   R   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR"     s   	
	t   override_system_checksc           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   s   
    Acts as a decorator. Overrides list of registered system checks.
    Useful when you override `INSTALLED_APPS`, e.g. if you exclude `auth` app,
    you also need to exclude its system checks.
    c         C   sB   d d l  m } | |  _ | |  _ | |  _ t t |   j   d  S(   Ni(   t   registry(   t   django.core.checks.registryR   t
   new_checkst   deployment_checksR6   R   R+   (   R*   R   R   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR+     s
    			c         C   sR   |  j  j |  _ |  j |  j  _ |  j  j |  _ |  j d  k	 rN |  j |  j  _ n  d  S(   N(   R   t   registered_checkst
   old_checksR   R   t   old_deployment_checksRB   (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s
    c         C   s"   |  j  |  j _ |  j |  j _ d  S(   N(   R   R   R   R   R   (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s    N(   R   R   RA   RB   R+   R   R   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s   	c            s  t  j d      f d    d    d      f d    d        f d    d   } t |  |  \ }  } |  j   j d	 d
  }  | j   j d	 d
  } |  j d  s d } | |  }  | | } n  | t |    } | t |   }  | |  S(   sp  Tries to do a 'xml-comparison' of want and got.  Plain string
    comparison doesn't always work because, for example, attribute
    ordering should not be important. Comment nodes are not considered in the
    comparison. Leading and trailing whitespace is ignored on both chunks.

    Based on https://github.com/lxml/lxml/blob/master/src/lxml/doctestcompare.py
    s   [ \t\n][ \t\n]+c            s     j  d |   S(   Nt    (   t   sub(   t   v(   t   _norm_whitespace_re(    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   norm_whitespace  s    c         S   s   d j  d   |  j D  S(   Nt    c         s   s*   |  ]  } | j  t j k r | j Vq d  S(   N(   t   nodeTypeR   t	   TEXT_NODEt   data(   t   .0t   c(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pys	   <genexpr>  s    (   R   t
   childNodes(   t   element(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt
   child_text  s    c         S   s,   g  |  j  D] } | j t j k r
 | ^ q
 S(   N(   R   R   R   t   ELEMENT_NODE(   R   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   children  s    c            s      |    S(   N(    (   R   (   R   R   (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   norm_child_text"  s    c         S   s   t  |  j j    S(   N(   R@   t
   attributesRa   (   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt
   attrs_dict%  s    c            s   |  j  | j  k r t S |    |  k r2 t S  |     |  k rN t S |   }  |  } t |  t |  k r t Sx0 t | |  D] \ } }  | |  s t Sq Wt S(   N(   t   tagNameR<   R   t   zipR.   (   t   want_elementt   got_elementt   want_childrent   got_childrent   wantt   got(   R   t   check_elementR   R   (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR   (  s    c         S   s.   x' |  j  D] } | j t j k r
 | Sq
 Wd  S(   N(   R   R   R   t   COMMENT_NODE(   t   documentt   node(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt
   first_node8  s    s   \ns   
s   <?xmls   <root>%s</root>(   t   ret   compilet   strip_quotest   stript   replacet
   startswithR   (   R   R   R  t   wrappert	   want_roott   got_root(    (   R   R   R   R   R   R   R   s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   compare_xml  s$    				
c         C   s   d   } d   } | |   rS | |  rS |  j    d d !}  | j    d d !} nA | |   r | |  r |  j    d d !}  | j    d d !} n  |  | f S(   s   
    Strip quotes of doctests output values:

    >>> strip_quotes("'foo'")
    "foo"
    >>> strip_quotes('"foo"')
    "foo"
    c         S   s@   |  j    }  t |   d k o? |  d |  d k o? |  d d k S(   Ni   i    it   "t   '(   R  R  (   R  R   (   t   s(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   is_quoted_stringX  s    c         S   sP   |  j    }  t |   d k oO |  d d k oO |  d |  d k oO |  d d k S(	   Ni   i    t   ui   iR  R  (   R  R  (   R  R   (   R  (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   is_quoted_unicode\  s    i   ii   (   R  (   R   R   R  R  (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR  O  s    			c         C   s   |  i t  j r d n d d 6S(   NR   R  R   (   R   t   PY3(   R  (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt
   str_prefixi  s    t   CaptureQueriesContextc           B   sS   e  Z d  Z d   Z d   Z d   Z d   Z e d    Z d   Z	 d   Z
 RS(   sU   
    Context manager that captures queries executed by the specified connection.
    c         C   s   | |  _  d  S(   N(   Rv   (   R*   Rv   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR+   q  s    c         C   s   t  |  j  S(   N(   t   itert   captured_queries(   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   __iter__t  s    c         C   s   |  j  | S(   N(   R  (   R*   Rw   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR7   w  s    c         C   s   t  |  j  S(   N(   R   R  (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   __len__z  s    c         C   s   |  j  j |  j |  j !S(   N(   Rv   t   queriest   initial_queriest   final_queries(   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR  }  s    c         C   sJ   |  j  j |  _ t |  j  _ t |  j  j  |  _ d  |  _ t j	 t
  |  S(   N(   Rv   Ri   R.   R   t   queries_logR  RB   R  R   t
   disconnectR   (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s    	c         C   sE   |  j  |  j _  t j t  | d  k	 r, d  St |  j j  |  _ d  S(   N(	   Ri   Rv   R   t   connectR   RB   R   R  R  (   R*   R   R   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s
    (   R   R   RA   R+   R  R7   R  t   propertyR  R   R   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR  m  s   					t   ignore_warningsc           B   s#   e  Z d    Z d   Z d   Z RS(   c         K   sY   | |  _  d |  j  k s' d |  j  k r6 t j |  _ n t j |  _ t t |   j   d  S(   Nt   messaget   module(   t   ignore_kwargst   warningst   filterwarningst   filter_funct   simplefilterR6   R!  R+   (   R*   Rm   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR+     s
    	c         C   s3   t  j   |  _ |  j j   |  j d |  j  d  S(   Nt   ignore(   R%  t   catch_warningsR   R'  R$  (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s    c         C   s   |  j  j t j     d  S(   N(   R*  R   t   syst   exc_info(   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR     s    (   R   R   R+   R   R   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR!    s   		c         #   sg   g       f d   } t  j |   } t | |  } t | | |  z	   VWd t | | |  Xd S(   s   
    Context manager that takes a named logger and the logging level
    and provides a simple mock-like list of messages received
    c            s-   |  | }   j   r" | | f n |  d  S(   N(   Rb   (   t   msgR   Rm   t   call(   t   callst
   log_kwargs(    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   replacement  s    
N(   t   loggingt	   getLoggerR   R   (   t   logger_namet	   log_levelR0  R1  t   loggert   orig(    (   R/  R0  s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   patch_logger  s    	s|   This test relies on the ability to run a program in an arbitrary time zone, but your operating system isn't able to do that.c          g   s4   t  j } t  j j |   z	 d VWd | t  _ Xd S(   s5   Context manager to temporarily add paths to sys.path.N(   R+  t   patht   extend(   t   pathst   _orig_sys_path(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   extend_sys_path  s
    
	c         c   s%   |  j    z	 d VWd |  j    Xd S(   s?   Clear the cache of an LRU cache object on entering and exiting.N(   t   cache_clear(   t   lru_cache_object(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR      s    
	c         c   sO   t  t |   } t t |  t j    z t  t |   VWd t t |  |  Xd S(   s  Return a context manager used by captured_stdout/stdin/stderr
    that temporarily replaces the sys stream *stream_name* with a StringIO.

    Note: This function and the following ``captured_std*`` are copied
          from CPython's ``test.support`` module.N(   R   R+  R   R   t   StringIO(   t   stream_namet   orig_stdout(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   captured_output  s
    c           C   s
   t  d  S(   s   Capture the output of sys.stdout:

       with captured_stdout() as stdout:
           print("hello")
       self.assertEqual(stdout.getvalue(), "hello
")
    t   stdout(   RC  (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   captured_stdout  s    c           C   s
   t  d  S(   s   Capture the output of sys.stderr:

       with captured_stderr() as stderr:
           print("hello", file=sys.stderr)
       self.assertEqual(stderr.getvalue(), "hello
")
    t   stderr(   RC  (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   captured_stderr  s    c           C   s
   t  d  S(   s  Capture the input to sys.stdin:

       with captured_stdin() as stdin:
           stdin.write('hello
')
           stdin.seek(0)
           # call test code that consumes from sys.stdin
           captured = input()
       self.assertEqual(captured, "hello")
    t   stdin(   RC  (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   captured_stdin  s    
c          C   sI   d }  x< t  j j   D]+ } t | |   r t | |   j   q q Wd S(   s  
    Clear warning registry for all modules. This is required in some tests
    because of a bug in Python that prevents warnings.simplefilter("always")
    from always making warnings appear: http://bugs.python.org/issue4180

    The bug was fixed in Python 3.4.2.
    t   __warningregistry__N(   R+  t   modulest   valuesRM   R   t   clear(   R8   t   mod(    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   reset_warning_registry  s    c         #   s5   t  j  }   f d   t  _  z	 d VWd | t  _  Xd S(   sM  
    Context manager to temporarily freeze time.time(). This temporarily
    modifies the time function of the time module. Modules which import the
    time function directly (e.g. `from time import time`) won't be affected
    This isn't meant as a public API, but helps reduce some repetitive code in
    Django's test suite.
    c              s     S(   N(    (    (   t   t(    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   <lambda>   R   N(   t   time(   RP  t
   _real_time(    (   RP  s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   freeze_time  s
    			c         C   sd   t  t d	 k d  |   }  t d i d d 6t d 6i d d 6t d 6i t d 6d 6g  |   }  |  S(
   s   
    Decorator to enable a Jinja2 template engine in addition to the regular
    Django template engine for a test or skip it if Jinja2 isn't available.
    s   this test requires jinja2t	   TEMPLATESs/   django.template.backends.django.DjangoTemplatest   BACKENDt   APP_DIRSs&   django.template.backends.jinja2.Jinja2t   keep_trailing_newlinet   OPTIONSN(   R   t   jinja2RB   R#   R.   (   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   require_jinja2'  s    		t   override_script_prefixc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sO   
    Decorator or context manager to temporary override the script prefix.
    c         C   s    | |  _  t t |   j   d  S(   N(   t   prefixR6   R\  R+   (   R*   R]  (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR+   <  s    	c         C   s   t    |  _ t |  j  d  S(   N(   R   t
   old_prefixR   R]  (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR   @  s    c         C   s   t  |  j  d  S(   N(   R   R^  (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR   D  s    (   R   R   RA   R+   R   R   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR\  8  s   		t   LoggingCaptureMixinc           B   s    e  Z d  Z d   Z d   Z RS(   sn   
    Capture the output from the 'django' logger and store it on the class's
    logger_output attribute.
    c         C   sQ   t  j d  |  _ |  j j d j |  _ t j   |  _ |  j |  j j d _ d  S(   Nt   djangoi    (	   R2  R3  R6  t   handlerst   streamt
   old_streamR   R@  t   logger_output(   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR   M  s    c         C   s   |  j  |  j j d _ d  S(   Ni    (   Rc  R6  Ra  Rb  (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR   S  s    (   R   R   RA   R   R   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR_  H  s   	t   isolate_appsc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s  
    Act as either a decorator or a context manager to register models defined
    in its wrapped context to an isolated registry.

    The list of installed apps the isolated registry should contain must be
    passed as arguments.

    Two optional keyword arguments can be specified:

    `attr_name`: attribute assigned the isolated registry if used as a class
                 decorator.

    `kwarg_name`: keyword argument passing the isolated registry if used as a
                  function decorator.
    c         O   s#   | |  _  t t |   j |   d  S(   N(   t   installed_appsR6   Re  R+   (   R*   Rf  Rm   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR+   h  s    	c         C   s/   t  j |  _ t |  j  } t t  d |  | S(   Nt   default_apps(   R   Rg  t   old_appsR   Rf  R   (   R*   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR   l  s    c         C   s   t  t d |  j  d  S(   NRg  (   R   R   Rh  (   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyR   r  s    (   R   R   RA   R+   R   R   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyRe  W  s   		c             s     f d   } | S(   s:   
    Decorator to add tags to a test class or method.
    c            s   t  |  d t     |  S(   Nt   tags(   R   R>   (   t   obj(   Ri  (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt	   decoratorz  s    (    (   Ri  Rk  (    (   Ri  s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   tagv  s    (	   R   R   R    R!   R"   R#   R$   R%   R&   (c   R   R2  R  R+  RR  R%  t
   contextlibR    t	   functoolsR   t   unittestR   R   R   t   xml.dom.minidomR   R   t   django.appsR   t   django.apps.registryR   t   django.confR	   R
   t   django.coreR   t   django.core.exceptionsR   t   django.core.signalsR   t	   django.dbR   R   R   t   django.db.models.optionsR   t   django.templateR   t   django.test.signalsR   R   t   django.urlsR   R   t   django.utilsR   t   django.utils.decoratorsR   t   django.utils.encodingR   t   django.utils.translationR   R  t   typesR   t   objectRZ  t   ImportErrorRB   t   __all__RM   t
   TZ_SUPPORTR   RR   R   RI   RJ   R%   R&   R<   Ry   R   R`   R   R!   R   R#   R"   R   R  R  R  R  R!  R8  R$   R=  R    RC  RE  RG  RI  RO  RT  R[  R\  R_  Re  Rl  (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/test/utils.pyt   <module>   s   	
   %		$	.	*	-A90	B		$	
	
	
			