
    i0                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJr  SSKJrJrJrJr  SSKJr  SSKJr  SSKrSS	KJr  SS
KJrJr  SSKJrJr  SSKJ r   SSK!J"r"   SSK#r#Sr%Sr&\RN                  " S\RP                  5      r)\RN                  " S\RP                  5      r*S\+S\,\+\+4   4S jr-S\+S\+S\+4S jr. " S S\5      r/SS.S\S\
\,\+\+4      S\,\+S4   S\,\+\+\+4   S-  4S jjr0SS.S\S\
\,\+\+4      S\,\+S4   S \1\+\4   S\,\+\+4   S-  4
S! jjr2S"SS#\" S$3S%.S&\
\,\+\+\+4      S'\+S(\S-  S)\+S\+4
S* jjr3S+S,.S-\+S.\+S\4S/ jjr4S1S.\+SS4S0 jjr5g! \$ a    Sr# GNf = f)2aF  
Write patches which add @example() decorators for discovered test cases.

Requires `hypothesis[codemods,ghostwriter]` installed, i.e. black and libcst.

This module is used by Hypothesis' builtin pytest plugin for failing examples
discovered during testing, and by HypoFuzz for _covering_ examples discovered
during fuzzing.
    N)literal_eval)Sequence)suppress)datedatetime	timedeltatimezone)Path)Any)matchers)CodemodContextVisitorBasedCodemodCommand)ExpressionContextExpressionContextProvider)storage_directory)__version__zqFrom HEAD Mon Sep 17 00:00:00 2001
From: {author}
Date: {when:%a, %d %b %Y %H:%M:%S}
Subject: [PATCH] {msg}

---
zdiscovered failurez^ +$z(^[ ]*)(?:[^ 
])textreturnc                     [         R                  SU 5      n [        [        R	                  U 5      [
        S9n[        R                  " SU-   SU 5      U4$ )N keyz(?m)^)_space_only_resubmin_leading_space_refindalllenrer   prefixs     Y/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/hypothesis/extra/_patching.pydedentr#   =   sI    b$'D"**40c:F66(V#R.66    r!   c                 T   ^ SR                  U4S jU R                  SS9 5       5      $ )Nr   c              3   .   >#    U  H
  nTU-   v   M     g 7fN ).0liner!   s     r"   	<genexpr>indent.<locals>.<genexpr>E   s     L-KT6D=-Ks   Tkeepends)join
splitlinesr    s    `r"   indentr1   D   s#    77LT__d_-KLLLr$   c                     ^  \ rS rSrSr   SS\S\\\\	\
R                  \4      4   S\	\S4   S\S\4
U 4S	 jjjrS
\
R                  S\S\
R                  S-  4S jrS\
R                   S\
R                   S\
R                   4S jrSrU =r$ )AddExamplesCodemodH   z'Add explicit examples to failing tests.contextfn_examples	strip_via.	decoratorwidthc           	      N  >^ ^^	 U(       d   S5       e[         T
T ]  U5        [        R                  " U5      T l        UT l        [        R                  " U4S j5      n[        R                  " [        R                  " [        R                  " 5       [        R                  " S5      5      [        R                  " [        R                  " 5       U-  5      /5      T l        UR                  5        VVs0 s H  u  pxU[        U	U 4S jU 5       5      _M     snnT l        gs  snnf )zAdd @example() decorator(s) for failing test(s).

`code` is the source code of the module where the test functions are defined.
`fn_examples` is a dict of function name to list-of-failing-examples.
z.This codemod does nothing without fn_examples.c                 4   > [        U R                  5      T;   $ r'   )r   value)xr7   s    r"   <lambda>-AddExamplesCodemod.__init__.<locals>.<lambda>^   s    l177+y8r$   viac              3   `   >#    U  H#  u  pTR                  X5      =m(       d  M  Tv   M%     g 7fr'   )-_AddExamplesCodemod__call_node_to_example_dec)r)   noder@   dselfs      r"   r+   .AddExamplesCodemod.__init__.<locals>.<genexpr>g   s2      #(KT88CCAC #(s   .	.N)super__init__cstparse_expressiondecorator_funcline_lengthmMatchIfTrueCall	AttributeNameArgSimpleStringstrip_matchingitemstupler6   )rE   r5   r6   r7   r8   r9   value_in_strip_viaknodesrD   	__class__s   `  `     @r"   rH   AddExamplesCodemod.__init__K   s     LLL{!!229= "#--8#
  ffKK!&&-0UU1>>#&889:
 (--/
 0 u #(  
 0
 
s   4#D!rC   r@   r   Nc                    UR                  U R                  [        (       a  UR                   Vs/ s Ho  nUR                  [        R
                  " UR                  [        R                  " 5       5      (       a  UR                  O[        R                  R                  S9PMq     snOUR                  S9n[        R                  " [        R                  " U[        R                  " S5      5      [        R                  " [        R                  " [!        U5      5      5      /S9n[        (       ay   [        R"                  " [        R$                  " / 5      R'                  U5      [        R(                  " U R*                  S9S9n[        R0                  " UR3                  5       5      n[        R4                  " U5      $ s  snf ! [,        [.        4 a     g f = f)N)comma)funcargsr@   )rL   )mode)with_changesrK   blackr_   rM   r   r]   CommentrI   MaybeSentinelDEFAULTrO   rP   rQ   rR   rS   repr
format_strModulecode_for_nodeModerL   ImportErrorAttributeErrorrJ   strip	Decorator)rE   rC   r@   aprettys        r"   __call_node_to_example_dec-AddExamplesCodemod.__call_node_to_example_deco   sg      $$ 5 "YY	 ' NN  !yy!))+>> GG!$!2!2!:!:	 #  '	 YY ! 
" #&((tSXXe_5''#**49567#
 5))JJrN0050@0@A &&v||~6C}}S!!7	0  0 s   A6G
3AG GG_original_nodeupdated_nodec                    ^  UR                  [        U 4S jUR                   5       5      T R                  R	                  UR
                  R                  S5      -   S9$ )Nc              3   x   >#    U  H/  n[         R                  " UTR                  5      (       a  M+  Uv   M1     g 7fr'   )rM   r   rT   )r)   rD   rE   s     r"   r+   7AddExamplesCodemod.leave_FunctionDef.<locals>.<genexpr>   s.      0AyyD$7$78 0s   *:	:r(   )
decorators)ra   rV   rx   r6   getnamer<   )rE   rs   rt   s   `  r"   leave_FunctionDef$AddExamplesCodemod.leave_FunctionDef   sb     (( %00  ""<#4#4#:#:B?@ ) 	
 		
r$   )rK   r6   rL   rT   )r(   exampleX   )__name__
__module____qualname____firstlineno__DESCRIPTIONr   dictstrlistrV   rI   rO   intrH   rn   rB   FunctionDefr{   __static_attributes____classcell__)rZ   s   @r"   r3   r3   H   s    ;K &(""
"
 #tE#((C-$899:"
 c?	"

 "
 "
 "
H""HH""#&""		""H
!oo
=@__
	
 
r$   r3   r(   )r7   r^   examplesr7   .c                x    [         R                  U R                     n[        UR                  5      nUR                  [        R                  " 5       5      (       a$  UR                  [        R                  " 5       5      OUn[        XX#R                  S9nUc  g Uu  px[        U5      Xx4$ ! [
         a     g f = f)N)r7   	namespace)sysmodulesr   r
   __file__	Exceptionis_relative_tocwdrelative_to_get_patch_for__dict__r   )	r^   r   r7   module	file_pathfnamepatchbeforeafters	            r"   get_patch_forr      s    T__-)	 ##DHHJ// 	dhhj) 

 )E }OVJ&&  s   2B, ,
B98B9r   c                <
    [         R                  " U 5      n[        S UR	                  5        5       S S9n/ n[        5       nU GH  u  pX4U;   a  M  UR                  X45        [        [        5         [        R                  " U5      n
U
R                  S   R                  S   R                  n[        U[        R                  5      (       d   U5       e[        R                  " [        R                  " [        R                   " S5      [        R                  " [        R"                  " 5       5      /S95      n[        R$                  " U[        R                  " [        R&                  " 5       U[        R&                  " 5       /S95      (       a   S S S 5          g 0 n[(        R*                  " [(        R,                  " US5      5       H  n[        U[(        R                   5      (       d  M$  [        UR.                  [(        R0                  5      (       d  MO  UR2                  U;  d  Ma  UR2                  U;  d  Ms  U HT  u  nnUR2                  UR4                  ;   d  M"  [        R6                  " U SUR2                   35      XR2                  '     M     M     [        [        5         [        R8                  R;                  U
5      n[        R<                  " U[        R                  " [        R                   " 5       S	95       V
s1 s H  n
U
R>                  iM     nn
[        R@                  " U[        R                   " [        RB                  " URD                  5      S
9[        RF                  " [H        [J        RL                  5      -  [        RB                  " U4S j5      -  U4S jS9n
S S S 5        W
R                  S   R                  S   R                  n
[        U
[        R                  5      (       d   U
5       eURO                  X45        S S S 5        GM     U(       d  g URQ                  S5      [R        RT                  S   L a	  SU;  a  SnOSn[W        U5      u  nn [        R                  " U5      n
[Y        [[        5       U R\                  U0UUS[_        U5      -
  S9Ra                  U
5      nU[c        URd                  US94$ ! [         a     g f = fs  sn
f ! , (       d  f       GN>= f! , (       d  f       GM  = f! [         a     g f = f)Nc              3   n   #    U  H+  u  p[        U[        R                  5      (       d  M&  X4v   M-     g 7fr'   )
isinstancetypes
ModuleType)r)   rX   vs      r"   r+   !_get_patch_for.<locals>.<genexpr>   s'     S/FQ:aAQAQ3R!/s   %5
5c                 2    [        U S   R                  5      $ )N   )r   r   )kvs    r"   r>    _get_patch_for.<locals>.<lambda>   s    s2a5>>*r$   r   r   data)r_   eval.)keywordr<   c                 
    X;  $ r'   r(   )nrX   s     r"   r>   r     s    QZr$   c                     X R                      $ r'   r   )rC   _nss      r"   r>   r     s
    "ZZ.r$   )replacement
hypothesisgivenzhypothesis.exampler}   r~   )r6   r7   r8   r9   )r!   )3inspect	getsourcer   sortedrU   setaddr   rI   parse_modulebodyr<   r   rO   rM   rR   rQ   Ellipsismatches
ZeroOrMoreastwalkparsectxLoadidr   rJ   metadataMetadataWrapperr   r   replacerN   __contains__MatchMetadatar   r   LOADappendry   r   r   r#   r3   r   r   r   transform_moduler1   code)r^   r   r7   r   r   modules_in_test_scope
call_nodesseen_examplesexr@   rC   the_callr   namesanoderX   r   wrapperkwarg_namesrK   dedentedr!   r   s                          r"   r   r      s   ""4( #Sioo/S* .0J EM9%2)$i ((,Dyy|((+11Hh11;8;155vaeeAJJL6I5JKLDyy166alln/U#VWW !  E#))B"78uchh//"599chh77-	1 51 88qzz1.1.B.BaS%((CT.UE((O! !6 9  )$,,66t< !"		'1553J K K LL K   yyFFu/A/A!BCoo&?ARAWAWXYmm$GHI 49 H % 99Q<$$Q'--DdCHH--3t3-tk*Y !  f  	l#s{{<'@@9$-" f~Hf) ]]J/ 3v; t 
 F5::f566u  d %$; ! z  s   S 6D S; AS;1'S;S;.S;  S;$A	S;-AS)S$
!BS)2A&S;,T 
S! S!$S))
S83S;;
T	
TTz!Hypothesis: add explicit exampleszHypothesis z <no-reply@hypothesis.works>msgwhenauthortriplesr   r   r   c                   U (       d   S5       eU=(       d"    [         R                  " [        R                  S9n0 nU  H1  u  pVnUR	                  [        U5      / 5      R                  Xg45        M3     [        R                  XUS9/n[        UR                  5       5       H  u  pYUR                  SS9=pU	 H4  u  pgUR                  UR                  5       UR                  5       S5      nM6     [        R                  " U
R!                  SS9UR!                  SS9S	U 3S	U 3S
9nUR                  SR#                  U5      5        M     SR#                  U5      $ )z2Create a patch for (fname, before, after) triples.zattempted to create empty patch)tzr   utf-8encodingr   Tr-   z./)fromfiletofiler   )r   nowr	   utc
setdefaultr
   r   HEADERformatr   rU   	read_textr   rstripdifflibunified_diffr0   r/   )r   r   r   r   by_fnamer   r   r   diffschangessource_beforesource_afteruds                r"   
make_patchr   &  s7    555708<<8<<0D24H 'uDK,33VOD !( ]]sf]=>E !12','HH$MF'//QRSL %!!$$d$3##T#2%\w<	
 	RWWR[! 3 775>r$   r   )slugr   r   c          
      "   [         R                  " SU5      (       d   SU< 35       e[        R                  " 5       R	                  5       n[         R
                  " SSU S[         R                  S9n[        R                  " UR                  5       5      R                  5       S S n[        [        SU S	U U S
35      5      nUR                  R                  SSS9  UR                  U SS9  UR!                  [        R"                  " 5       5      $ )Nz|[a-z]+-zmalformed slug=z^Date: .+?$r   r   )countflags   patches--z.patchT)parentsexist_okr   r   )r   	fullmatchr   today	isoformatr   	MULTILINEhashlibsha1encode	hexdigestr
   r   parentmkdir
write_textr   r   )r   r   r   cleanedhash8r   s         r"   
save_patchr  D  s    <<T**@.>,@@*
**,
 
 
"Cff^Rar||LGLL)*446r:E"9RveWF.KLME	LLtd3	UW-TXXZ((r$   c                 .   [         R                  " 5       [        SS9-
  n[        [	        S5      5      R                  SU  S35       HK  n[         R                  " UR                  R                  S5      S   5      U:  d  M;  UR                  5         MM     g )N   )daysr   z????-??-??--z????????.patchr   r   )
r   r   r   r
   r   globfromisoformatstemsplitunlink)r   cutoffr   s      r"   
gc_patchesr  O  su    ZZ\I1--F'	2388
tfN+ ejj..t4Q786ALLN	r$   )r   )6__doc__r   r   r  r   r   r   r   r   collections.abcr   
contextlibr   r   r   r   r	   pathlibr
   typingr   libcstrI   r   rM   libcst.codemodr   r   libcst.metadatar   r   hypothesis.configurationr   hypothesis.versionr   rb   rk   r   FAIL_MSGcompiler  r   r   r   rV   r#   r1   r3   r   r   r   r   r  r  r(   r$   r"   <module>r"     s5       	 
   $  8 8      E H 6 *
  FBLL1JJ2BLLA 7 7sCx 7M Mc Mc MW
3 W
| "$	'
'uS#X'' S#X	'
 3S=D 'D "$	c7
c7uS#X'c7 S#X	c7
 CH~c7 38_tc7R 3 },HIeCcM*+ 
 T/	
  	< +- )c )C ) )S $ E	  Es   0E* *E65E6