
 X6[                 @   s  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 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 l- m. Z. d  d l/ m0 Z0 y d  d l1 Z1 Wn e2 k
 rd Z1 Yn XdS Z3 e4 e d  Z5 Gd d   d e6  Z7 Gd  d   d e8  Z9 d! d"   Z: d# d   Z; d$ d   Z< d d% d  Z= Gd& d'   d' e6  Z> Gd( d   d e>  Z? Gd) d   d e?  Z@ Gd* d+   d+ e>  ZA d, d-   ZB d. d/   ZC d0 d1   ZD Gd2 d3   d3 e6  ZE Gd4 d5   d5 e>  ZF e d6 d7 d8   ZG e e5 d9  ZH e d: d;    ZI e d< d    ZJ e d= d>    ZK d? d@   ZL dA dB   ZM dC dD   ZN dE dF   ZO e dG dH    ZP dI dJ   ZQ GdK dL   dL e>  ZR GdM dN   dN e6  ZS GdO dP   dP e>  ZT dQ dR   ZU d S)T    N)contextmanager)wraps)TestCaseskipIf
skipUnless)NodeparseString)apps)Apps)UserSettingsHoldersettings)mail)request_started)reset_queries)Options)request)Template)setting_changedtemplate_rendered)get_script_prefixset_script_prefix)six)available_attrs)	force_str)
deactivateApproximateContextListisolate_lru_cache
get_runnermodify_settingsoverride_settingsrequires_tz_supportsetup_test_environmentteardown_test_environmenttzsetc               @   s7   e  Z d  Z d d d  Z d d   Z d d   Z d S)	r      c             C   s   | |  _  | |  _ d  S)N)valplaces)selfr&   r'    r)   ?/home/ubuntu/projects/ifolica/build/django/django/test/utils.py__init__,   s    	zApproximate.__init__c             C   s   t  |  j  S)N)reprr&   )r(   r)   r)   r*   __repr__0   s    zApproximate.__repr__c             C   s6   |  j  | k r d St t |  j  |  |  j  d k S)NTr   )r&   roundabsr'   )r(   otherr)   r)   r*   __eq__3   s    zApproximate.__eq__N)__name__
__module____qualname__r+   r-   r1   r)   r)   r)   r*   r   +   s   c                   s@   e  Z d  Z d Z   f d d   Z d d   Z d d   Z   S)r   zkA wrapper that provides direct key access to context items contained
    in a list of context objects.
    c                s`   t  | t j  rF x" |  D] } | | k r | | Sq Wt |   n t t |   j |  Sd  S)N)
isinstancer   string_typesKeyErrorsuperr   __getitem__)r(   key
subcontext)	__class__r)   r*   r9   =   s    zContextList.__getitem__c             C   s)   y |  | Wn t  k
 r$ d SYn Xd S)NFT)r7   )r(   r:   r)   r)   r*   __contains__F   s
    	zContextList.__contains__c             C   sE   t    } x5 |  D]- } x$ | D] } | t  | j    O} q Wq W| S)z0
        Flattened keys of subcontexts.
        )setkeys)r(   r?   r;   dictr)   r)   r*   r?   M   s
    	zContextList.keys)r2   r3   r4   __doc__r9   r=   r?   r)   r)   )r<   r*   r   9   s   	c             C   s,   t  j d |  d |  d |  |  j j |  S)zz
    An instrumented Template render method, providing a signal
    that can be intercepted by the test system Client
    sendertemplatecontext)r   sendnodelistrender)r(   rD   r)   r)   r*   instrumented_test_renderX   s    rH   c               C   sV   t  j t  _ t t  _ t j t _ d t _ t j t	 _
 d g t _ g  t _ t   d S)z
    Perform global pre-test setup, such as installing the instrumented template
    renderer and setting the email backend to the locmem email backend.
    z-django.core.mail.backends.locmem.EmailBackend*N)r   _render_original_renderrH   r   EMAIL_BACKENDr   _original_email_backendALLOWED_HOSTSr   _original_allowed_hostsoutboxr   r)   r)   r)   r*   r"   a   s    			c               C   s@   t  j t  _ t  ` t j t _ t ` t j t _	 t ` t `
 d S)z
    Perform any global post-test teardown, such as restoring the original
    template renderer and restoring the email sending functions.
    N)r   rK   rJ   r   rM   r   rL   r   rO   rN   rP   r)   r)   r)   r*   r#   w   s    c             C   s   | s |  j  } n  | j d  } t |  d k rO d j | d  d   } n d } t | i  i  t | d   } t | | d  } | S)N.   rS   rS   )ZTEST_RUNNERsplitlenjoin
__import__r   getattr)r   Ztest_runner_classZ	test_pathZtest_module_nameZtest_moduleZtest_runnerr)   r)   r*   r      s    c               @   s|   e  Z d  Z d Z d d d d  Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z	 d d   Z
 d d   Z d S)TestContextDecoratora  
    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.
    Nc             C   s   | |  _  | |  _ d  S)N)	attr_name
kwarg_name)r(   rZ   r[   r)   r)   r*   r+      s    	zTestContextDecorator.__init__c             C   s
   t   d  S)N)NotImplementedError)r(   r)   r)   r*   enable   s    zTestContextDecorator.enablec             C   s
   t   d  S)N)r\   )r(   r)   r)   r*   disable   s    zTestContextDecorator.disablec             C   s
   |  j    S)N)r]   )r(   r)   r)   r*   	__enter__   s    zTestContextDecorator.__enter__c             C   s   |  j    d  S)N)r^   )r(   exc_type	exc_value	tracebackr)   r)   r*   __exit__   s    zTestContextDecorator.__exit__c                sq   t  | t  ra | j   | j     f d d   }   f d d   } | | _ | | _ | St d   d  S)Nc                s9    j    }  j r+ t |   j |  n    |   d  S)N)r]   rZ   setattr)
inner_selfrD   )decorated_setUpr(   r)   r*   setUp   s    	z2TestContextDecorator.decorate_class.<locals>.setUpc                s     |    j    d  S)N)r^   )re   )decorated_tearDownr(   r)   r*   tearDown   s    
z5TestContextDecorator.decorate_class.<locals>.tearDownz1Can only decorate subclasses of unittest.TestCase)
issubclassr   rg   ri   	TypeError)r(   clsrg   ri   r)   )rf   rh   r(   r*   decorate_class   s    				z#TestContextDecorator.decorate_classc                s1   t    d t       f d d    } | S)Nassignedc           
      s9    - }  j  r" | |  j  <n    |  |   SWd  QXd  S)N)r[   )argskwargsrD   )funcr(   r)   r*   inner   s    		z5TestContextDecorator.decorate_callable.<locals>.inner)r   r   )r(   rq   rr   r)   )rq   r(   r*   decorate_callable   s    -z&TestContextDecorator.decorate_callablec             C   sO   t  | t  r |  j |  St |  r5 |  j |  St d t |    d  S)Nz!Cannot decorate object of type %s)r5   typerm   callablers   rk   )r(   	decoratedr)   r)   r*   __call__   s
    zTestContextDecorator.__call__)r2   r3   r4   rA   r+   r]   r^   r_   rc   rm   rs   rw   r)   r)   r)   r*   rY      s   	rY   c                   sX   e  Z d  Z d Z   f d d   Z d d   Z d d   Z d d	   Z d
 d   Z   S)r    a:  
    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                s    | |  _  t t |   j   d  S)N)optionsr8   r    r+   )r(   rp   )r<   r)   r*   r+      s    	zoverride_settings.__init__c             C   s   d |  j  k rL y t j |  j  d  WqL t k
 rH t j     YqL Xn  t t j  } x- |  j  j   D] \ } } t	 | | |  qk Wt j |  _
 | t _ xE |  j  j   D]4 \ } } t j d t j j d | d | d d  q Wd  S)NINSTALLED_APPSrB   settingvalueenterT)rx   r	   Zset_installed_apps	Exceptionunset_installed_appsr   r   _wrappeditemsrd   wrappedr   rE   r<   )r(   overrider:   	new_valuer)   r)   r*   r]      s    
	zoverride_settings.enablec          
   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 d  q8 Wd  S)Nry   rB   rz   r{   r|   F)
rx   r	   r~   r   r   r   rX   r   rE   r<   )r(   r:   r   r)   r)   r*   r^      s    zoverride_settings.disablec             C   s:   | j  d  k r |  j | _  n t | j  |  j  | _  d  S)N)Z_overridden_settingsrx   r@   )r(   	test_funcr)   r)   r*   save_options   s    zoverride_settings.save_optionsc             C   s?   d d l  m } t | |  s. t d   n  |  j |  | S)Nr   )SimpleTestCasezPOnly subclasses of Django SimpleTestCase can be decorated with override_settings)Zdjango.testr   rj   
ValueErrorr   )r(   rl   r   r)   r)   r*   rm     s    z override_settings.decorate_class)	r2   r3   r4   rA   r+   r]   r^   r   rm   r)   r)   )r<   r*   r       s   
c                   sF   e  Z d  Z d Z   f d d   Z d d   Z   f d d   Z   S)r   z
    Like override_settings, but makes it possible to append, prepend or remove
    items instead of redefining the entire list.
    c                s\   | r# | s t   | d |  _ n" | s0 t   t | j    |  _ t t |   j   d  S)Nr   )AssertionError
operationslistr   r8   r    r+   )r(   ro   rp   )r<   r)   r*   r+     s    zmodify_settings.__init__c             C   s;   | j  d  k r |  j | _  n t | j   |  j | _  d  S)N)Z_modified_settingsr   r   )r(   r   r)   r)   r*   r      s    zmodify_settings.save_optionsc                sP  i  |  _  x-|  j D]"\ } } y |  j  |  Wn* t k
 r\ t t t | g     Yn Xx | j   D] \ }   t   t j	  r   g   n  | d k r   f d d     D  qj | d k r  f d d     D   qj | d k r  f d d    D  qj t
 d |   qj W |  j  | <q Wt t |   j   d  S)	Nappendc                s"   g  |  ] } |   k r |  q Sr)   r)   ).0item)r{   r)   r*   
<listcomp>6  s   	 z*modify_settings.enable.<locals>.<listcomp>prependc                s"   g  |  ] } |   k r |  q Sr)   r)   )r   r   )r{   r)   r*   r   8  s   	 removec                s"   g  |  ] } |   k r |  q Sr)   r)   )r   r   )r   r)   r*   r   :  s   	 zUnsupported action: %s)rx   r   r7   r   rX   r   r   r5   r   r6   r   r8   r   r]   )r(   namer   action)r<   )r   r{   r*   r]   (  s$    	  zmodify_settings.enable)r2   r3   r4   rA   r+   r   r]   r)   r)   )r<   r*   r     s   
c                   sC   e  Z d  Z d Z d   f d d  Z d d   Z d d   Z   S)	override_system_checksz
    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.
    Nc                sB   d d l  m } | |  _ | |  _ | |  _ t t |   j   d  S)Nr   )registry)Zdjango.core.checks.registryr   
new_checksdeployment_checksr8   r   r+   )r(   r   r   r   )r<   r)   r*   r+   G  s
    			zoverride_system_checks.__init__c             C   sR   |  j  j |  _ |  j |  j  _ |  j  j |  _ |  j d  k	 rN |  j |  j  _ n  d  S)N)r   registered_checks
old_checksr   r   old_deployment_checks)r(   r)   r)   r*   r]   N  s
    zoverride_system_checks.enablec             C   s"   |  j  |  j _ |  j |  j _ d  S)N)r   r   r   r   r   )r(   r)   r)   r*   r^   U  s    zoverride_system_checks.disable)r2   r3   r4   rA   r+   r]   r^   r)   r)   )r<   r*   r   A  s   r   c                s#  t  j d      f d d    d d    d d      f d d	    d
 d        f d d    d d   } t |  |  \ }  } |  j   j d d  }  | j   j d d  } |  j d  s d } | |  }  | | } n  | t |    } | t |   }  | |  S)ap  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
    z[ \t\n][ \t\n]+c                s     j  d |   S)N )sub)v)_norm_whitespace_rer)   r*   norm_whitespaced  s    z$compare_xml.<locals>.norm_whitespacec             S   s   d j  d d   |  j D  S)N c             s   s*   |  ]  } | j  t j k r | j Vq d  S)N)nodeTyper   Z	TEXT_NODEdata)r   cr)   r)   r*   	<genexpr>h  s    z2compare_xml.<locals>.child_text.<locals>.<genexpr>)rV   
childNodes)elementr)   r)   r*   
child_textg  s    zcompare_xml.<locals>.child_textc             S   s   d d   |  j  D S)Nc             S   s(   g  |  ] } | j  t j k r |  q Sr)   )r   r   ZELEMENT_NODE)r   r   r)   r)   r*   r   l  s   	 z1compare_xml.<locals>.children.<locals>.<listcomp>)r   )r   r)   r)   r*   childrenk  s    zcompare_xml.<locals>.childrenc                s      |    S)Nr)   )r   )r   r   r)   r*   norm_child_texto  s    z$compare_xml.<locals>.norm_child_textc             S   s   t  |  j j    S)N)r@   
attributesr   )r   r)   r)   r*   
attrs_dictr  s    zcompare_xml.<locals>.attrs_dictc                s   |  j  | j  k r d S |    |  k r2 d S  |     |  k rN d S |   }  |  } t |  t |  k r d Sx0 t | |  D] \ } }  | |  s d Sq Wd S)NFT)ZtagNamerU   zip)Zwant_elementZgot_elementZwant_childrenZgot_childrenwantgot)r   check_elementr   r   r)   r*   r   u  s    z"compare_xml.<locals>.check_elementc             S   s.   x' |  j  D] } | j t j k r
 | Sq
 Wd  S)N)r   r   r   ZCOMMENT_NODE)documentnoder)   r)   r*   
first_node  s    zcompare_xml.<locals>.first_nodez\n
z<?xmlz<root>%s</root>)recompilestrip_quotesstripreplace
startswithr   )r   r   r   wrapperZ	want_rootZgot_rootr)   )r   r   r   r   r   r   r   r*   compare_xmlZ  s$    
r   c             C   s   d d   } d d   } | |   r_ | |  r_ |  j    d d  }  | j    d d  } nG | |   r | |  r |  j    d d	  }  | j    d d
  } n  |  | f S)z
    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)N   r   rR   "'rS   )r   r   )r   rU   )sr)   r)   r*   is_quoted_string  s    z&strip_quotes.<locals>.is_quoted_stringc             S   sP   |  j    }  t |   d k oO |  d d k oO |  d |  d k oO |  d d k S)	N   r   urR   r   r   rS   )r   r   )r   rU   )r   r)   r)   r*   is_quoted_unicode  s    z'strip_quotes.<locals>.is_quoted_unicoderR   r   rS   rS   rS   rS   )r   )r   r   r   r   r)   r)   r*   r     s    	r   c             C   s   |  i t  j r d n d d 6S)Nr   r   _)r   PY3)r   r)   r)   r*   
str_prefix  s    r   c               @   sp   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z e d
 d    Z	 d d   Z
 d d   Z d S)CaptureQueriesContextzU
    Context manager that captures queries executed by the specified connection.
    c             C   s   | |  _  d  S)N)
connection)r(   r   r)   r)   r*   r+     s    zCaptureQueriesContext.__init__c             C   s   t  |  j  S)N)itercaptured_queries)r(   r)   r)   r*   __iter__  s    zCaptureQueriesContext.__iter__c             C   s   |  j  | S)N)r   )r(   indexr)   r)   r*   r9     s    z!CaptureQueriesContext.__getitem__c             C   s   t  |  j  S)N)rU   r   )r(   r)   r)   r*   __len__  s    zCaptureQueriesContext.__len__c             C   s   |  j  j |  j |  j  S)N)r   Zqueriesinitial_queriesfinal_queries)r(   r)   r)   r*   r     s    z&CaptureQueriesContext.captured_queriesc             C   sJ   |  j  j |  _ d |  j  _ t |  j  j  |  _ d  |  _ t j t  |  S)NT)	r   force_debug_cursorrU   queries_logr   r   r   Z
disconnectr   )r(   r)   r)   r*   r_     s    	zCaptureQueriesContext.__enter__c             C   sE   |  j  |  j _  t j t  | d  k	 r, d  St |  j j  |  _ d  S)N)r   r   r   connectr   rU   r   r   )r(   r`   ra   rb   r)   r)   r*   rc     s
    zCaptureQueriesContext.__exit__N)r2   r3   r4   rA   r+   r   r9   r   propertyr   r_   rc   r)   r)   r)   r*   r     s   r   c                   s:   e  Z d  Z   f d d   Z d d   Z d d   Z   S)ignore_warningsc                sY   | |  _  d |  j  k s' d |  j  k r6 t j |  _ n t j |  _ t t |   j   d  S)Nmessagemodule)ignore_kwargswarningsfilterwarningsfilter_funcsimplefilterr8   r   r+   )r(   rp   )r<   r)   r*   r+     s
    	zignore_warnings.__init__c             C   s3   t  j   |  _ |  j j   |  j d |  j  d  S)Nignore)r   catch_warningsr_   r   r   )r(   r)   r)   r*   r]     s    zignore_warnings.enablec             C   s   |  j  j t j     d  S)N)r   rc   sysexc_info)r(   r)   r)   r*   r^     s    zignore_warnings.disable)r2   r3   r4   r+   r]   r^   r)   r)   )r<   r*   r     s   r   Fc             #   sj   g       f d d   } t  j |   } t | |  } t | | |  z	   VWd t | | |  Xd S)z
    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)r   )msgro   rp   call)calls
log_kwargsr)   r*   replacement  s    
z!patch_logger.<locals>.replacementN)logging	getLoggerrX   rd   )Zlogger_nameZ	log_levelr   r   loggerorigr)   )r   r   r*   patch_logger  s    	r   z|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   s=   t  j d d  } t  j j |   z	 d VWd | t  _ Xd S)z5Context manager to temporarily add paths to sys.path.N)r   pathextend)pathsZ_orig_sys_pathr)   r)   r*   extend_sys_path  s
    	r   c          
   c   s%   |  j    z	 d VWd |  j    Xd S)z?Clear the cache of an LRU cache object on entering and exiting.N)cache_clear)Zlru_cache_objectr)   r)   r*   r     s    
	c             c   sO   t  t |   } t t |  t j    z t  t |   VWd t t |  |  Xd S)a  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)rX   r   rd   r   StringIO)Zstream_nameorig_stdoutr)   r)   r*   captured_output%  s
    r   c               C   s
   t  d  S)zCapture the output of sys.stdout:

       with captured_stdout() as stdout:
           print("hello")
       self.assertEqual(stdout.getvalue(), "hello
")
    stdout)r   r)   r)   r)   r*   captured_stdout4  s    r   c               C   s
   t  d  S)zCapture the output of sys.stderr:

       with captured_stderr() as stderr:
           print("hello", file=sys.stderr)
       self.assertEqual(stderr.getvalue(), "hello
")
    stderr)r   r)   r)   r)   r*   captured_stderr>  s    r   c               C   s
   t  d  S)a  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")
    stdin)r   r)   r)   r)   r*   captured_stdinH  s    
r   c              C   sI   d }  x< t  j j   D]+ } t | |   r t | |   j   q q Wd S)a  
    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.
    __warningregistry__N)r   modulesvalueshasattrrX   clear)r:   modr)   r)   r*   reset_warning_registryU  s    r   c             #   s8   t  j  }   f d d   t  _  z	 d VWd | t  _  Xd S)aM  
    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)Nr)   r)   )tr)   r*   <lambda>m  s    zfreeze_time.<locals>.<lambda>N)time)r   Z
_real_timer)   )r   r*   freeze_timec  s
    			r  c             C   sd   t  t d k d  |   }  t d i d d 6d d 6i d d 6d d 6i d d	 6d
 6g  |   }  |  S)z
    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.
    Nzthis test requires jinja2Z	TEMPLATESz/django.template.backends.django.DjangoTemplatesZBACKENDTZAPP_DIRSz&django.template.backends.jinja2.Jinja2Zkeep_trailing_newlineOPTIONS)r   jinja2r    )r   r)   r)   r*   require_jinja2t  s    		r  c                   s@   e  Z d  Z d Z   f d d   Z d d   Z d d   Z   S)override_script_prefixzO
    Decorator or context manager to temporary override the script prefix.
    c                s    | |  _  t t |   j   d  S)N)prefixr8   r  r+   )r(   r  )r<   r)   r*   r+     s    	zoverride_script_prefix.__init__c             C   s   t    |  _ t |  j  d  S)N)r   
old_prefixr   r  )r(   r)   r)   r*   r]     s    zoverride_script_prefix.enablec             C   s   t  |  j  d  S)N)r   r  )r(   r)   r)   r*   r^     s    zoverride_script_prefix.disable)r2   r3   r4   rA   r+   r]   r^   r)   r)   )r<   r*   r    s   r  c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)LoggingCaptureMixinzn
    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)NZdjangor   )	r   r   r   handlersstream
old_streamr   r   Zlogger_output)r(   r)   r)   r*   rg     s    zLoggingCaptureMixin.setUpc             C   s   |  j  |  j j d _ d  S)Nr   )r  r   r	  r
  )r(   r)   r)   r*   ri     s    zLoggingCaptureMixin.tearDownN)r2   r3   r4   rA   rg   ri   r)   r)   r)   r*   r    s   r  c                   s@   e  Z d  Z d Z   f d d   Z d d   Z d d   Z   S)isolate_appsa  
    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                s#   | |  _  t t |   j |   d  S)N)installed_appsr8   r  r+   )r(   r  rp   )r<   r)   r*   r+     s    	zisolate_apps.__init__c             C   s/   t  j |  _ t |  j  } t t  d |  | S)Ndefault_apps)r   r  old_appsr
   r  rd   )r(   r	   r)   r)   r*   r]     s    zisolate_apps.enablec             C   s   t  t d |  j  d  S)Nr  )rd   r   r  )r(   r)   r)   r*   r^     s    zisolate_apps.disable)r2   r3   r4   rA   r+   r]   r^   r)   r)   )r<   r*   r    s   r  c                 s     f d d   } | S)z:
    Decorator to add tags to a test class or method.
    c                s   t  |  d t     |  S)Ntags)rd   r>   )obj)r  r)   r*   	decorator  s    ztag.<locals>.decoratorr)   )r  r  r)   )r  r*   tag  s    r  )	zApproximatezContextListzisolate_lru_cachez
get_runnerzmodify_settingszoverride_settingszrequires_tz_supportzsetup_test_environmentzteardown_test_environment)Vr   r   r   r   r   
contextlibr   	functoolsr   Zunittestr   r   r   Zxml.dom.minidomr   r   Zdjango.appsr	   Zdjango.apps.registryr
   Zdjango.confr   r   Zdjango.corer   Zdjango.core.signalsr   Z	django.dbr   Zdjango.db.models.optionsr   Zdjango.httpr   Zdjango.templater   Zdjango.test.signalsr   r   Zdjango.urlsr   r   Zdjango.utilsr   Zdjango.utils.decoratorsr   Zdjango.utils.encodingr   Zdjango.utils.translationr   r  ImportError__all__r   Z
TZ_SUPPORTobjectr   r   r   rH   r"   r#   r   rY   r    r   r   r   r   r   r   r   r   r!   r   r   r   r   r   r   r   r  r  r  r  r  r  r)   r)   r)   r*   <module>   s      	A90B$	


