
    X-Phv                    ,   U d Z 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
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mZmZ dd
lmZ ddlZddlmZ ddlm Z m!Z!m"Z"m#Z# ej$        %                    e           Z&ddgZ'de(d<    G d de          Z) G d de          Z*ee)e*f         Z+de(d<   dXdZ,dYdZ- G d dej.                  Z/dZd!Z0e G d" d#                      Z1d[d'Z2d\d*Z3d\d+Z4d]d-Z5d^d1Z6d_d3Z7d_d4Z8d`d7Z9dad9Z: ej;        d:;          dbd>            Z<dcdCZ= ej>        dD          Z?dddKZ@ G dL dMejA                  ZB G dN dOe          ZC G dP dFejD                  ZEdedRZFdfdUZGdfdVZH G dW dH          ZIdS )gzGUtilities for processing .test files containing test case descriptions.    )annotationsN)abstractmethod)Iterator)	dataclass)Path)Pattern)AnyFinal
NamedTupleNoReturnUnion)	TypeAlias)defaults)PREFIXmypyc_output_dirtest_data_prefixtest_temp_dirgdblldbr
   SUPPORTED_DEBUGGERSc                  .    e Zd ZU ded<   ded<   ded<   dS )
UpdateFilestrmodulecontenttarget_pathN__name__
__module____qualname____annotations__     N/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/test/data.pyr   r   "   s0         KKKLLLr#   r   c                  $    e Zd ZU ded<   ded<   dS )
DeleteFiler   r   pathNr   r"   r#   r$   r&   r&   )   s"         KKKIIIIIr#   r&   
_TypeAliasFileOperationfilenamer   returnc                    t           j                            |           \  } }|                     d          }|d         dk    r|                                 d                    |          S )N/__init__.)osr'   splitextsplitpopjoin)r*   _partss      r$   _file_arg_to_moduler8   1   sX    '""8,,KHaNN3ERyJ		88E??r#   caseDataDrivenTestCaseNonec                V   + t           j         j                  } j        j        } j        j        rt          j        j        }nt          j        } j        j
        }g }g }g }i }i }	i }
i }g }i }g }dI fd}|d         x+}|                    d           |dd	         D ]+dI +fd
}+j        dv r
+j        J t          d                    +j                            } ||+j                  }+j        dk    r'|                    t          +j                             +j        dv r|                    ||f           +j        dk    rG|                    |t!          j        |                                t           j                  f           +j        dk    r|                    ||f           +j        dk    r+j        J  |t          j                             j                  +j                  }t-          |d          5 }|                     ||d          |                                f           d	d	d	           n# 1 swxY w Y   É+j        dk    r+j        J  |t          j                             j                  +j                  }t-          |d          5 }|                     ||d          |                                f           d	d	d	           n# 1 swxY w Y   h+j        dk    r+j        J  |t          j                             j                  +j                  }t-          |d          5 }|                     ||d          |                                f           d	d	d	           n# 1 swxY w Y   t!          j        d+j                  r~+j        dk    rdn(t3          +j        t5          d          d	                   }|dk    sJ +j        t7                      n#d +j                            d          D             }||
|<   t!          j        d+j                  r~+j        dk    rdn(t3          +j        t5          d          d	                   }|dk    sJ +j        t7                      n#d +j                            d          D             }|||<   =t!          j        d +j                  rr+j        d!k    rdn(t3          +j        t5          d!          d	                   }|dk    sJ +j        g n#d" +j                            d          D             }|||<   ɉ+j        d#k    rĉ+j        J t!          j        d$+j                  }| |d%+j                   t3          |                    d&                    }|d&k     r |d'|             |||                    d                    }|	                    |t7                                                    |           t!          j        d(+j                  r +j        g }n+j                            d          }d)}|D ]H}|                     d*          r/|d+d,         } | d-vr |d.           |d,d	         }!	 tC          d/ |!                    d0          D                       }"n# tD          $ r  ||!d1           Y nw xY w| d2k    r;|"tF          j$        k    r || d3tF          j$                    tJ          j&        |"k    }| d4k    ry|"tF          j$        k     r || d5tF          j$                    dt5          |"          cxk     rd6k     sn  |d7|!           tJ          j&        d	t5          |"                   |"k    }J|rd8 +j        D             }#t          j        j'        d9k    r j(        rd: |#D             }#+j        d;k    s+j        d<k    r|#}n6t3          +j        t5          d;          d	                   }|dk    sJ |#||<   d=}+j        d>k    r+j        	+j        }Ή+j        +j        r
d?+j         nd@z   }$ |dA|$ dB j                   |r |dC j                   |
)                                D ]I}||vr|
|         ||<   ||
v r4||v r0|
|         *                    ||                   s |dD| dE           Jt5          |          }%|j        }&tW          |&|dF           |D ])\  }'}tW          |                    d          ||'           *t7                      }(|D ]-\  })}*|)|(v r |dG|) dH           |(                    |)           .|& _,        | _-        |% _.        | _/         j0        +j0        z   t5          +j                  z   d&z
   _1        | _2        | _3        |
 _4        | _5        |	 _6        |pg  _7        | _8        | _9        d	S )JzParse and prepare a single case from suite with test case descriptions.

    This method is part of the setup phase, just before the test case is run.
    msgr   r+   r   c                X    t          j        j         dj         d|  d           d S )N:: Fpytrace)pytestfailfileline)r=   r9   s    r$   
_case_failz#parse_test_case.<locals>._case_failR   s8    ty55495555uEEEEEEr#   r   __main__   Nc                r    j         j         z   dz
  }t          j        j         d| d|  d           d S )N   r?   r@   FrA   )rF   rC   rD   rE   )r=   item_abs_liner9   items     r$   
_item_failz#parse_test_case.<locals>._item_fail[   sI     I	1A5MK49==}====uMMMMMMr#   >   rE   fixtureoutfile
outfile-re
rO   >   rE   rO   rQ   rP   builtinsutf8encodingzbuiltins.pyitypingz
typing.pyi	_typeshedz_typeshed.pyizstale[0-9]*$stalec                6    h | ]}|                                 S r"   strip.0ts     r$   	<setcomp>z"parse_test_case.<locals>.<setcomp>        5]5]5]Aaggii5]5]5]r#   ,zrechecked[0-9]*$	recheckedc                6    h | ]}|                                 S r"   r[   r]   s     r$   r`   z"parse_test_case.<locals>.<setcomp>   ra   r#   ztargets[0-9]*$targetsc                6    g | ]}|                                 S r"   r[   r]   s     r$   
<listcomp>z#parse_test_case.<locals>.<listcomp>   s     6^6^6^Qqwwyy6^6^6^r#   deletez(.*)\.([0-9]+)$zInvalid delete section rK   zCan't delete during step z
out[0-9]*$Tversion   	   >   ==>=z5Only >= and == version checks are currently supportedc              3  4   K   | ]}t          |          V  d S N)int)r^   xs     r$   	<genexpr>z"parse_test_case.<locals>.<genexpr>   s(      'O'O1A'O'O'O'O'O'Or#   r0   z is not a valid python versionrm   z. always true since minimum runtime version is rl   z/ always false since minimum runtime version is    zFOnly minor or patch version checks are currently supported with "==": c                ,    g | ]}t          |          S r"   )expand_variablesr^   rF   s     r$   rg   z#parse_test_case.<locals>.<listcomp>   s!    KKK.t44KKKr#   \c                ,    g | ]}t          |          S r"   )fix_win_pathrv   s     r$   rg   z#parse_test_case.<locals>.<listcomp>   s     !L!L!L,t"4"4!L!L!Lr#   outout1F	triggered  zInvalid section header [z
] in case z*Required output section not found in case zStale modules after pass z& must be a subset of rechecked modulesmainzDuplicated filename z$. Did you include it multiple times?)r=   r   r+   r   ):parse_test_datadatanamesuite	base_path
native_sepr1   r'   r5   	posixpathrequired_out_sectionappendidargru   r8   recompilerstripSdirnamerE   openreadmatchrp   lensetr3   group
setdefaultadd
startswithtuple
ValueErrorr   PYTHON3_VERSIONsysversion_infosepnormalize_outputkeysissubsetexpand_errorsinputoutputoutput_inline_startoutput2rF   	last_linefilesoutput_filesexpected_stale_modulesexpected_rechecked_modulesdeleted_pathsr|   expected_fine_grained_targetstest_modules),r9   
test_itemsr   r5   out_section_missingr   r   r   r   r   stale_modulesrechecked_modulesr|   re   r   rG   
first_itemrN   contentsr'   mpathfsrc_pathpassnummodulesreprocessedmnumfullargsversion_checkr   
compare_opversion_strri   
tmp_outputsection_strr   r   	file_path
seen_filesrE   r6   rM   s,   `                                          @r$   parse_test_caser   9   s2   
 !DI66J
$Iz w|~*9#%E9;LF$&G)+M)+M-/I$&G LF F F F F F
 #1%D:
###122 oX oX	N 	N 	N 	N 	N 	N 	N 7BBB8''''		$)(<(<==H4	48,,Dw)####$7$A$ABBBw---dH-....L((##T2:hoo6G6G+N+N$OPPPPI%%##T8$4555W
""8'''D33TX>>Eef--- Jdd9n==qvvxxHIIIJ J J J J J J J J J J J J J JW  8'''tBGOODI66AAHh000 HAdd9l;;QVVXXFGGGH H H H H H H H H H H H H H HW##8'''tBGOODI66AAHh000 KAdd9o>>IJJJK K K K K K K K K K K K K K KXotw// J	X7g--aa3tws7||~~7N3O3OGQ;;;;#x/ceee5]5]X[I\I\5]5]5]G%,M'""X)4733 E	X7k11aas473{CSCSCUCU;V7W7WGQ;;;;#x/ceee5]5]X[I\I\5]5]5]G)0g&&X'11 @	X7i//aaSYAQAQ9R5S5SGQ;;;; $ 0""6^6^$(..Y\J]J]6^6^6^K*GGW  8'''+TX66Ay
ATXAABBBaggajj//CQww
<s<<===4	1771::..D$$S#%%0044T::::XmTW-- 0	Xxx~~c** M T T>>),, T!$QqSJ!55"
#Z[[["%abb'KU"''O'O8I8I#8N8N'O'O'O"O"O% U U U"
k#S#S#STTTTTU!T))"h&>>>&J#& p pV^Vn p p   ),(8G(C#t++"X%===&J#& q qW_Wo q q    !3w<<3333!3333&J xit x x   ),(83w<<(HG(S 
,KKKKK
7;$&&4+@&!L!L!L!L!LJ7e##tw&'8'8'FF!$'#e**,,"788G"Q;;;;'1GG$&+#W##(8	II'tx%G^^^^RHKJV+VVVVWWWW O
M	MMNNN %%'' 
d 
d+++ *7w)?g&}$$,,,!'*334Eg4NOO - Jb7bbbcccf++OE%((($ ? ?	8hnnT**FI>>>>J  a:JXdXXXYYYtDJDK2DDLY*S^^;a?DNDJ$D"/D&7D#&D_"DN)0D&$DsH   4II	I	=4K==L	L	"4N""N&	)N&	:,[''\\c                       e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   dZdZded<   ded<   ded<   ded<   d	ed<   ded<   ded<   ded<   ded<   ded<   d8 fd*Zd9d+Zd9d,Z	d9d-Z
d:d/Z	 d;d<d5Zd=d7Z xZS )>r:   zNHolds parsed data-driven test cases, and handles directory setup and teardown.DataFileCollectorparent	list[str]r   r   rp   r   zdict[int, list[str]]r   r~   r   zlist[tuple[str, str]]r   r   zdict[int, set[str]]r   r   r   boolr   r   z$list[tuple[str, str | Pattern[str]]]r   r   r|   r   	DataSuiterE   r   r   writescache	only_whenplatform
str | Noneskipxfailr   rF   r+   r;   c       
        p   t          |t                    sJ t                                          ||           || _        || _        || _        || _        || _        |dk    rt          j
        dk    s|dk    rt          j
        dk    rd}	|	| _        |
| _        || _        || _        d | _        d | _        d S )Nwindowswin32posixT)
isinstancer   superr/   r   rE   r   r   r   r   r   r   r   r   rF   old_cwdtmpdir)selfr   r   rE   r   r   r   r   r   r   r   r   rF   	__class__s                r$   r/   zDataDrivenTestCase.__init__  s      &"344444v&&&
	&" 0	!!clg&=&=CLG$;$;D	
		#'"&r#   c                J   | j         rt          j                      n+| j        r$|                     t          j        j                   |                     t                    }|
J d            |                                }|                                 	 |	                    |            d S # t          $ r | j                            dd           }|r| j        J t          j                            |t          j                            | j                            }t%          d| j         d|            t          j                            |          s.| j        sJ t          j                            | j        |          }t-          j        | j        |            w xY w)NzShould not happen--save-failures-tozCopying data from test z to )r   rC   r   
add_markermark	getparentDataSuiteCollectorobjsetuprun_case	Exceptionconfig	getoptionr   r1   r'   r5   basenameprintr   isabsr   shutilcopytree)r   r   r   save_dir
target_dirs        r$   runtestzDataDrivenTestCase.runtest8  s|   9 	/KMMMMZ 	/OOFK-... 233!!#6!!!

	NN4      	 	 	#';#8#89Mt#T#TH 9{...W\\(BG4D4DT[4Q4QRR
K	KKzKKLLLw}}Z00 H<'''!#dlJ!G!GJZ888	s   B- -C5F"c                   t          |            t          j                    | _        t	          j        d          | _        t          j        | j                   t          j        t                     i | j
        D ]\  }}t          j        d|          }|rt          |                    d                    }|dk    sJ t          j        dd|          }t!          |          }t#          |||          }                    |g                               |           t          j                            |          }t          j        |d	
           t/          |dd          5 }	|	                    |           d d d            n# 1 swxY w Y   | j                                        D ]X\  }}
|dk    sJ |
D ]H}t!          |          }                    |g                               t7          ||                     IYrt9                    nd}fdt;          d|dz             D             | _        d S )N)r9   z
mypy-test-)prefixz.*\.([0-9]+)$rI   rK   z	\.[0-9]+$r~   T)exist_okwrT   rU   c                <    g | ]}                     |g           S r"   )get)r^   r   stepss     r$   rg   z,DataDrivenTestCase.setup.<locals>.<listcomp>s  s'    KKKSeiiR((KKKr#   )r   r1   getcwdr   tempfilemkdtempr   chdirmkdirr   r   r   r   rp   r   submodule_from_pathr   r   r   r'   r   makedirsr   writer   itemsr&   maxranger   )r   r'   r   r   r   r   r   	operationdirr   pathsmax_stepr   s               @r$   r   zDataDrivenTestCase.setupQ  sy   T""""y{{&l;;;

 13!Z 	% 	%MD')400A % !''!**ooaxxxx f\2t<<)+66&vwDD	  b))00;;;; good++C$////$f555 %GGG$$$% % % % % % % % % % % % % % % ,2244 	K 	KJC!8888 K K)$//  b))00FD1I1IJJJJK "'-3u:::AKKKKE!X\4J4JKKK


s   -FF	F	c                    | j         t          j        | j                    | j        t	          j        | j        d           d | _         d | _        d S )NT)ignore_errors)r   r1   r   r   r   rmtreer   s    r$   teardownzDataDrivenTestCase.teardownu  sM    <#HT\""";"M$+T::::r#   tuple[str, int, str]c                *    | j         | j        | j        fS ro   )rE   rF   r   r  s    r$   
reportinfozDataDrivenTestCase.reportinfo}  s    y$)TY..r#   Nexcinfo#pytest.ExceptionInfo[BaseException]style
Any | Nonec                ~   t          |j        t                    r|                                }nzt          |j        t          j        j                  r!|j        j        s|                                }n5| j        	                    |          |_
        |                    d          }d| j         d| j         d| S )Nshort)r  zdata: r?   z:
)r   value
SystemExitexconlyrC   rD   r   rB   r   _traceback_filter	tracebackgetreprrE   rF   )r   r  r  excreprs       r$   repr_failurezDataDrivenTestCase.repr_failure  s     gmZ00 
	5
 oo''GGv{'<== 	5gmF[ 	5oo''GG $ = =g F FGooGo44G;	;;DI;;';;;r#   list[list[FileOperation]]c                    | j         S )ax  Return a list of descriptions of file operations for each incremental step.

        The first list item corresponds to the first incremental step, the second for the
        second step, etc. Each operation can either be a file modification/creation (UpdateFile)
        or deletion (DeleteFile).

        Defaults to having two steps if there aern't any operations.
        )r   r  s    r$   
find_stepszDataDrivenTestCase.find_steps  s     zr#   )r   r   r   r   rE   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   rp   r+   r;   r+   r;   )r+   r  ro   )r  r  r  r  r+   r   )r+   r  )r   r   r    __doc__r!   rE   rF   r/   r   r   r  r  r  r   __classcell__r   s   @r$   r:   r:      s        XX !!!! DD !   ////33337777  NNN6666&&&& '  '  '  '  '  'D   2"L "L "L "LH   / / / / QU< < < < <$	 	 	 	 	 	 	 	r#   r'   c                    t          j        dd|           } t          j        d|           }|d= d                    |          }t          j        dd|          }|S )Nz\.pyi?$r~   z[/\\]r   r0   z\.__init__$)r   r   r3   r5   )r'   r7   r   s      r$   r   r     sT    6*b$''DHXt$$EaXXe__FVNB//FMr#   c                  ^    e Zd ZU dZded<   ded<   ded<   ded	<   ded
<   edd            ZdS )TestItemzVParsed test caseitem.

    An item is of the form
      [id arg]
      .. data ..
    r   r   r   r   r   r   rp   rF   end_liner+   c                J    | j         | j        z
  t          | j                  z
  S ro   )r(  rF   r   r   r  s    r$   trimmed_newlineszTestItem.trimmed_newlines  s    }ty(3ty>>99r#   N)r+   rp   )r   r   r    r"  r!   propertyr*  r"   r#   r$   r'  r'    sm           GGGOOOOOOIIIMMM: : : X: : :r#   r'  raw_datar   list[TestItem]c           
        dd|z   dz   g|                      d          z   }g }g }d}d}d}d}|t          |          k     r||                                         }	||                             d          r|	                    d          r|rGt          |          }t          |          }|                    t          ||||dz   |                     |}|	dd	         }d}d
|v r=||	                    d
          dz   d         }|d|	                    d
                   }g }n||                             d          r$|                    ||         dd                    nu||                             d          s|                    ||                    n>||                             d          r#|                    ||         dd                    |dz  }|t          |          k     |rJt          |          }t          |          }|                    t          ||||dz   |dz
                       |S )z>Parse a list of lines that represent a sequence of test items.r~   z[case ]rR   Nr   [rI   r.   r}   z\[z--z----rK   )
r3   r   r\   r   endswithcollapse_line_continuation
strip_listr   r'  index)
r,  r   linesretr   r   r   ii0ss
             r$   r   r     sL    D3&'(..*>*>>ECDBC	A	
B
c%jj..!HNN8s## 	&

3 	& ?1$77!$''

8BT261==>>>B1R4BCbyy#*,,-"((3--(DD1X  '' 	&KKa%%%%q$$T** 	&KKa!!!!1X  (( 	&KKa%%%	Q- c%jj..2 
 ;)$//$

8BT261q599:::Jr#   lr   c                    g }| D ]+}|                     t          j        dd|                     ,|r.|d         dk    r"|                                 |r|d         dk    "|S )zReturn a stripped copy of l.

    Strip whitespace at the end of all lines, and strip all empty
    lines from the end of the array.
    z\s+$r~   r.   )r   r   r   r4   )r:  rr9  s      r$   r3  r3    sy     A ) )	Q''((((
 "	  " Hr#   c           	         g }d}| D ]i}t          j        dd|          }|r%|dxx         t          j        dd|          z  cc<   n|                    |           |                    d          }j|S )NFz\\$r~   r.   z^ +rw   )r   r   r   r1  )r:  r<  contr9  sss        r$   r2  r2    s    AD    VFB"" 	bEEERVE2r***EEEEHHRLLLzz$Hr#   r9  c                8    |                      dt                    S )Nz<ROOT>)replaceroot_dir)r9  s    r$   ru   ru     s    99Xx(((r#   r   r   fnamc                   t          t          |                     D ]3}| |                             d          dd         D ]}t          j        d|                                          }|r|                    d          dk    rd}n7|                    d          dk    rd}n|                    d          d	k    rd
}|                    d          }|                    d          }|                    dd          }|$|                    | d|dz    d| d|            |                    | d|dz    d| d| d| 	           5dS )zTransform comments such as '# E: message' or
    '# E:3: message' in input.

    The result is lines like 'fnam:line: error: message'.
    z # rI   Nz*^([ENW]):((?P<col>\d+):)? (?P<message>.*)$EerrorNnoteWwarningcolmessagez\##r?   r@   )	r  r   r3   r   searchr\   r   rA  r   )	r   r   rC  r7  possible_err_commentr   severityrK  rL  s	            r$   r   r     s    3u:: R R$)!HNN5$9$9!""$= 	R 	R 	=?S?Y?Y?[?[ A  R771::$$&HHWWQZZ3&&%HHWWQZZ3&&(Hggenn''),,!//%55;MMT"J"JAE"J"JX"J"J"J"JKKKKMMT"P"PAE"P"PC"P"P8"P"Pw"P"PQQQ#	RR Rr#   rF   c                &   |                      t          t                               dd                    } t          j        d|           }|s| S |                                \  }}}d                    |                     dd          |pd|          S )z`Changes Windows paths to Linux paths in error messages.

    E.g. foo\bar.py -> foo/bar.py.
    rw   r-   z^([\S/]+):(\d+:)?(\s+.*)z{}:{}{}r~   )rA  rB  r   r   groupsformat)rF   r   r*   linenorL  s        r$   ry   ry   ,  s    
 <<("2"24"="=>>D
,d33A T$%HHJJ!&' 0 0s ; ;V\r7SSSr#   c                   t          j        d|           }|s| S d                    | d|                    d                   |                    d                              dd          | |                    d          d                   S )zChanges filename paths to Linux paths in Cobertura output files.

    E.g. filename="pkg\subpkg\a.py" -> filename="pkg/subpkg/a.py".
    z&<class .* filename="(?P<filename>.*?)"z{}{}{}NrI   r*   rw   r-   )r   rN  rS  startr   rA  end)rF   r   s     r$   fix_cobertura_filenamerX  :  s    
 		;TBBA ??\qwwqzz\AGGJ//77cBBDqDT  r#   sessionr	   c                    t           j                            t                    rt	          j        t                     d S d S ro   )r1   r'   isdirr   r   r
  )rY  s    r$   pytest_sessionstartr\  N  s<     
w}}%&& (&'''''( (r#   parserc                2   |                      d          }|                    dddd           |                    dd d	           |                    d
dd           |                    dddd           |                    dd dt          d           d S )Nmypy--update-data
store_trueFzLUpdate test data to reflect actual output (supported only for certain tests))actiondefaulthelpr   zBCopy the temp directories from failing tests to a target directory)rc  rd  z--mypy-verbosecountz/Set the verbose flag when creating mypy Options)rb  rd  z--mypyc-showcz%Display C code on mypyc test failuresz--mypyc-debugdebuggerz8Run the first mypyc run test with the specified debugger)rc  destchoicesrd  )getgroup	addoptionr   )r]  r   s     r$   pytest_addoptionrk  W  s    OOF##E	OO[	     
OOQ    
 
OO/`     
OO4	     
OO#G      r#   T)tryfirstr   pytest.Configc                z    |                      d          rd S |                      d          rd| j        _        d S d S )Nz--collectonlyr`  r   )r   optionnumprocesses)r   s    r$   pytest_cmdline_mainrq  v  sM    (( (( '%&"""' 'r#   	collectorr   objectr  c                    t          |t                    r:t          |t                    r%|t          urt                              | |          S dS )zCalled by pytest on each object in modules configured in conftest.py files.

    collector is pytest.Collector, returns Optional[pytest.Class]
    r   r   N)r   type
issubclassr   r   from_parent)rr  r   r   s      r$   pytest_pycollect_makeitemry    sT    
 #t Oc9%% 	O#Y*>*> &111NNN4r#   z(?P<name>[a-zA-Z_0-9]+)(?P<writescache>-writescache)?(?P<only_when>-only_when_cache|-only_when_nocache)?(?P<skip_path_normalization>-skip_path_normalization)?(-(?P<platform>posix|windows))?(?P<skip>-skip)?(?P<xfail>-xfail)?r   r   r   r   rE   Iterator[DataDrivenTestCase]c              #  |  K   t          |d          5 }|                                }ddd           n# 1 swxY w Y   t          j        d|t          j        t          j        z            }t          |          }t          |                              d          dz   }t                      }|D ]}	t          |          }t                              |	          }
|
st          d|	          |
                    d	          }||v r)t          d
                    || j        |                    t                               | ||t%          ||j                  t)          |
                    d                    |
                    d          |
                    d          t)          |
                    d                    t)          |
                    d                    |
                    d           ||          V  ||                    d          dz   z  }|                    |h           dS )zIterate over raw test cases in file, at collection time, ignoring sub items.

    The collection phase is slow, so any heavy processing should be deferred to after
    uninteresting tests are filtered (when using -k PATTERN switch).
    zutf-8rU   Nz^\[case ([^]+)]+)\][ \t]*$\n)flagsrR   rI   zInvalid testcase id r   z1Found a duplicate test name "{}" in {} on line {}r   r   r   r   r   skip_path_normalization)r   r   rE   r   r   r   r   r   r   r   r   rF   )r   r   r   r3   DOTALL	MULTILINEiternextre  r   _case_name_pattern	fullmatchRuntimeErrorr   rS  r   r:   rx  add_test_name_suffixtest_name_suffixr   update)r   r   rE   r   r   cases
cases_iterline_no
test_namescase_idr   r   s               r$   split_test_casesr    sc      
dW	%	%	% vvxx              H4d")blBZ[[[EeJ:$$T**Q.GJ " "J((11 	CAgAABBBwwv:CJJ&+w   
 !,,%dE,BCCQWW]3344ggk**WWZ((aggfoo&&qwww''((!")B!C!CC - 
 
 	
 	
 	
 	4::d##a'' 	4&!!!!=" "s   599c                      e Zd ZddZdS )r   r+   Iterator[DataFileCollector]c              #     K   | j         }t          j                            |j                  sJ d|j         d            |j        D ] }t                              | |          V  !dS )zNCalled by pytest on each of the object returned from pytest_pycollect_makeitemzTest data prefix (z) not set correctlyru  N)r   r1   r'   r[  data_prefixr   r   rx  )r   r   	data_files      r$   collectzDataSuiteCollector.collect  s        8w}}
 
 	G 	GF 1FFF	G 	G 	G  	M 	MI#//t)/LLLLLL	M 	Mr#   N)r+   r  )r   r   r    r  r"   r#   r$   r   r     s.        M M M M M Mr#   r   c                  .    e Zd ZU ded<   ded<   ded<   dS )DataFileFixrp   rT  
end_linenor   r5  Nr   r"   r#   r$   r  r    s0         KKKOOOr#   r  c                  z     e Zd ZU dZded<   ded<   ed fd	            ZddZd fdZd fdZ	ddZ
ddZ xZS )r   zvRepresents a single `.test` data driven test file.

    More context: https://github.com/python/mypy/issues/11662
    r   r   zlist[DataFileFix]_fixesr   r   r+   c               |    t                                          ||          }t          |t                    sJ |S )N)r   )r   rx  r   r   )clsr   r   rr  r   s       r$   rx  zDataFileCollector.from_parent  s>     GG''T'::	)%677777r#   rz  c              #     K   t          | | j        j        t          j                            | j        j        j        | j                            E d {V  d S )N)r   r   rE   )r  r   r   r1   r'   r5   r  r   r  s    r$   r  zDataFileCollector.collect  sk      #+/dko949EE
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r#   r;   c                V    t                                                       g | _        d S ro   )r   r   r  r   r   s    r$   r   zDataFileCollector.setup  s    r#   c                p    t                                                       |                                  d S ro   )r   r  _apply_fixesr  s    r$   r  zDataFileCollector.teardown  s1    r#   fixr  c                :    | j                             |           d S ro   )r  r   )r   r  s     r$   enqueue_fixzDataFileCollector.enqueue_fix   s    3r#   c                l   | j         sd S t          | j        j        j                  | j        z  }|                                                    d          }t          | j         d          D ]}|j	        ||j
        dz
  |j        dz
  <   |                    d                    |                     d S )NrR   T)reverserI   )r  r   r   r   r  r   	read_textr3   sortedr5  rT  r  
write_textr5   )r   	data_pathr5  r  s       r$   r  zDataFileCollector._apply_fixes  s    { 	F455	A	##%%++D11$+t444 	C 	CC9<E#*q.3>A#5566TYYu--.....r#   )r   r   r   r   r+   r   )r+   rz  r!  )r  r  r+   r;   )r   r   r    r"  r!   classmethodrx  r  r   r  r  r  r#  r$  s   @r$   r   r     s          
      [
 
 
 
                 / / / / / / / /r#   suffixc                    t          j        d|           }|r3|                    d          }| d t          |                    |z   |z   S | |z   S )Nz-[-A-Za-z0-9]+$r   )r   rN  r   r   )r   r  r   magic_suffixs       r$   r  r    s]    
	$d++A  wwqzz(s<(((()F2\AAf}r#   testcaser   c                J    d| j                                         v pd| j        v S )Nincremental)r   lowerrE   )r  s    r$   is_incrementalr    s'    HM//111S]hm5SSr#   c                    t          d | j        D                       rdS | j        D ]:\  }}t          j                            |                              d          r dS ;dS )Nc              3  @   K   | ]}t          j        d |          V  dS )z# flags[2-9]:N)r   r   rv   s     r$   rr   z#has_stable_flags.<locals>.<genexpr>   s/      
G
G28$d++
G
G
G
G
G
Gr#   Fz	mypy.ini.T)anyr   r   r1   r'   r   r   )r  r*   r   s      r$   has_stable_flagsr    su    

G
G
G
G
GGG u&n  (7H%%00== 	55	4r#   c                  N    e Zd ZU ded<   eZeZdZdZ	dZ
ddZedd
            ZdS )r   r   r   Fr~   r+   r;   c                    dS )zSetup fixtures (ad-hoc)Nr"   r  s    r$   r   zDataSuite.setup9  s      r#   r  r:   c                    t           ro   )NotImplementedError)r   r  s     r$   r   zDataSuite.run_case<  s    !!r#   Nr!  )r  r:   r+   r;   )r   r   r    r!   r   r   r   r  r   r   r  r   r   r   r"   r#   r$   r   r   (  su         I #K J & & & & " " " ^" " "r#   )r*   r   r+   r   )r9   r:   r+   r;   )r'   r   r+   r   )r,  r   r   r   r+   r-  )r:  r   r+   r   )r9  r   r+   r   )r   r   r   r   rC  r   r+   r;   )rF   r   r+   r   )rY  r	   r+   r;   )r]  r	   r+   r;   )r   rm  r+   r;   )rr  r	   r   r   r   rs  r+   r  )r   r   r   r   rE   r   r+   rz  )r   r   r  r   r+   r   )r  r:   r+   r   )Jr"  
__future__r   r1   os.pathr   r   r   r   r   abcr   collections.abcr   dataclassesr   pathlibr   r   rW   r	   r
   r   r   r   typing_extensionsr   r(   rC   r_  r   mypy.test.configr   r   r   r   r'   normpathrB  r   r!   r   r&   r)   r8   r   Itemr:   r   r'  r   r3  r2  ru   r   ry   rX  r\  rk  hookimplrq  ry  r   r  r  Classr   r  	Collectorr   r  r  r  r   r"   r#   r$   <module>r     s   M M M " " " " " " 				      				  



        $ $ $ $ $ $ ! ! ! ! ! !             : : : : : : : : : : : : : : 5 5 5 5 5 5        V V V V V V V V V V V V7F##
 $V_  , , , ,              
 "*j"89 9 9 9 9   y% y% y% y%xf f f f f f f fR    : : : : : : : :,* * * *Z   $
 
 
 
) ) ) )R R R R:T T T T
 
 
 
(( ( ( (   > $' ' '  '     RZ  ," ," ," ,"^M M M M M M M M    *   ,/ ,/ ,/ ,/ ,/( ,/ ,/ ,/^
 
 
 
T T T T   " " " " " " " " " "r#   