
    BTh9                        d dl Z d dlmZ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mZmZmZ d dlmZmZmZmZmZ d dlmZmZmZmZmZ d d	lmZ d d
l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d dl'm(Z(m)Z)m*Z*m+Z+ e
rd dl,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3  G d de      Z4 G d de      Z5de6de7fdZ8 G d d      Z9 G d d      Z: G d de4e5e9e:      Z;y)    N)ABCabstractmethod)gettext)zip_longest)Path)TYPE_CHECKINGCallableDictIteratorListOptionalSetTuple)DISABLE_COLOR_ENV_VARSNAPSHOT_DIRNAMESYMBOL_CARRIAGESYMBOL_ELLIPSISSYMBOL_NEW_LINE)
DiffedLineSnapshotSnapshotCollectionSnapshotCollectionsSnapshotEmptyCollection)SnapshotDoesNotExist)context_stylereceived_diff_stylereceived_styleresetsnapshot_diff_stylesnapshot_style)env_context	obj_attrsqdiffwalk_snapshot_dir)PyTestLocation)PropertyFilterPropertyMatcherSerializableDataSerializedDataSnapshotIndexc                   N    e Zd Zeddddddded   ded   ded	   d
df
d       Zy)SnapshotSerializerN)excludeincludematcherdatar(   r-   r&   r.   r/   r'   returnr)   c                    t         )z
        Serializes a python object / data structure into a string
        to be used for comparison with snapshot data from disk.
        NotImplementedError)selfr0   r-   r.   r/   s        h/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/syrupy/extensions/base.py	serializezSnapshotSerializer.serialize>   s
     "!    )__name__
__module____qualname__r   r   r7    r8   r6   r,   r,   =   sa    
 /3.2/3" " *+	"
 *+" +," 
" "r8   r,   c            
          e Zd ZdZedddddddefd	       Zedddddefd
       ZdedefdZ	ddddde
ee      ddfdZdddddeddfdZededeed      ddfd       Zededee   ddfd       Zededdfd       Zedededede
d   fd       Zee	 	 	 	 d"d              Zedddefd        Zedddddefd!       Zy)#SnapshotCollectionStorage r   )indextest_locationr%   r@   r*   r1   c                d    d}t        |t        f      rd| d}n|rd| }|j                   | S )z@Get the snapshot name for the assertion index in a test locationr?   [].)
isinstancestrsnapshot_name)clsrA   r@   index_suffixs       r6   get_snapshot_namez+SnapshotCollectionStorage.get_snapshot_nameQ   sF    
 ecV$ugQ<Lug;L--.|n==r8   c                    | j                  ||      }| j                  rd| j                   nd}t        t        | j	                  |            j                  | |             S )z4Returns full filepath where snapshot data is stored.rA   r@   rE   r?   rA   )_get_file_basename_file_extensionrG   r   dirnamejoinpath)rI   rA   r@   basenamefileexts        r6   get_locationz&SnapshotCollectionStorage.get_location]   sm    
 ))U)S/2/B/BAc))*+=9:CC*WI&
 	
r8   locationc                8    |j                  | j                        S )z@Checks if supplied location is valid for this snapshot extension)endswithrP   )r5   rV   s     r6   is_snapshot_locationz.SnapshotCollectionStorage.is_snapshot_locationj   s      !5!566r8   Nignore_extensionsr[   r   c                   t               }t        | j                  |      |      D ]\  }| j                  |      r+| j	                  |      }|j
                  st        |      }nt        |      }|j                  |       ^ |S )z?
        Returns all snapshot collections in test site
        rN   rZ   rV   )snapshot_location)	r   r$   rQ   rY   _read_snapshot_collectionhas_snapshotsr   r   add)r5   rA   r[   
discoveredfilepathsnapshot_collections         r6   discover_snapshotsz,SnapshotCollectionStorage.discover_snapshotsn   s     )*
)LL}L5/
 	0H ((((;&*&D&D&. 'E '# +88*A8*T'&8(&K#NN./	0 r8   
session_idr)   c                    | j                  ||      }| j                  ||      }| j                  |||      }|
t               |S )z
        This method is _final_, do not override. You can override
        `_read_snapshot_data_from_location` in a subclass to change behaviour.
        rM   )r^   rH   rf   )rU   rK   !_read_snapshot_data_from_locationr   )r5   rA   r@   rf   r^   rH   snapshot_datas          r6   read_snapshotz'SnapshotCollectionStorage.read_snapshot   sf     !--MQV-W..]RW.X>>/'! ? 

  &((r8   r^   	snapshots)r)   r%   r*   c                p   |syt        |      }|D ]  \  }}}| j                  ||      }t        ||      }|j                  |       |j	                  |      s>t        d      j                  ||j                  d      }	t        j                  |	d	       |j                  |j                        rt        d
      j                  |j                  |j                  d      }	t        j                  |	d	        t        |      j                  j                  dd       | j!                  |       y)z
        This method is _final_, do not override. You can override
        `_write_snapshot_collection` in a subclass to change behaviour.
        Nr]   rM   )namer0   z~{line_end}Can not relate snapshot location '{}' to the test location.{line_end}Consider adding '{}' to the generated location.
)line_end   )
stacklevelzv{line_end}Can not relate snapshot name '{}' to the test location.{line_end}Consider adding '{}' to the generated name.T)parentsexist_ok)rd   )r   rK   r   ra   matches_snapshot_locationr   formatrS   warningswarnmatches_snapshot_namerm   testnamer   parentmkdir_write_snapshot_collection)
rI   r^   rk   rd   r0   rA   r@   rH   snapshotwarning_msgs
             r6   write_snapshotz(SnapshotCollectionStorage.write_snapshot   sC    
 1:KL*3 	9&D-11+5 2 M  ]>H##H- ::;LM%F &%!**!  	  ka8 66x}}E%B &MM!**!  	  ka8;	9@ 	&&,,TD,I&&;N&Or8   snapshot_namesc                    t         )z{
        Remove snapshots from a snapshot file.
        If the snapshot file will be empty remove the entire file.
        r3   )r5   r^   r   s      r6   delete_snapshotsz*SnapshotCollectionStorage.delete_snapshots   
     "!r8   r   c                    t         )zW
        Read the snapshot location and construct a snapshot collection object
        r3   )r5   r^   s     r6   r_   z3SnapshotCollectionStorage._read_snapshot_collection   
     "!r8   rH   c                    t         )zH
        Get only the snapshot data from location for assertion
        r3   )r5   r^   rH   rf   s       r6   rh   z;SnapshotCollectionStorage._read_snapshot_data_from_location   r   r8   c                    t         )zP
        Adds the snapshot data to the snapshots in collection location
        r3   )rI   rd   s     r6   r|   z4SnapshotCollectionStorage._write_snapshot_collection   r   r8   c                |    t        |j                        j                  }t        |j	                  t
                    S N)r   rc   rz   rG   rR   r   )rI   rA   test_dirs      r6   rQ   z!SnapshotCollectionStorage.dirname   s/    ../668$$%5677r8   c                    |j                   S )zFReturns file basename without extension. Used to create full filepath.)rS   )rI   rA   r@   s      r6   rO   z,SnapshotCollectionStorage._get_file_basename   s    
 %%%r8   )rd   r   r1   N)r9   r:   r;   rP   classmethodrG   rK   rU   boolrY   r   r   re   rj   r   r   r   r   r   r_   rh   r|   rQ   rO   r<   r8   r6   r>   r>   N   s   OJK	>/	>8G	>		> 	> 

/

8G

	

 

7 7 7 26	 ( $DI.	
 
6 ( 	
  
, 3P 3P QRS	3P
 
3P 3Pj "$'"9<S"	" " "$'"	" " "$'"8;"IL"	"	#" " "%9"	"  " 8'7 8C 8 8 &/&8G&	& &r8   r>   sr1   c                 L    t        |       t        | j                               z
  S r   )lenlstrip)r   s    r6   _count_leading_whitespacer     s    q6C
O##r8   c                   N   e Zd ZdZ	 	 	 	 	 	 ddZdddddee   fdZede	eef   fd       Z
edefd	       Zedefd
       Zedefd       Zedefd       Zdededee   fdZdededed   fdZdededeegef   deegef   dedefdZdee   dee   fdZdedefdZy)SnapshotReporterrp   serialized_datar)   ri   r1   c                     t         di}ddi}t        di |5  t        | |      5  dj                  | j	                  ||            cd d d        cd d d        S # 1 sw Y   nxY wd d d        y # 1 sw Y   y xY w)Ntrue_context_line_countr   rn   r<   )r   r!   r"   join
diff_lines)r5   r   ri   envattrss        r6   diff_snapshotszSnapshotReporter.diff_snapshots  s{     %f-&*3 	N4!7 	N99T___mLM	N 	N 	N 	N 	N 	N 	Ns"   A.!A	A.A"	A..A7c              #   x   K   | j                  t        |      t        |            D ]  }t        |        y wr   )_SnapshotReporter__diff_linesrG   r   )r5   r   ri   lines       r6   r   zSnapshotReporter.diff_lines  s8      %%c-&8#o:NO 	D+	s   8:c                 4    | j                   | j                  dS )N)rn   )_marker_new_line_marker_carriager5   s    r6   _endszSnapshotReporter._ends  s    ++43H3HIIr8   c                      | j                   dz  S )N   )r   r   s    r6   _context_line_maxz"SnapshotReporter._context_line_max!  s    ''!++r8   c                     t         S r   )r   r   s    r6   _marker_context_maxz$SnapshotReporter._marker_context_max%      r8   c                     t         S r   )r   r   s    r6   r   z!SnapshotReporter._marker_new_line)  r   r8   c                     t         S r   )r   r   s    r6   r   z!SnapshotReporter._marker_carriage-  r   r8   abc              #     K   | j                  ||      D ]1  }|j                  rY| j                  |j                  |j                  dd  nd      | j                  |j                  |j                  dd  nd      k(  nd}|j
                  r?|j                  3| j                  |j                  |j                  t        t        |       |j                  r?|j                  3| j                  |j                  |j                  t        t        |       t        t        | j!                  |j"                              E d {    4 y 7 w)Nrp   r?   F)_SnapshotReporter__diffed_linesis_complete_SnapshotReporter__strip_endsr   r   has_snapshot_SnapshotReporter__format_linediff_ar    r   has_receiveddiff_br   r   mapr    _SnapshotReporter__limit_contextc)r5   r   r   r   	show_endss        r6   __diff_lineszSnapshotReporter.__diff_lines1  s$    ''1- 	HD ## !!0B$&&*K$$4663ETVVABZ2NO 	    TVV%7((FFDKK9Li    TVV%7((FFDKK9Li  =$*>*>tvv*FGGG	H Hs   E EE	Er   c              #     K   d }t        |j                  d      |j                  d            D ]  }|d   dk(  }|d   dk(  }|d   dk(  }|d   dk(  }|s|r| j                  |      }|r|r(|j                  r||_        n|j
                  r||_        n}|j                  xs5 |j
                  xr |xs# |j                  xr |xs |j                  xr | }	|	r| d }n1|r||_	        n'|r||_
        n|r|j                  j                  |       |r|rt        |      }|rt        |	      }|st        |g
      } |r| y y w)NT)keependsr    -+?)r   )r   )r   )r#   
splitlinesr   r   r   r   r   r   
is_contextr   r   r   appendr   )
r5   r   r   staged_diffed_liner   is_context_lineis_snapshot_lineis_received_lineis_diff_lineshould_unstages
             r6   __diffed_lineszSnapshotReporter.__diffed_linesC  s    37!,,,5q||T|7RS (	>D"1gnO#Aw#~#Aw#~7c>L,((.!)6648*1+8848*1
 +66 S.;;P@PS.;;P@PS /99Q/>Q	 # &00-1*)/3*,)/3*,(*,,33D9%#)3d);&%)3d);&$)3tf)=&Q(	>X $$ s   DE!E9Er   diff_markers
line_style
diff_styler   c                     |r5| j                   j                         D ]  \  }}|j                  ||      } n| j                  |      }dj	                  fdt        |j                         |      D              S )Nr?   c              3   b   K   | ]&  \  }}|t        |      dv r |      n |       ( y w)Nz-+^)rG   ).0markercharr   r   s      r6   	<genexpr>z1SnapshotReporter.__format_line.<locals>.<genexpr>  s=      
 !$Fu 4Jt*T:JJ
s   ,/)r   itemsreplacer   r   r   rstrip)r5   r   r   r   r   r   oldnews      ``   r6   __format_linezSnapshotReporter.__format_linet  sx      JJ,,. .S||C-. $$T*Dww 
 +L,?,?,A4 H
 
 	
r8   linesc              #     K   |d | j                    E d {    t        |      }|r|| j                  kD  rj| j                   r9t        || j                   dz
           t        || j                             z   dz  }nt        ||dz           }d|z  | j                  z    | j                   r|dkD  r|| j                    d  E d {    y y y y 7 7 
w)Nrp   r   r   )r   r   r   r   r   )r5   r   	num_lines	num_spaces       r6   __limit_contextz SnapshotReporter.__limit_context  s     3433444J	4111++1%8P8PST8T2UV3E4;S;S:S4TUV!I
 !:%	Q:O PIIo(@(@@@''IM $":":!:!<=== -:'  	5 >s"   CCB.CC	CCc                 r    |j                  dj                  | j                  j                                     S )Nr?   )r   r   r   keys)r5   r   s     r6   __strip_endszSnapshotReporter.__strip_ends  s%    {{2774::??#4566r8   N)r   r)   ri   r)   r1   r)   )r9   r:   r;   r   r   r   rG   r   propertyr
   r   intr   r   r   r   r   r   r	   r   r   r   r   r   r<   r8   r6   r   r     s   N/N@PN	N/@P	# JtCH~ J J ,3 , , S   #   #  Hc Hc Hhsm H$/% /% /%0F /%b

 
 cUCZ(	

 cUCZ(
 
 

&>T#Y >8C= > 7 7 7r8   r   c                        e Zd ZdddddefdZy)SnapshotComparatorr   r(   ri   r1   c                    t        ||k(        S )zd
        Compares serialized data and snapshot data and returns
        whether they match.
        )r   )r5   r   ri   s      r6   matcheszSnapshotComparator.matches  s     O}455r8   N)r9   r:   r;   r   r   r<   r8   r6   r   r     s%    
6 ,
6 *	
6
 

6r8   r   c                       e Zd Zy)AbstractSyrupyExtensionN)r9   r:   r;   r<   r8   r6   r   r     s     	r8   r   )<rv   abcr   r   r   	itertoolsr   pathlibr   typingr   r	   r
   r   r   r   r   r   syrupy.constantsr   r   r   r   r   syrupy.datar   r   r   r   r   syrupy.exceptionsr   syrupy.terminalr   r   r   r   r   r    syrupy.utilsr!   r"   r#   r$   syrupy.locationr%   syrupy.typesr&   r'   r(   r)   r*   r,   r>   rG   r   r   r   r   r   r<   r8   r6   <module>r      s      ! 	 	 	   3   . " ""w& w&t$ $ $L7 L7^6 6	13CEW	r8   