Ñò
™í±Mc           @   s3  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k l Z d  d k l Z d  d k l	 Z	 d  d k
 l Z d  d k l Z l Z l Z d  d k l Z d  d k l Z d Z d Z d	 e f d „  ƒ  YZ d
 e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e  d „ Z! d „  Z" d S(   iÿÿÿÿN(   t   settings(   t   mail(   t   locmem(   t   signals(   t   Templatet   loadert   TemplateDoesNotExist(   t   cached(   t
   deactivatet   Approximatet   ContextListt   setup_test_environmentt   teardown_test_environmentt
   get_runnert!   _original_template_source_loadersc           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.6/dist-packages/django/test/utils.pyt   __init__   s    	c         C   s   t  |  i ƒ S(   N(   t   reprR   (   R   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyt   __repr__   s    c         C   s8   |  i  | j o t St t |  i  | ƒ |  i ƒ d j S(   Ni    (   R   t   Truet   roundt   absR   (   R   t   other(    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyt   __eq__   s    (   t   __name__t
   __module__R   R   R   (    (    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyR	      s   	c           B   s    e  Z 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   sa   t  | t ƒ o7 x$ |  D] } | | j o	 | | Sq Wt | ƒ ‚ n t t |  ƒ i | ƒ Sd  S(   N(   t
   isinstancet
   basestringt   KeyErrort   superR
   t   __getitem__(   R   t   keyt
   subcontext(    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyR    %   s     c         C   s)   y |  | } Wn t  j
 o t SXt S(   N(   R   t   FalseR   (   R   R!   t   value(    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyt   __contains__.   s
    (   R   R   t   __doc__R    R%   (    (    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyR
   !   s   		c         C   s/   t  i i d |  d |  d | ƒ |  i i | ƒ 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   template_renderedt   sendt   nodelistt   render(   R   R)   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyt   instrumented_test_render6   s    c           C   sV   t  i t  _ t t  _ t i t _ t i t _ t	 i
 t _ d t	 _
 g  t _ t ƒ  d S(   sð   Perform any global pre-test setup. This involves:

        - Installing the instrumented test renderer
        - Set the email backend to the locmem email backend.
        - Setting the active locale to match the LANGUAGE_CODE setting.
    s-   django.core.mail.backends.locmem.EmailBackendN(   R   t   _rendert   original_renderR.   R   t   SMTPConnectiont   original_SMTPConnectionR   t   EmailBackendR    t   EMAIL_BACKENDt   original_email_backendt   outboxR   (    (    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyR   ?   s    			c           C   s@   t  i t  _ t  ` t i t _ t ` t i t _ t ` t `	 d S(   s›   Perform any global post-test teardown. This involves:

        - Restoring the original test renderer
        - Restoring the email sending functions

    N(
   R   R0   R/   R   R2   R1   R5   R    R4   R6   (    (    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyR   T   s    c           C   s   t  i S(   sG   
    Returns an object containing the state of the warnings module
    (   t   warningst   filters(    (    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyt   get_warnings_stateg   s    c         C   s   |  t  _ d S(   sw   
    Restores the state of the warnings module when passed an object that was
    returned by get_warnings_state()
    N(   R7   R8   (   t   state(    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyt   restore_warnings_stateq   s    c         C   sr   |  i  i d ƒ } t | ƒ d j o d i | d  ƒ } n d } t | h  h  | d ƒ } t | | d ƒ } | S(   Nt   .i   iÿÿÿÿ(   t   TEST_RUNNERt   splitt   lent   joint
   __import__t   getattr(   R    t	   test_patht   test_module_namet   test_modulet   test_runner(    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyR   y   s    c            s…   t  t t ƒ o t d t ƒ ‚ n d ‡  f d † } | o t i d ƒ } | f | _ n | } t t t t i	 ƒ | f t _	 | S(   s   
    Changes Django to only find templates from within a dictionary (where each
    key is the template name and each value is the corresponding template
    content to return).

    Use meth:`restore_template_loaders` to restore the original loaders.
    s   loader.%s already existsc            s<   y ˆ  |  d |  f SWn t  j
 o t |  ƒ ‚ n Xd S(   s@   A custom template loader that loads templates from a dictionary.s   test:%sN(   R   R   (   t   template_namet   template_dirs(   t   templates_dict(    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyt   test_template_loader   s    RJ   N(   s   test_template_loader(
   t   hasattrR   t   RESTORE_LOADERS_ATTRt	   Exceptiont   NoneR   t   Loadert   _cached_loaderst   setattrt   template_source_loaders(   RI   t   use_cached_loaderRJ   t   template_loader(    (   RI   s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyt   setup_test_template_loader…   s    c           C   s#   t  t t ƒ t _ t t t ƒ d S(   sk   
    Restores the original template loaders after
    :meth:`setup_test_template_loader` has been run.
    N(   RB   R   RL   RR   t   delattr(    (    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyt   restore_template_loaders¢   s    (   s   Approximates   ContextLists   setup_test_environments   teardown_test_environments
   get_runner(#   t   syst   timet   osR7   t   django.confR    t   django.coreR   t   django.core.mail.backendsR   t   django.testR   t   django.templateR   R   R   t   django.template.loadersR   t   django.utils.translationR   t   __all__RL   t   objectR	   t   listR
   R.   R   R   R9   R;   R   R#   RU   RW   (    (    (    s;   /usr/local/lib/python2.6/dist-packages/django/test/utils.pyt   <module>   s.    					
		