a
    ,=icì  ã                   @   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
)Zcodingz"""Docstring."""
z"""Docstring."""
# line 2
)ÚformatÚassertEqualr   Zsanitize_source)ÚselfZcoding_linesZsrc_templateZsanitized_srcÚlineÚsrcÚ
src_prefix© r   új/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/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   ÚtreeZ
class_nodeZ
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   Zimport_nodeZ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   Zif_blockZ
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   sp   d}t  d¡jd }t  |¡}|jd }|jd }|  tj¡ t |||¡ W d   ƒ n1 sb0    Y  d S )Nzdef foo():
  return 1
x = 1
zbar()r   r"   )r   r   r   ÚassertRaisesr   ZInvalidAstErrorr   r#   )r   r   r$   r%   r&   r'   r   r   r   ÚtestReplaceChildInvalids   s    


z&AlterChildTest.testReplaceChildInvalidN)r   r   r   r   r    r!   r(   r*   r   r   r   r   r   5   s
   	r   )Ú__doc__Ú
__future__r   r   r   r   Zpasta.augmentr   Z
pasta.baser   r   ZTestCaser   r   r   r   r   r   Ú<module>   s   