o
    
i9                     @   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/home/ubuntu/.local/lib/python3.10/site-packages/srsly/tests/ruamel_yaml/test_comment_manipulation.pyload
   s   r   c                 K   s    t | fi |t|ksJ d S r   )r   r   )datar	   kwr
   r
   r   compare   s    r   c                 C   s@   d|v sJ t |dddd}t| dd|ksJ d S )NEOL 
z|
)r   replacer   )r   r	   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   *   t d}|jdddd d}t|| d S )N;
        - a   # comment 1
        - b
        - c
        	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      zITestCommentsManipulation.test_seq_set_comment_on_existing_explicit_columnc                 C   r   )Nr   r   r   r   r   z;
        - a   # comment 2
        - b
        - c
        r   r    r
   r
   r   6test_seq_overwrite_comment_on_existing_explicit_column+   r$   zOTestCommentsManipulation.test_seq_overwrite_comment_on_existing_explicit_columnc                 C   r   )Nz-
        - a
        - b
        - c
        z	comment 1r   r   r   z;
        - a
        - b   # comment 1
        - c
        r   r    r
   r
   r   &test_seq_first_comment_explicit_column;   r$   z?TestCommentsManipulation.test_seq_first_comment_explicit_columnc                 C   (   t d}|jddd d}t|| d S )NW
        - a   # comment 1
        - b
        - c
        - d     # comment 3
        r   r   r   ze
        - a   # comment 1
        - b   # comment 2
        - c
        - d     # comment 3
        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 )Nr(   r      r)   zg
        - a   # comment 1
        - b
        - c     # comment 2
        - d     # comment 3
        r   print_yaml_commentr   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 )b
        no comment line before or after, take the latest before
        the new position
        zo
        - a   # comment 1
        - b
        - c
        - d
        - e
        - f     # comment 3
        r      r)   z}
        - a   # comment 1
        - b
        - c
        - d   # comment 2
        - e
        - f     # comment 3
        Nr,   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   r   )Nr   z#  comment 2r   r   r   zJ
        - a   # comment 1
        - b   #  comment 2
        - c
        r   r    r
   r
   r   :test_seq_set_comment_on_existing_explicit_column_with_hash   r$   zSTestCommentsManipulation.test_seq_set_comment_on_existing_explicit_column_with_hashc                 C   r   )NX
        a: 1   # comment 1
        b: 2
        c: 3
        d: 4
        e: 5
        r   c   r   zf
        a: 1   # comment 1
        b: 2
        c: 3   # comment 2
        d: 4
        e: 5
        r   r    r
   r
   r   1test_dict_set_comment_on_existing_explicit_column      	zJTestCommentsManipulation.test_dict_set_comment_on_existing_explicit_columnc                 C   r   )Nr4   r   ar6   r   zX
        a: 1   # comment 2
        b: 2
        c: 3
        d: 4
        e: 5
        r   r    r
   r
   r   7test_dict_overwrite_comment_on_existing_explicit_column   r8   zPTestCommentsManipulation.test_dict_overwrite_comment_on_existing_explicit_columnc                 C   r'   )N
            a: 1   # comment 1
            b: 2
            c: 3
            d: 4
            e: 5     # comment 3
            r   br)   z
            a: 1   # comment 1
            b: 2   # comment 2
            c: 3
            d: 4
            e: 5     # comment 3
            r   r    r
   r
   r   ,test_map_set_comment_on_existing_column_prev      	zETestCommentsManipulation.test_map_set_comment_on_existing_column_prevc                 C   r'   )Nr;   r   dr)   z
            a: 1   # comment 1
            b: 2
            c: 3
            d: 4     # comment 2
            e: 5     # comment 3
            r   r    r
   r
   r   ,test_map_set_comment_on_existing_column_next   r>   zETestCommentsManipulation.test_map_set_comment_on_existing_column_nextc                 C   s4   t d}|jddd tt| d}t|| dS )r0   r;   r   r5   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   4test_map_set_comment_on_existing_column_further_away   s   	zMTestCommentsManipulation.test_map_set_comment_on_existing_column_further_awayc                 C   ,   t d}|d d}t||jdd d S )Nz#
        a: 1
        b: 2
        Hello
World
zC
        # Hello
        # World
        a: 1
        b: 2
        #commentr   yaml_set_start_commentr   formatr    r
   r
   r   test_before_top_map_rt  s   
z/TestCommentsManipulation.test_before_top_map_rtc                 C   rB   )NzC
        # abc
        # def
        a: 1 # 1
        b: 2
        rC   zG
        # Hello
        # World
        a: 1 # 1
        b: 2
        rD   rE   rG   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< |d d}t||jd	d
 d S )Nr   CommentedMapr   r9   r+   r<   rC   zW
            # Hello
            # World
            a: 1
            b: 2
            rD   rE   srsly.ruamel_yaml.commentsrM   rH   r   rI   )r!   rM   r   r"   r
   r
   r    test_before_top_map_from_scratch.  s   
z9TestCommentsManipulation.test_before_top_map_from_scratchc                 C   s0   t d}|d tt| d}t|| d S )Nz!
        - a
        - b
        rC   A
        # Hello
        # World
        - a
        - b
        )r   rH   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}|d tt| d}t||jdd d S )Nz?
        # this
        # that
        - a
        - b
        rD   rE   rC   rQ   )r   rI   rH   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} | }|d |d |d tt| d}t||jdd d S )	Nr   )CommentedSeqr9   r<   rC   rQ   rD   rE   )rO   rT   appendrH   r-   r   r   rI   )r!   rT   r   r"   r
   r
   r    test_before_top_seq_from_scratchb  s   


z9TestCommentsManipulation.test_before_top_seq_from_scratchc                 C   s0   t d}|d d d}t||jdd d S )N?
        a: 1
        b:
          c: 2
          d: 3
        r<   rC   _
        a: 1
        b:
        # Hello
        # World
          c: 2
          d: 3
        rD   rE   rG   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 )	NrW   r<   rC   r+   indentzc
        a: 1
        b:
          # Hello
          # World
          c: 2
          d: 3
        rD   rE   )r   rH   r   rI   r-   car    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 d
 d}t||jdd d S )Nr   rL   r   r9   r<   r+   r5   r1   r?   rC   rX   rD   rE   rN   )r!   rM   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< |d |d |d jdd	d
 d}t||jdd d S )Nr   rM   rT   r   r9   r<   r5   r?   rC   r+   rZ   z]
        a: 1
        b:
          # Hello
          # World
        - c
        - d
        rD   rE   rO   rM   rT   rU   rH   r   rI   r!   rM   rT   r   r^   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< |d |d |d jdd	d
 d}t||jdddd	d d S )Nr   r`   r   r9   r<   r5   r?   rC   r+   rZ   za
        a: 1
        b:
          # Hello
          # World
          - c
          - d
        rD   rE      )r[   block_seq_indentra   rb   r
   r
   r   4test_before_nested_seq_from_scratch_block_seq_indent  s   

zMTestCommentsManipulation.test_before_nested_seq_from_scratch_block_seq_indentc                 C   @   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
                test1before test1 (top level)zbefore test2aftertest2after test2rd   rZ   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_keyrH   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   rg   )Ny
        xyz:
          a: 1    # comment 1
          b: 2

        test1:
          test2:
            test3: 3
        rh   ri   before test2

rj   rl   rm   rd   rZ   z
        xyz:
          a: 1    # comment 1
          b: 2

        # before test1 (top level)
        test1:
          # before test2
          EOL
          test2:
            # after test2
            test3: 3
        r   ro   rH   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   rg   )Nrq   rh   ri   rr   rj   rl   rm   rd   rZ   z
        xyz:
          a: 1    # comment 1
          b: 2

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

          test2:
            # after test2
            test3: 3
        rn   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   B   t d}|jddddd |d d jddd	 d
}t|| d S )Nrq   rh   xyz

before test1 (top level)
before test2rd   rk   after_indentrl   rm   rZ   z
        xyz:
          a: 1    # comment 1
          b: 2

        # xyz

        # before test1 (top level)
        test1:
            EOL
            # before test2
          test2:
            # after test2
            test3: 3
        rs   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   rv   )Nrq   rh   rw   rx   rd   ry   rl   rm   rZ   z
        xyz:
          a: 1    # comment 1
          b: 2

        # xyz

        # before test1 (top level)
        test1:

            # before test2
          test2:
            # after test2
            test3: 3
        rn   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/   r2   r3   r7   r:   r=   r@   rA   rJ   rK   rP   rR   rS   rV   rY   r]   r_   rc   rf   rp   rt   ru   r{   r|   r
   r
   r
   r   r      s:    "%r   )
__future__r   pytest	roundtripr   r   r   r   r   r   r   r   r
   r
   r
   r   <module>   s   