o
    2h                     @   s|   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
 d
e
jZG dd de
jZdS )zTests for ast_utils.    )absolute_import)division)print_functionN)errors)	ast_utils)
test_utilsc                   @   s   e Zd Zdd ZdS )	UtilsTestc                 C   st   d}d}d}|D ]/}|j |d}| |t| d}| || t||  d}| || t||  qd S )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_prefix r   T/var/www/html/chatgem/venv/lib/python3.10/site-packages/pasta/base/ast_utils_test.pytest_sanitize_source   s   

zUtilsTest.test_sanitize_sourceN)__name__
__module____qualname__r   r   r   r   r   r      s    r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )AlterChildTestc                 C   sL   d}t |}|jd }|jd }t|| t |}d}| || d S )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expectedr   r   r   testRemoveChildMethod7   s   



z$AlterChildTest.testRemoveChildMethodc                 C   sD   d}t |}|jd }|jd }t|| | t |d d S )Nzfrom a import b, cr   zfrom a import c)r   r   r   namesr   r   r   r   )r   r   r    import_nodealias1r   r   r   testRemoveAliasM   s   


zAlterChildTest.testRemoveAliasc                 C   sH   d}t |}|jd }|jd }t|| d}| t || d S )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$   r   r   r   testRemoveFromBlockV   s   


z"AlterChildTest.testRemoveFromBlockc                 C   sZ   d}t djd }d}t |}|jd }|jd }t||| | |t | d S )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_replacer   r   r   testReplaceChildInBodyg   s   


z%AlterChildTest.testReplaceChildInBodyc                 C   sr   d}t djd }t |}|jd }|jd }| tj t||| W d    d S 1 s2w   Y  d S )Nzdef foo():
  return 1
x = 1
zbar()r   r-   )r   r   r   assertRaisesr   InvalidAstErrorr   r.   )r   r   r/   r0   r1   r2   r   r   r   testReplaceChildInvalids   s   


"z&AlterChildTest.testReplaceChildInvalidN)r   r   r   r%   r)   r,   r3   r6   r   r   r   r   r   5   s    	r   )__doc__
__future__r   r   r   r   pasta.augmentr   
pasta.baser   r   TestCaser   r   r   r   r   r   <module>   s   