
    \jH                    B   d dl m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	Z	d dl
mZ d dlmZmZmZ d dlmZ d dlmZmZ d dlmZ eZd dlZd dlm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"m#Z# d dl$m%Z%m&Z&m'Z'm(Z( ej)        j*        Z*dZ+dodZ,dpdZ-dej.        dddqd"Z/drd$Z0dsd%Z1dtd(Z2d)d)d*dud1Z3dvd4Z4dwd5Z5dxd8Z6dyd:Z7ej8        dzd<            Z9d{d?Z:d|dAZ;d}d~dGZ<ddJZ=dddNZ>ddQZ?ddTZ@ddZZAdd]ZBdd_ZCddbZD	 dddfZEddhZFddiZGdddmZHdydnZIdS )    )annotationsN)defaultdict)CallableIterableIterator)Pattern)IOAny)TestCase)defaults)process_options)Options)test_data_prefixtest_temp_dir)DataDrivenTestCase
DeleteFile
UpdateFilefix_cobertura_filename   args	list[str]returnNonec                    d}t          j        | ddgz             \  }}}|dk    rVt          j                            |           t          j                            |           t          j        dd           d S d S )NTz--show-tracebackz--no-silence-site-packagesr   zSample check failedF)reasonpytrace)apirunsysstdoutwritestderrpytestfail)r   __tracebackhide__outvalerrvalstatuss        U/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/mypy/test/helpers.pyrun_mypyr*   '   s     !WT-?A],^%^__FFF{{
   
   0%@@@@@@ {    leftright3tuple[list[tuple[int, int]], list[tuple[int, int]]]c                   t          j        d | |          }|                                }d}d}g }g }|D ]}|                    ||j        f           |                    ||j        f           |j        |j        z   }|j        |j        z   }|                    |j        |f           |                    |j        |f           ||fS )Nr   )difflibSequenceMatcherget_matching_blocksappendabsize)	r,   r-   seqblocksijleft_rangesright_rangesblocks	            r)   diff_rangesr>   2   s     
!$e
4
4C$$&&F	A	AKL 
* 
*Auw<(((QL)))Gej Gej  	EGQ<(((UWaL))))$$r+      )colouroutputindentrangeslist[tuple[int, int]]contentr@   
str | NonerA   IO[str]rB   intc                  t          |           D ]\  }}|dz  dk    }||d         |d                  }t          |          D ]\  }	}
|r>|	dk    r8|	t          |          dz
  k     r"|	dk    r|                    d|z  dz              E|s|r|                    |           |                    d|z  |
z              |s,|r|                    d           |                    d           |                    d	           d S )
Nr?      r       z...
z[0mz (diff)
)	enumeratelenr!   )rC   rE   r@   rA   rB   r9   
line_rangeis_matchinglinesr:   lines              r)   render_diff_rangerT   K   sA    #6**  :!eqj
1
156 '' 	 	GAt FFE

Q&&66LLv!7888 %6 %V$$$LLv,--- ( ,LL+++Y'''LL+	 r+   errorsc                    t           j                            d           | D ]$}t           j                            |dz              %d S )NzOriginal errors:
rM   )r   r"   r!   )rU   errs     r)   dump_original_errorsrX   n   sO    J)*** % %
t$$$$% %r+   c                   g }t                      }g }| D ][}d|vr&t          |            t          j        d|            |                    dd          \  }}|                    |           \t          |          D ]s\  }}|dk    r:|||dz
           k    r+||v r't          |            t          j        d| d           ||vr*|                    |           |                    |           t|S )N:z-Only module scoped errors are supported, got rJ   maxsplitr   z&Each module must form a single block, z appears split)setrX   r#   r$   splitr3   rN   add)rU   resultseenmodsemod_r9   s           r)   module_orderrf   t   s   F55DD  a<< (((KKKKLLLq))QCD//  3q55d1q5k!!cTkk$V,,,XSXXXYYYd??MM#HHSMMMMr+   actualexpected_orderc                H   t          t                    }t          |           }t          |          t          |          k    r| S | D ]7}|                    dd          \  }}||                             |           8g }|D ]}|                    ||                    |S )NrZ   rJ   r[   )r   listrf   r]   r^   r3   extend)rg   rh   actual_by_modactual_orderr4   rd   re   r`   s           r)   match_module_orderrn      s    %%M''L
<C//// % %q))Qc!!!$$$$F * *mC())))Mr+   F)	tracebackignore_modules_orderexpectedmsgstrro   boolrp   c          	        t          |          }|rt          |           }t          ||          }| |k    rt          | |          \  }}t          j                            d           t          j        dk    rdnd}t          || |           t          j                            d           t          j        dk    rdnd}	t          |||	           t          j                            d           t          d	 t          t          | |                    D             t          t          |           t          |                              }
d
|
cxk    rt          |          k     r[n nXt          | |
                   t          k    st          ||
                   t          k    rt          | |
         ||
                    t          j                            d           t!          j        ||           dS dS )zdAssert that two string arrays are equal.

    Display any differences in a human-readable form.
    z
Expected:
win32z[31mN)r@   zActual:
z[32mrM   c              3  2   K   | ]\  }\  }}||k    |V  d S N ).0r9   r4   r5   s       r)   	<genexpr>z-assert_string_arrays_equal.<locals>.<genexpr>   s.      KK91fq!AFFQFFFFKKr+   r   zUpdate the test output using --update-data (implies -n0; you can additionally use the -k selector to update only specific tests)
)r   )clean_uprf   rn   r>   r   r"   r!   platformrT   nextrN   zipmaxrO   MIN_LINE_LENGTH_FOR_ALIGNMENTshow_align_messager#   r$   )rq   rg   rr   ro   rp   expected_module_orderexpected_rangesactual_rangesredgreen
first_diffs              r)   assert_string_arrays_equalr      s    fF C ,X 6 6#F,ABB6)4Xv)F)F&
'''LG33jj/8C@@@@
%%%!lg55

4->>>>
KK	#h*?*? @ @KKKHs6{{++
 

 
((((S[[((((($%%)FFF6*%&&*GGG x
3VJ5GHHH
f	
 	
 	
 	C++++++5 r+   nameIterable[str]c           
        t          |          }t          t          |                              dh                    }t          ||d                    d                    |          d                    |          |                      d S )N__main__zEActual modules ({}) do not match expected modules ({}) for "[{} ...]", )sortedr]   
differencer   formatjoin)r   rq   rg   expected_normalizedactual_normalizeds        r)   assert_module_equivalencer      s     **s6{{55zlCCDD	PXXII'(($))4G*H*H$	
 	
    r+   c           
         t          ||d                    d                    |          d                    |          |                      dS )z6Compare actual and expected targets (order sensitive).zEActual targets ({}) do not match expected targets ({}) for "[{} ...]"r   N)r   r   r   )r   rq   rg   s      r)   assert_target_equivalencer      sV    	PXXIIftyy22D	
 	
    r+   s1s2c                   t          |           dk     rdS d}t          j                            d           d}| dd         |dd         k    r,| dd         } |dd         }d}| dd         |dd         k    ,|r
d	| z   } d	|z   }t	          t          |           t          |                    }d
}||k    rd	}t          j                            d| d|          | d           t          j                            d|d|          | d           t          j                            d           t          t          |t	          t          |           t          |                                        D ]^}| ||dz            |||dz            k    r!t          j                            d            n t          j                            d           _t          j                            d           dS )aQ  Align s1 and s2 so that the their first difference is highlighted.

    For example, if s1 is 'foobar' and s2 is 'fobar', display the
    following lines:

      E: foobar
      A: fobar
           ^

    If s1 and s2 are long, only display a fragment of the strings around the
    first difference. If s1 is very short, do nothing.
       NH   z$Alignment of first line difference:
F   
   Tz... z  E: rM   z  A: z     rJ   ^rL   )rO   r   r"   r!   r   rangemin)r   r   maxwtruncmax_lenextrar:   s          r)   r   r      s     2ww{{DJ<===E
SbS'RW

WW SbS'RW


  RZRZ#b''3r77##GE~~ J1RY1111222J1RY1111222JW3tSR#b''223344 " "a!a%i=Bq1q5yM))JS!!!EJS!!!!JTr+   r4   c                   g }t          j                    }|dz   }| D ]}t           j        }|}||                    t           j        d          fD ]0}|dk    r(|dk    r"|dk    r|dk    r|                    |d          }1d|v rt	          j        dd	|          }t	          j        d
d|          }|                    |d          }|                    t	          j        dd|                     |S )zRemove common directory prefix from all strings in a.

    This uses a naive string replace; it seems to work well enough. Also
    remove trailing carriage returns.
    z
/driver.py/z//\z\\r   zat 0xz(at 0x)\w+>z\g<1>000000000000>z +$z	driver.pyz\r$)osgetcwdsepreplaceresubr3   )r4   respwddriversprefixssps           r)   r|   r|     s     C
)++C<F + +444 	' 	'ACxxAII!t))VZZ2&&b==(=rBBBVE2r""ZZ,,

26&"b))****Jr+   Iterator[None]c               #    K   t           j                                        } dt           j        v s.dt           j        v s t           j                            dd           	 dV  | t           _        dS # | t           _        w xY w)zTemporary insert current directory into sys.path.

    This can be used by test cases that do runtime imports, for example
    by the stubgen tests.
    r   .r   N)r   pathcopyinsert)old_sys_paths    r)   local_sys_path_setr   *  sn       8==??L#(NNcSXoo2 <s   A0 0A>r   tuple[int, int]c                    t          j        d|           x}r<t          dt          |                    d                    ft
          j                  S t
          j        S )Nzpython3([0-9]+)\.test$rK   rJ   )r   searchr   rH   groupr   PYTHON3_VERSION_MIN)r   ms     r)   testfile_pyversionr   :  sO    I/666q , As1771::')EFFF++r+   messagesc                z    g }| D ]5}|                     |                    t          j        d                     6|S )z@Translate an array of error messages to use / as path separator.r   )r3   r   r   r   )r   r4   r   s      r)   normalize_error_messagesr   C  sB     	A ) )	263''((((Hr+         ?funcCallable[[], Any]max_waitfloatc                    t          j                     }d}	 	  |              dS # t          $ rH t          |dz  ||z   t          j                     z
            }|dk    r t          j        |           Y nw xY wc)a   Retry callback with exponential backoff when it raises OSError.

    If the function still generates an error after max_wait seconds, propagate
    the exception.

    This can be effective against random file system operation failures on
    Windows.
    g{Gz?TNr?   )timeOSErrorr   sleep)r   r   t0	wait_times       r)   retry_on_errorr   L  s     
BI	"	"DFFFF 	" 	" 	"IM2=49;;+FGGID  Jy!!!!!	"		"s   
$ AA65A6objobjectc                V   t          | t                    r|                     d          dk    rmdg}|                     d          D ]/}|                    t          d|z             dd                    0|dxx         dz  cc<   d                    |          S t          |           S )NrM   rJ   z'''\"r?   z''')
isinstancers   countr^   r3   reprr   )r   bitsrS   s      r)   	good_reprr   c  s    #s #99T??Q9D		$ 4 4Dt,,QrT23333HHHHHH99T??"99r+   {} != {}r5   fmtc                    d}| |k    r=t          |                    t          |           t          |                              d S )NT)AssertionErrorr   r   )r4   r5   r   r%   s       r)   assert_equalr   o  s@    AvvSZZ	!illCCDDD vr+   ttypec                    dt          |           v r;t          |                               d          d                             d          S t          |           dd         S )Nr   r   z'>   )rs   r^   rstrip)r   s    r)   typenamer   u  sP    
c!ff}}1vv||C  $++D1111vvad|r+   typvaluec                    d}t          |          | k    r<t          dt          t          |                     dt          |                      d S )NTzInvalid type z, expected )r   r   r   )r   r   r%   s      r)   assert_typer   |  sU    E{{c^Xd5kk-B-B^^xX[}}^^___ r+   program_texttestcaser   incremental_stepr   c                $   t                      }t          j        d| t          j                  }|dk    r)t          j        d| d| t          j                  }|r|}|rm|                    d                                          }|                    d           t          |d          \  }}|rt          d	          d
|vrd|_	        ng }t                      }d|_
        d|_	        t          d |D                       rt          |j                  |_        |j                            d          r|j                            d          |_        |j                            d          r|j                            d          |_        |S )z4Parse comments like '# flags: --foo' in a test case.z# flags: (.*)$)flagsrJ   z# flagsz: (.*)$z--no-site-packagesF)require_targetsz9Specifying targets via the flags pragma is not supported.z--show-error-codesTc              3  T   K   | ]#}|                     d           d         dk    V  $dS )=r   z--python-versionN)r^   )rz   flags     r)   r{   z parse_options.<locals>.<genexpr>  s7      
J
J4::c??1!33
J
J
J
J
J
Jr+   z--mypy-verbosez--mypy-num-workers)r   r   r   	MULTILINEr   r^   r3   r   RuntimeErrorhide_error_codeserror_summaryallr   filepython_versionconfig	getoption	verbositynum_workers)r   r   r   optionsr   flags2	flag_listtargetss           r)   parse_optionsr    s    iiGI&BLIIIE!>%5>>>TVT`aaa 	E (KKNN((**	-...*9eLLL 	\Z[[[y00'+G$	)) %#'  
J
J	
J
J
JJJ C!3HM!B!B  !122 H$O556FGG  !566 N&o778LMMNr+   streamsbytesc                     d | D             S )zDReturns a single list of string lines from the byte streams in args.c                f    g | ].}|                     d                                           D ]}|/S )utf8)decode
splitlines)rz   streamr   s      r)   
<listcomp>zsplit_lines.<locals>.<listcomp>  s=    PPP&V]]6-B-B-M-M-O-OPPAPPPPr+   ry   )r  s    r)   split_linesr    s    PPGPPPPr+   target_pathc                   d }t           j                            |          rt          j        |          j        dz   }t           j                            |          }t          j        |d           t          |dd          5 }|                    |            d d d            n# 1 swxY w Y   |rt          j	        |||f           d S d S )NrJ   T)exist_okwzutf-8encoding)times)
r   r   isfilestatst_mtimedirnamemakedirsopenr!   utime)rE   r  new_timedirtargets        r)   write_and_fudge_mtimer#    s    H	w~~k"" 57;''014
'//+
&
&CKd####	k3	1	1	1 VW                :
Xx$8999999: :s   B''B+.B+
operationslist[UpdateFile | DeleteFile]c                X   | D ]}t          |t                    rt          |j        |j                   2t
          j                            |j                  r6|j                            d          sJ t          j
        |j                   |j        t          fd           d S )Ntmpc                 ,    t          j                   S rx   )r   remove)r   s   r)   <lambda>z)perform_file_operations.<locals>.<lambda>  s    ry r+   )r   r   r#  rE   r  r   r   isdir
startswithshutilrmtreer   )r$  opr   s     @r)   perform_file_operationsr0    s     8 8b*%% 	8!"*bn==== w}}RW%% 8w))%00000bg&&&& w666677778 8r+   r   stepstrip_prefixc           
        | j         D ]\  }}|                    |          }t          j                            |          s/t          d                    || j        rd|z  nd                    t          |d          5 }|	                                }d d d            n# 1 swxY w Y   t          |t                    r9|                    |          t          d                    ||                    t          |                                t          j                            t                               }| j        r<| j        j        r!t          j        j        dk    rd |D             }t+          |          }t          j                            | j                  d	k    rt1          |          }t3          |                                |d
                    || j        rd|z  nd                     d S )Nz0Expected file {} was not produced by test case{}z on step %dr   r  r  zCOutput file {} did not match its expected output pattern
---
{}
---r   c                ,    g | ]}t          |          S ry   )r   rz   rS   s     r)   r  z+check_test_output_files.<locals>.<listcomp>  s!    $`$`$`d%;D%A%A$`$`$`r+   zreports.testz2Output file {} did not match its expected output{})output_filesremoveprefixr   r   existsr   r   output2r  readr   r   	fullmatchnormalize_file_outputr  abspathr   normalize_outputsuite
native_sepr   r   basenamer   normalize_report_metar   )r   r1  r2  r   expected_contentoutput_fileactual_output_contentnormalized_outputs           r)   check_test_output_filesrG    sZ    #+"7 %
 %
  ..w~~d## 	 BII(2BJ-$..   
 $((( 	7K$/$4$4$6$6!	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 &00 	))*?@@L X__/    2!,,..0N0N
 

 $ 	L~( aRW[D-@-@$`$`N_$`$`$`! 89J K K7HM**n<< 56G H H"''))@GGh.>Fmd**B 	
 	
 	
 	
?%
 %
s   B##B'	*B'	current_abs_pathc                    t          j        d          fd| D             }t          j        j        fd|D             }t          t          j        d          fd|D             }fd|D             }|S )z%Normalize file output for comparison.z\d{10}c                <    g | ]}|                     d           S )z$PWD)r   )rz   xrH  s     r)   r  z)normalize_file_output.<locals>.<listcomp>  s(    CCCaaii(&11CCCr+   c                l    g | ]0}t          j        d t          j                  z   d z   d|          1S z\bz$VERSIONr   r   escape)rz   rK  versions     r)   r  z)normalize_file_output.<locals>.<listcomp>  s;    XXXAbfURYw///%7QGGXXXr+   base_versionc                l    g | ]0}t          j        d t          j                  z   d z   d|          1S rM  rN  )rz   rK  rQ  s     r)   r  z)normalize_file_output.<locals>.<listcomp>  s<    ]]]QRbfURY|444u<j!LL]]]r+   c                <    g | ]}                     d |          S )z
$TIMESTAMP)r   )rz   rK  timestamp_regexs     r)   r  z)normalize_file_output.<locals>.<listcomp>  s)    CCCqo!!,22CCCr+   )r   compilemypyrP  __version__getattr)rE   rH  r`   rQ  rT  rP  s    ` @@@r)   r<  r<    s    j++OCCCC7CCCFl&GXXXXQWXXXF 4<AAL]]]]V\]]]FCCCCFCCCFMr+   c                $    dfd| D             S )NzC<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">c                $    g | ]}|k    rd n|S )z<meta charset="UTF-8">ry   )rz   rK  	html_metas     r)   r  z)normalize_report_meta.<locals>.<listcomp>  s'    OOO!Y$$AOOOr+   ry   )rE   r[  s    @r)   rB  rB    s%     VIOOOOwOOOOr+   patternexcludelist[str] | Nonec                t    fdt          j        t                                        |           D             S )Nc                4    g | ]}|j         pg v|j         S ry   )r   )rz   r   r]  s     r)   r  z#find_test_files.<locals>.<listcomp>  s6       9W]++ 		+++r+   )pathlibPathr   rglob)r\  r]  s    `r)   find_test_filesrd    sG       \"23399'BB   r+   c                    d | D             S )Nc                :    g | ]}t          j        d d|          S )z`-?\d+r   )r   r   r5  s     r)   r  z&remove_typevar_ids.<locals>.<listcomp>  s&    666DBF9b$''666r+   ry   )r4   s    r)   remove_typevar_idsrg    s    66A6666r+   )r   r   r   r   )r,   r   r-   r   r   r.   )rC   rD   rE   r   r@   rF   rA   rG   rB   rH   r   r   )rU   r   r   r   )rU   r   r   r   )rg   r   rh   r   r   r   )rq   r   rg   r   rr   rs   ro   rt   rp   rt   r   r   )r   rs   rq   r   rg   r   r   r   )r   rs   rq   r   rg   r   r   r   )r   rs   r   rs   r   r   )r4   r   r   r   )r   r   )r   rs   r   r   )r   r   r   r   )r   )r   r   r   r   r   r   )r   r   r   rs   )r   )r4   r   r5   r   r   rs   r   r   )r   r   r   rs   )r   r   r   r   r   r   )r   rs   r   r   r   rH   r   r   )r  r	  r   r   )rE   rs   r  rs   r   r   )r$  r%  r   r   )r   )r   r   r1  rH   r2  rs   r   r   )rE   r   rH  rs   r   r   )rE   r   r   r   rx   )r\  rs   r]  r^  r   r   )J
__future__r   
contextlibr0   r   ra  r   r-  r   r   collectionsr   collections.abcr   r   r   r   typingr	   r
   unittestr   Suiter#   mypy.apir   mypy.versionrV  r   	mypy.mainr   mypy.optionsr   mypy.test.configr   r   mypy.test.datar   r   r   r   markskipr   r*   r>   r"   rT   rX   rf   rn   r   r   r   r   r|   contextmanagerr   r   r   r   r   r   r   r   r  r  r#  r0  rG  r<  rB  rd  rg  ry   r+   r)   <module>rx     s(   " " " " " "      				  				  



  # # # # # # 8 8 8 8 8 8 8 8 8 8                                      % % % % % %             < < < < < < < < ] ] ] ] ] ] ] ] ] ] ] ]{ !" A A A A% % % %: j           F% % % %   *   ( !&*, *, *, *, *, *,Z	 	 	 	   1 1 1 1h   4        , , , ,   " " " " ".	 	 	 	E E E E E   ` ` ` `# # # #LQ Q Q Q
: : : :*8 8 8 8$ BD(
 (
 (
 (
 (
V   P P P P    7 7 7 7 7 7r+   