
    h\8                         S r SSKrSSKJr  SSKrSSKrSSKJrJrJrJ	r	J
r
  S rS r " S S	5      r " S
 S5      r " S S5      r " S S5      rg)z6
testing of anchors and the aliases referring to them
    N)dedent   )
round_tripr   round_trip_loadround_trip_dumpYAMLc                 *    [        [        U 5      5      $ N)r   r   )ss    ]/home/james-whalen/.local/lib/python3.13/site-packages/srsly/tests/ruamel_yaml/test_anchor.pyloadr      s    6!9%%    c                 8    [        U 5      [        U5      :X  d   eg r
   )r   r   )dr   s     r   comparer      s    1***r   c                       \ rS rSrS rS rS rS r\R                  R                  \R                  " 5       S:H  SS9S	 5       rS
 r\" S5      rS rS rS rS rS rS rS rS rS rSrg)TestAnchorsAliases   c                 b    SSK Jn  UR                  S:X  d   e[        S5      n[	        US5        g )Nr   )
Serializerzid%03dzK
        a: &id002
          b: 1
          c: 2
        d: *id002
        zK
        a: &id001
          b: 1
          c: 2
        d: *id001
        )srsly.ruamel_yaml.serializerr   ANCHOR_TEMPLATEr   r   )selfr   datas      r   test_anchor_id_renumber*TestAnchorsAliases.test_anchor_id_renumber   s:    ;))X555
 		
r   c                     SSK Jn  U" S5      (       d   eU" S5      (       d   eU" S5      (       d   eU" S5      (       d   eU" S5      (       d   eU" S5      (       a   eU" S	5      (       a   eU" S
5      (       a   eg)z&test if id matches the anchor templater   )templated_idid001id999id1000id0001id0000id02id000x000N)r   r   )r   r   s     r   test_template_matcher(TestAnchorsAliases.test_template_matcher2   s    =H%%%%H%%%%I&&&&I&&&&I&&&&(((())))(((((r   c                 &   SSK Jn  [        S5      nUS   n[        X15      (       d   eUR	                  5       b   eUS   n[        XA5      (       d   eUR	                  5       R
                  S:X  d   eUR	                  5       R                  SL d   eg )Nr   CommentedMap
        a: &id002
          b: 1
          c: 2
        d: *id002
        e: &etemplate
          b: 1
          c: 2
        f: *etemplate
        r   e	etemplateF)srsly.ruamel_yaml.commentsr+   r   
isinstanceyaml_anchorvaluealways_dump)r   r+   r   r   r-   s        r   test_anchor_assigned'TestAnchorsAliases.test_anchor_assignedE   s    ;	
 I!****}}&&&I!****}}$$333}}**e333r   c                 2    [        S5      n[        US5        g )Nr,   z
        a: &id001
          b: 1
          c: 2
        d: *id001
        e: &etemplate
          b: 1
          c: 2
        f: *etemplate
        )r   r   r   r   s     r   test_anchor_id_retained*TestAnchorsAliases.test_anchor_id_retained\   s#    	
 			
r   JythonzJython throws RepresenterError)reasonc                     SSK Jn  [        R                  " U5         [	        S5      nUnS S S 5        g ! , (       d  f       g = f)Nr   )ComposerErrorz_
            d: *id002
            a: &id002
              b: 1
              c: 2
            )srsly.ruamel_yaml.composerr=   pytestraisesr   )r   r=   r   s      r   test_alias_before_anchor+TestAnchorsAliases.test_alias_before_anchorw   s5    
 	=]]=)D D *))s	   4
Ac                     SSK Jn  [        S5      nUS   n[        X15      (       d   eUR	                  5       c   eUR	                  5       R
                  S:X  d   eg )Nr   )CommentedSeqz
        nut1: &alice
         - 1
         - 2
        nut2: &blake
         - some data
         - *alice
        nut3:
         - *blake
         - *alice
        nut1alice)r/   rD   r   r0   r1   r2   )r   rD   r   rs       r   test_anchor_on_sequence*TestAnchorsAliases.test_anchor_on_sequence   s^     	<

 L!****}}***}}$$///r   a  
        - &CENTER {x: 1, y: 2}
        - &LEFT {x: 0, y: 2}
        - &BIG {r: 10}
        - &SMALL {r: 1}
        # All the following maps are equal:
        # Explicit keys
        - x: 1
          y: 2
          r: 10
          label: center/small
        # Merge one map
        - <<: *CENTER
          r: 10
          label: center/medium
        # Merge multiple maps
        - <<: [*CENTER, *BIG]
          label: center/big
        # Override
        - <<: [*BIG, *LEFT, *SMALL]
          x: 1
          label: center/huge
        c           
         [        U R                  5      nUS   nSnU H  nS H  nUR                  U5      nX   R                  U5      n[        U[        5      (       d(  UR                  S5      S   nUR                  S5      S   nXg:w  d  Mk  Sn[        SXBR                  U5      X   R                  U5      5        M     M     U(       d   eg )N   T)         /r   Fkey)r   
merge_yamlgetr0   intsplitprint)r   r   r   okkoxys           r   test_merge_00 TestAnchorsAliases.test_merge_00   s    DOO$GAEE!HGKKN!!S))QAQA6B%EE!Hdgkk!n=   	rr   c                 |    SSK JnJn  [        S5      nUS   n[	        XA5      (       d   e[        XB5      (       d   eg )Nr   )r+   merge_attribz
        k: &level_2 { a: 1, b2 }
        l: &level_1 { a: 10, c: 3 }
        m:
          <<: *level_1
          c: 30
          d: 40
        m)r/   r+   r^   r   r0   hasattr)r   r+   r^   r   r   s        r   test_merge_accessible(TestAnchorsAliases.test_merge_accessible   sA    I	
 I!****q''''r   c                 X    [        U R                  5      n[        XR                  5        g r
   )r   rQ   r   r7   s     r   test_merge_01 TestAnchorsAliases.test_merge_01   s    DOO$oo&r   c                     Sn[        U5      ng )Nz
        a:
          <<: &content
            1: plugh
            2: plover
          0: xyzzy
        b:
          <<: *content
        r   r   yamlr   s      r   test_merge_nested$TestAnchorsAliases.test_merge_nested   s     $r   c                     Sn[        U5      ng )Nz
        a:
          <<: &content
            <<: &y2
              1: plugh
            2: plover
          0: xyzzy
        b:
          <<: [*content, *y2]
        rg   rh   s      r   test_merge_nested_with_sequence2TestAnchorsAliases.test_merge_nested_with_sequence   s    	 $r   c                     SSK Jn  U" 5       nU" 5       nX2S'   SUS'   SUS'   UR                  SS	S
9  US   R                  SS	S
9  [        US5        g )Nr   r*   a   c   bklmT)r3   xyzzB
        &klm
        a: &xyz
          c: 3
        b: 2
        )r/   r+   yaml_set_anchorr   )r   r+   r   data_as       r   test_add_anchor"TestAnchorsAliases.test_add_anchor   sf    ;~S	sS	U5S	!!%T!:	
r   c                     SSK Jn  Sn[        R                  " U5         [	        U5      nS S S 5        g ! , (       d  f       g = f)Nr   )ReusedAnchorWarningzc
        - &a
          x: 1
        - <<: *a
        - &a
          x: 2
        - <<: *a
        )srsly.ruamel_yaml.errorr|   r?   warnsr   )r   r|   ri   r   s       r   test_reused_anchor%TestAnchorsAliases.test_reused_anchor  s1    ? \\-.d#D /..s	   4
Ac                     [        S5      n[        R                  R                  U5      nUS   S   S   S   S   S:X  d   eg )Na          components:
          server: &server_component
            type: spark.server:ServerComponent
            host: 0.0.0.0
            port: 8000
          shell: &shell_component
            type: spark.shell:ShellComponent

        services:
          server: &server_service
            <<: *server_component
          shell: &shell_service
            <<: *shell_component
            components:
              server: {<<: *server_service}
        servicesshell
componentsserverporti@  r   srslyruamel_yaml	safe_loadr   ysr   s      r   test_issue_130!TestAnchorsAliases.test_issue_130  sP    
&   **2.J(6x@HDPPPr   c                     [        S5      n[        R                  R                  U5      nUS   S   S   S   S   S:X  d   eg )Na          components:
          server: &server_component
            type: spark.server:ServerComponent
            host: 0.0.0.0
            port: 8000
          shell: &shell_component
            type: spark.shell:ShellComponent

        services:
          server: &server_service
            <<: *server_component
            port: 4000
          shell: &shell_service
            <<: *shell_component
            components:
              server: {<<: *server_service}
        r   r   r   r   r   i  r   r   s      r   test_issue_130a"TestAnchorsAliases.test_issue_130a3  sP    
(   **2.J(6x@HDPPPr    N)__name__
__module____qualname____firstlineno__r   r'   r4   r8   r?   markskipifplatformpython_implementationrA   rH   r   rQ   r[   ra   rd   rj   rm   ry   r   r   r   __static_attributes__r   r   r   r   r      s    
,)&4.
6 [[&&(H4/  	0. 	J4 ("'
  
*$Q0Qr   r   c                   T    \ rS rSr\" S5      rS rS rS rS r	S r
S rS	 rS
 rSrg)TestMergeKeysValuesiM  z    - &mx
      a: x1
      b: x2
      c: x3
    - &my
      a: y1
      b: y2  # masked by the one in &mx
      d: y4
    -
      a: 1
      <<: [*mx, *my]
      m: 6
    c                     SSK Jn  U" U R                  5      n[        U R                  5      nSnUS    H  nUS-  n[	        XE5        M     U[        US   5      :X  d   eg Nr   r   rs   r   )srsly.ruamel_yamlr   yaml_strr   rU   lenr   r   r   r   countrY   s         r   test_merge_for"TestMergeKeysValues.test_merge_forb  s\    /dmm$t}}-aAQJE%O  AaD	!!!r   c                     SSK Jn  U" U R                  5      n[        U R                  5      nSnUS   R	                  5        H  nUS-  n[        XE5        M     U[        US   5      :X  d   eg r   )r   r   r   r   keysrU   r   r   s         r   test_merge_keys#TestMergeKeysValues.test_merge_keysm  sb    /dmm$t}}-aAQJE%O   AaD	!!!r   c                     SSK Jn  U" U R                  5      n[        U R                  5      nSnUS   R	                  5        H  nUS-  n[        XE5        M     U[        US   5      :X  d   eg r   )r   r   r   r   valuesrU   r   r   s         r   test_merge_values%TestMergeKeysValues.test_merge_valuesx  sc    /dmm$t}}-a!AQJE%O " AaD	!!!r   c                     SSK Jn  U" U R                  5      n[        U R                  5      nSnUS   R	                  5        H  nUS-  n[        XE5        M     U[        US   5      :X  d   eg r   )r   r   r   r   itemsrU   r   r   s         r   test_merge_items$TestMergeKeysValues.test_merge_items  sb    /dmm$t}}-aAQJE%O ! AaD	!!!r   c           	      Z   SSK Jn  SSKJn  U" U R                  5      n[        U R                  5      nUS   R                  5       n[        SUS   R                  5       [        US   R                  5       5      U[        U5      5        [        US   R                  5       5      n[        SU5        [        U5      U:X  d   eUS   S	 U(       a  US-  n[        U5      U:X  d   eUS   S		 U(       a  US-  n[        U5      U:X  d   eUS   S
	 U(       a  US-  n[        U5      U:X  d   eg )Nr   r   )PY3rs   zd2 itemsrefr_   r   r   rp   )	r   r   srsly.ruamel_yaml.compatr   r   r   r   rU   r   )r   r   r   r   r   rY   r   s          r   test_len_items_delete)TestMergeKeysValues.test_len_items_delete  s   /0dmm$t}}-GMMOj!A$**,AaDJJL(91c!fE!A$**,eS1v}}GCL1HC1v}}GCL1HC1v}}GCL1HC1v}}r   c                    SSK Jn  U" 5       nUR                  S5      S   nU H  n[        SU5        M     UR	                  5        H  n[        SU5        M     [        S[        UR                  5       5      5        [        S[        UR                  5       5      5        [        S[        UR                  5       5      5        [        [        U5      5        [        S5        S	U;   d   e0 nU H	  nXE   Xe'   M     S	U;   d   eS	UR                  5       ;   d   eUS	   S
:X  d   eUR                  S	5      S
:X  d   eS	[        U5      ;   d   eS	[        UR                  5       5      ;   d   eg )Nr   r   zi        anchored: &anchor
          a : 1

        mapping:
          <<: *anchor
          b: 2
        mappingrW   kcvz-----rp   r   )r   r   r   rU   copylistr   r   r   r   __getitem__dict)r   capsysr   ri   r   rW   rY   s          r   test_issue_196_cast_of_dict/TestMergeKeysValues.test_issue_196_cast_of_dict  sG   *v))	
 	 A#qM A$N   	c4'(c4()*c4()c'lg
 g~~A:AD axxglln$$$s|q   ""3'1,,,d7m###d7==?++++r   c                     SSK Jn  U" 5       nUR                  [        U R                  5      5      n[        US   R                  5       5      / SQ:X  d   eg )Nr   r   rs   )r   rM   x2x3y4)r   r   r   r   r   r   r   )r   r   ri   r   s       r   test_values_of_merged)TestMergeKeysValues.test_values_of_merged  sB    *vyy./DGNN$%)AAAAr   c                     SSK Jn  U" 5       nUR                  S5      S   nUS   S:X  d   eUR                  5       nUS   S:X  d   e[	        SU5        US	 SU;  d   eSU;   d   eg )Nr   r   zY        foo: &foo
          a: a
        foo2:
          <<: *foo
          b: b
        foo2rp   r   )r   r   r   r   rU   )r   r   ri   r   d2s        r   test_issue_213_copy_of_merge0TestMergeKeysValues.test_issue_213_copy_of_merge  s~    *vII
  v}}VVX#w#~~c1cF!||byyr   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   M  s;    	H&	"	"	"	"0&,PBr   r   c                        \ rS rSrS rS rSrg)TestDuplicateKeyThroughAnchori  c                 "   SSK Jn  SSK JnJn  SSKJnJn  [        S5      nUS:  a  g US:  aO  [        R                  " U5         U" U5        S S S 5        [        R                  " U5         U" U5        S S S 5        g [        R                  " U5         U" U5        S S S 5        [        R                  " U5         U" U5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f! , (       d  f       NX= f! , (       d  f       g = f)Nr   version_info)r   r   )DuplicateKeyFutureWarningDuplicateKeyErrorz        &anchor foo:
            foo: bar
            *anchor : duplicate key
            baz: bat
            *anchor : duplicate key
        r      r   )r      r   )r   r   r   r   srsly.ruamel_yaml.constructorr   r   r   r?   r~   r@   )r   r   r   r   r   r   r   s          r   test_duplicate_key_003TestDuplicateKeyThroughAnchor.test_duplicate_key_00  s    2@	

 
 *$J&78! 978" 98 01! 201" 21 9888 2111s0   	C,	C	C/;	D 
C
C,/
C= 
Dc                 j   SSK Jn  SSKJn  [	        S5      nUS:  a  g [
        R                  " U5         [        SS9nUR                  U5        S S S 5        [
        R                  " U5         [        5       nUR                  U5        S S S 5        g ! , (       d  f       NI= f! , (       d  f       g = f)Nr   r   )r   z        - &name-name
          a: 1
        - &help-name
          b: 2
        - <<: *name-name
          <<: *help-name
        r   safe)typ)	r   r   r   r   r   r?   r@   r   r   )r   r   r   r   ri   s        r   test_duplicate_key_013TestDuplicateKeyThroughAnchor.test_duplicate_key_01
  s    2C	
 *$01'		! 2 01v		! 21 21 21s   B.B$
B!$
B2r   N)r   r   r   r   r   r   r   r   r   r   r   r     s    #<r   r   c                   &    \ rS rSrS rS rS rSrg)TestFullCharSetAnchorsi$  c                     Sn[        U5      ng )Nz
        - collection: &Backend.Civilizations.RacialPerk
            items:
                  - key: perk_population_growth_modifier
        - *Backend.Civilizations.RacialPerk
        )r   r   r   r   s      r   test_master_of_orion+TestFullCharSetAnchors.test_master_of_orion%  s     H~r   c                     Sn[        U5      ng )Nza
        - &dotted.words.here
          a: 1
          b: 2
        - *dotted.words.here
        rg   r   s      r   test_roundtrip_00(TestFullCharSetAnchors.test_roundtrip_000  s     (#r   c                 T    Sn[        U5      n[        X!R                  SS5      5        g )NzI
        - &dotted.words.here[a, b]
        - *dotted.words.here
        [z [)r   r   replacer   s      r   test_roundtrip_01(TestFullCharSetAnchors.test_roundtrip_019  s)     H~&&sD12r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   $  s    	$3r   r   )__doc__r?   textwrapr   r   r   	roundtripr   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s]        &+oQ oQd	[ [|6 6r3 3r   