
    1Vh                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddlm
Z
  G d	 d
e
j                        Z G d de
j                        Zy)zTests for ast_utils.    )absolute_import)division)print_functionN)errors)	ast_utils)
test_utilsc                       e Zd Zd Zy)	UtilsTestc                 @   d}d}d}|D ]  }|j                  |      }| j                  |t        j                  |             d}| j                  ||z   t        j                  ||z                d}| j                  ||z   t        j                  ||z                 y )N)z# -*- coding: latin-1 -*-z# -*- coding: iso-8859-15 -*-z# vim: set fileencoding=ascii :z5# This Python file uses the following encoding: utf-8z{coding}
a = 123
z# (removed coding)
a = 123
)codingz"""Docstring."""
z"""Docstring."""
# line 2
)formatassertEqualr   sanitize_source)selfcoding_linessrc_templatesanitized_srclinesrc
src_prefixs          I/home/dcms/DCMS/lib/python3.12/site-packages/pasta/base/ast_utils_test.pytest_sanitize_sourcezUtilsTest.test_sanitize_source   s    L )L3M Dt,c }i&?&?&DE'j
zM1 00c1ABD 2j
zC' 00c1ABDD    N)__name__
__module____qualname__r    r   r   r
   r
      s    Dr   r
   c                   *    e Zd Zd Zd Zd Zd Zd Zy)AlterChildTestc                     d}t        j                  |      }|j                  d   }|j                  d   }t        j                  ||       t        j
                  |      }d}| j                  ||       y )NzEclass C():
  def f(x):
    return x + 2
  def g(x):
    return x + 3
r   z(class C():
  def g(x):
    return x + 3
)pastaparsebodyr   remove_childdumpr   )r   r   tree
class_node
meth1_noderesultexpecteds          r   testRemoveChildMethodz$AlterChildTest.testRemoveChildMethod7   sk    C ;;sD1J#J:z2ZZFH
 	VX&r   c                     d}t        j                  |      }|j                  d   }|j                  d   }t	        j
                  ||       | j                  t        j                  |      d       y )Nzfrom a import b, cr   zfrom a import c)r!   r"   r#   namesr   r$   r   r%   )r   r   r&   import_nodealias1s        r   testRemoveAliaszAlterChildTest.testRemoveAliasM   s\    
C;;sD))A,Kq!F;/UZZ%'89r   c                     d}t        j                  |      }|j                  d   }|j                  d   }t        j                  ||       d}| j                  t        j                  |      |       y )Nzif a:
  print("foo!")
  x = 1
r   zif a:
  x = 1
)r!   r"   r#   r   r$   r   r%   )r   r   r&   if_block
print_stmtr*   s         r   testRemoveFromBlockz"AlterChildTest.testRemoveFromBlockV   sf    C
 ;;sDyy|Hq!J8Z0H 	UZZ%x0r   c                 .   d}t        j                  d      j                  d   }d}t        j                  |      }|j                  d   }|j                  d   }t        j                  |||       | j                  |t        j                  |             y )Nz6def foo():
  a = 0
  a += 1 # replace this
  return a
zfoo(a + 1)  # trailing comment
r   z:def foo():
  a = 0
  foo(a + 1) # replace this
  return a
   )r!   r"   r#   r   replace_childr   r%   )r   r   replace_withr*   tparentnode_to_replaces          r   testReplaceChildInBodyz%AlterChildTest.testReplaceChildInBodyg   sx    
FC;;ABGGJLOHCAVVAYFkk!nOFO\BXuzz!}-r   c                 H   d}t        j                  d      j                  d   }t        j                  |      }|j                  d   }|j                  d   }| j                  t        j
                        5  t        j                  |||       d d d        y # 1 sw Y   y xY w)Nzdef foo():
  return 1
x = 1
zbar()r   r6   )r!   r"   r#   assertRaisesr   InvalidAstErrorr   r7   )r   r   r8   r9   r:   r;   s         r   testReplaceChildInvalidz&AlterChildTest.testReplaceChildInvalids   s    
+C;;w',,Q/LCAVVAYFffQiO			611	2 Efo|DE E Es   7BB!N)r   r   r   r+   r0   r4   r<   r@   r   r   r   r   r   5   s    ',:1"
.Er   r   )__doc__
__future__r   r   r   r!   pasta.augmentr   
pasta.baser   r   TestCaser
   r   r   r   r   <module>rF      sI     '  %      !D
## D4FEZ(( FEr   