o
    
iIP                     @   s   d Z ddlZddlZddlmZmZmZmZ G dd dZG dd dZ	G d	d
 d
Z
G dd dZG dd dZG dd dZG dd dZdZG dd dZdS )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                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3S )4TestCommentsc                 C   sL   d}t |dd tt t |dd W d   dS 1 sw   Y  dS )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x r   Y/home/ubuntu/.local/lib/python3.10/site-packages/srsly/tests/ruamel_yaml/test_comments.pytest_no_end_of_file_eol   s
   "z$TestComments.test_no_end_of_file_eolc                 C      t d d S )Nz[
        - europe: 10
        - usa:
          - ohio: 2
          - california: 9
        r   r   r   r   r   test_no_comments      zTestComments.test_no_commentsc                 C   r   )Nzs
        a: 1
        b: 2
        c: 3
        b1: 2
        b2: 2
        d: 4
        e: 5
        f: 6
        r   r   r   r   r   test_round_trip_ordering'   r   z%TestComments.test_round_trip_orderingc                 C   r   )Nze
        - europe: 10 # top
        - usa:
          - ohio: 2
          - california: 9 # o
        r   r   r   r   r   test_complex5   r   zTestComments.test_complexc                 C   s   d}t |d d S )Nz5        # comment
        scalar
        ...
        zscalar
...
r   r   sr   r   r   test_dropped?   s   zTestComments.test_droppedc                 C   r   )Nz
        # C start a
        # C start b
        abc: 1
        ghi: 2
        klm: 3
        # C end a
        # C end b
        r   r   r   r   r   test_main_mapping_begin_endG   r   z(TestComments.test_main_mapping_begin_endc                 C   s,   d}t |}t|dd}|tdksJ d S )NzM        a:
          b:     # comment 1
            c: 1 # comment 2
           indentzQ        a:
            b:   # comment 1
                c: 1 # comment 2
        )r   r   r   )r   r   dyr   r   r   test_reindentT   s   zTestComments.test_reindentc                 C   r   )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   r   r   r   &test_main_mapping_begin_end_items_postd   r   z3TestComments.test_main_mapping_begin_end_items_postc                 C   r   )Nz
        # C start a
        # C start b
        - abc
        - ghi
        - klm
        # C end a
        # C end b
        r   r   r   r   r   test_main_sequence_begin_endq   r   z)TestComments.test_main_sequence_begin_endc                 C   r   )Nz
        # C start a
        # C start b
        - abc      # abc comment
        - ghi
        - klm      # klm comment
        # C end a
        # C end b
        r   r   r   r   r   'test_main_sequence_begin_end_items_post~   r   z4TestComments.test_main_sequence_begin_end_items_postc                 C   r   )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   r   r   r   #test_main_mapping_begin_end_complex   r   z0TestComments.test_main_mapping_begin_end_complexc                 C      d}t |ddd d S )Nz        hr: # 1998 hr ranking
          - Mark McGwire
          - Sammy Sosa
        rbi:
          # 1998 rbi ranking
          - Sammy Sosa
          - Ken Griffey
        r      r   block_seq_indentr   r   r   r   r   test_09   s   	zTestComments.test_09c                 C   r   )Nz
        hr: # 1998 hr ranking
        - Mark McGwire
        - Sammy Sosa
        rbi:
          # 1998 rbi ranking
        - Sammy Sosa
        - Ken Griffey
        r   r   r   r   r   test_09a   r   zTestComments.test_09ac                 C   r   )NzE
        abc: 1
        # C 3a
        # C 3b
        ghi: 2
        r   r   r   r   r   test_simple_map_middle_comment   r   z+TestComments.test_simple_map_middle_commentc                 C   r   )Nz`
        map1: # comment 1
          # comment 2
          map2:
            key1: val1
        r   r   r   r   r   test_map_in_map_0   r   zTestComments.test_map_in_map_0c                 C   r   )NzT
        map1:
          # comment 1
          map2:
            key1: val1
        r   r   r   r   r   test_map_in_map_1      zTestComments.test_map_in_map_1c                 C   r   )Nz
        args:
          username: anthon
          passwd: secret
          fullname: Anthon van der Neut
          tmux:
            session-name: test
          loop:
            wait: 10
        r   r   r   r   r   test_application_arguments   r0   z'TestComments.test_application_argumentsc                 C   s<   d}t |}d|d d< |dd}t|t|ksJ d S )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   datar   r   r   test_substitute   s
   
zTestComments.test_substitutec                 C   r   )Nz
        !!set
        # the beginning
        ? a
        # next one is B (lowercase)
        ? b  #  You see? Promised you.
        ? c
        # this is the end
        r   r   r   r   r   test_set_comment   r   zTestComments.test_set_commentc                 C   r   )Nzd
        !!omap
        - a: 1
        - b: 2  # two
        - c: 3  # three
        - d: 4
        r   r   r   r   r   test_omap_comment_roundtrip   r   z(TestComments.test_omap_comment_roundtripc                 C   r   )Nzw
        !!omap
        - a: 1
        - b: 2  # two
        - c: 3  # three
        # last one
        - d: 4
        r   r   r   r   r   'test_omap_comment_roundtrip_pre_comment
  r   z4TestComments.test_omap_comment_roundtrip_pre_commentc                 C   r   )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   r   r   r   test_non_ascii  r   zTestComments.test_non_asciic                 C   N   dd l }td}t|}|jj}dD ]}|jj|d||d}||ks$J qd S 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   r5   dumperutfr!   r   r   r   test_dump_utf8.     zTestComments.test_dump_utf8c                 C   r;   r<   r@   rE   r   r   r   test_dump_unicode_utf8@  rJ   z#TestComments.test_dump_unicode_utf8c                 C   sh   d}t |}|jg ddddksJ tt |g ddk W d    d S 1 s-w   Y  d S )Nzq        a:
        - b:
          c: 42
        - d:
            f: 196
          e:
            g: 3.14
        )ar   r    fT)list_ok   )r   mlgetr
   r   r   )r   r   r    r   r   r   test_mlget_00R  s   	"zTestComments.test_mlget_00N)__name__
__module____qualname__r   r   r   r   r   r   r"   r#   r$   r%   r&   r+   r,   r-   r.   r/   r1   r6   r7   r8   r9   r:   rI   rK   rQ   r   r   r   r   r      s4    	



r   c                   @   sT   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd ZdS )TestInsertPopListzslist insertion is more complex than dict insertion, as you
    need to move the values to subsequent keys on insertc                 C      dS )Nz        ab:
        - a      # a
        - b      # b
        - c
        - d      # d

        de:
        - 1
        - 2
        r   r   r   r   r   insf     zTestInsertPopList.insc                 C   :   t | j}|d dd t|dd}|tdksJ d S )Nabr   xyzr(   r   z        ab:
        - xyz
        - a      # a
        - b      # b
        - c
        - d      # d

        de:
        - 1
        - 2
        r   rW   insertr   r   r   r    r!   r   r   r   test_insert_0t     
zTestInsertPopList.test_insert_0c                 C   rY   )NrZ   r   r[   r(   r   z        ab:
        - a      # a
        - b      # b
        - c
        - d      # d

        - xyz
        de:
        - 1
        - 2
        r\   r^   r   r   r   test_insert_1  r`   zTestInsertPopList.test_insert_1c                 C   rY   )NrZ   r   r[   r(   r   z        ab:
        - a      # a
        - xyz
        - b      # b
        - c
        - d      # d

        de:
        - 1
        - 2
        r\   r^   r   r   r   test_insert_2  r`   zTestInsertPopList.test_insert_2c                 C   @   t | j}|d d t|dd}t| |tdksJ d S )NrZ   r   r(   r   zo        ab:
        - b      # b
        - c
        - d      # d

        de:
        - 1
        - 2
        r   rW   popr   printr   r^   r   r   r   
test_pop_0     
zTestInsertPopList.test_pop_0c                 C   rc   )NrZ   r   r(   r   zo        ab:
        - a      # a
        - c
        - d      # d

        de:
        - 1
        - 2
        rd   r^   r   r   r   
test_pop_1  rh   zTestInsertPopList.test_pop_1c                 C   s@   t | j}|d d t|dd}t| |tdksJ d S )NrZ   r(   r   zx        ab:
        - a      # a
        - b      # b
        - d      # d

        de:
        - 1
        - 2
        rd   r^   r   r   r   
test_pop_2  rh   zTestInsertPopList.test_pop_2c                 C   rc   )NrZ      r(   r   zn        ab:
        - a      # a
        - b      # b
        - c
        de:
        - 1
        - 2
        rd   r^   r   r   r   
test_pop_3  rh   zTestInsertPopList.test_pop_3N)rR   rS   rT   __doc__propertyrW   r_   ra   rb   rg   ri   rj   rl   r   r   r   r   rU   b  s    
rU   c                   @   s0   e Zd Zedd Zdd Zdd Zdd Zd	S )
TestInsertInMappingc                 C   rV   )Nz        first_name: Art
        occupation: Architect  # This is an occupation comment
        about: Art Vandelay is a fictional character that George invents...
        r   r   r   r   r   rW     rX   zTestInsertInMapping.insc                 C   @   t | j}|jddddd t|}t| |tdksJ d S )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   rW   r]   r   rf   r   r^   r   r   r   test_insert_at_pos_1      
z(TestInsertInMapping.test_insert_at_pos_1c                 C   rp   )Nr   rq   rr   rs   rt   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...
        rv   r^   r   r   r   test_insert_at_pos_0  rx   z(TestInsertInMapping.test_insert_at_pos_0c                 C   rp   )Nrk   rq   rr   rs   rt   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
        rv   r^   r   r   r   test_insert_at_pos_3  s   
z(TestInsertInMapping.test_insert_at_pos_3N)rR   rS   rT   rn   rW   rw   ry   rz   r   r   r   r   ro     s    
ro   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestCommentedMapMergec                 C   sT   t d}|d d dksJ d|d v sJ |d d dks J d|d v s(J d S )Nz
        x: &base
          a: 1
          b: 2
          c: 3
        y:
          <<: *base
          k: 4
          l: 5
        r   rL   r   r!   )r   r   r5   r   r   r   test_in_operator-  s   z&TestCommentedMapMerge.test_in_operatorc                 C   j   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 d S t|d dks3J d S )	NzH
        x: &base
          a: 1
        y:
          <<: *base
        r   rL   r   r!   rk      zordereddict({'a': 1})zordereddict([('a', 1)])r   sysversion_infostrr|   r   r   r   test_issue_60?  s   
z#TestCommentedMapMerge.test_issue_60c                 C   r~   )	NzW
        x: &base
          a: 1
        y:
          <<: *base
          b: 2
        r   rL   r   r!   r   zordereddict({'b': 2, 'a': 1})z!ordereddict([('b', 2), ('a', 1)])r   r|   r   r   r   test_issue_60_1O  s   	
z%TestCommentedMapMerge.test_issue_60_1N)rR   rS   rT   r}   r   r   r   r   r   r   r{   ,  s    r{   c                   @   s   e Zd Zdd Zdd Zejjdddd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!S )"TestEmptyLinesc                 C   s0   t d}t|dd}t|dd}||ksJ d S )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!   r   r   r   test_issue_46c  s   zTestEmptyLines.test_issue_46c                 C   r   )NzH
        a: 1x

        b: 2x


        c: 3x



        d: 4x

        r   r   r   r   r   test_multispace_mapt  r   z"TestEmptyLines.test_multispace_mapT)strictc                 C   r   )NzI

        a: 1x

        b: 2x


        c: 3x



        d: 4x

        r   r   r   r   r   test_multispace_map_initial  r0   z*TestEmptyLines.test_multispace_map_initialc                 C   r   )Nz:
        - a: 1y
          b: 2y

          c: 3y
        r   r   r   r   r   test_embedded_map  r   z TestEmptyLines.test_embedded_mapc                 C   r   )Nz.        - 1

        - 2

        - 3
        r   r   r   r   r   test_toplevel_seq  r   z TestEmptyLines.test_toplevel_seqc                 C   r   )NzN
        a:
          b:
          - 1

          - 2


          - 3
        r   r   r   r   r   test_embedded_seq  r   z TestEmptyLines.test_embedded_seqc                 C   Z   d}t |dd}t|dd}d}| D ]}|| d 7 }t|d  q||ks+J d S )Nz---

a: 'x'
 
b: y
Tr   r    r   $r   r   
splitlinesrstriprf   r   r   r    r!   strippedliner   r   r   test_line_with_only_spaces     z)TestEmptyLines.test_line_with_only_spacesc                 C   r   )Nz---  
  
a: "x"  
   
b: y  
Tr   r   r   r   r   r   r   r   r   r   test_some_eol_spaces  r   z#TestEmptyLines.test_some_eol_spacesc                 C   sF   t d}t|}t|j t|dd}t|dd ||ks!J d S )NzP        toplevel:

            # some comment
            sublevel: 300
        r   r   r   z$
)r   r   rf   car   r4   r   r   r   r   test_issue_54_not_ok  s   
z#TestEmptyLines.test_issue_54_not_okc                 C   s,   t d}t|}t|dd}||ksJ d S )NzO        toplevel:
            # some comment
            sublevel: 300
        r   r   r   r   r   r   r   test_issue_54_ok  s   zTestEmptyLines.test_issue_54_okc                 C   r   )Nzz        a:
          b:
          - c1: cat  # a1
          # my comment on catfish
          - c2: catfish  # a2
        r   r   r   r   r   test_issue_93  r   zTestEmptyLines.test_issue_93c                 C   r   )Nzn        a:
        - - c1: cat   # a1
          # my comment on catfish
          - c2: catfish  # a2
        r   r   r   r   r   test_issue_93_00  r   zTestEmptyLines.test_issue_93_00c                 C   r   )Nzc        - - c1: cat   # a1
          # my comment on catfish
          - c2: catfish  # a2
        r   r   r   r   r   test_issue_93_01  r   zTestEmptyLines.test_issue_93_01c                 C   r   )NzP        - c1: cat
        # my comment on catfish
        - c2: catfish
        r   r   r   r   r   test_issue_93_02
  r0   zTestEmptyLines.test_issue_93_02c                 C   r   )Nzg        a:
          b:
            c: c_val
            d:

          e:
            g: g_val
        r   r   r   r   r   test_issue_96  r0   zTestEmptyLines.test_issue_96N)rR   rS   rT   r   r   r
   markxfailr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   a  s"    


	
r   c                   @   s*   e Zd Zejjejdk dddd ZdS )TestUnicodeComments)r(      zwide unicode)reasonc                 C   r   )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   r   r   r   test_issue_55$  r0   z!TestUnicodeComments.test_issue_55N)	rR   rS   rT   r
   r   skipifr   r   r   r   r   r   r   r   #  s    r   c                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )TestEmptyValueBeforeCommentsc                 C   r   )NzK        - a: b
          c: d
          d:  # foo
          - e: f
        r   r   r   r   r   test_issue_25a;  r   z+TestEmptyValueBeforeComments.test_issue_25ac                 C   r   )NzK        - a: b
          c: d
          d:  # foo
            e: f
        r   r   r   r   r   test_issue_25a1E  r   z,TestEmptyValueBeforeComments.test_issue_25a1c                 C   r   )Nz?        var1: #empty
        var2: something #notempty
        r   r   r   r   r   test_issue_25bO  r   z+TestEmptyValueBeforeComments.test_issue_25bc                 C   r   )Nzi        params:
          a: 1 # comment a
          b:   # comment b
          c: 3 # comment c
        r   r   r   r   r   test_issue_25cW  r   z+TestEmptyValueBeforeComments.test_issue_25cc                 C   r   )Nz{        params:
          a: 1 # comment a
          b:   # comment b
          # extra
          c: 3 # comment c
        r   r   r   r   r   test_issue_25c1a  r   z,TestEmptyValueBeforeComments.test_issue_25c1c                 C   r   )NzN        params:
          a: 1 # comment a
          b:   # comment b
        r   r   r   r   r   test_issue_25_00l  r   z-TestEmptyValueBeforeComments.test_issue_25_00c                 C   r   )Nz        a:        # comment 1
                  #  comment 2
        - b:      #   comment 3
            c: 1  #    comment 4
        r   r   r   r   r   test_issue_25_01u  r   z-TestEmptyValueBeforeComments.test_issue_25_01c                 C   r   )Nze        a:        # comment 1
                  #  comment 2
        - b: 2    #   comment 3
        r   r   r   r   r   test_issue_25_02  r   z-TestEmptyValueBeforeComments.test_issue_25_02c                 C   r'   )Nze        a:        # comment 1
                  #  comment 2
          - b: 2  #   comment 3
        r   r(   r)   r   r   r   r   r   test_issue_25_03  s   z-TestEmptyValueBeforeComments.test_issue_25_03c                 C   r   )Nze        a:        # comment 1
                  #  comment 2
          b: 1    #   comment 3
        r   r   r   r   r   test_issue_25_04  r   z-TestEmptyValueBeforeComments.test_issue_25_04c                 C   r   )Nz        # comment 1
        - a
        - b
        # comment 2
        - c
        - d
        # comment 3
        - [e]
        - f
        # comment 4
        - []
        r   r   r   r   r   test_flow_seq_within_seq  r   z5TestEmptyValueBeforeComments.test_flow_seq_within_seqN)rR   rS   rT   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   :  s    


	
		r   z%y: p
# Some comment

a: |
  x
{}b: y
c                   @   s   e Zd Zdd ZdS )TestBlockScalarWithCommentsc                 C   s@   dd l }dD ]}t|}|j|}|j||ksJ qd S )Nr   )r   r   z
# Another comment
z



# abc
#xyz
r   z# abc

#xyz
z

  # abc
  #xyz
)rA   )test_block_scalar_commented_line_templateformatrB   r   r   )r   rF   r   commented_liner5   r   r   r   test_scalar_with_comments  s   
z5TestBlockScalarWithComments.test_scalar_with_commentsN)rR   rS   rT   r   r   r   r   r   r     s    r   )rm   r
   r   	roundtripr   r   r   r   r   rU   ro   r{   r   r   r   r   r   r   r   r   r   <module>   s"   
  Q 55 Cq
