a
    Ø
þd°*  ã                   @   sR   d Z ddlZddlZddlmZ ddlmZ G dd„ dejƒZedkrNe 	¡  dS )zTests for yapf.comment_splicer.é    N)Úcomment_splicer)Úpytree_utilsc                   @   s¨   e Zd Zdd„ Zd)dd„Z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!d"„ Zd#d$„ Zd%d&„ Zd'd(„ ZdS )+ÚCommentSplicerTestc                 C   s   |   |t |¡¡ d S )N)ÚassertEqualr   ÚNodeName)ÚselfÚexpected_typeÚnode© r
   úg/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/yapftests/comment_splicer_test.pyÚ_AssertNodeType   s    z"CommentSplicerTest._AssertNodeTypeNc                 C   sX   t  |¡dkr.|  d|jd ¡ |jd j}n|  d|¡ |j}|d urT|  ||¡ d S )NZsimple_stmtÚCOMMENTr   )r   r   r   ÚchildrenÚvalueZassertIn)r   r	   Ztext_in_commentZ
node_valuer
   r
   r   Ú_AssertNodeIsComment   s    z'CommentSplicerTest._AssertNodeIsCommenté   c                    sJ   t ‡ fdd„| ¡ D ƒƒD ]\}}||d kr|  S qtd |¡ƒ‚d S )Nc                    s   g | ]}t  |¡ˆ kr|‘qS r
   )r   r   )Ú.0Úc©Únamer
   r   Ú
<listcomp>(   ó    z9CommentSplicerTest._FindNthChildNamed.<locals>.<listcomp>r   zNo Nth child for n={0})Ú	enumerateZ	pre_orderÚRuntimeErrorÚformat)r   r	   r   ÚnÚiÚchildr
   r   r   Ú_FindNthChildNamed&   s    ÿ
z%CommentSplicerTest._FindNthChildNamedc                 C   s`   d}t  |¡}t |¡ |jd jd }|  d|¡ |  dt|jƒ¡ |jd }|  |d¡ d S )Nzfoo = 1 # and a comment
r   Z	expr_stmté   é   z# and a comment)	r   ÚParseCodeToTreer   ÚSpliceCommentsr   r   r   Úlenr   )r   ÚcodeÚtreeÚexprÚcomment_noder
   r
   r   ÚtestSimpleInline-   s    


z#CommentSplicerTest.testSimpleInlinec                 C   sH   t  d¡}t |¡}t |¡ |  dt|jƒ¡ |jd }|  	|¡ d S )Nz9
      foo = 1
      # first comment
      bar = 2
      r   r   ©
ÚtextwrapÚdedentr   r!   r   r"   r   r#   r   r   )r   r$   r%   r'   r
   r
   r   ÚtestSimpleSeparateLine:   s    



z)CommentSplicerTest.testSimpleSeparateLinec                 C   sD   t  d¡}t |¡}t |¡ |  dt|jƒ¡ |  	|jd ¡ d S )NzP
      foo = 1
      # first comment
      # second comment
      bar = 2
      r   r   r)   )r   r$   r%   r
   r
   r   ÚtestTwoLineCommentI   s
    


z%CommentSplicerTest.testTwoLineCommentc                 C   sT   t  d¡}t |¡}t |¡ |jd jd }|  d|jd ¡ |  |jd ¡ d S )Nz7
      if x:
        # a comment
        foo = 1
      r   r    ÚNEWLINEr   ©	r*   r+   r   r!   r   r"   r   r   r   ©r   r$   r%   Zif_suiter
   r
   r   Ú!testCommentIsFirstChildInCompoundW   s    


z4CommentSplicerTest.testCommentIsFirstChildInCompoundc                 C   sT   t  d¡}t |¡}t |¡ |jd jd }|  d|jd ¡ |  |jd ¡ d S )Nz7
      if x:
        foo = 1
        # a comment
      r   r    ÚDEDENTéÿÿÿÿéþÿÿÿr/   r0   r
   r
   r   Ú testCommentIsLastChildInCompoundg   s    


z3CommentSplicerTest.testCommentIsLastChildInCompoundc                 C   s^   t  d¡}t |¡}t |¡ |jd }|  |d¡ |jd jd }|jd }|  |d¡ d S )NzI
      bar = 1
      # line comment
      foo = 1 # inline comment
      r   ú# line commenté   r   r3   ú# inline comment©r*   r+   r   r!   r   r"   r   r   ©r   r$   r%   Zsep_comment_noder&   Zinline_comment_noder
   r
   r   ÚtestInlineAfterSeparateLinew   s    




z.CommentSplicerTest.testInlineAfterSeparateLinec                 C   s^   t  d¡}t |¡}t |¡ |jd }|  |d¡ |jd jd }|jd }|  |d¡ d S )NzI
      bar = 1
      foo = 1 # inline comment
      # line comment
      r4   r6   r   r   r3   r8   r9   r:   r
   r
   r   ÚtestSeparateLineAfterInline‰   s    




z.CommentSplicerTest.testSeparateLineAfterInlinec                 C   sT   t  d¡}t |¡}t |¡ |  |jd ¡ |jd jd }|  d|jd ¡ d S )NzA
      if bar:
        z = 1
      # a comment
      j = 2
      r   r   r    r2   r3   )	r*   r+   r   r!   r   r"   r   r   r   r0   r
   r
   r   ÚtestCommentBeforeDedent›   s    


z*CommentSplicerTest.testCommentBeforeDedentc                 C   sT   t  d¡}t |¡}t |¡ |jd jd }|  |jd ¡ |  d|jd ¡ d S )NzU
      if foo:
        if bar:
          z = 1
        # a comment
      y = 1
      r   r    r4   r2   r3   ©	r*   r+   r   r!   r   r"   r   r   r   r0   r
   r
   r   ÚtestCommentBeforeDedentTwoLevelª   s    


z2CommentSplicerTest.testCommentBeforeDedentTwoLevelc                 C   sT   t  d¡}t |¡}t |¡ |jd jd }|  |jd ¡ |  d|jd ¡ d S )NzV
      if foo:
        if bar:
          z = 1
         # comment 2
      y = 1
      r   r    r4   r2   r3   r>   r0   r
   r
   r   Ú1testCommentBeforeDedentTwoLevelImproperlyIndented»   s    


zDCommentSplicerTest.testCommentBeforeDedentTwoLevelImproperlyIndentedc                 C   sœ   t  d¡}t |¡}t |¡ |  |jd d¡ | j|ddd}|  |jd d¡ |  	d|jd	 ¡ | j|dd
d}|  |jd d¡ |  	d|jd	 ¡ d S )Nz}
      if foo:
        if bar:
          z = 1
          # comment 2
        # comment 1
      # comment 0
      j = 2
      r   z# comment 0Zsuite)r   r4   z# comment 1r2   r3   r7   z# comment 2)
r*   r+   r   r!   r   r"   r   r   r   r   )r   r$   r%   Z
if_suite_1Z
if_suite_2r
   r
   r   Ú!testCommentBeforeDedentThreeLevelÏ   s    
	

z4CommentSplicerTest.testCommentBeforeDedentThreeLevelc                 C   sh   t  d¡}t |¡}t |¡ |jd jd }|jd }|  |d¡ |jd }|jd }|  |d¡ d S )Nz…
      class Foo:
        """docstring abc..."""
        # top-level comment
        def foo(): pass
        # another comment
      r   r    r4   z	# anotherz# top-levelr9   )r   r$   r%   Úclass_suiteZanother_commentÚfuncdefZtoplevel_commentr
   r
   r   ÚtestCommentsInClassê   s    





z&CommentSplicerTest.testCommentsInClassc                 C   sX   t  d¡}t |¡}t |¡ |jd }|jd }|  |d¡ |jd }|  |d¡ d S )Nzl
        # Block comment number 1

        # Block comment number 2
        def f():
          pass
        r   z# Block comment number 1r   z# Block comment number 2r9   )r   r$   r%   rC   Zblock_comment_1Zblock_comment_2r
   r
   r   ÚtestMultipleBlockComments   s    





z,CommentSplicerTest.testMultipleBlockCommentsc                 C   sb   t  d¡}t |¡}t |¡ |jd }|jd }|jd }|  |d¡ |jd }|  |d¡ d S )Nz¶
        class Foo(object):
          # A comment for qux.
          def qux(self):
            pass

          # Interim comment.

          def mux(self):
            pass
        r   é   r   z# A comment for qux.r   z# Interim comment.r9   )r   r$   r%   ZclassdefrB   Zqux_commentZinterim_commentr
   r
   r   ÚtestCommentsOnDedents  s    






z(CommentSplicerTest.testCommentsOnDedentsc                 C   sF   t  d¡}t |¡}t |¡ |  |dd¡}|jd }|  |d¡ d S )NzH
      foo( # Request fractions of an hour.
        948.0/3600, 20)
    Útrailerr   z# Request fractions of an hour.)	r*   r+   r   r!   r   r"   r   r   r   )r   r$   r%   rH   Úcommentr
   r
   r   ÚtestExprComments+  s    



z#CommentSplicerTest.testExprCommentsc                 C   s‚   t  d¡}t |¡}t |¡ |  |dd¡}|  |jd d¡ |  |dd¡}|  |jd d¡ |  |dd¡}|  |jd	 d
¡ d S )NzV
      foo( # com 1
        948.0/3600, # com 2
        20 + 12 # com 3
        )
    rH   r   z# com 1Úarglistr7   z# com 2Ú
arith_exprr3   z# com 3)	r*   r+   r   r!   r   r"   r   r   r   )r   r$   r%   rH   rK   rL   r
   r
   r   ÚtestMultipleCommentsInOneExpr7  s    


z0CommentSplicerTest.testMultipleCommentsInOneExpr)N)r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r(   r,   r-   r1   r5   r;   r<   r=   r?   r@   rA   rD   rE   rG   rJ   rM   r
   r
   r
   r   r      s&   


r   Ú__main__)
Ú__doc__r*   ZunittestZyapf.pytreer   r   ZTestCaser   rN   Úmainr
   r
   r
   r   Ú<module>   s     6