
    i;                     V   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
Jr  SSKJr  SSKJr  SSKJrJr  SSKJrJrJrJrJrJrJrJr  SSKJrJrJr  SS	KJ r   SS
K!J"r"  SSK#J$r$  SSK%J&r&J'r'  SSK(J)r)  \RT                  S:  a  SSKJ+r+  OSSK,J+r+  \SLS\S\\   4S jj5       r- " S S5      r. " S S\+5      r/ " S S5      r0 " S S\+5      r1SLS\\2   SS4S jjr3SMS jr4S\Rj                  " 5       4S\2S \6S!\2SS4S" jjr7S\Rj                  " 5       4S\2S \6S!\2S\24S# jjr8 SLS$\&S%\\\2      SS4S& jjr9S'\2S(\S\2\\2   4   S\24S) jr:SS*SS+S, 4S-\S.\S%\\2   S/\\2\\2   4   S0\\2\\2   4   S1\S\2\\2   4   S2\2S3\\\2\24      S4\;S5\S6\\2   4   S\24S7 jjr<SLS8\S9\S\24S: jjr=    SNS8\S9\S;\;S<\;S=\;S\\2\24   4S> jjr>    SOS8\S9\S<\;S=\;S?\\?   S\\2\24   4S@ jjr@SA\2S\24SB jrA SPSC\2SD\2SE\2SF\2SS4
SG jjrB SPSC\2SD\2SE\2SF\2SS4
SH jjrC SPSI\2SJ\2SE\2SF\2SS4
SK jjrDg)Qz
Utilities used by tests
    N)contextmanager)unified_diff)Path)PIPEPopen)AnyCallableDictIteratorListOptionalTupleUnion)	Container
DictConfig	OmegaConf)Hydra)detect_task_name)GlobalHydra)	JobReturnvalidate_config_path)TaskFunction)      r   )Protocolenter_resultreturnc              #      #    U v   g 7fN )r   s    Z/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/hydra/test_utils/test_utils.pydoes_not_raiser"   "   s     
s   c                   X    \ rS rSrSrSS jrS\S\4S jrSS jr	S	\S
\S\SS4S jr
Srg)TaskTestFunction'   
Context function
r   Nc                     S U l         S U l        S U l        S U l        S U l        S U l        S U l        S U l        SU l        g NF)	temp_dir	overridescalling_filecalling_moduleconfig_pathconfig_namehydrajob_retconfigure_loggingselfs    r!   __init__TaskTestFunction.__init__,   sF    '+.2+/-1*.*.&*
,0',    cfgc                     gz)
Actual function being executed by Hydra
d   r    r3   r7   s     r!   __call__TaskTestFunction.__call__7   s    
 r6   c                 t    [        U R                  5        [        U R                  U R                  5      n[
        R                  " U R                  U R                  U R                  US9U l        [        R                  " 5       U l
        [        R                  " U R                  5      nUc   eUR                  SU R                   35        U R                  R                  U R                   U UU R"                  S9U l        U ['        5       R)                  5         $ ! ['        5       R)                  5         f = f)Nr+   r,   r-   job_namezhydra.run.dir=r.   task_functionr*   with_log_configuration)r   r-   r   r+   r,   r    create_main_hydra_file_or_moduler/   tempfilemkdtempr)   copydeepcopyr*   appendrunr.   r1   r0   r   clear)r3   r@   r*   s      r!   	__enter__TaskTestFunction.__enter__>   s    	" !1!12'(9(94;N;NOH??!..#22 ,,!	DJ %,,.DMdnn5I(((~dmm_=>::>> ,,"#'+'='=	 * DL M!KM!s   DD D7exc_typeexc_valexc_tbc                     U R                   (       a  [        R                  " 5         U R                  c   e[        R
                  " U R                  SS9  g NT)ignore_errorsr1   loggingshutdownr)   shutilrmtreer3   rN   rO   rP   s       r!   __exit__TaskTestFunction.__exit__X   s9    !!}}(((dmm48r6   )	r+   r,   r.   r-   r1   r/   r0   r*   r)   r   N)r   r$   __name__
__module____qualname____firstlineno____doc__r4   r   r   r<   rL   rZ   __static_attributes__r    r6   r!   r$   r$   '   sE    	-J 3 "49 9s 9C 9D 9r6   r$   c                   f    \ rS rSr  SS\\   S\\   S\\   S\\   S\\\      S\S	\4S
 jjr	Sr
g)TTaskRunner`   Nr+   r,   r-   r.   r*   r1   r   c                     g r   r    )r3   r+   r,   r-   r.   r*   r1   s          r!   r<   TTaskRunner.__call__a   s     	r6   r    r(   )r^   r_   r`   ra   r   strr   boolr$   r<   rc   r    r6   r!   re   re   `   sq     *."'	sm	 !	 c]		
 c]	 DI&	  	 
	 	r6   re   c                   X    \ rS rSrSrSS jrS\S\4S jrSS jr	S	\S
\S\SS4S jr
Srg)SweepTaskFunctionm   r&   r   Nc                     SU l         SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l	        g)za
if sweep_dir is None,  we use a temp dir, else we will create dir with the path from sweep_dir.
NF)
r)   r*   r+   r,   rB   r-   r.   sweepsreturnsr1   r2   s    r!   r4   SweepTaskFunction.__init__r   sP     (,.2+/-159*.*.',r6   r7   c                 @    U R                   b  U R                  U5      $ gr9   )rB   r;   s     r!   r<   SweepTaskFunction.__call__   s$     )%%c**r6   c                    [         R                  " U R                  5      nUc   eU R                  (       a$  [	        U R                  5      R                  SSS9  O[        R                  " 5       U l        UR                  SU R                   35         [        U R                  5        [        U R                  U R                  5      n[        R                  " U R                  U R                  U R                  US9nUR!                  U R"                  U UU R$                  S9U l        [)        5       R+                  5         U $ ! [)        5       R+                  5         f = f)NTparentsexist_okzhydra.sweep.dir=r?   rA   )rG   rH   r*   r)   r   mkdirrE   rF   rI   r   r-   r   r+   r,   r   rD   multirunr.   r1   rp   r   rK   )r3   r*   r@   hydra_s       r!   rL   SweepTaskFunction.__enter__   s   MM$..1	$$$==%%dT%B$,,.DM+DMM?;<	" !1!12'(9(94;N;NOH;;!..#22 ,,!	F "?? ,,"#'+'='=	 + DL M! M!s   BE ErN   rO   rP   c                     U R                   (       a  [        R                  " 5         U R                  c   e[        R
                  " U R                  SS9  g rR   rT   rY   s       r!   rZ   SweepTaskFunction.__exit__   s9    !!}}(((dmm48r6   )
r+   r,   r.   r-   r1   r*   rp   ro   rB   r)   r\   )r   rl   r]   r    r6   r!   rl   rl   m   sE    -J 3 >9 9s 9C 9D 9r6   rl   c                       \ rS rSr% \\\      \S'    SS\\   S\\   S\\	   S\\   S\\   S	\\\      S
\\
   S\4S jjrSrg)TSweepRunner   rp   Nr+   r,   rB   r-   r.   r*   r)   r   c                     g r   r    )r3   r+   r,   rB   r-   r.   r*   r)   s           r!   r<   TSweepRunner.__call__   s     	r6   r    r   )r^   r_   r`   ra   r   r   __annotations__r   ri   r   r   rl   r<   rc   r    r6   r!   r   r      s    $y/"" $(
sm
 !
  -	

 c]
 c]
 DI&
 4.
 

 
r6   r   subdirc                 J    [        SS9  U b  [        R                  " U 5        gg)zx
Change the cwd to the root of the hydra project.
used from unit tests to make them runnable from anywhere in the tree.
ATTRIBUTIONtargetN)_chdir_to_dir_containingoschdir)r   s    r!   chdir_hydra_rootr      s#    
 M2
 r6   c                      [        SS9  g)zA
Change the cwd to the root of the plugin (location of setup.py)
zsetup.pyr   N)r   r    r6   r!   chdir_plugin_rootr      s     J/r6      r   max_upinitial_dirc                 H    [        XU5      n[        R                  " U5        g r   )find_parent_dir_containingr   r   r   r   r   curs       r!   r   r      s     %V[
ACHHSMr6   c                    Un[         R                  R                  [         R                  R                  X05      5      (       d  US:  a  [         R                  R	                  [         R                  R                  US5      5      nUS-
  n[         R                  R                  [         R                  R                  X05      5      (       d  US:  a  M  US:X  a$  [        SU  S[         R                  " 5        35      eU$ )Nr   z..   zCould not find z in parents of )r   pathexistsjoinrelpathIOErrorgetcwdr   s       r!   r   r      s     CggnnRWW\\#677FQJggoobggll356! ggnnRWW\\#677FQJ {xryy{mLMMJr6   
job_returnr*   c                    [        U [        5      (       d   eU R                  c   eU R                  c   eU R                  c   e[
        R                  R                  [
        R                  R                  U R                  U R                  S-   5      5      (       d   e[
        R                  R                  U R                  U R                  R                  R                  5      n[
        R                  R                  [
        R                  R                  US5      5      (       d   e[
        R                  R                  [
        R                  R                  US5      5      (       d   e[        R                  " [
        R                  R                  US5      5      [        R                  " U=(       d    / 5      :X  d   eg)z*
Verify that directory output makes sense
Nz.logconfig.yamlzoverrides.yaml)
isinstancer   working_dir	task_name	hydra_cfgr   r   r   r   r/   output_subdirr   loadcreate)r   r*   	hydra_dirs      r!   verify_dir_outputsr      sS    j),,,,!!---++++++77>>
Z++Z-A-AF-JK    
 4 4 : : H HI 77>>"'',,y-@AAAA77>>"'',,y2BCDDDD>>
Y 01			)/r	*+ + +r6   indent
statementsc                     [        U[        5      (       a  U/nSnUb  [        U5      S:X  a  SnU$ U H  nX  U S3-  nM     U$ )N r   pass
)r   ri   len)r   r   codeps       r!   _get_statementsr      s\    *c"" \
DS_1 K Ahqc$$D Kr6   ztask.pyFc                     U $ r   r    )cmdargskwargss      r!   <lambda>r     s    QTr6   tmpdirtask_configprintsexpected_outputsprologfilenameenv_overrideclean_environmentgenerate_custom_cmd.c
                    [        U 5      R                  SSS9  [        U[        5      (       a  U/n[        U[        5      (       d  [
        R                  " U5      n[        U[        5      (       a  U/nU V
s/ s H	  n
SU
 S3PM     nn
[        R                  " S5      n[        SUS9n[        SUS9nUbJ  U S	-  n[        [        U5      S
5       nUR                  S5        [
        R                  " X5        S S S 5        [        U S-  5      nUR                  SS5      nUR                  UUUS9nX-  nUR                  [        U5      SS9  [         R"                  [        U5      /n[$        R&                  " 5       n [$        R(                  " [        U 5      5        U	" UU5      nUR+                  U5        U(       a  0 nO2[$        R,                  R/                  5       nUb  UR1                  U5        [2        R4                  " UUS9  [        US5       nUR7                  5       n[        R9                  U5      nS S S 5        UbR  [;        W5      [;        U5      :X  d   SU SW 35       e[=        [;        U5      5       H  n[?        UU   UU   5        M     W[$        R(                  " U5        $ s  sn
f ! , (       d  f       GN= f! , (       d  f       N= f! [$        R(                  " U5        f = f)NTru   zf.write(z + "\n")a
  import hydra
import os
from hydra.core.hydra_config import HydraConfig

$PROLOG

@hydra.main(version_base=None, config_path='.', config_name='config')
def experiment(cfg):
    with open("$OUTPUT_FILE", "w") as f:
$PRINTS

if __name__ == "__main__":
    experiment()
z        )r   r   r   r   wz# @package _global_
z
output.txt\z\\)PRINTSOUTPUT_FILEPROLOGutf-8)encoding)envrz'Unexpected number of output lines from z, output lines:

) r   rx   r   ri   r   r   r   stringTemplater   openwritesavereplace
substitute
write_textsys
executabler   r   r   extendenvironrG   update
subprocess
check_callread
splitlinesr   rangeassert_regex_match)r   r   r*   r   r   r   r   r   r   r   r   s
print_codeprolog_codecfg_filefoutput_filer   	task_filer   orig_dirmodified_envfile_stroutputidxs                            r!   integration_testr   	  s    	Ltd3"C((,-k9--&&{3&#/56v!9%vF6		A" !
vFJ!?KM)#h-%GG+,NN;* & f|+,K%%dF3K<<  D
 !ITW5>>3y>
*Cyy{H
V!#x0

9L::??,L'##L1c|4+s#qvvxH^^H-F $ 'v;# #  b8CVW_V`ab  S[)"#3C#8&+F * 
C 70 &%8 $# 	s8   9J2(J7BK &K	=AK 7
K	
KK K2r   r   c                 6   [         R                  S/U -   n [        U [        [        US9 nUR	                  5       u  p4UR                  S5      R                  5       R                  SS5      nUR                  S:w  d   e S S S 5        U$ ! , (       d  f       W$ = f)N-Werror)stdoutstderrr   r   
r   r   )	r   r   r   r   communicatedecoderstripr   
returncode)r   r   r   _stdoutr   errs         r!   run_with_errorr   `  s    >>9
%
+C	s4#	6!--/mmG$++-55fdC||q    
7 J	 
7	6 Js   AB		
Ballow_warningsprint_errorraise_exceptionc                 |    U(       a  [         R                  /U -   n O[         R                  S/U -   n [        XX45      $ )Nr   )r   r   run_process)r   r   r   r   r   s        r!   run_python_scriptr   i  s8     ~~$~~y)C/s>>r6   timeoutc                     [         R                  " U SU[         R                  [         R                  S9nUR                  US9u  pg[	        UR                  5       R                  5       5      n[	        UR                  5       R                  5       5      n	UR                  S:w  aP  U(       a#  [        R                  R                  SU	 S35        U(       a  [         R                  " UR                  U S9eX4$ ! [         aB  n
U(       a4  SR                  U 5      n [        R                  R                  S	U  S
35        U
eS n
A
ff = f)NF)r   shellr   r   r   )r   r   zSubprocess error:
r   )r   r    z=== Error executing:
z
===================)r   r   r   r   normalize_newlinesr   r   r   r   r   r   CalledProcessError	Exceptionr   )r   r   r   r   r   processbstdoutbstderrr   r   es              r!   r   r   w  s   ""????
 #..w.?#GNN$4$;$;$=>#GNN$4$;$;$=>"

  #6vhb!AB 33&11s  ~ ((3-CJJ5cU:OPQ	s   C5C8 8
E=D??Er   c                 F    U R                  SS5      R                  SS5      $ )ze
Normalizes new lines such they are comparable across different operating systems
:param s:
:return:
r   r   )r   )r   s    r!   r  r    s"     99VT"**466r6   	from_lineto_line	from_nameto_namec                 :   [        U 5      n [        U5      n[        U R                  5       UR                  5       UUS9 Vs/ s H  nUPM     nnSR                  U5      n[	        U5      S:  a(  [        S5        [        U5        [        S5         S5       eg s  snf )N)abfromfiletofiler   r   z 
------------ DIFF --------------------------------------------z)Mismatch between expected and actual text)r  r   r   r   r   print)r  r  r  r  linelinesdiffs          r!   assert_text_samer    s     #9-I )G !""$  "	

D 	
 
  99UD
4y1}12d/0AAAu	 s   Bc                    [        U 5      R                  S5       Vs/ s H  oD(       d  M  UPM     nn[        U5      R                  S5       Vs/ s H  oD(       d  M  UPM     nn[        U5      [        U5      :w  a  [        U UUUS9  [	        XV5       H1  u  pxXx:w  d  M  [
        R                  " Xx5      b  M%  [        U UUUS9  M3     gs  snf s  snf )zCheck that the lines of `from_line` (which can be a regex expression)
matches the corresponding lines of `to_line` string.

In case the regex match fails, we display the diff as if `from_line` was a regular string.
r   )r  r  r  r  N)r  splitr   r  ziprematch)	r  r  r  r  xnormalized_from_linenormalized_to_lineline1line2s	            r!   r   r     s     (:)'D'J'J4'PV'P!TUA'PV%7%@%F%Ft%LR%LPQ!%LR
 C(:$;;		
 0E>bhhu4<##	 F WRs   
C
C

CCpatternr   c                     [        U 5      n [        U5      n[        R                  " X[        R                  S9c>  [	        S5        [	        U 5        [	        S5        [	        U5        [	        S5         S5       eg)zCheck that `pattern` (which can be a regex expression)
matches the corresponding lines of `string` string.
In case the regex match fails, we display the diff as if `pattern` was a regular string.
)flagsNz
-------- PATTERN: -----------z---------- STRING: ------------r  zRegex pattern did not match)r  r  search	MULTILINEr  )r$  r   r  r  s       r!   assert_multiline_regex_searchr)    sf     !)G'F	yy5=/0g/0f/0333u >r6   r   r\   )NFTT)NTTN)ExpectedActual)Erb   rG   rU   r   r  rW   r   r   r   rE   
contextlibr   difflibr   pathlibr   r   r   typingr   r	   r
   r   r   r   r   r   	omegaconfr   r   r   hydra._internal.hydrar   hydra._internal.utilsr   hydra.core.global_hydrar   hydra.core.utilsr   r   hydra.typesr   version_infor   typing_extensionsr"   r$   re   rl   r   ri   r   r   r   intr   r   r   r   rj   r   r   r   floatr   r  r  r   r)  r    r6   r!   <module>r:     s     	 	    
  %    " N N N 6 6 ' 2 / < $y *    69 69r
( 
?9 ?9D8  Xc] d 0  !RYY[/2	  !RYY[			/2		 =A++&.tCy&9+	+0
C 
U4d3i3G-H 
S 
& +/-1#4TTTT CyT #tCy.!	T
 CcN+T $T#Y&'T T 4S>*T T "#tCy.1T 	Tn #     ?	?	? ? 	?
 ? 38_?   #		  	
 e_ 38_B7# 7# 7 OWBB B-0BHKB	B0 OW -0HK	8 LT444*-4EH4	4r6   