
    iIP                         d Z ddlZddlZddlmZmZmZmZ  G d d      Z G d d      Z	 G d	 d
      Z
 G d d      Z G d d      Z G d d      Z G d d      ZdZ G d d      Zy)z
comment testing is all about roundtrips
these can be done in the "old" way by creating a file.data and file.roundtrip
but there is little flexibility in doing that

but some things are not easily tested, eog. how a
roundtrip changes

    N   )
round_tripdedentround_trip_loadround_trip_dumpc                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestCommentsc                     d}t        |d       t        j                  t              5  t        |d       ddd       y# 1 sw Y   yxY w)z~not excluding comments caused some problems if at the end of
        the file without a newline. First error, then included   z        - europe: 10 # abc
)extraza
N)r   pytestraisesAssertionError)selfxs     v/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/srsly/tests/ruamel_yaml/test_comments.pytest_no_end_of_file_eolz$TestComments.test_no_end_of_file_eol   s>    1D!]]>* 	'q&	' 	' 	's   A  A	c                     t        d       y )Nz[
        - europe: 10
        - usa:
          - ohio: 2
          - california: 9
        r   r   s    r   test_no_commentszTestComments.test_no_comments       	
    c                     t        d       y )Nzs
        a: 1
        b: 2
        c: 3
        b1: 2
        b2: 2
        d: 4
        e: 5
        f: 6
        r   r   s    r   test_round_trip_orderingz%TestComments.test_round_trip_ordering'       		
r   c                     t        d       y )Nze
        - europe: 10 # top
        - usa:
          - ohio: 2
          - california: 9 # o
        r   r   s    r   test_complexzTestComments.test_complex5   r   r   c                      d}t        |d       y )Nz5        # comment
        scalar
        ...
        zscalar
...
r   r   ss     r   test_droppedzTestComments.test_dropped?   s    
 	1o&r   c                     t        d       y )Nz
        # C start a
        # C start b
        abc: 1
        ghi: 2
        klm: 3
        # C end a
        # C end b
        r   r   s    r   test_main_mapping_begin_endz(TestComments.test_main_mapping_begin_endG       
	
r   c                 X    d}t        |      }t        |d      }|t        d      k(  sJ y )NzM        a:
          b:     # comment 1
            c: 1 # comment 2
           indentzQ        a:
            b:   # comment 1
                c: 1 # comment 2
        )r   r   r   )r   r   dys       r   test_reindentzTestComments.test_reindentT   s?    
 AAa(F
 
 	
 
r   c                     t        d       y )Nz
        # C start a
        # C start b
        abc: 1      # abc comment
        ghi: 2
        klm: 3      # klm comment
        # C end a
        # C end b
        r   r   s    r   &test_main_mapping_begin_end_items_postz3TestComments.test_main_mapping_begin_end_items_postd   r%   r   c                     t        d       y )Nz
        # C start a
        # C start b
        - abc
        - ghi
        - klm
        # C end a
        # C end b
        r   r   s    r   test_main_sequence_begin_endz)TestComments.test_main_sequence_begin_endq   r%   r   c                     t        d       y )Nz
        # C start a
        # C start b
        - abc      # abc comment
        - ghi
        - klm      # klm comment
        # C end a
        # C end b
        r   r   s    r   'test_main_sequence_begin_end_items_postz4TestComments.test_main_sequence_begin_end_items_post~   r%   r   c                     t        d       y )Nz
        # C start a
        # C start b
        abc: 1
        ghi: 2
        klm:
          3a: alpha
          3b: beta   # it is all greek to me
        # C end a
        # C end b
        r   r   s    r   #test_main_mapping_begin_end_complexz0TestComments.test_main_mapping_begin_end_complex   s    
	
r   c                 $    d}t        |dd       y )Nz        hr: # 1998 hr ranking
          - Mark McGwire
          - Sammy Sosa
        rbi:
          # 1998 rbi ranking
          - Sammy Sosa
          - Ken Griffey
        r'      r)   block_seq_indentr   r    s     r   test_09zTestComments.test_09   s     	1Q3r   c                     t        d       y )Nz
        hr: # 1998 hr ranking
        - Mark McGwire
        - Sammy Sosa
        rbi:
          # 1998 rbi ranking
        - Sammy Sosa
        - Ken Griffey
        r   r   s    r   test_09azTestComments.test_09a   r%   r   c                     t        d       y )NzE
        abc: 1
        # C 3a
        # C 3b
        ghi: 2
        r   r   s    r   test_simple_map_middle_commentz+TestComments.test_simple_map_middle_comment   r   r   c                     t        d       y )Nz`
        map1: # comment 1
          # comment 2
          map2:
            key1: val1
        r   r   s    r   test_map_in_map_0zTestComments.test_map_in_map_0   r   r   c                     t        d       y )NzT
        map1:
          # comment 1
          map2:
            key1: val1
        r   r   s    r   test_map_in_map_1zTestComments.test_map_in_map_1   s    	
r   c                     t        d       y )Nz
        args:
          username: anthon
          passwd: secret
          fullname: Anthon van der Neut
          tmux:
            session-name: test
          loop:
            wait: 10
        r   r   s    r   test_application_argumentsz'TestComments.test_application_arguments   s    		
r   c                     d}t        |      }d|d   d<   |j                  dd      }t        |      t        |      k(  sJ y )Nz
        args:
          username: anthon          # name
          passwd: secret            # password
          fullname: Anthon van der Neut
          tmux:
            session-name: test
          loop:
            wait: 10
        zdeleted passwordargspasswdz: secret          z: deleted password)r   replacer   r   )r   r   datas      r   test_substitutezTestComments.test_substitute   sL    	 q!!3VXII*,@At$q	111r   c                     t        d       y )Nz
        !!set
        # the beginning
        ? a
        # next one is B (lowercase)
        ? b  #  You see? Promised you.
        ? c
        # this is the end
        r   r   s    r   test_set_commentzTestComments.test_set_comment   r%   r   c                     t        d       y )Nzd
        !!omap
        - a: 1
        - b: 2  # two
        - c: 3  # three
        - d: 4
        r   r   s    r   test_omap_comment_roundtripz(TestComments.test_omap_comment_roundtrip       	
r   c                     t        d       y )Nzw
        !!omap
        - a: 1
        - b: 2  # two
        - c: 3  # three
        # last one
        - d: 4
        r   r   s    r   'test_omap_comment_roundtrip_pre_commentz4TestComments.test_omap_comment_roundtrip_pre_comment
  s    		
r   c                     t        d       y )Nu  
        verbosity: 1                  # 0 is minimal output, -1 none
        base_url: http://gopher.net
        special_indices: [1, 5, 8]
        also_special:
        - a
        - 19
        - 32
        asia and europe: &asia_europe
          Turkey: Ankara
          Russia: Moscow
        countries:
          Asia:
            <<: *asia_europe
            Japan: Tokyo # 東京
          Europe:
            <<: *asia_europe
            Spain: Madrid
            Italy: Rome
        r   r   s    r   test_non_asciizTestComments.test_non_ascii  s    	
r   c                     dd l }t        d      }t        |      }|j                  j                  }dD ](  }|j                  j                  |d||      }||k(  r(J  y Nr   zG        ab:
        - x  # comment
        - y  # more comment
        )TFF)default_flow_styleDumperallow_unicodesrsly.ruamel_yamlr   r   ruamel_yamlRoundTripDumperdumpr   srslyr   rH   dumperutfr+   s          r   test_dump_utf8zTestComments.test_dump_utf8.  q     
 q!""22  	C!!&&vS ' A 6M6		r   c                     dd l }t        d      }t        |      }|j                  j                  }dD ](  }|j                  j                  |d||      }||k(  r(J  y rT   rX   r]   s          r   test_dump_unicode_utf8z#TestComments.test_dump_unicode_utf8@  rb   r   c                     d}t        |      }|j                  g dd      dk(  sJ t        j                  t              5  |j                  g d      dk(   d d d        y # 1 sw Y   y xY w)Nzq        a:
        - b:
          c: 42
        - d:
            f: 196
          e:
            g: 3.14
        )ar   r*   fT)list_ok   )r   mlgetr   r   r   )r   r   r*   s      r   test_mlget_00zTestComments.test_mlget_00R  sd     Aww)4w8C???]]>* 	/GG&'3.	/ 	/ 	/s   A!!A*N)__name__
__module____qualname__r   r   r   r   r"   r$   r,   r.   r0   r2   r4   r9   r;   r=   r?   rA   rC   rI   rK   rM   rP   rR   ra   rd   rk    r   r   r	   r	      s    '


'

 




4


	

2"
	



0$$/r   r	   c                   J    e Zd ZdZed        Zd Zd Zd Zd Z	d Z
d Zd	 Zy
)TestInsertPopListzslist insertion is more complex than dict insertion, as you
    need to move the values to subsequent keys on insertc                      y)Nz        ab:
        - a      # a
        - b      # b
        - c
        - d      # d

        de:
        - 1
        - 2
        ro   r   s    r   inszTestInsertPopList.insf  s    
r   c                     t        | j                        }|d   j                  dd       t        |d      }|t	        d      k(  sJ y )Nabr   xyzr6   r(   z        ab:
        - xyz
        - a      # a
        - b      # b
        - c
        - d      # d

        de:
        - 1
        - 2
        r   rs   insertr   r   r   r*   r+   s      r   test_insert_0zTestInsertPopList.test_insert_0t  L    DHH%	$q% Aa(F
 
 	
 
r   c                     t        | j                        }|d   j                  dd       t        |d      }|t	        d      k(  sJ y )Nru   r'   rv   r6   r(   z        ab:
        - a      # a
        - b      # b
        - c
        - d      # d

        - xyz
        de:
        - 1
        - 2
        rw   ry   s      r   test_insert_1zTestInsertPopList.test_insert_1  r{   r   c                     t        | j                        }|d   j                  dd       t        |d      }|t	        d      k(  sJ y )Nru   r   rv   r6   r(   z        ab:
        - a      # a
        - xyz
        - b      # b
        - c
        - d      # d

        de:
        - 1
        - 2
        rw   ry   s      r   test_insert_2zTestInsertPopList.test_insert_2  r{   r   c                     t        | j                        }|d   j                  d       t        |d      }t	        |       |t        d      k(  sJ y )Nru   r   r6   r(   zo        ab:
        - b      # b
        - c
        - d      # d

        de:
        - 1
        - 2
        r   rs   popr   printr   ry   s      r   
test_pop_0zTestInsertPopList.test_pop_0  P    DHH%	$AAa(aF	
 
 	
 
r   c                     t        | j                        }|d   j                  d       t        |d      }t	        |       |t        d      k(  sJ y )Nru   r   r6   r(   zo        ab:
        - a      # a
        - c
        - d      # d

        de:
        - 1
        - 2
        r   ry   s      r   
test_pop_1zTestInsertPopList.test_pop_1  r   r   c                     t        | j                        }|d   j                  d       t        |d      }t	        |       |t        d      k(  sJ y )Nru   r6   r(   zx        ab:
        - a      # a
        - b      # b
        - d      # d

        de:
        - 1
        - 2
        r   ry   s      r   
test_pop_2zTestInsertPopList.test_pop_2  r   r   c                     t        | j                        }|d   j                  d       t        |d      }t	        |       |t        d      k(  sJ y )Nru      r6   r(   zn        ab:
        - a      # a
        - b      # b
        - c
        de:
        - 1
        - 2
        r   ry   s      r   
test_pop_3zTestInsertPopList.test_pop_3  sP    DHH%	$AAa(aF

 

 
	
 

r   N)rl   rm   rn   __doc__propertyrs   rz   r}   r   r   r   r   r   ro   r   r   rq   rq   b  s>    <  
&
&
&
$
$
$
r   rq   c                   .    e Zd Zed        Zd Zd Zd Zy)TestInsertInMappingc                      y)Nz        first_name: Art
        occupation: Architect  # This is an occupation comment
        about: Art Vandelay is a fictional character that George invents...
        ro   r   s    r   rs   zTestInsertInMapping.ins  s    r   c                     t        | j                        }|j                  dddd       t        |      }t	        |       |t        d      k(  sJ y )Nr   	last nameVandelaynew keycommentz        first_name: Art
        last name: Vandelay    # new key
        occupation: Architect  # This is an occupation comment
        about: Art Vandelay is a fictional character that George invents...
        r   rs   rx   r   r   r   ry   s      r   test_insert_at_pos_1z(TestInsertInMapping.test_insert_at_pos_1   S    DHH%	KY?AaF
 
 	
 
r   c                     t        | j                        }|j                  dddd       t        |      }t	        |       |t        d      k(  sJ y )Nr   r   r   r   r   z        last name: Vandelay  # new key
        first_name: Art
        occupation: Architect  # This is an occupation comment
        about: Art Vandelay is a fictional character that George invents...
        r   ry   s      r   test_insert_at_pos_0z(TestInsertInMapping.test_insert_at_pos_0  r   r   c                     t        | j                        }|j                  dddd       t        |      }t	        |       |t        d      k(  sJ y )Nr   r   r   r   r   z        first_name: Art
        occupation: Architect  # This is an occupation comment
        about: Art Vandelay is a fictional character that George invents...
        last name: Vandelay  # new key
        r   ry   s      r   test_insert_at_pos_3z(TestInsertInMapping.test_insert_at_pos_3  sS    DHH%	KY?AaF
 
 	
 
r   N)rl   rm   rn   r   rs   r   r   r   ro   r   r   r   r     s#     


r   r   c                       e Zd Zd Zd Zd Zy)TestCommentedMapMergec                 r    t        d      }|d   d   dk(  sJ d|d   v sJ |d   d   dk(  sJ d|d   v sJ y )Nz
        x: &base
          a: 1
          b: 2
          c: 3
        y:
          <<: *base
          k: 4
          l: 5
        r   rf   r   r+   )r   r   rH   s     r   test_in_operatorz&TestCommentedMapMerge.test_in_operator-  sc    	
 Cy~"""d3iCy~"""d3ir   c                     t        d      }|d   d   dk(  sJ |d   d   dk(  sJ t        j                  dk\  rt        |d         dk(  sJ y t        |d         dk(  sJ y )	NzH
        x: &base
          a: 1
        y:
          <<: *base
        r   rf   r   r+   r      zordereddict({'a': 1})zordereddict([('a', 1)])r   sysversion_infostrr   s     r   test_issue_60z#TestCommentedMapMerge.test_issue_60?  s{    
 Cy~"""Cy~"""w&tCy>%@@@@tCy>%BBBBr   c                     t        d      }|d   d   dk(  sJ |d   d   dk(  sJ t        j                  dk\  rt        |d         dk(  sJ y t        |d         dk(  sJ y )	NzW
        x: &base
          a: 1
        y:
          <<: *base
          b: 2
        r   rf   r   r+   r   zordereddict({'b': 2, 'a': 1})z!ordereddict([('b', 2), ('a', 1)])r   r   s     r   test_issue_60_1z%TestCommentedMapMerge.test_issue_60_1O  s{    
 Cy~"""Cy~"""w&tCy>%HHHHtCy>%LLLLr   N)rl   rm   rn   r   r   r   ro   r   r   r   r   ,  s     $C Mr   r   c                       e Zd Zd Zd Zej                  j                  d      d        Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zy)TestEmptyLinesc                 \    t        d      }t        |d      }t        |d      }||k(  sJ y )Na          ---
        # Please add key/value pairs in alphabetical order

        aws_s3_bucket: 'mys3bucket'

        jenkins_ad_credentials:
          bind_name: 'CN=svc-AAA-BBB-T,OU=Example,DC=COM,DC=EXAMPLE,DC=Local'
          bind_pass: 'xxxxyyyy{'
        Tpreserve_quotesexplicit_startr   r   r   r   yaml_strr*   r+   s       r   test_issue_46zTestEmptyLines.test_issue_46c  s7    	
 Hd;Ad31}}r   c                     t        d       y )NzH
        a: 1x

        b: 2x


        c: 3x



        d: 4x

        r   r   s    r   test_multispace_mapz"TestEmptyLines.test_multispace_mapt      	
r   T)strictc                     t        d       y )NzI

        a: 1x

        b: 2x


        c: 3x



        d: 4x

        r   r   s    r   test_multispace_map_initialz*TestEmptyLines.test_multispace_map_initial  s    	
r   c                     t        d       y )Nz:
        - a: 1y
          b: 2y

          c: 3y
        r   r   s    r   test_embedded_mapz TestEmptyLines.test_embedded_map  r   r   c                     t        d       y )Nz.        - 1

        - 2

        - 3
        r   r   s    r   test_toplevel_seqz TestEmptyLines.test_toplevel_seq  rN   r   c                     t        d       y )NzN
        a:
          b:
          - 1

          - 2


          - 3
        r   r   s    r   test_embedded_seqz TestEmptyLines.test_embedded_seq  r   r   c                     d}t        |d      }t        |d      }d}|j                         D ]&  }||j                         dz   z  }t	        |dz          ( ||k(  sJ y )Nz---

a: 'x'
 
b: y
Tr   r    r   $r   r   
splitlinesrstripr   r   r   r*   r+   strippedlines         r   test_line_with_only_spacesz)TestEmptyLines.test_line_with_only_spaces  sk    -Hd;Ad3'') 	D,,H$*	 1}}r   c                     d}t        |d      }t        |d      }d}|j                         D ]&  }||j                         dz   z  }t	        |dz          ( ||k(  sJ y )Nz---  
  
a: "x"  
   
b: y  
Tr   r   r   r   r   r   r   s         r   test_some_eol_spacesz#TestEmptyLines.test_some_eol_spaces  sk    7Hd;Ad3'') 	D,,H$*	 1}}r   c                     t        d      }t        |      }t        |j                         t	        |d      }t        |j                  dd             ||k(  sJ y )NzP        toplevel:

            # some comment
            sublevel: 300
        r'   r(   r   z$
)r   r   r   car   rG   r   s       r   test_issue_54_not_okz#TestEmptyLines.test_issue_54_not_ok  sS    
 H%addAa(aiie$%1}}r   c                 X    t        d      }t        |      }t        |d      }||k(  sJ y )NzO        toplevel:
            # some comment
            sublevel: 300
        r'   r(   r   r   s       r   test_issue_54_okzTestEmptyLines.test_issue_54_ok  s5    
 H%Aa(1}}r   c                     t        d       y )Nzz        a:
          b:
          - c1: cat  # a1
          # my comment on catfish
          - c2: catfish  # a2
        r   r   s    r   test_issue_93zTestEmptyLines.test_issue_93  rN   r   c                     t        d       y )Nzn        a:
        - - c1: cat   # a1
          # my comment on catfish
          - c2: catfish  # a2
        r   r   s    r   test_issue_93_00zTestEmptyLines.test_issue_93_00  r   r   c                     t        d       y )Nzc        - - c1: cat   # a1
          # my comment on catfish
          - c2: catfish  # a2
        r   r   s    r   test_issue_93_01zTestEmptyLines.test_issue_93_01      	
r   c                     t        d       y )NzP        - c1: cat
        # my comment on catfish
        - c2: catfish
        r   r   s    r   test_issue_93_02zTestEmptyLines.test_issue_93_02
  s    	
r   c                     t        d       y )Nzg        a:
          b:
            c: c_val
            d:

          e:
            g: g_val
        r   r   s    r   test_issue_96zTestEmptyLines.test_issue_96  s    
	
r   N)rl   rm   rn   r   r   r   markxfailr   r   r   r   r   r   r   r   r   r   r   r   r   ro   r   r   r   r   a  sn    "
" [[d#
 $
$
	

		
	




r   r   c                   l    e Zd Zej                  j                  ej                  dk  d      d        Zy)TestUnicodeComments)r6      zwide unicode)reasonc                     t        d       y )Nu          name: TEST
        description: test using
        author: Harguroicha
        sql:
          command: |-
            select name from testtbl where no = :no

          ci-test:
          - :no: 04043709 # 小花
          - :no: 05161690 # 茶
          - :no: 05293147 # 〇𤋥川
          - :no: 05338777 # 〇〇啓
          - :no: 05273867 # 〇
          - :no: 05205786 # 〇𤦌
        r   r   s    r   test_issue_55z!TestUnicodeComments.test_issue_55$  s    	
r   N)	rl   rm   rn   r   r   skipifr   r   r   ro   r   r   r   r   #  s4    [[((61.I
 J
r   r   c                   N    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)TestEmptyValueBeforeCommentsc                     t        d       y )NzK        - a: b
          c: d
          d:  # foo
          - e: f
        r   r   s    r   test_issue_25az+TestEmptyValueBeforeComments.test_issue_25a;  r   r   c                     t        d       y )NzK        - a: b
          c: d
          d:  # foo
            e: f
        r   r   s    r   test_issue_25a1z,TestEmptyValueBeforeComments.test_issue_25a1E  r   r   c                     t        d       y )Nz?        var1: #empty
        var2: something #notempty
        r   r   s    r   test_issue_25bz+TestEmptyValueBeforeComments.test_issue_25bO  s    	
r   c                     t        d       y )Nzi        params:
          a: 1 # comment a
          b:   # comment b
          c: 3 # comment c
        r   r   s    r   test_issue_25cz+TestEmptyValueBeforeComments.test_issue_25cW  r   r   c                     t        d       y )Nz{        params:
          a: 1 # comment a
          b:   # comment b
          # extra
          c: 3 # comment c
        r   r   s    r   test_issue_25c1z,TestEmptyValueBeforeComments.test_issue_25c1a  rN   r   c                     t        d       y )NzN        params:
          a: 1 # comment a
          b:   # comment b
        r   r   s    r   test_issue_25_00z-TestEmptyValueBeforeComments.test_issue_25_00l  r   r   c                     t        d       y )Nz        a:        # comment 1
                  #  comment 2
        - b:      #   comment 3
            c: 1  #    comment 4
        r   r   s    r   test_issue_25_01z-TestEmptyValueBeforeComments.test_issue_25_01u  r   r   c                     t        d       y )Nze        a:        # comment 1
                  #  comment 2
        - b: 2    #   comment 3
        r   r   s    r   test_issue_25_02z-TestEmptyValueBeforeComments.test_issue_25_02  r   r   c                 $    d}t        |dd       y )Nze        a:        # comment 1
                  #  comment 2
          - b: 2  #   comment 3
        r'   r6   r7   r   r    s     r   test_issue_25_03z-TestEmptyValueBeforeComments.test_issue_25_03  s    
 	1Q3r   c                     t        d       y )Nze        a:        # comment 1
                  #  comment 2
          b: 1    #   comment 3
        r   r   s    r   test_issue_25_04z-TestEmptyValueBeforeComments.test_issue_25_04  r   r   c                     t        d       y )Nz        # comment 1
        - a
        - b
        # comment 2
        - c
        - d
        # comment 3
        - [e]
        - f
        # comment 4
        - []
        r   r   s    r   test_flow_seq_within_seqz5TestEmptyValueBeforeComments.test_flow_seq_within_seq  r   r   N)rl   rm   rn   r   r   r   r   r   r   r   r   r   r   r  ro   r   r   r   r   :  s9    



	



4

r   r   z%y: p
# Some comment

a: |
  x
{}b: y
c                       e Zd Zd Zy)TestBlockScalarWithCommentsc                     dd l }dD ]R  }t        j                  |      }|j                  j	                  |      }|j                  j                  |      |k(  rRJ  y )Nr   )r   r   z
# Another comment
z



# abc
#xyz
r  z# abc

#xyz
z

  # abc
  #xyz
)rY   )test_block_scalar_commented_line_templateformatrZ   r   r   )r   r^   r   commented_linerH   s        r   test_scalar_with_commentsz5TestBlockScalarWithComments.test_scalar_with_comments  s`     	
 	MA GMMaPN$$44^DD$$44T:nLLL	Mr   N)rl   rm   rn   r	  ro   r   r   r  r    s    Mr   r  )r   r   r   	roundtripr   r   r   r   r	   rq   r   r   r   r   r   r  r  ro   r   r   <module>r     s     
 K KL/ L/^
P
 P
j2
 2
j2M 2Mj
 
D
 
.n
 n
b- )M Mr   