3
Îédû9  ã               @   sV   d dl mZ d dlZddlmZmZmZmZ dd„ Zdd„ Z	d	d
„ Z
G dd„ dƒZdS )é    )Úprint_functionNé   )Ú
round_tripÚdedentÚround_trip_loadÚround_trip_dumpc             C   s   t t| ƒƒS )N)r   r   )Ús© r	   úe/var/www/html/virt/lib64/python3.6/site-packages/srsly/tests/ruamel_yaml/test_comment_manipulation.pyÚload
   s    r   c             K   s   t | f|Žt|ƒkst‚d S )N)r   r   ÚAssertionError)Údatar   Úkwr	   r	   r
   Úcompare   s    r   c             C   s@   d|kst ‚t|ƒjddƒjddƒ}t| ƒjddƒ|ks<t ‚d S )NZEOLÚ Ú
z|
)r   r   Úreplacer   )r   r   Zdsr	   r	   r
   Úcompare_eol   s    r   c               @   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d3d4„ Zd5d6„ Zd7d8„ Zd9S ):ÚTestCommentsManipulationc             C   s*   t dƒ}|jdddd d}t||ƒ d S )Nz;
        - a   # comment 1
        - b
        - c
        z	comment 2r   é   )ÚkeyÚcolumnzI
        - a   # comment 1
        - b   # comment 2
        - c
        )r   Úyaml_add_eol_commentr   )Úselfr   Úexpr	   r	   r
   Ú0test_seq_set_comment_on_existing_explicit_column   s
    zITestCommentsManipulation.test_seq_set_comment_on_existing_explicit_columnc             C   s*   t dƒ}|jdddd d}t||ƒ d S )Nz;
        - a   # comment 1
        - b
        - c
        z	comment 2r   r   )r   r   z;
        - a   # comment 2
        - b
        - c
        )r   r   r   )r   r   r   r	   r	   r
   Ú6test_seq_overwrite_comment_on_existing_explicit_column+   s
    zOTestCommentsManipulation.test_seq_overwrite_comment_on_existing_explicit_columnc             C   s*   t dƒ}|jdddd d}t||ƒ d S )Nz-
        - a
        - b
        - c
        z	comment 1r   r   )r   r   z;
        - a
        - b   # comment 1
        - c
        )r   r   r   )r   r   r   r	   r	   r
   Ú&test_seq_first_comment_explicit_column;   s
    z?TestCommentsManipulation.test_seq_first_comment_explicit_columnc             C   s(   t dƒ}|jddd d}t||ƒ d S )NzW
        - a   # comment 1
        - b
        - c
        - d     # comment 3
        z	comment 2r   )r   ze
        - a   # comment 1
        - b   # comment 2
        - c
        - d     # comment 3
        )r   r   r   )r   r   r   r	   r	   r
   Ú,test_seq_set_comment_on_existing_column_prevK   s
    zETestCommentsManipulation.test_seq_set_comment_on_existing_column_prevc             C   s2   t dƒ}t|jƒ |jddd d}t||ƒ d S )NzW
        - a   # comment 1
        - b
        - c
        - d     # comment 3
        z	comment 2é   )r   zg
        - a   # comment 1
        - b
        - c     # comment 2
        - d     # comment 3
        )r   ÚprintÚ_yaml_commentr   r   )r   r   r   r	   r	   r
   Ú,test_seq_set_comment_on_existing_column_next]   s    
zETestCommentsManipulation.test_seq_set_comment_on_existing_column_nextc             C   s2   t dƒ}t|jƒ |jddd d}t||ƒ dS )zb
        no comment line before or after, take the latest before
        the new position
        zo
        - a   # comment 1
        - b
        - c
        - d
        - e
        - f     # comment 3
        z	comment 2é   )r   z}
        - a   # comment 1
        - b
        - c
        - d   # comment 2
        - e
        - f     # comment 3
        N)r   r    r!   r   r   )r   r   r   r	   r	   r
   Ú4test_seq_set_comment_on_existing_column_further_aways   s    
zMTestCommentsManipulation.test_seq_set_comment_on_existing_column_further_awayc             C   s*   t dƒ}|jdddd d}t||ƒ d S )Nz;
        - a   # comment 1
        - b
        - c
        z#  comment 2r   r   )r   r   zJ
        - a   # comment 1
        - b   #  comment 2
        - c
        )r   r   r   )r   r   r   r	   r	   r
   Ú:test_seq_set_comment_on_existing_explicit_column_with_hash‘   s
    zSTestCommentsManipulation.test_seq_set_comment_on_existing_explicit_column_with_hashc             C   s*   t dƒ}|jdddd d}t||ƒ d S )NzX
        a: 1   # comment 1
        b: 2
        c: 3
        d: 4
        e: 5
        z	comment 2Úcé   )r   r   zf
        a: 1   # comment 1
        b: 2
        c: 3   # comment 2
        d: 4
        e: 5
        )r   r   r   )r   r   r   r	   r	   r
   Ú1test_dict_set_comment_on_existing_explicit_column£   s
    zJTestCommentsManipulation.test_dict_set_comment_on_existing_explicit_columnc             C   s*   t dƒ}|jdddd d}t||ƒ d S )NzX
        a: 1   # comment 1
        b: 2
        c: 3
        d: 4
        e: 5
        z	comment 2Úar'   )r   r   zX
        a: 1   # comment 2
        b: 2
        c: 3
        d: 4
        e: 5
        )r   r   r   )r   r   r   r	   r	   r
   Ú7test_dict_overwrite_comment_on_existing_explicit_column·   s
    zPTestCommentsManipulation.test_dict_overwrite_comment_on_existing_explicit_columnc             C   s(   t dƒ}|jddd d}t||ƒ d S )Nz€
            a: 1   # comment 1
            b: 2
            c: 3
            d: 4
            e: 5     # comment 3
            z	comment 2Úb)r   zŽ
            a: 1   # comment 1
            b: 2   # comment 2
            c: 3
            d: 4
            e: 5     # comment 3
            )r   r   r   )r   r   r   r	   r	   r
   Ú,test_map_set_comment_on_existing_column_prevË   s
    zETestCommentsManipulation.test_map_set_comment_on_existing_column_prevc             C   s(   t dƒ}|jddd d}t||ƒ d S )Nz€
            a: 1   # comment 1
            b: 2
            c: 3
            d: 4
            e: 5     # comment 3
            z	comment 2Úd)r   z
            a: 1   # comment 1
            b: 2
            c: 3
            d: 4     # comment 2
            e: 5     # comment 3
            )r   r   r   )r   r   r   r	   r	   r
   Ú,test_map_set_comment_on_existing_column_nextß   s
    zETestCommentsManipulation.test_map_set_comment_on_existing_column_nextc             C   s4   t dƒ}|jddd tt|ƒƒ d}t||ƒ dS )zb
        no comment line before or after, take the latest before
        the new position
        z€
            a: 1   # comment 1
            b: 2
            c: 3
            d: 4
            e: 5     # comment 3
            z	comment 2r&   )r   zŽ
            a: 1   # comment 1
            b: 2
            c: 3   # comment 2
            d: 4
            e: 5     # comment 3
            N)r   r   r    r   r   )r   r   r   r	   r	   r
   Ú4test_map_set_comment_on_existing_column_further_awayó   s    zMTestCommentsManipulation.test_map_set_comment_on_existing_column_further_awayc             C   s,   t dƒ}|jdƒ d}t||jddƒ d S )Nz#
        a: 1
        b: 2
        zHello
World
zC
        # Hello
        # World
        a: 1
        b: 2
        ú#)Úcomment)r   Úyaml_set_start_commentr   Úformat)r   r   r   r	   r	   r
   Útest_before_top_map_rt  s
    
z/TestCommentsManipulation.test_before_top_map_rtc             C   s,   t dƒ}|jdƒ d}t||jddƒ d S )NzC
        # abc
        # def
        a: 1 # 1
        b: 2
        zHello
World
zG
        # Hello
        # World
        a: 1 # 1
        b: 2
        r0   )r1   )r   r2   r   r3   )r   r   r   r	   r	   r
   Útest_before_top_map_replace  s
    
z4TestCommentsManipulation.test_before_top_map_replacec             C   sF   ddl m} |ƒ }d|d< d|d< |jdƒ d}t||jd	d
ƒ d S )Nr   )ÚCommentedMapr   r)   r   r+   zHello
World
zW
            # Hello
            # World
            a: 1
            b: 2
            r0   )r1   )Úsrsly.ruamel_yaml.commentsr6   r2   r   r3   )r   r6   r   r   r	   r	   r
   Ú test_before_top_map_from_scratch.  s    
z9TestCommentsManipulation.test_before_top_map_from_scratchc             C   s0   t dƒ}|jdƒ tt|ƒƒ d}t||ƒ d S )Nz!
        - a
        - b
        zHello
World
zA
        # Hello
        # World
        - a
        - b
        )r   r2   r    r   r   )r   r   r   r	   r	   r
   Útest_before_top_seq_rt?  s    
z/TestCommentsManipulation.test_before_top_seq_rtc             C   sD   d}t |jddƒ}|jdƒ tt|ƒƒ d}t||jddƒ d S )Nz?
        # this
        # that
        - a
        - b
        r0   )r1   zHello
World
zA
        # Hello
        # World
        - a
        - b
        )r   r3   r2   r    r   r   )r   r   r   r   r	   r	   r
   Útest_before_top_seq_rt_replaceP  s    
z7TestCommentsManipulation.test_before_top_seq_rt_replacec             C   sV   ddl m} |ƒ }|jdƒ |jdƒ |jdƒ tt|ƒƒ d}t||jddƒ d S )	Nr   )ÚCommentedSeqr)   r+   zHello
World
zA
        # Hello
        # World
        - a
        - b
        r0   )r1   )r7   r;   Úappendr2   r    r   r   r3   )r   r;   r   r   r	   r	   r
   Ú test_before_top_seq_from_scratchb  s    


z9TestCommentsManipulation.test_before_top_seq_from_scratchc             C   s0   t dƒ}|d jdƒ d}t||jddƒ d S )Nz?
        a: 1
        b:
          c: 2
          d: 3
        r+   zHello
World
z_
        a: 1
        b:
        # Hello
        # World
          c: 2
          d: 3
        r0   )r1   )r   r2   r   r3   )r   r   r   r	   r	   r
   Útest_before_nested_map_rts  s
    z2TestCommentsManipulation.test_before_nested_map_rtc             C   sB   t dƒ}|d jddd d}t||jddƒ t|d jƒ d S )	Nz?
        a: 1
        b:
          c: 2
          d: 3
        r+   zHello
World
r   )Úindentzc
        a: 1
        b:
          # Hello
          # World
          c: 2
          d: 3
        r0   )r1   )r   r2   r   r3   r    Úca)r   r   r   r	   r	   r
   Ú test_before_nested_map_rt_indent‡  s    z9TestCommentsManipulation.test_before_nested_map_rt_indentc             C   s`   ddl m} |ƒ }|ƒ }d|d< ||d< d|d< d|d	< |d jd
ƒ d}t||jddƒ d S )Nr   )r6   r   r)   r+   r   r&   r#   r-   zHello
World
z_
        a: 1
        b:
        # Hello
        # World
          c: 2
          d: 3
        r0   )r1   )r7   r6   r2   r   r3   )r   r6   r   Údatabr   r	   r	   r
   Ú#test_before_nested_map_from_scratchœ  s    z<TestCommentsManipulation.test_before_nested_map_from_scratchc             C   sl   ddl m}m} |ƒ }|ƒ }d|d< ||d< |jdƒ |jdƒ |d jdd	d
 d}t||jddƒ d S )Nr   )r6   r;   r   r)   r+   r&   r-   zHello
World
r   )r?   z]
        a: 1
        b:
          # Hello
          # World
        - c
        - d
        r0   )r1   )r7   r6   r;   r<   r2   r   r3   )r   r6   r;   r   rB   r   r	   r	   r
   Ú#test_before_nested_seq_from_scratch°  s    

z<TestCommentsManipulation.test_before_nested_seq_from_scratchc             C   sr   ddl m}m} |ƒ }|ƒ }d|d< ||d< |jdƒ |jdƒ |d jdd	d
 d}t||jdddd	d d S )Nr   )r6   r;   r   r)   r+   r&   r-   zHello
World
r   )r?   za
        a: 1
        b:
          # Hello
          # World
          - c
          - d
        r0   )r1   é   )r?   Zblock_seq_indent)r7   r6   r;   r<   r2   r   r3   )r   r6   r;   r   rB   r   r	   r	   r
   Ú4test_before_nested_seq_from_scratch_block_seq_indentÄ  s    

zMTestCommentsManipulation.test_before_nested_seq_from_scratch_block_seq_indentc             C   s@   t dƒ}|jdddd |d d jddd	 d
}t||ƒ d S )Nz
        xyz:
          a: 1    # comment 1
          b: 2

        test1:
          test2:
            test3: 3
                Útest1zbefore test1 (top level)zbefore test2)ÚafterÚtest2zafter test2rE   )r?   zÏ
        xyz:
          a: 1    # comment 1
          b: 2

        # before test1 (top level)
        test1:
          # before test2
          test2:
            # after test2
            test3: 3
        )r   Ú!yaml_set_comment_before_after_keyr2   r   )r   r   r   r	   r	   r
   Ú6test_map_set_comment_before_and_after_non_first_key_00Ø  s    	zOTestCommentsManipulation.test_map_set_comment_before_and_after_non_first_key_00c             C   s@   t dƒ}|jdddd |d d jddd	 d
}t||ƒ d S )Nzy
        xyz:
          a: 1    # comment 1
          b: 2

        test1:
          test2:
            test3: 3
        rG   zbefore test1 (top level)zbefore test2

)rH   rI   zafter test2rE   )r?   zÝ
        xyz:
          a: 1    # comment 1
          b: 2

        # before test1 (top level)
        test1:
          # before test2
          EOL
          test2:
            # after test2
            test3: 3
        )r   rJ   r2   r   )r   r   r   r	   r	   r
   Ú7Xtest_map_set_comment_before_and_after_non_first_key_01÷  s    	zPTestCommentsManipulation.Xtest_map_set_comment_before_and_after_non_first_key_01c             C   s@   t dƒ}|jdddd |d d jddd	 d
}t||ƒ d S )Nzy
        xyz:
          a: 1    # comment 1
          b: 2

        test1:
          test2:
            test3: 3
        rG   zbefore test1 (top level)zbefore test2

)rH   rI   zafter test2rE   )r?   zÐ
        xyz:
          a: 1    # comment 1
          b: 2

        # before test1 (top level)
        test1:
          # before test2

          test2:
            # after test2
            test3: 3
        )r   rJ   r2   r   )r   r   r   r	   r	   r
   Ú6test_map_set_comment_before_and_after_non_first_key_01  s    	zOTestCommentsManipulation.test_map_set_comment_before_and_after_non_first_key_01c             C   sB   t dƒ}|jddddd |d d jddd	 d
}t||ƒ d S )Nzy
        xyz:
          a: 1    # comment 1
          b: 2

        test1:
          test2:
            test3: 3
        rG   zxyz

before test1 (top level)z
before test2rE   )rH   Úafter_indentrI   zafter test2)r?   zð
        xyz:
          a: 1    # comment 1
          b: 2

        # xyz

        # before test1 (top level)
        test1:
            EOL
            # before test2
          test2:
            # after test2
            test3: 3
        )r   rJ   r2   r   )r   r   r   r	   r	   r
   Ú7Xtest_map_set_comment_before_and_after_non_first_key_028  s    	zPTestCommentsManipulation.Xtest_map_set_comment_before_and_after_non_first_key_02c             C   sB   t dƒ}|jddddd |d d jddd	 d
}t||ƒ d S )Nzy
        xyz:
          a: 1    # comment 1
          b: 2

        test1:
          test2:
            test3: 3
        rG   zxyz

before test1 (top level)z
before test2rE   )rH   rN   rI   zafter test2)r?   zá
        xyz:
          a: 1    # comment 1
          b: 2

        # xyz

        # before test1 (top level)
        test1:

            # before test2
          test2:
            # after test2
            test3: 3
        )r   rJ   r2   r   )r   r   r   r	   r	   r
   Ú6test_map_set_comment_before_and_after_non_first_key_02]  s    	zOTestCommentsManipulation.test_map_set_comment_before_and_after_non_first_key_02N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r"   r$   r%   r(   r*   r,   r.   r/   r4   r5   r8   r9   r:   r=   r>   rA   rC   rD   rF   rK   rL   rM   rO   rP   r	   r	   r	   r
   r      s8   "%r   )Ú
__future__r   ZpytestZ	roundtripr   r   r   r   r   r   r   r   r	   r	   r	   r
   Ú<module>   s   