o
    ÆN iģ  ć                   @   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   śM/home/ubuntu/.local/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   