
    6 fu                       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mZ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! 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<   dRdZ*dSdZ+ G d dej,                  Z-dTdZ.e G d  d!                      Z/dUd%Z0dVd(Z1dVd)Z2dWd+Z3dXd/Z4dYd1Z5dYd2Z6dZd5Z7d[d8Z8d\d=Z9 ej:        d>          Z;d]dEZ< G dF dGej=                  Z> G dH dIe          Z? G dJ d@ej@                  ZAd^dLZBd_dOZCd_dPZD G dQ dB          ZEdS )`zGUtilities for processing .test files containing test case descriptions.    )annotationsN)abstractmethod)	dataclass)Path)AnyFinalIterator
NamedTupleNoReturnPatternUnion)	TypeAlias)defaults)PREFIX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__     D/var/www/equiseq/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_moduler7   /   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<   r8   s    r#   
_case_failz#parse_test_case.<locals>._case_failP   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?   Fr@   )rE   rB   rC   rD   )r<   item_abs_liner8   items     r#   
_item_failz#parse_test_case.<locals>._item_failY   sI     I	1A5MK49==}====uMMMMMMr"   >   rD   fixtureoutfile
outfile-re
rN   >   rD   rN   rP   rO   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!   rZ   r\   s     r#   r_   z"parse_test_case.<locals>.<setcomp>   r`   r"   ztargets[0-9]*$targetsc                6    g | ]}|                                 S r!   rZ   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 rJ   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"   r/   z is not a valid python versionrl   z. always true since minimum runtime version is rk   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]   rE   s     r#   rf   z#parse_test_case.<locals>.<listcomp>   s!    KKK.t44KKKr"   \c                ,    g | ]}t          |          S r!   )fix_win_pathru   s     r#   rf   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_sepr0   r&   r4   	posixpathrequired_out_sectionappendidargrt   r7   recompilerstripSdirnamerD   openreadmatchro   lensetr2   group
setdefaultadd
startswithtuple
ValueErrorr   PYTHON3_VERSIONsysversion_infosepnormalize_outputkeysissubsetexpand_errorsinputoutputoutput_inline_startoutput2rE   	last_linefilesoutput_filesexpected_stale_modulesexpected_rechecked_modulesdeleted_pathsr{   expected_fine_grained_targetstest_modules),r8   
test_itemsr   r4   out_section_missingr   r   r   r   r   stale_modulesrechecked_modulesr{   rd   r   rF   
first_itemrM   contentsr&   mpathfsrc_pathpassnummodulesreprocessedmnumfullargsversion_checkr   
compare_opversion_strrh   
tmp_outputsection_strr   r   	file_path
seen_filesrD   r5   rL   s,   `                                          @r#   parse_test_caser   7   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 )>r9   zNHolds parsed data-driven test cases, and handles directory setup and teardown.DataSuiteCollectorparent	list[str]r   r   ro   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   	DataSuiterD   r   r   writescache	only_whenplatform
str | Noneskipxfailr   rE   r*   r:   c       
        B   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)superr.   r   rD   r   r   r   r   r   r   r   r   rE   old_cwdtmpdir)selfr   r   rD   r   r   r   r   r   r   r   r   rE   	__class__s                r#   r.   zDataDrivenTestCase.__init__  s      	v&&&
	&" 0	!!clg&=&=CLG$;$;D	
		#'?Cr"   c                ^   | 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        j                            }t'          d| j         d|            t          j                            |          s.| j        sJ t          j                            | j        |          }t-          j        | j        j        |            w xY w)NzShould not happen--save-failures-tozCopying data from test z to )r   rB   r   
add_markermark	getparentr   objsetuprun_case	Exceptionconfig	getoptionr   r0   r&   r4   basenamer   printisabsr   shutilcopytree)r   r   r   save_dir
target_dirs        r#   runtestzDataDrivenTestCase.runtest5  s   9 	/KMMMMZ 	/OOFK-... 233!!#6!!!

	NN4      	 	 	#';#8#89Mt#T#TH >{...W\\(BG4D4DT[EU4V4VWW
K	KKzKKLLLw}}Z00 H<''<!#dlJ!G!GJ 0*===	s   B- -C?F,c                   t          |            t          j                    | _        t	          j        d          | _        t          j        | 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	
           t1          |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                               t9          ||                     IYrt;                    nd}fdt=          d|dz             D             | _        d S )N)r8   z
mypy-test-)prefixz.*\.([0-9]+)$rH   rJ   z	\.[0-9]+$r}   T)exist_okwrS   rT   c                <    g | ]}                     |g           S r!   )get)r]   r   stepss     r#   rf   z,DataDrivenTestCase.setup.<locals>.<listcomp>p  s'    KKKSeiiR((KKKr"   ) r   r0   getcwdr   tempfileTemporaryDirectoryr   chdirr   mkdirr   r   r   r   ro   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.setupN  s|   T""""y{{1FFF
!"""
 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   2FF	F	c                    | j         t          j        | j                    | j        +	 | j                                         n# t
          $ r Y nw xY wd | _         d | _        d S rn   )r   r0   r   r   cleanupOSErrorr   s    r#   teardownzDataDrivenTestCase.teardownr  sr    <#HT\""";"##%%%%   s   A 
AAtuple[str, int, str]c                *    | j         | j        | j        fS rn   )rD   rE   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:
)
isinstancevalue
SystemExitexconlyrB   rC   r   rA   r   _traceback_filter	tracebackgetreprrD   rE   )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   rD   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rE   ro   r*   r:   r*   r:   )r*   r
  rn   )r  r  r  r  r*   r   )r*   r  )r   r   r   __doc__r    rD   rE   r.   r   r   r	  r  r  r  __classcell__r   s   @r#   r9   r9      s        XX !!!! DD !   ////33337777  NNN6666&&&&D D D D D DB   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   r/   z\.__init__$)r   r   r2   r4   )r&   r6   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   ro   rE   end_liner*   c                J    | j         | j        z
  t          | j                  z
  S rn   )r&  rE   r   r   r  s    r#   trimmed_newlineszTestItem.trimmed_newlines  s    }ty(3ty>>99r"   N)r*   ro   )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 ]rQ   Nr   [rH   r-   r|   z\[z--z----rJ   )
r2   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   r3   )r8  rr7  s      r#   r1  r1    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^ +rv   )r   r   r   r/  )r8  r:  contr7  sss        r#   r0  r0    s    AD    VFB"" 	bEEERVE2r***EEEEHHRLLLzz$Hr"   r7  c                8    |                      dt                    S )Nz<ROOT>)replaceroot_dir)r7  s    r#   rt   rt     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 # rH   Nz*^([ENW]):((?P<col>\d+):)? (?P<message>.*)$EerrorNnoteWwarningcolmessagez\##r>   r?   )	r   r   r2   r   searchr[   r   r?  r   )	r   r   rA  r5  possible_err_commentr   severityrI  rJ  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"   rE   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.
    rv   r,   z^([\S/]+):(\d+:)?(\s+.*)z{}:{}{}r}   )r?  r@  r   r   groupsformat)rE   r   r)   linenorJ  s        r#   rx   rx   ,  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{}{}{}NrH   r)   rv   r,   )r   rL  rQ  startr   r?  end)rE   r   s     r#   fix_cobertura_filenamerV  :  s    
 		;TBBA ??\qwwqzz\AGGJ//77cBBDqDT  r"   parserr   c                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)r]  r^  z--mypy-verbosecountz/Set the verbose flag when creating mypy Options)r\  r^  z--mypyc-showcz%Display C code on mypyc test failuresz--mypyc-debugdebuggerz8Run the first mypyc run test with the specified debugger)r]  destchoicesr^  )getgroup	addoptionr   )rW  r   s     r#   pytest_addoptionre  P  s    OOF##E	OO[	     
OOQ    
 
OO/`     
OO4	     
OO#G      r"   r   pytest.Configc                    |                      d          r/|                      dd          dk    rt          j        d          d S d S )NrZ  z--numprocessesrH   )r]  zD--update-data incompatible with parallelized tests; re-run with -n 1)r   rB   
UsageError)r   s    r#   pytest_configureri  o  s`    (( 
V-=-=>NXY-=-Z-Z]^-^-^R
 
 	

 
-^-^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)rj  r   r   s      r#   pytest_pycollect_makeitemrq  x  s]    
 #t c9%% 	#Y*>*> &11 t 2    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   DataFileCollectorr   r   rD   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-8rT   Nz^\[case ([^]+)]+)\][ \t]*$\n)flagsrQ   rH   zInvalid testcase id r   z1Found a duplicate test name "{}" in {} on line {}r   r   r   r   r   skip_path_normalization)r   r   rD   r   r   r   r   r   r   r   r   rE   )r   r   r   r2   DOTALL	MULTILINEiternextr_  r   _case_name_pattern	fullmatchRuntimeErrorr   rQ  r   r9   rp  add_test_name_suffixtest_name_suffixr   update)r   r   rD   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 correctlyrm  N)r   r0   r&   isdirdata_prefixr   rr  rp  )r   r   	data_files      r#   collectzDataSuiteCollector.collect  s        8w}}
 
 	G 	GF 1FFF	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 )DataFileFixro   rR  
end_linenor   r3  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 )rr  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   rp  r  rr  )clsr   r   rj  r   s       r#   rp  zDataFileCollector.from_parent  s>     GG''T'::	)%677777r"   rs  c              #     K   t          | | j        j        t          j                            | j        j        j        | j                            E d {V  d S )N)r   r   rD   )r  r   r   r0   r&   r4   r  r   r  s    r#   r  zDataFileCollector.collect  sk      #+/dko949EE
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r"   r:   c                V    t                                                       g | _        d S rn   )r   r   r  r   r   s    r#   r   zDataFileCollector.setup  s    r"   c                p    t                                                       |                                  d S rn   )r   r	  _apply_fixesr  s    r#   r	  zDataFileCollector.teardown  s1    r"   fixr  c                :    | j                             |           d S rn   )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 )NrQ   T)reverserH   )r  r   r   r   r  r   	read_textr2   sortedr3  rR  r  
write_textr4   )r   	data_pathr3  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*   rr  )r*   rs  r  )r  r  r*   r:   )r   r   r   r   r    classmethodrp  r  r   r	  r  r  r!  r"  s   @r#   rr  rr    s          
      [
 
 
 
                 / / / / / / / /r"   suffixc                    t          j        d|           }|r3|                    d          }| d t          |                    |z   |z   S | |z   S )Nz-[-A-Za-z0-9]+$r   )r   rL  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   lowerrD   )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   ru   s     r#   rq   z#has_stable_flags.<locals>.<genexpr>  s/      
G
G28$d++
G
G
G
G
G
Gr"   Fz	mypy.ini.T)anyr   r   r0   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.setup2  s      r"   r  r9   c                    t           rn   )NotImplementedError)r   r  s     r#   r   zDataSuite.run_case5  s    !!r"   Nr  )r  r9   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   )r8   r9   r*   r:   )r&   r   r*   r   )r*  r   r   r   r*   r+  )r8  r   r*   r   )r7  r   r*   r   )r   r   r   r   rA  r   r*   r:   )rE   r   r*   r   )rW  r   r*   r:   )r   rf  r*   r:   )rj  r   r   r   r   rk  r*   r  )r   rr  r   r   rD   r   r*   rs  )r   r   r  r   r*   r   )r  r9   r*   r   )Fr   
__future__r   r0   os.pathr   r   r   r   r   abcr   dataclassesr   pathlibr   rV   r   r   r	   r
   r   r   r   typing_extensionsr   r'   rB   rY  r   mypy.test.configr   r   r   r&   normpathr@  r   r    r   r%   r(   r7   r   Itemr9   r   r%  r   r1  r0  rt   r   rx   rV  re  ri  rq  r   r{  r  Classr   r  	Collectorrr  r~  r  r  r   r!   r"   r#   <module>r     s`   M M M " " " " " " 				      				  



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