
    i9                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
JrJrJrJrJrJr  \R"                  " S5      r\R&                  S:  rS\S\S\4S jrS\S\S\4S	 jrS
\S\4S jrS\S\S\4S jr " S S5      r\" 5       rS\S\S\4S jr\R>                  " S\R@                  5      r!S\S\S\S\S\\\4   4
S jr"S\\\4   S\S\4S jr#S\S\S\SS4S jr$ " S S5      r%\RL                   " S  S!5      5       r'S"\'S\S#\SS4S$ jr( S/SS\$S%S&.S\S\S'\S"\\'   S(\\\\4      S)\
S*\SS4S+ jjjr) " S, S-\RT                  5      r*\+S.:X  a  S SK,r,\,RZ                  " 5         gg)0    N)AnyCallableDictListMatchTupleOptionalEXPECTTEST_ACCEPT)      srclinenoreturnc                 n    US:  d   eSn[        US-
  5       H  nU R                  SU5      S-   nM     U$ )ze
Compute the starting index of the n-th line (where n is 1-indexed)

>>> nth_line("aaa\nbb\nc", 2)
4
   r   
)rangefindr   r   pos_s       R/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/expecttest/__init__.pynth_liner      sB     Q;;
C6A:hhtS!A% J    c                     US:  d   eSn[        U5       H+  nU R                  SUS-   5      nUS:X  d  M   [        U 5      s  $    U$ )zv
Compute the ending index of the n-th line (before the newline,
where n is 1-indexed)

>>> nth_eol("aaa\nbb\nc", 2)
6
r   r   )r   r   lenr   s       r   nth_eolr   !   sN     Q;;
C6]hhtS1W%"9s8O  Jr   tc                 F    U R                  SS5      R                  SS5      $ )Nz
r   )replace)r   s    r   normalize_nlr#   2   s     99VT"**466r   squotec                 <    U (       a  U S   U:X  a  U S S S-   U-   $ U $ )Nr   \ r$   r%   s     r   escape_trailing_quoter*   6   s)    QrUe^"v}u$$r   c            
           \ rS rSr% \\\\\\4      4   \	S'   \\\\\4   4   \	S'   SS jr
S\SS4S jrS\S	\S\4S
 jrS\S\4S jrS\S	\S\\   4S jrS\S	\S\S\SS4
S jrSrg)EditHistory=   stateseenr   Nc                      0 U l         0 U l        g N)r.   r/   selfs    r   __init__EditHistory.__init__A   s    
	r   fnc                     0 nU R                   R                  U0 5      R                  5        H  u  p4XBU R                  X5      '   M     X R                   U'   U R                  R                  US5        g)a  
The idea is that if you reload a file, the line numbers
from traceback are now up to date, but we do NOT want to clear
out seen list as it will tell us if we are expecting the
same line multiple times.  Instead, we need to adjust
the seen list for the new world order.
N)r/   getitemsadjust_linenor.   pop)r3   r6   new_seenseen_locseen_strs        r   reload_fileEditHistory.reload_fileE   sa     "&))--B"7"="="?H9AT''56 #@ !		"

r4 r   r   c                 n    XR                   ;  a  U$ U R                   U    H  u  p4X#:  d  M  X$-  nM     U$ r1   r.   )r3   r6   r   edit_loc	edit_diffs        r   r:   EditHistory.adjust_linenoT   s;    ZZM#'::b>H # $2 r   c                     XR                   ;   $ r1   rB   )r3   r6   s     r   	seen_fileEditHistory.seen_file\   s    ZZr   c                 Z    U R                   R                  U0 5      R                  US 5      $ r1   )r/   r8   )r3   r6   r   s      r   	seen_editEditHistory.seen_edit_   s$    yy}}R$((66r   deltaexpectc                     U R                   R                  U/ 5      R                  X#45        X@R                  R                  U0 5      U'   g r1   )r.   
setdefaultappendr/   )r3   r6   r   rL   rM   s        r   record_editEditHistory.record_editb   s<    

b"%,,f_=/5		R$V,r   )r/   r.   r   N)__name__
__module____qualname____firstlineno__r   strr   r   int__annotations__r4   r?   r:   boolrG   r	   rJ   rQ   __static_attributes__r(   r   r   r,   r,   =   s    T%S/**++
sDcN"
##!c !d ! S S  C  D  7C 7 7# 76c 63 6s 6C 6D 6r   r,   c                 P    US-  U ;  =(       a    U (       + =(       d
    U S   US4;  $ )a[  
Is this string representable inside a raw triple-quoted string?
Due to the fact that backslashes are always treated literally,
some strings are not representable.

>>> ok_for_raw_triple_quoted_string("blah", quote="'")
True
>>> ok_for_raw_triple_quoted_string("'", quote="'")
False
>>> ok_for_raw_triple_quoted_string("a ''' b", quote="'")
False
r   r   r'   r(   r)   s     r   ok_for_raw_triple_quoted_stringr^   j   s,     19AGq5#FAbE%,FGr   z4(?P<raw>r?)(?P<quote>'''|""")(?P<body>.*?)(?P=quote)start_lineno
end_lineno
new_stringc                 h  ^^ [        S T 5       5      (       d   [        T5      5       e[        T5      mTR                  S5      mTS:  a  TS-  mX::  d   e[	        X5      n[        X5      nXE::  d   eS[        [           S[        4UU4S jjnU SU [        R                  X`XE SS	9-   XS -   T4$ )
a  
Replace a triple quoted string literal with new contents.
Only handles printable ASCII correctly at the moment.  This
will preserve the quote style of the original string, and
makes a best effort to preserve raw-ness (unless it is impossible
to do so.)

Returns a tuple of the replaced string, as well as a delta of
number of lines added/removed.

>>> replace_string_literal("'''arf'''", 1, 1, "barf")
("'''barf'''", 0)
>>> r = replace_string_literal("  moo = '''arf'''", 1, 1, "'a'\n\\b\n")
>>> print(r[0])
  moo = '''\
'a'
\\b
'''
>>> r[1]
3
>>> replace_string_literal("  moo = '''\\\narf'''", 1, 2, "'a'\n\\b\n")[1]
2
>>> print(replace_string_literal("    f('''\"\"\"''')", 1, 1, "a ''' b")[0])
    f('''a \'\'\' b''')
c              3   F   #    U  H  o[         R                  ;   v   M     g 7fr1   )string	printable).0cs     r   	<genexpr>)replace_string_literal.<locals>.<genexpr>   s     9jF$$$js   !r   r   r   mr   c                 (  > TnU R                  S5      S:H  nU(       a   [        XR                  S5      S   S9(       db  SnUR                  SS5      nU R                  S5      S	:X  a  [        US
5      R                  S	S5      nO[        US5      R                  SS5      nSU;   a  U(       d  SU-   OUnTU R                  S5      R	                  S5      -  mSR                  U(       a  SOSU R                  S5      UU R                  S5      /5      $ )Nrawrr%   r   )r%   Fr'   z\\z''''z\'\'\'"z"""z\"\"\"r   z\
body )groupr^   r"   r*   countjoin)rj   r$   rl   new_bodyrL   ra   s       r   r"   'replace_string_literal.<locals>.replace   s     ggen#9!777CSTUCVWC		$'Awww5()!S199%K)!S199%K!%36A:A&&t,,ww  	
 	
r   N)rs   )
allreprr#   rs   r   r   r   rX   	RE_EXPECTsub)r   r_   r`   ra   startendr"   rL   s      `   @r   replace_string_literalr}      s    : 9j999K4
;KK9j)JT"Eqy
%%%S'E
#
"C<<
5: 
# 
 
2 	FUimmG^1mEED	Q r   reptextc                   ^  T R                  5        VVs0 s H  u  p#[        R                  " U5      U_M     snnm [        R                  " SR	                  T R                  5       5      5      nUR                  U 4S jU5      $ s  snnf )N|c                 T   > T[         R                  " U R                  S5      5         $ )Nr   )reescaperr   )rj   r~   s    r   <lambda>replace_many.<locals>.<lambda>   s    RYYqwwqz%:!;r   )r9   r   r   compilert   keysrz   )r~   r   kvpatterns   `    r   replace_manyr      s_    '*yy{
3{tq299Q<?{
3Cjj#((*-.G;;;TBB 4s   #BrM   actualmsgc          	          X:w  aU  SR                  [        R                  " U R                  S5      UR                  S5      SSS95      n[	        SU SU 35      eg )Nrq   Tz
expect.txtz
actual.txt)fromfiletofilez-Mismatch between actual and expect strings:

z

)rt   difflibunified_diff
splitlinesAssertionError)rM   r   r   diffs       r   	assert_eqr      sj    ww  !!$'!!$'%#	
 =dV4uM
 	
 r   c                   `    \ rS rSrSrSS.S\S\4S jjrS\S	S
4S jrS	\4S jr	S	\4S jr
Srg
)Expect   a  
An expected string literal, analogous to expect_test::expect! in Rust.

This saves its position so that you can pass it around for e.g.
parameterized tests and similar.

Example:
>>> e = Expect("value") # expected value
>>> e.assert_expected("value") # actual value
r   skipexpectedr   c                p    Xl         [        R                  " SU-   S9nUS   u  pE  n[        XE5      U l        g)z,
Creates an expectation of the given value.
   limitr   N)r   	tracebackextract_stackPositionInfor   )r3   r   r   tbr6   r   r   s          r   r4   Expect.__init__   s;     ! $$1t84a5Aq+r   r   r   Nc                 @    [        XR                  U R                  S9  g )N)r   )assert_expected_inliner   r   )r3   r   s     r   assert_expectedExpect.assert_expected   s    v}}$((Cr   c                 $    SU R                   < S3$ )NzExpect()r   r2   s    r   __repr__Expect.__repr__   s    )++r   c                     U R                   $ r1   r   r2   s    r   __str__Expect.__str__   s    }}r   )r   r   )rT   rU   rV   rW   __doc__rX   rY   r4   r   r   r   r\   r(   r   r   r   r      sM    	 67 , ,s ,Dc Dd D,# , r   r   c                   8    \ rS rSr% \\S'   \\S'   S\4S jrSrg)r      filenamer   r   c                 8    U R                    SU R                   3$ )N:)r   r   r2   s    r   r   PositionInfo.__str__  s    --$++//r   r(   N)	rT   rU   rV   rW   rX   rZ   rY   r   r\   r(   r   r   r   r      s    MK0 0r   r   r   debug_suffixc                 P   [        SR                  X 5      5        [        U R                  S5       nUR	                  5       n[
        R                  " U5      n[        R                  U R                  U R                  5      nUnUn[
        R                  " U5       H  n	[        U	[
        R                  5      (       d  M$  [        U	S5      (       a>  U	R                  (       a-  [        (       d   eU	R                  U:X  a  U	R                  nMq  Ms  U	R                  U:X  d  M  U	R                  nM     [!        XGX5      u  pXJ:w  d   SU  SU  35       e[        R#                  U R                  5      (       d3  [        U R                  S-   S5       nUR%                  U5        SSS5        UR'                  S	5        UR)                  S	5        UR%                  U
5        SSS5        [        R+                  U R                  WWU5        g! , (       d  f       Nl= f! , (       d  f       NB= f)
zc
Replaces the string literal at "pos" (according to the interpreter) with
the new string "actual".
zAccepting new output{} at {}zr+r`   zFailed to substitute string at z; did you use triple quotes?  If this is unexpected, please file a bug report at https://github.com/ezyang/expecttest/issues/new with the contents of the source file near z.bakwNr   )printformatopenr   readastparseEDIT_HISTORYr:   r   walk
isinstanceExprhasattrr`   LINENO_AT_STARTr}   rG   writeseektruncaterQ   )r   r   r   foldold_astr   r_   r`   nnewrL   f_baks                r   _accept_outputr     s    

(
/
/
BC	cllD	!Qffh))C.
 ++CLL#**E 
 '"A!SXX&&1l++*?*?xx</%&\\
 0 xx:-'(xx # ,z

 z 	
-cU 39 :=?	
z %%cll33cllV+S1UC  2	q		

1	Y 
"\ S\\65&A 21O 
"	!s2   BH AH!A-HH ;H
H	H
H%rq   )r   expect_filtersr   debug_idr   r   r   r   c          	         Ub  [        X@5      n [        R                  " S5      (       a  X:w  a  U(       d+  [        R                  " SU-   S9nUS   u  p  n
[        X5      nU(       d  SOSU 3n[        R                  UR                  UR                  5      =nb*  U" U USU S	U S
3S9  [        SR                  X5      5        g[        X0US9  ggSnU" XUS9  g)  
Assert that actual is equal to expect.  The expect argument
MUST be a string literal (triple-quoted strings OK), and will
get updated directly in source when you run the test suite
with EXPECTTEST_ACCEPT=1.

If you want to write a helper function that makes use of
assertExpectedInline (e.g., expect is not a string literal),
set the skip argument to how many function calls we should
skip to find the string literal to update.
Nr
   r   r   r   rq   z for z!Uh oh, accepting different valuesz at zx.  Are you running a parametrized test?  If so, you need a separate assertExpectedInline invocation per distinct output.r   z(Skipping already accepted output{} at {})r   r   r   zTo accept the new output, re-run test with envvar EXPECTTEST_ACCEPT=1 (we recommend staging/committing your changes before doing this))r   osgetenvr   r   r   r   rJ   r   r   r   r   r   )r   rM   r   r   r   r   r   r   r6   r   r   r   prev_actual	help_texts                 r   r   r   C  s    * !n5
 
yy$%%,,1t8<#%a5 Aq"2.%-2U8*3EL+55cllCJJOO\;L>cU  SK  L
 >EE$
 sM) .A 	
 	&i0r   c                       \ rS rSr% Sr\\\4   \S'   S\S\SS4S jrSS	\S
\S\	SS4S jjr
S\S\S\4   S
\S\S\SS4S jrS
\S	\S\S\SS4
S jrSrg)TestCasei}  T_expect_filtersr   replacementr   Nc                    ^  [        T S5      (       d   0 T l        SU 4S jjnT R                  U5        UT R                  ;   a(  [        SR	                  XT R                  U   5      5      eUT R                  U'   g )Nr   c                  
   > T ? g r1   r   r2   s   r   expect_filters_cleanup;TestCase.substituteExpected.<locals>.expect_filters_cleanup  s	    (r   z.Cannot remap {} to {} (existing mapping is {})rS   )r   r   
addCleanupRuntimeErrorr   )r3   r   r   r   s   `   r   substituteExpectedTestCase.substituteExpected  sx    t.//#%D ) OO23d***@GG$*>*>w*G 
 )4W%r   r   rM   r   c           
      l    [        UUUS-   [        U SS5      U R                  5       U R                  S9  g)r   r   r   N)r   r   r   r   )r   getattrid!assertMultiLineEqualMaybeCppStack)r3   r   rM   r   s       r   assertExpectedInlineTestCase.assertExpectedInline  s8     	"4):DAWWY<<	
r   exc_typecallable.argskwargsc                      U" U0 UD6  U R                  SS9  g! U a$  nU R                  [        U5      USS9   SnAgSnAff = f)z
Like assertExpectedInline, but tests the str() representation of
the raised exception from callable.  The raised exeption must
be exc_type.
r   r   NzDid not raise when expected tor   )r   rX   fail)r3   r   r   rM   r   r   es          r   assertExpectedRaisesInline#TestCase.assertExpectedRaisesInline  sS    	d%f%
 			6	7	  	%%c!ff1%=	s    A?Ac                     SnXR;   a  UR                  USS9S   n[        U S5      (       a  U R                  " X/UQ70 UD6  g U R                  " X/UQ70 UD6  g )Nz
Exception raised fromr   )maxsplitr   assertMultiLineEqual)rsplitr   r   assertEqual)r3   rM   r   r   r   cpp_stack_headers         r   r   *TestCase.assertMultiLineEqualMaybeCppStack  sf     5%]]#3a]@CF4/00%%fFtFvFV=d=f=r   r   r   )rT   rU   rV   rW   longMessager   rX   rZ   r   rY   r   r   r   r   r   r\   r(   r   r   r   r   }  s    K#s(^#4# 4C 4D 4 
3 
 
3 
t 
*88 38$8 	8
 8 8 
8*	>	>#&	>/2	>>A	>		>r   r   __main__r   ).r   r   r   rd   sysr   unittestr   dataclassestypingr   r   r   r   r   r   r	   r   ACCEPTversion_infor   rX   rY   r   r   r#   r*   r,   r   r[   r^   r   DOTALLry   r}   r   r   r   	dataclassr   r   r   r   rT   doctesttestmodr(   r   r   <module>r     s   
 	 	  
     D D D 
&	'""f,# s s  c c "7C 7C 7S   '6 '6T }Hs H3 H4 H  JJLryy	
E	EE-0E>AE
38_EPCd38n CC CC C
c 
3 
 
 
  D 0 0 08B	8B8B 8B 
	8B| 71
 #'/3717171 71
 
,	71 T#s(^,71 71 71 
71tG>x   G>T zOO r   