
    Evg}                     "   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Zd dl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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! d dl"m#Z# d dl$m%Z% d dl&m'Z'm(Z( d dl)m*Z*m+Z+m,Z, d dl-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7 d dl8m9Z9 	 d dl:Z:n# e;$ r dZ:Y nw xY wdZ< e=ed          Z> G d d          Z? G d de@          ZAd ZB G d d          ZCdNd ZDd! ZEdd"d"d ddd#d$ZFd% ZGd& ZHdNd'ZIdOd(ZJdNd)ZK G d* d+          ZL G d, d-eL          ZM G d. d/eM          ZN G d0 d1eL          ZOd2 ZP G d3 d4          ZQ G d5 d6eL          ZR ee>d7          ZSe	d8             ZTe	d9             ZUe	d:             ZVd; ZWd< ZXd= ZYe	d>             ZZd? Z[ G d@ dAeL          Z\ G dB dC          Z] G dD dEeL          Z^ G dF dG          Z_ G dH dI          Z`dJ Zae	ddKdL            ZbdM ZcdS )P    N)contextmanager)wraps)StringIO)chain)SimpleNamespace)TestCaseskipIf
skipUnless)NodeparseString)iscoroutinefunction)apps)Apps)UserSettingsHoldersettings)mail)ImproperlyConfigured)request_startedsetting_changed)DEFAULT_DB_ALIASconnectionsreset_queries)Options)Template)template_rendered)get_script_prefixset_script_prefix)
deactivate)PYPY)ApproximateContextListisolate_lru_cachegarbage_collect
get_runnerCaptureQueriesContextignore_warningsisolate_appsmodify_settingsoverride_settingsoverride_system_checkstagrequires_tz_supportsetup_databasessetup_test_environmentteardown_test_environmenttzsetc                   "    e Zd ZddZd Zd ZdS )r       c                 "    || _         || _        d S N)valplaces)selfr5   r6   s      N/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/test/utils.py__init__zApproximate.__init__>   s        c                 *    t          | j                  S r4   )reprr5   r7   s    r8   __repr__zApproximate.__repr__B   s    DH~~r:   c                 t    | j         |k    p-t          t          | j         |z
            | j                  dk    S Nr   )r5   roundabsr6   )r7   others     r8   __eq__zApproximate.__eq__E   s5    x5 RE#dh.>*?*?$M$MQR$RRr:   N)r2   )__name__
__module____qualname__r9   r>   rD    r:   r8   r    r    =   sK             S S S S Sr:   r    c                   6     e Zd ZdZ fdZddZd Zd Z xZS )r!   zp
    A wrapper that provides direct key access to context items contained
    in a list of context objects.
    c                     t          |t                    r"| D ]}||v r
||         c S t          |          t                                          |          S r4   )
isinstancestrKeyErrorsuper__getitem__)r7   key
subcontext	__class__s      r8   rO   zContextList.__getitem__O   sh    c3 	," + +
*$$%c?*** %3--77&&s+++r:   Nc                 R    	 |                      |          S # t          $ r |cY S w xY wr4   )rO   rM   )r7   rP   defaults      r8   getzContextList.getX   s?    	##C((( 	 	 	NNN	s    &&c                 <    	 | |          n# t           $ r Y dS w xY wdS )NFT)rM   )r7   rP   s     r8   __contains__zContextList.__contains__^   s9    	III 	 	 	55	ts    
c                 X    t          t          j        d | D                                 S )z0
        Flattened keys of subcontexts.
        c              3   $   K   | ]}|D ]}|V  d S r4   rH   ).0rQ   ds      r8   	<genexpr>z#ContextList.keys.<locals>.<genexpr>i   s/      &T&TZ&T&TAq&T&T&T&T&T&T&Tr:   )setr   from_iterabler=   s    r8   keyszContextList.keyse   s,     5&&T&T4&T&T&TTTUUUr:   r4   )	rE   rF   rG   __doc__rO   rU   rW   r_   __classcell__rR   s   @r8   r!   r!   I   s{         
, , , , ,     V V V V V V Vr:   r!   c                 d    t          j        | | |           | j                            |          S )zt
    An instrumented Template render method, providing a signal that can be
    intercepted by the test Client.
    )sendertemplatecontext)r   sendnodelistrender)r7   rf   s     r8   instrumented_test_renderrj   l   s2    
 $wGGGG=(((r:   c                       e Zd ZdS )
_TestStateN)rE   rF   rG   rH   r:   r8   rl   rl   u   s        Dr:   rl   c                    t          t          d          rt          d          | t          j        } t                      }|t          _        t          j        |_        g t          j        dt          _        t          j        |_	        | t          _        t          j
        |_        dt          _
        t          j        |_        t          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.
    
saved_datazxsetup_test_environment() was already called and can't be called again without first calling teardown_test_environment().N
testserverz-django.core.mail.backends.locmem.EmailBackend)hasattrrl   RuntimeErrorr   DEBUGr   rn   ALLOWED_HOSTSallowed_hostsdebugEMAIL_BACKENDemail_backendr   _rendertemplate_renderrj   r   outboxr   )ru   rn   s     r8   r.   r.   y   s    
 z<(( 
G
 
 	

 } ""J&J'5JDx5D|DH~JHN'5JLH!)!1J/HDKLLLLLr:   c                      t           j        } | j        t          _        | j        t          _        | j        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)rl   rn   rt   r   rs   ru   rr   rw   rv   ry   r   rx   r   rz   )rn   s    r8   r/   r/      sF    
 &J'5H%HN'5H!1Hr:   F)time_keeperkeepdb	debug_sqlparallelaliasesserialized_aliasesc          
         |t                      }t          |          \  }	}
g }|	                                D ]<\  }}d}|D ]0}t          |         }|                    |||du f           ||}|                    d|z            5  |du p||v }|j                            | | ||           ddd           n# 1 swxY w Y   |dk    rot          |          D ]_}|                    d|z            5  |j        	                    t          |dz             | |           ddd           n# 1 swxY w Y   `t          |         j                            t          |         j                   2>|
                                D ]:\  }}t          |         j                            t          |         j                   ;|rt          D ]}dt          |         _        |S )zCreate the test databases.Nz  Creating '%s')	verbosityautoclobberr}   	serialize   z  Cloning '%s'suffixr   r}   T)NullTimeKeeper get_unique_databases_and_mirrorsvaluesr   appendtimedcreationcreate_test_dbrangeclone_test_dbrL   set_as_test_mirrorsettings_dictitemsforce_debug_cursor)r   interactiver|   r}   r~   r   r   r   kwargstest_databasesmirrored_aliases	old_namesdb_namefirst_aliasalias
connectionserialize_aliasindexmirror_aliass                      r8   r-   r-      s    $&&'G'P'P$N$I*1133   	 	E$U+Jj';$3FGHHH "# &&'85'@AA 	 	*d2Qe?Q6Q $ '66"+(3O%"1	 7   		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 a<<!&x  (../?%/GHH  &/=='*519~~*3'- >                  E"+>>,:   7	@  05577 
 
|E#66%3	
 	
 	
 	
  9  	9 	9E48K11s$   	(B==CC7.D1	1D58D5c              #      K   | D ]\}t          |t                    rt          d|d| d          t          |t                    r|V  Gt	          |          E d{V  ]dS )z
    Return an iterator over a test suite's unittest.TestCase objects.

    The tests argument can also be an iterable of TestCase objects.
    zTest z< must be a test case or test suite not string (was found in z).N)rK   rL   	TypeErrorr   iter_test_cases)teststests     r8   r   r      s        - -dC   	 - - -!&- - -   dH%% 	-JJJJ 't,,,,,,,,,,- -r:   c                 &   g }t                      }i }| D ]p\  }\  }}t                      }|D ]+}	|                    |                    |	g                      ,|                    |          st	          d|z            |||<   q| rd}
g }| D ]m\  }\  }}||                             |          r1|                    |           |                    |||ff           d}
T|                    |||ff           n|
st	          d          |} | |S )zp
    Reorder test_databases into an order that honors the dependencies
    described in TEST[DEPENDENCIES].
    zHCircular dependency: databases %r depend on each other, but are aliases.FTz)Circular dependency in TEST[DEPENDENCIES])r]   updaterU   
isdisjointr   issubsetr   )r   dependenciesordered_test_databasesresolved_databasesdependencies_mapsig_r   all_depsr   changeddeferred	signaturer   s                 r8   dependency_orderedr     s   
    , 	) 	)\a55 	9 	9EOOL,,UB778888""7++ 	&#%,-   !)
 " .< 	A 	A)I)	*334FGG A"))'222&--y7G:L.MNNNWg,> ?@@@@ 	T&'RSSS!  "  "!r:   c                    | t           } i }i }i }t           t                   j                                        }t           D ]	}t           |         }|j        d         }|d         r|d         ||<   1|| v r|                    |j                                        |j        d         g f          }|t          k    r|d                             d|           n|d                             |           d|v r|d         ||<   |t          k    r<|j                                        |k    r|                    dt          g          ||<   t          t          |                                |                    }||fS )a  
    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.
    NTESTMIRRORNAMEr   r   DEPENDENCIES)r   r   r   test_db_signaturer   
setdefaultinsertr   rU   dictr   r   )	r   r   r   r   default_sigr   r   test_settingsitems	            r8   r   r   .  s    NL./8JJLLK   '
"08" 	&3H&=U##g ",,#5577)&126 D (((Qq%((((Qu%%%..&3N&CU## ---"+==??;NN*7*;*;&)9(:+ +L' ,^-A-A-C-C\RRSSN+++r:   c                     | D ]i\  }}}|ra|dk    r?t          |          D ]/}|j                            t          |dz             ||           0|j                            |||           jdS )z%Destroy all the non-mirror databases.r   r   N)r   r   destroy_test_dbrL   )
old_configr   r   r}   r   old_namedestroyr   s           r8   teardown_databasesr   f  s    )3 	M 	M%
Hg 	M!||"8__  E'77"519~~"+% 8    
 //)VLLL	M 	Mr:   c                     |p| j         }|                    d          }t          |          dk    rd                    |d d                   }nd}t	          |i i |d                   }t          ||d                   S )N.r   )TEST_RUNNERsplitlenjoin
__import__getattr)r   test_runner_class	test_pathtest_module_nametest_modules        r8   r$   r$   t  s    )AX-A!'',,I
9~~88IcrcN33-r2y}EEK;	"...r:   c                   D    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
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                 "    || _         || _        d S r4   )	attr_name
kwarg_name)r7   r   r   s      r8   r9   zTestContextDecorator.__init__  s    "$r:   c                     t           r4   NotImplementedErrorr=   s    r8   enablezTestContextDecorator.enable      !!r:   c                     t           r4   r   r=   s    r8   disablezTestContextDecorator.disable  r   r:   c                 *    |                                  S r4   )r   r=   s    r8   	__enter__zTestContextDecorator.__enter__  s    {{}}r:   c                 .    |                                   d S r4   )r   r7   exc_type	exc_value	tracebacks       r8   __exit__zTestContextDecorator.__exit__  s    r:   c                 z     t          |t                    r|j         fd}||_        |S t          d          )Nc                                                      }|                     j                   j        rt	          | j        |            |            d S r4   )r   
addCleanupr   r   setattr)
inner_selfrf   decorated_setUpr7   s     r8   setUpz2TestContextDecorator.decorate_class.<locals>.setUp  s[    ++--%%dl333> AJ@@@
+++++r:   z1Can only decorate subclasses of unittest.TestCase)
issubclassr   r   r   )r7   clsr   r   s   `  @r8   decorate_classz#TestContextDecorator.decorate_class  sX    c8$$ 	!iO, , , , , , CIJKLLLr:   c                      t                    rt                     fd            }nt                     fd            }|S )Nc                  ~   K   5 }j         r
||j         <    | i | d {V cd d d            S # 1 swxY w Y   d S r4   r   argsr   rf   funcr7   s      r8   innerz5TestContextDecorator.decorate_callable.<locals>.inner  s       7W :29t/!%t!6v!6!66666667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s   266c                  n    5 }j         r
||j         <    | i |cd d d            S # 1 swxY w Y   d S r4   r   r   s      r8   r   z5TestContextDecorator.decorate_callable.<locals>.inner  s     1W :29t/40001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1s   *..)r   r   )r7   r   r   s   `` r8   decorate_callablez&TestContextDecorator.decorate_callable  s    t$$ 	1 4[[7 7 7 7 7 [7 7 4[[1 1 1 1 1 [1 r:   c                     t          |t                    r|                     |          S t          |          r|                     |          S t          dt          |          z            )Nz!Cannot decorate object of type %s)rK   typer   callabler   r   )r7   	decorateds     r8   __call__zTestContextDecorator.__call__  sf    i&& 	5&&y111i   	5)))444;d9ooMNNNr:   )NN)rE   rF   rG   r`   r9   r   r   r   r   r   r   r   rH   r:   r8   r   r     s        
 
% % % %" " "" " "    M M M  ,O O O O Or:   r   c                   >     e Zd ZdZdZ fdZd Zd Zd Zd Z	 xZ
S )r)   a4  
    Act as either a decorator or a context manager. If it's a decorator, take a
    function and return a wrapped function. If it's a contextmanager, use it
    with the ``with`` statement. In either event, entering/exiting are called
    before and after, respectively, the function/block is executed.
    Nc                 V    || _         t                                                       d S r4   )optionsrN   r9   r7   r   rR   s     r8   r9   zoverride_settings.__init__  s&    r:   c                 \   d| j         v rC	 t          j        | j         d                    n"# t          $ r t          j                      w xY wt          t          j                  }| j                                         D ]\  }}t          |||           t          j        | _
        |t          _        | j                                         D ]_\  }}	 t          j        t          j        j        ||d           .# t          $ r%}|| _        |                                  Y d }~Xd }~ww xY wd S )NINSTALLED_APPSTrd   settingvalueenter)r  r   set_installed_apps	Exceptionunset_installed_appsr   r   _wrappedr   r   wrappedr   rg   rR   enable_exceptionr   )r7   overriderP   	new_valueexcs        r8   r   zoverride_settings.enable  sZ    t|++'5E(FGGGG   )+++ &h&788"l0022 	. 	.NCHc9----($"l0022 
	 
	NC	$#,6#	        (+%
	 
	s!   + A
'C::
D)D$$D)c                    d| j         v rt          j                     | j        t          _        | `g }| j         D ]T}t          t          |d           }t          j        t          j        j	        ||d          }|
                    |           U| j        | j        }d | _        ||D ]\  }}t          |t                    r|d S )Nr  Fr  )r  r   r  r  r   r  r   r   send_robustrR   extendr  rK   r  )r7   	responsesrP   r  responses_for_settingr  r   responses           r8   r   zoverride_settings.disable  s    t|++%''' LL	< 	4 	4C#t44I$3$?(2	% % %! 23333 ,'C$(D!I$ 	 	KAx(I.. 	 	r:   c                 Z    |j         | j        |_         d S i |j         | j        |_         d S r4   )_overridden_settingsr  r7   	test_funcs     r8   save_optionszoverride_settings.save_options	  s@    )1-1\I***.0.,.I***r:   c                 z    ddl m} t          ||          st          d          |                     |           |S )Nr   )SimpleTestCasezPOnly subclasses of Django SimpleTestCase can be decorated with override_settings)django.testr   r   
ValueErrorr  )r7   r   r   s      r8   r   z override_settings.decorate_class  sX    ......#~.. 	)   	#
r:   )rE   rF   rG   r`   r  r9   r   r   r  r   ra   rb   s   @r8   r)   r)     s                4  .  	 	 	 	 	 	 	r:   r)   c                   2     e Zd ZdZ fdZd Z fdZ xZS )r(   z
    Like override_settings, but makes it possible to append, prepend, or remove
    items instead of redefining the entire list.
    c                     |r|rJ |d         | _         n*|rJ t          |                                          | _         t          t          |                                            d S r@   )
operationslistr   rN   r)   r9   )r7   r   r   rR   s      r8   r9   zmodify_settings.__init__%  sg     	3"1gDOOOOO"6<<>>22DO&&//11111r:   c                 r    |j         | j        |_         d S t          |j                   | j        z   |_         d S r4   )_modified_settingsr%  r&  r  s     r8   r  zmodify_settings.save_options/  s@    '/+/?I((( Y122T_D (((r:   c           	         i | _         | j        D ]\  }}	 | j         |         n3# t          $ r& t          t	          t
          |g                     Y nw xY w|                                D ]s\  }t          t                    rg|dk    rfdD             z  5|dk    rfdD             z   M|dk    rfdD             bt          d|z            | j         |<   t                                                       d S )Nr   c                     g | ]}|v|	S rH   rH   rZ   r   r	  s     r8   
<listcomp>z*modify_settings.enable.<locals>.<listcomp>F  s#    JJJtE8I8Id8I8I8Ir:   prependc                     g | ]}|v|	S rH   rH   r+  s     r8   r,  z*modify_settings.enable.<locals>.<listcomp>H  #    IIIdt57H7HT7H7H7Hr:   removec                     g | ]}|v|	S rH   rH   )rZ   r   r   s     r8   r,  z*modify_settings.enable.<locals>.<listcomp>J  r/  r:   zUnsupported action: %s)r  r%  rM   r&  r   r   r   rK   rL   r"  rN   r   )r7   namer%  actionr   r	  rR   s       @@r8   r   zmodify_settings.enable8  sc    $ 	' 	'D*: T* : : :WXtR8899:!+!1!1!3!3 H HeS)) $"GEX%%JJJJuJJJJEEy((IIIIeIIIEQEEx''IIIIeIIIEE$%=%FGGG!&DLs   &-AA)rE   rF   rG   r`   r9   r  r   ra   rb   s   @r8   r(   r(     sj         
2 2 2 2 2          r:   r(   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )r*   z
    Act as a decorator. Override 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                 ~    ddl m} || _        || _        || _        t	                                                       d S )Nr   )registry)django.core.checks.registryr6  
new_checksdeployment_checksrN   r9   )r7   r8  r9  r6  rR   s       r8   r9   zoverride_system_checks.__init__X  sG    888888 $!2r:   c           	      r   | j         j        | _        t                      | j         _        | j        D ]$} | j         j        |gt          |dd          R   %| j         j        | _        | j        Gt                      | j         _        | j        D ])} | j         j        |gt          |dd          R ddi (d S d S )NtagsrH   deployT)	r6  registered_checks
old_checksr]   r8  registerr   r9  old_deployment_checks)r7   checks     r8   r   zoverride_system_checks.enable`  s    -9*-%%'_ 	G 	GE"DM"5F75&"+E+EFFFFF%)]%D"!-.1eeDM+/ X X&&uWwufb/I/IWWWRVWWWW .-X Xr:   c                 J    | j         | j        _        | j        | j        _        d S r4   )r>  r6  r=  r@  r9  r=   s    r8   r   zoverride_system_checks.disablek  s!    *./'*.*D'''r:   r4   rE   rF   rG   r`   r9   r   r   ra   rb   s   @r8   r*   r*   Q  so              	X 	X 	XE E E E E E Er:   r*   c                   	
 t          j        d          fdd 	d 
	fdd 
fdd }|                                                     d	d
          } |                                                    d	d
          }|                     d          sd}|| z  } ||z  } |t          |                     } |t          |                    } ||          S )al  
    Try 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. Ignore comment nodes, processing instructions, document type
    node, and leading and trailing whitespaces.

    Based on https://github.com/lxml/lxml/blob/master/src/lxml/doctestcompare.py
    z[ \t\n][ \t\n]+c                 0                         d|           S )N )sub)v_norm_whitespace_res    r8   norm_whitespacez$compare_xml.<locals>.norm_whitespace{  s    "&&sA...r:   c                 J    d                     d | j        D                       S )N c              3   N   K   | ] }|j         t          j        k    |j        V  !d S r4   )nodeTyper   	TEXT_NODEdatarZ   cs     r8   r\   z2compare_xml.<locals>.child_text.<locals>.<genexpr>  s;       
 
!*2N2NAF2N2N2N2N
 
r:   )r   
childNodeselements    r8   
child_textzcompare_xml.<locals>.child_text~  s7    ww 
 
#.
 
 
 
 
 	
r:   c                 $    d | j         D             S )Nc                 <    g | ]}|j         t          j        k    |S rH   )rN  r   ELEMENT_NODErQ  s     r8   r,  z1compare_xml.<locals>.children.<locals>.<listcomp>  s'    QQQat?P1P1P1P1P1Pr:   )rS  rT  s    r8   childrenzcompare_xml.<locals>.children  s    QQ7-QQQQr:   c                 ,      |                     S r4   rH   )rU  rV  rJ  s    r8   norm_child_textz$compare_xml.<locals>.norm_child_text  s    zz'22333r:   c                 N    t          | j                                                  S r4   )r   
attributesr   rT  s    r8   
attrs_dictzcompare_xml.<locals>.attrs_dict  s    G&,,..///r:   c                 R   | j         |j         k    rdS  |            |          k    rdS  |            |          k    rdS  |           } |          }t          |          t          |          k    rdS t          fdt          ||          D                       S )NFc              3   6   K   | ]\  }} ||          V  d S r4   rH   )rZ   wantgotcheck_elements      r8   r\   z5compare_xml.<locals>.check_element.<locals>.<genexpr>  sD       
 
)2sMM$$$
 
 
 
 
 
r:   )tagNamer   allzip)want_elementgot_elementwant_childrengot_childrenr_  rd  rZ  r\  s       r8   rd  z"compare_xml.<locals>.check_element  s    ;#6665?<((OOK,H,HHH5:l##zz+'>'>>>5 ..x,,}\!2!2225 
 
 
 
69-6V6V
 
 
 
 
 	
r:   c                 v    | j         D ]0}|j        t          j        t          j        t          j        fvr|c S 1d S r4   )rS  rN  r   COMMENT_NODEDOCUMENT_TYPE_NODEPROCESSING_INSTRUCTION_NODE)documentnodes     r8   
first_nodezcompare_xml.<locals>.first_node  sT    ' 	 	D}!'0%  
 	 	r:   z\n
z<?xmlz<root>%s</root>)recompilestripreplace
startswithr   )rb  rc  rr  wrapper	want_rootgot_rootrI  r_  rd  rV  rZ  r\  rJ  s         @@@@@@@r8   compare_xmlr|  p  se    *%788/ / / / /
 
 

R R R4 4 4 4 4 40 0 0
 
 
 
 
 
 
 
   ::<<t,,D
))++

eT
*
*C ??7## #~m 
;t,,--Iz+c**++H=H---r:   c                   L    e Zd ZdZd Zd Zd Zd Zed             Z	d Z
d Zd	S )
r%   zU
    Context manager that captures queries executed by the specified connection.
    c                     || _         d S r4   )r   )r7   r   s     r8   r9   zCaptureQueriesContext.__init__  s    $r:   c                 *    t          | j                  S r4   )itercaptured_queriesr=   s    r8   __iter__zCaptureQueriesContext.__iter__  s    D)***r:   c                     | j         |         S r4   )r  )r7   r   s     r8   rO   z!CaptureQueriesContext.__getitem__  s    $U++r:   c                 *    t          | j                  S r4   )r   r  r=   s    r8   __len__zCaptureQueriesContext.__len__  s    4()))r:   c                 >    | j         j        | j        | j                 S r4   )r   queriesinitial_queriesfinal_queriesr=   s    r8   r  z&CaptureQueriesContext.captured_queries  s    &t';d>P'PQQr:   c                     | j         j        | _        d| j         _        | j                                          t          | j         j                  | _        d | _        t          j        t                     | S )NT)
r   r   ensure_connectionr   queries_logr  r  r   
disconnectr   r=   s    r8   r   zCaptureQueriesContext.__enter__  sb    "&/"D-1* 	))+++"4?#>??!"=111r:   c                     | j         | j        _         t          j        t                     |d S t          | j        j                  | _        d S r4   )r   r   r   connectr   r   r  r  r   s       r8   r   zCaptureQueriesContext.__exit__  sF    -1-D*...F !<==r:   N)rE   rF   rG   r`   r9   r  rO   r  propertyr  r   r   rH   r:   r8   r%   r%     s         % % %+ + +, , ,* * * R R XR	 	 	> > > > >r:   r%   c                   *     e Zd Z fdZd Zd Z xZS )r&   c                     || _         d| j         v s	d| j         v rt          j        | _        nt          j        | _        t                                                       d S )Nmessagemodule)ignore_kwargswarningsfilterwarningsfilter_funcsimplefilterrN   r9   r  s     r8   r9   zignore_warnings.__init__  s[    #***h$:L.L.L'6D'4Dr:   c                     t          j                    | _        | j                                          | j        di | j         d S )Nignore)r  )r  catch_warningsr   r  r  r=   s    r8   r   zignore_warnings.enable  sJ    &577%%'''88T%788888r:   c                 F     | j         j        t          j                      d S r4   )r  r   sysexc_infor=   s    r8   r   zignore_warnings.disable  s!    $$clnn5555r:   )rE   rF   rG   r9   r   r   ra   rb   s   @r8   r&   r&     sV            9 9 9
6 6 6 6 6 6 6r:   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               '      K   t           j        dd         }t           j                            |            	 dV  |t           _        dS # |t           _        w xY w)z5Context manager to temporarily add paths to sys.path.N)r  pathr  )paths_orig_sys_paths     r8   extend_sys_pathr    sW       Xaaa[NHOOE"!>!!!!s   A	 	Ac              #      K   |                                   	 dV  |                                   dS # |                                   w xY w)z?Clear the cache of an LRU cache object on entering and exiting.N)cache_clear)lru_cache_objects    r8   r"   r"     sY         """'$$&&&&&$$&&&&s	   2 Ac              #   
  K   t          t          |           }t          t          | t                                 	 t          t          |           V  t          t          | |           dS # t          t          | |           w xY w)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)r   r  r   r   )stream_nameorig_stdouts     r8   captured_outputr    sx       #{++KChjj)))/c;'''''[+.....[+....s   A* *Bc                       t          d          S )zCapture the output of sys.stdout:

    with captured_stdout() as stdout:
        print("hello")
    self.assertEqual(stdout.getvalue(), "hello
")
    stdoutr  rH   r:   r8   captured_stdoutr         8$$$r:   c                       t          d          S )zCapture the output of sys.stderr:

    with captured_stderr() as stderr:
        print("hello", file=sys.stderr)
    self.assertEqual(stderr.getvalue(), "hello
")
    stderrr  rH   r:   r8   captured_stderrr  )  r  r:   c                       t          d          S )zCapture 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")
    stdinr  rH   r:   r8   captured_stdinr  3  s     7###r:   c              #       K   t           j         } fdt           _         	 dV  |t           _         dS # |t           _         w xY w)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 r4   rH   )ts   r8   <lambda>zfreeze_time.<locals>.<lambda>J  s     r:   N)time)r  
_real_times   ` r8   freeze_timer  @  sI       J			DI			J	s	   2 A c                      t          t          du d          |           }  t          dddddddidg	          |           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/django.template.backends.django.DjangoTemplatesT)BACKENDAPP_DIRSz&django.template.backends.jinja2.Jinja2keep_trailing_newline)r  r  OPTIONS)	TEMPLATES)r	   jinja2r)   )r  s    r8   require_jinja2r  Q  s    
 Dv~'BCCINNI M  
 D 3T: 

     r:   c                   .     e Zd ZdZ fdZd Zd Z xZS )override_script_prefixzEDecorator or context manager to temporary override the script prefix.c                 V    || _         t                                                       d S r4   )prefixrN   r9   )r7   r  rR   s     r8   r9   zoverride_script_prefix.__init__i  s&    r:   c                 T    t                      | _        t          | j                   d S r4   )r   
old_prefixr   r  r=   s    r8   r   zoverride_script_prefix.enablem  s%    +--$+&&&&&r:   c                 .    t          | j                   d S r4   )r   r  r=   s    r8   r   zoverride_script_prefix.disableq  s    $/*****r:   rC  rb   s   @r8   r  r  f  s\        OO    ' ' '+ + + + + + +r:   r  c                       e Zd ZdZd Zd ZdS )LoggingCaptureMixinzn
    Capture the output from the 'django' logger and store it on the class's
    logger_output attribute.
    c                     t          j        d          | _        | j        j        d         j        | _        t                      | _        | j        | j        j        d         _        d S )Ndjangor   )logging	getLoggerloggerhandlersstream
old_streamr   logger_outputr=   s    r8   r   zLoggingCaptureMixin.setUp{  sO    '11+.q18%ZZ)-);Q&&&r:   c                 >    | j         | j        j        d         _        d S r@   )r  r  r  r  r=   s    r8   tearDownzLoggingCaptureMixin.tearDown  s    )-Q&&&r:   N)rE   rF   rG   r`   r   r  rH   r:   r8   r  r  u  s<         
< < <9 9 9 9 9r:   r  c                   .     e Zd ZdZ fdZd Zd Z xZS )r'   a  
    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                 H    || _          t                      j        di | d S )NrH   )installed_appsrN   r9   )r7   r  r   rR   s      r8   r9   zisolate_apps.__init__  s.    ,""6"""""r:   c                 |    t           j        | _        t          | j                  }t          t           d|           |S Ndefault_apps)r   r  old_appsr   r  r   )r7   r   s     r8   r   zisolate_apps.enable  s3    ,D'((...r:   c                 <    t          t          d| j                   d S r  )r   r   r  r=   s    r8   r   zisolate_apps.disable  s    77777r:   rC  rb   s   @r8   r'   r'     s`          # # # # #  8 8 8 8 8 8 8r:   r'   c                   0    e Zd Zd Zed             Zd ZdS )
TimeKeeperc                 B    t          j        t                    | _        d S r4   )collectionsdefaultdictr&  recordsr=   s    r8   r9   zTimeKeeper.__init__  s    ".t44r:   c              #   6  K   | j         |          t          j                    }	 d V  t          j                    |z
  }| j         |                             |           d S # t          j                    |z
  }| j         |                             |           w xY wr4   )r  r  perf_counterr   )r7   r2  
start_timeend_times       r8   r   zTimeKeeper.timed  s      T&((
	0EEE(**Z7HL%%h///// (**Z7HL%%h////s   A   8Bc                     | j                                         D ]=\  }}|D ]5}d||fz  }t          j                            |t
          j        z              6>d S )Nz%s took %.3fs)r  r   r  r  writeoslinesep)r7   r2  	end_timesrecord_timerecords        r8   print_resultszTimeKeeper.print_results  sp    #|1133 	6 	6OD)( 6 6(D++>>
  "*!455556	6 	6r:   N)rE   rF   rG   r9   r   r   r  rH   r:   r8   r  r    sM        5 5 5 0 0 ^06 6 6 6 6r:   r  c                   *    e Zd Zed             Zd ZdS )r   c              #      K   d V  d S r4   rH   )r7   r2  s     r8   r   zNullTimeKeeper.timed  s      r:   c                     d S r4   rH   r=   s    r8   r  zNullTimeKeeper.print_results  s    r:   N)rE   rF   rG   r   r   r  rH   r:   r8   r   r     s<          ^    r:   r   c                        fd}|S )z0Decorator to add tags to a test class or method.c                     t          | d          r | j                                      | _        nt          | dt	                               | S )Nr;  )rp   r;  unionr   r]   )objr;  s    r8   	decoratorztag.<locals>.decorator  sI    3 	,x~~d++CHHCT+++
r:   rH   )r;  r  s   ` r8   r+   r+     s$         r:   )lookup_namec             '      K   	 |D ]}|                      ||           dV  |D ]}|                     ||           dS # |D ]}|                     ||           w xY w)z
    Context manager to temporarily register lookups on a model field using
    lookup_name (or the lookup's lookup_name if not provided).
    N)register_lookup_unregister_lookup)fieldr  lookupslookups       r8   r  r    s      : 	7 	7F!!&+6666 	: 	:F$$V[9999	: 	:g 	: 	:F$$V[9999	:s   A   Ac                  d    t          j                     t          rt          j                     d S d S r4   )gccollectr   rH   r:   r8   r#   r#     s.    JLLL 

 r:   r4   )r   F)dr  r  r  r  rt  r  r  r  
contextlibr   	functoolsr   ior   	itertoolsr   typesr   unittestr   r	   r
   xml.dom.minidomr   r   asgiref.syncr   django.appsr   django.apps.registryr   django.confr   r   django.corer   django.core.exceptionsr   django.core.signalsr   r   	django.dbr   r   r   django.db.models.optionsr   django.templater   django.test.signalsr   django.urlsr   r   django.utils.translationr   django.utils.versionr   r  ImportError__all__rp   
TZ_SUPPORTr    r&  r!   rj   rl   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'   r  r   r+   r  r#   rH   r:   r8   <module>r     s       				  				 				 



   % % % % % %                   ! ! ! ! ! ! 1 1 1 1 1 1 1 1 1 1 - - - - - - - - , , , , , ,       % % % % % % 4 4 4 4 4 4 4 4       7 7 7 7 7 7 @ @ @ @ @ @ @ @ B B B B B B B B B B , , , , , , $ $ $ $ $ $ 1 1 1 1 1 1 < < < < < < < < / / / / / / % % % % % %MMMM   FFF& WT7##
	S 	S 	S 	S 	S 	S 	S 	S V  V  V  V  V$  V  V  VF) ) )	 	 	 	 	 	 	 	! ! ! !H  ( ? ? ? ? ?D- - -*'" '" '"T5, 5, 5, 5,pM M M M	/ 	/ 	/ 	/GO GO GO GO GO GO GO GOTR R R R R, R R Rj/ / / / /' / / /dE E E E E1 E E E>B. B. B.J%> %> %> %> %> %> %> %>P6 6 6 6 6* 6 6 6. !jB   " " " ' ' ' / / /% % %% % %
$ 
$ 
$      *+ + + + +1 + + +9 9 9 9 9 9 9 9 8 8 8 8 8' 8 8 8>6 6 6 6 6 6 6 6*       
 
 
 15 : : : : :    s   0B5 5B?>B?