3
dKO                 @   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   s6   d}t |dd tjt t |dd W dQ R X 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/var/www/html/virt/lib64/python3.6/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   s   t d d S )Nz[
        - europe: 10
        - usa:
          - ohio: 2
          - california: 9
        )r   )r   r   r   r   test_no_comments   s    zTestComments.test_no_commentsc             C   s   t d d S )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'   s    
z%TestComments.test_round_trip_orderingc             C   s   t d d S )Nze
        - europe: 10 # top
        - usa:
          - ohio: 2
          - california: 9 # o
        )r   )r   r   r   r   test_complex5   s    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   s   t d d S )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   s    	z(TestComments.test_main_mapping_begin_endc             C   s,   d}t |}t|dd}|tdks(t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   r   dyr   r   r   test_reindentT   s
    zTestComments.test_reindentc             C   s   t d d S )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   s    	z3TestComments.test_main_mapping_begin_end_items_postc             C   s   t d d S )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   s    	z)TestComments.test_main_sequence_begin_endc             C   s   t d d S )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~   s    	z4TestComments.test_main_sequence_begin_end_items_postc             C   s   t d d S )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   s    z0TestComments.test_main_mapping_begin_end_complexc             C   s   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_indent)r   )r   r   r   r   r   test_09   s    	zTestComments.test_09c             C   s   t d d S )Nz
        hr: # 1998 hr ranking
        - Mark McGwire
        - Sammy Sosa
        rbi:
          # 1998 rbi ranking
        - Sammy Sosa
        - Ken Griffey
        )r   )r   r   r   r   test_09a   s    	zTestComments.test_09ac             C   s   t d d S )NzE
        abc: 1
        # C 3a
        # C 3b
        ghi: 2
        )r   )r   r   r   r   test_simple_map_middle_comment   s    z+TestComments.test_simple_map_middle_commentc             C   s   t d d S )Nz`
        map1: # comment 1
          # comment 2
          map2:
            key1: val1
        )r   )r   r   r   r   test_map_in_map_0   s    zTestComments.test_map_in_map_0c             C   s   t d d S )NzT
        map1:
          # comment 1
          map2:
            key1: val1
        )r   )r   r   r   r   test_map_in_map_1   s    zTestComments.test_map_in_map_1c             C   s   t d d S )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   s    
z'TestComments.test_application_argumentsc             C   s<   d}t |}d|d d< |jdd}t|t|ks8t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   r   datar   r   r   test_substitute   s
    
zTestComments.test_substitutec             C   s   t d d S )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   s    	zTestComments.test_set_commentc             C   s   t d d S )Nzd
        !!omap
        - a: 1
        - b: 2  # two
        - c: 3  # three
        - d: 4
        )r   )r   r   r   r   test_omap_comment_roundtrip   s    z(TestComments.test_omap_comment_roundtripc             C   s   t d d S )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
  s    z4TestComments.test_omap_comment_roundtrip_pre_commentc             C   s   t d d S )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  s    zTestComments.test_non_asciic             C   sR   dd l }td}t|}|jj}x,dD ]$}|jj|d||d}||ks&tq&W d S )Nr   zG        ab:
        - x  # comment
        - y  # more comment
        TF)default_flow_styleDumperallow_unicode)TF)srsly.ruamel_yamlr   r   ruamel_yamlRoundTripDumperdumpr   )r   srslyr   r,   dumperutfr   r   r   r   test_dump_utf8.  s    
zTestComments.test_dump_utf8c             C   sR   dd l }td}t|}|jj}x,dD ]$}|jj|d||d}||ks&tq&W d S )Nr   zG        ab:
        - x  # comment
        - y  # more comment
        TF)r2   r3   r4   )TF)r5   r   r   r6   r7   r8   r   )r   r9   r   r,   r:   r;   r   r   r   r   test_dump_unicode_utf8@  s    
z#TestComments.test_dump_unicode_utf8c             C   sZ   d}t |}|jddddgdddks*ttjt |jddddgdk W d Q R X d S )	Nzq        a:
        - b:
          c: 42
        - d:
            f: 196
          e:
            g: 3.14
        ar   r   fT)Zlist_ok   )r   Z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'   r(   r-   r.   r/   r0   r1   r<   r=   rA   r   r   r   r   r      s2   	



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   s   dS )Nz        ab:
        - a      # a
        - b      # b
        - c
        - d      # d

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

        de:
        - 1
        - 2
        )r   rF   insertr   r   r   )r   r   r   r   r   r   test_insert_0t  s
    
zTestInsertPopList.test_insert_0c             C   s:   t | j}|d jdd t|dd}|tdks6td S )NrG   r   rH   r!   )r   z        ab:
        - a      # a
        - b      # b
        - c
        - d      # d

        - xyz
        de:
        - 1
        - 2
        )r   rF   rI   r   r   r   )r   r   r   r   r   r   test_insert_1  s
    
zTestInsertPopList.test_insert_1c             C   s:   t | j}|d jdd t|dd}|tdks6td S )NrG   r   rH   r!   )r   z        ab:
        - a      # a
        - xyz
        - b      # b
        - c
        - d      # d

        de:
        - 1
        - 2
        )r   rF   rI   r   r   r   )r   r   r   r   r   r   test_insert_2  s
    
zTestInsertPopList.test_insert_2c             C   s@   t | j}|d jd t|dd}t| |tdks<td S )NrG   r   r!   )r   zo        ab:
        - b      # b
        - c
        - d      # d

        de:
        - 1
        - 2
        )r   rF   popr   printr   r   )r   r   r   r   r   r   
test_pop_0  s    

zTestInsertPopList.test_pop_0c             C   s@   t | j}|d jd t|dd}t| |tdks<td S )NrG   r   r!   )r   zo        ab:
        - a      # a
        - c
        - d      # d

        de:
        - 1
        - 2
        )r   rF   rM   r   rN   r   r   )r   r   r   r   r   r   
test_pop_1  s    

zTestInsertPopList.test_pop_1c             C   s@   t | j}|d jd t|dd}t| |tdks<td S )NrG   r!   )r   zx        ab:
        - a      # a
        - b      # b
        - d      # d

        de:
        - 1
        - 2
        )r   rF   rM   r   rN   r   r   )r   r   r   r   r   r   
test_pop_2  s    

zTestInsertPopList.test_pop_2c             C   s@   t | j}|d jd t|dd}t| |tdks<td S )NrG      r!   )r   zn        ab:
        - a      # a
        - b      # b
        - c
        de:
        - 1
        - 2
        )r   rF   rM   r   rN   r   r   )r   r   r   r   r   r   
test_pop_3  s    
	zTestInsertPopList.test_pop_3N)rB   rC   rD   __doc__propertyrF   rJ   rK   rL   rO   rP   rQ   rS   r   r   r   r   rE   b  s   rE   c               @   s0   e Zd Zedd Zdd Zdd Zdd Zd	S )
TestInsertInMappingc             C   s   dS )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   rF     s    zTestInsertInMapping.insc             C   s@   t | j}|jddddd t|}t| |tdks<td S )Nr   z	last nameVandelayz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   rF   rI   r   rN   r   r   )r   r   r   r   r   r   test_insert_at_pos_1   s    
z(TestInsertInMapping.test_insert_at_pos_1c             C   s@   t | j}|jddddd t|}t| |tdks<td S )Nr   z	last namerW   znew key)rX   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   rF   rI   r   rN   r   r   )r   r   r   r   r   r   test_insert_at_pos_0  s    
z(TestInsertInMapping.test_insert_at_pos_0c             C   s@   t | j}|jddddd t|}t| |tdks<td S )NrR   z	last namerW   znew key)rX   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   rF   rI   r   rN   r   r   )r   r   r   r   r   r   test_insert_at_pos_3  s    
z(TestInsertInMapping.test_insert_at_pos_3N)rB   rC   rD   rU   rF   rY   rZ   r[   r   r   r   r   rV     s   rV   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td|d ks,t|d d dks@td|d ksPtd S )Nz
        x: &base
          a: 1
          b: 2
          c: 3
        y:
          <<: *base
          k: 4
          l: 5
        r   r>   r   r   )r   r   )r   r,   r   r   r   test_in_operator-  s    
z&TestCommentedMapMerge.test_in_operatorc             C   sH   t d}|d d dkst|d d dks0tt|d dksDtd S )NzH
        x: &base
          a: 1
        y:
          <<: *base
        r   r>   r   r   zordereddict([('a', 1)]))r   r   str)r   r,   r   r   r   test_issue_60?  s
    z#TestCommentedMapMerge.test_issue_60c             C   sH   t d}|d d dkst|d d dks0tt|d dksDtd S )NzW
        x: &base
          a: 1
        y:
          <<: *base
          b: 2
        r   r>   r   r   z!ordereddict([('b', 2), ('a', 1)]))r   r   r^   )r   r,   r   r   r   test_issue_60_1L  s
    z%TestCommentedMapMerge.test_issue_60_1N)rB   rC   rD   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,t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   )r   yaml_strr   r   r   r   r   test_issue_46]  s
    
zTestEmptyLines.test_issue_46c             C   s   t d d S )NzH
        a: 1x

        b: 2x


        c: 3x



        d: 4x

        )r   )r   r   r   r   test_multispace_mapn  s    z"TestEmptyLines.test_multispace_mapT)strictc             C   s   t d d S )NzI

        a: 1x

        b: 2x


        c: 3x



        d: 4x

        )r   )r   r   r   r   test_multispace_map_initial  s    z*TestEmptyLines.test_multispace_map_initialc             C   s   t d d S )Nz:
        - a: 1y
          b: 2y

          c: 3y
        )r   )r   r   r   r   test_embedded_map  s    z TestEmptyLines.test_embedded_mapc             C   s   t d d S )Nz.        - 1

        - 2

        - 3
        )r   )r   r   r   r   test_toplevel_seq  s    z TestEmptyLines.test_toplevel_seqc             C   s   t d d S )NzN
        a:
          b:
          - 1

          - 2


          - 3
        )r   )r   r   r   r   test_embedded_seq  s    
z TestEmptyLines.test_embedded_seqc             C   s^   d}t |dd}t|dd}d}x,|j D ] }||j d 7 }t|d  q*W ||ksZtd S )Nz---

a: 'x'
 
b: y
T)rb   )rc    r   $)r   r   
splitlinesrstriprN   r   )r   rd   r   r   strippedliner   r   r   test_line_with_only_spaces  s    z)TestEmptyLines.test_line_with_only_spacesc             C   s^   d}t |dd}t|dd}d}x,|j D ] }||j d 7 }t|d  q*W ||ksZtd S )Nz---  
  
a: "x"  
   
b: y  
T)rb   )rc   rl   r   rm   )r   r   rn   ro   rN   r   )r   rd   r   r   rp   rq   r   r   r   test_some_eol_spaces  s    z#TestEmptyLines.test_some_eol_spacesc             C   sF   t d}t|}t|j t|dd}t|jdd ||ksBtd S )NzP        toplevel:

            # some comment
            sublevel: 300
        r   )r   r   z$
)r   r   rN   car   r+   r   )r   rd   r   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(td S )NzO        toplevel:
            # some comment
            sublevel: 300
        r   )r   )r   r   r   r   )r   rd   r   r   r   r   r   test_issue_54_ok  s
    zTestEmptyLines.test_issue_54_okc             C   s   t d d S )Nzz        a:
          b:
          - c1: cat  # a1
          # my comment on catfish
          - c2: catfish  # a2
        )r   )r   r   r   r   test_issue_93  s    zTestEmptyLines.test_issue_93c             C   s   t d d S )Nzn        a:
        - - c1: cat   # a1
          # my comment on catfish
          - c2: catfish  # a2
        )r   )r   r   r   r   test_issue_93_00  s    zTestEmptyLines.test_issue_93_00c             C   s   t d d S )Nzc        - - c1: cat   # a1
          # my comment on catfish
          - c2: catfish  # a2
        )r   )r   r   r   r   test_issue_93_01  s    zTestEmptyLines.test_issue_93_01c             C   s   t d d S )NzP        - c1: cat
        # my comment on catfish
        - c2: catfish
        )r   )r   r   r   r   test_issue_93_02  s    zTestEmptyLines.test_issue_93_02c             C   s   t d d S )Nzg        a:
          b:
            c: c_val
            d:

          e:
            g: g_val
        )r   )r   r   r   r   test_issue_96  s    	zTestEmptyLines.test_issue_96N)rB   rC   rD   re   rf   r
   markZxfailrh   ri   rj   rk   rr   rs   ru   rv   rw   rx   ry   rz   r{   r   r   r   r   ra   [  s   

	
ra   c               @   s*   e Zd Zejjejdk dddd ZdS )	TestUnicodeCommentsr!      zwide unicode)reasonc             C   s   t d d S )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  s    z!TestUnicodeComments.test_issue_55N)r!   r~   )	rB   rC   rD   r
   r|   Zskipifsysversion_infor   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   s   t d d S )NzK        - a: b
          c: d
          d:  # foo
          - e: f
        )r   )r   r   r   r   test_issue_25a5  s    z+TestEmptyValueBeforeComments.test_issue_25ac             C   s   t d d S )NzK        - a: b
          c: d
          d:  # foo
            e: f
        )r   )r   r   r   r   test_issue_25a1?  s    z,TestEmptyValueBeforeComments.test_issue_25a1c             C   s   t d d S )Nz?        var1: #empty
        var2: something #notempty
        )r   )r   r   r   r   test_issue_25bI  s    z+TestEmptyValueBeforeComments.test_issue_25bc             C   s   t d d S )Nzi        params:
          a: 1 # comment a
          b:   # comment b
          c: 3 # comment c
        )r   )r   r   r   r   test_issue_25cQ  s    z+TestEmptyValueBeforeComments.test_issue_25cc             C   s   t d d S )Nz{        params:
          a: 1 # comment a
          b:   # comment b
          # extra
          c: 3 # comment c
        )r   )r   r   r   r   test_issue_25c1[  s    z,TestEmptyValueBeforeComments.test_issue_25c1c             C   s   t d d S )NzN        params:
          a: 1 # comment a
          b:   # comment b
        )r   )r   r   r   r   test_issue_25_00f  s    z-TestEmptyValueBeforeComments.test_issue_25_00c             C   s   t d d S )Nz        a:        # comment 1
                  #  comment 2
        - b:      #   comment 3
            c: 1  #    comment 4
        )r   )r   r   r   r   test_issue_25_01o  s    z-TestEmptyValueBeforeComments.test_issue_25_01c             C   s   t d d S )Nze        a:        # comment 1
                  #  comment 2
        - b: 2    #   comment 3
        )r   )r   r   r   r   test_issue_25_02y  s    z-TestEmptyValueBeforeComments.test_issue_25_02c             C   s   d}t |ddd d S )Nze        a:        # comment 1
                  #  comment 2
          - b: 2  #   comment 3
        r   r!   )r   r"   )r   )r   r   r   r   r   test_issue_25_03  s    z-TestEmptyValueBeforeComments.test_issue_25_03c             C   s   t d d S )Nze        a:        # comment 1
                  #  comment 2
          b: 1    #   comment 3
        )r   )r   r   r   r   test_issue_25_04  s    z-TestEmptyValueBeforeComments.test_issue_25_04c             C   s   t d d S )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  s    z5TestEmptyValueBeforeComments.test_flow_seq_within_seqN)rB   rC   rD   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   4  s   


	
		r   z%y: p
# Some comment

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



# abc
#xyz
# abc

#xyz


  # abc
  #xyz
)rl   r   r   r   r   r   r   r   )r5   )test_block_scalar_commented_line_templateformatr6   r   r   r   )r   r9   r   Zcommented_liner,   r   r   r   test_scalar_with_comments  s           
z5TestBlockScalarWithComments.test_scalar_with_commentsN)rB   rC   rD   r   r   r   r   r   r     s   r   )rT   r
   r   Z	roundtripr   r   r   r   r   rE   rV   r\   ra   r}   r   r   r   r   r   r   r   <module>   s      Q 5/ Cx