Your IP : 216.73.216.196


Current Path : /opt/alt/python35/lib64/python3.5/lib2to3/tests/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/lib2to3/tests/__pycache__/test_util.cpython-35.opt-2.pyc



���]�R�@sxddlmZddlZddlmZmZddlmZddl	m
Z
mZmZm
Z
ddlmZddd	�ZGd
d�dej�ZGdd
�d
ej�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZdS)�)�support�N)�Node�Leaf)�
fixer_util)�Attr�Name�Call�Comma)�tokencCs@tj|�}x!t|�D]}|jd}qWd|_|S)Nr)rZparse_string�range�children�parent)�code�strip_levelsZtree�i�r�./opt/alt/python35/lib64/python3.5/test_util.py�parses
	rc@seZdZdd�ZdS)�
MacroTestCasecCsDt|ttf�r*ttjj|�}|jt|�|�dS)N)	�
isinstance�tuple�listrrZsymsZsimple_stmt�assertEqual�str)�self�node�stringrrr�	assertStrszMacroTestCase.assertStrN)�__name__�
__module__�__qualname__rrrrrrsrc@s4eZdZdd�Zdd�Zdd�ZdS)�
Test_is_tuplecCstjt|dd��S)Nr�)r�is_tupler)rrrrrr$ szTest_is_tuple.is_tuplecCsr|j|jd��|j|jd��|j|jd��|j|jd��|j|jd��dS)Nz(a, b)z(a, (b, c))z((a, (b, c)),)z(a,)z())�
assertTruer$)rrrr�
test_valid#s
zTest_is_tuple.test_validcCs0|j|jd��|j|jd��dS)Nz(a)z('foo') % (b, c))�assertFalser$)rrrr�test_invalid*szTest_is_tuple.test_invalidN)rr r!r$r&r(rrrrr"sr"c@s4eZdZdd�Zdd�Zdd�ZdS)�Test_is_listcCstjt|dd��S)Nrr#)r�is_listr)rrrrrr*0szTest_is_list.is_listcCsr|j|jd��|j|jd��|j|jd��|j|jd��|j|jd��dS)Nz[]z[a]z[a, b]z[a, [b, c]]z[[a, [b, c]],])r%r*)rrrrr&3s
zTest_is_list.test_validcCs|j|jd��dS)Nz[]+[])r'r*)rrrrr(:szTest_is_list.test_invalidN)rr r!r*r&r(rrrrr)/sr)c@s(eZdZdd�Zdd�ZdS)�	Test_AttrcCsZtddd�}|jttd�td��d�|jt|td��d�dS)Nzfoo()rr#�a�bza.bzfoo().b)rrrr)r�callrrr�test?s%zTest_Attr.testcCs5ttd�td��}|jt|�t�dS)Nr,r-)rrr�typer)r�attrrrr�test_returnsEszTest_Attr.test_returnsN)rr r!r/r2rrrrr+>sr+c@seZdZdd�ZdS)�	Test_NamecCsL|jtd�d�|jtd�d�|jtddd�d�dS)Nr,z
foo.foo().bar�prefixr-Zba)rr)rrrrr/KszTest_Name.testN)rr r!r/rrrrr3Jsr3c@s.eZdZdddd�Zdd�ZdS)�	Test_CallNcCscg}t|t�rMx+|D]#}|j|�|jt��qW|j�tt|�||�S)N)rr�appendr
�popr	r)r�name�argsr4r
�argrrr�_CallRs


zTest_Call._Callc	Cs"dttjd�ttjd�ttjd�gttjd�ttjd�ttjd�ttjd�gttjd�ttjddd�gg}|j|jd	�d
�|j|jd|d�d�|j|jd|d�d
�|j|jd|ddd�d�dS)Nrr#��r-�jr4� �AzA()zb(1,2,3)za.b().cza.b().c(1,3,2,4)�dz d(b, j))rr�NUMBER�STRINGrr;)rZkidsrrrr/\s!-  zTest_Call.test)rr r!r;r/rrrrr5Qs
r5c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�Test_does_tree_importcCsPtj||�}|r|Sx-|jD]"}|j||�}|r&|Sq&WdS)N)r�find_bindingr
�_find_bind_rec)rr8r�cZchildrrrrFksz$Test_does_tree_import._find_bind_reccCs1t|�}|jd|�}tj|||�S)N�start)rrFr�does_tree_import)r�packager8rrrrrrItsz&Test_does_tree_import.does_tree_importc	Cs�d}xk|D]c\}}}|j|||d	|�}|j|�|j|||d	|�}|j|�q
Wd }xk|D]c\}}}|j|||d	|�}|j|�|j|||d	|�}|j|�q�WdS)!Nr,�from a import b�a.d�from a.d import b�d.a�from d.a import b�import b�import b, c, d�
�from a import a�x�from x import a�from x import b, c, a, d�x.b�from x.b import a�from x.b import b, c, a, d�import a�import b, c, a, d�r,r,rK�rLr,rM�rNr,rO�Nr,rP�Nr,rQ)r\r]r^r_r`�r,r,rS�rTr,rU�rTr,rV�rWr,rX�rWr,rY�Nr,rZ�Nr,r[)rarbrcrdrerfrg)rIr'r%)rrZ
failing_testsrJr8�import_�nZ
passing_testsrrr�try_withzs,

zTest_does_tree_import.try_withcCs|jd�dS)Nzdef foo():
	bar.baz()
	start=3)rj)rrrr�test_in_function�sz&Test_does_tree_import.test_in_functionN)rr r!rFrIrjrkrrrrrDjs	rDc@s?eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�ZdS)4�Test_find_bindingNcCstj|t|�|�S)N)rrEr)rr8rrJrrrrE�szTest_find_binding.find_bindingcCs�|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��dS)Nr,za = bz
a = [b, c, d]z	a = foo()za = foo().foo.foo[6][foo]zfoo = azfoo = (a, b, c))r%rEr')rrrr�test_simple_assignment�sz(Test_find_binding.test_simple_assignmentcCs�|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��dS)Nr,z(a,) = bz(a, b, c) = [b, c, d]z(c, (d, a), b) = foo()z(a, b) = foo().foo[6][foo]z(foo, b) = (b, a)z(foo, (b, c)) = (a, b, c))r%rEr')rrrr�test_tuple_assignment�sz'Test_find_binding.test_tuple_assignmentcCs�|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��dS)Nr,z[a] = bz[a, b, c] = [b, c, d]z[c, [d, a], b] = foo()z[a, b] = foo().foo[a][foo]z[foo, b] = (b, a)z[foo, [b, c]] = (a, b, c))r%rEr')rrrr�test_list_assignment�sz&Test_find_binding.test_list_assignmentcCsh|j|jdd��|j|jdd��|j|jdd��|j|jdd��dS)Nr,z	foo.a = 5z
foo[a] = 5z
foo(a) = 5z
foo(a, b) = 5)r'rE)rrrr�test_invalid_assignments�sz*Test_find_binding.test_invalid_assignmentscCsh|j|jdd��|j|jdd��|j|jdd��|j|jdd��dS)Nr,zimport azimport b, c, a, dzimport bzimport b, c, d)r%rEr')rrrr�test_simple_import�sz$Test_find_binding.test_simple_importcCs�|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd	��dS)
Nr,zfrom x import azfrom a import azfrom x import b, c, a, dzfrom x.b import azfrom x.b import b, c, a, dzfrom a import bzfrom a.d import bzfrom d.a import b)r%rEr')rrrr�test_from_import�sz"Test_find_binding.test_from_importcCsh|j|jdd��|j|jdd��|j|jdd��|j|jdd��dS)Nr,z
import b as azimport b as a, c, a as f, dz
import a as fzimport b, c as f, d as e)r%rEr')rrrr�test_import_as�sz Test_find_binding.test_import_ascCs�|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��dS)	Nr,zfrom x import b as azfrom x import g as a, d as bzfrom x.b import t as azfrom x.b import g as a, dzfrom a import b as tzfrom a.d import b as tzfrom d.a import b as t)r%rEr')rrrr�test_from_import_as�sz%Test_find_binding.test_from_import_ascCsn|j|jdd��|j|jdd��|j|jddd��|j|jddd��dS)Nr-zimport bzimport b, c, drG)r%rEr')rrrr�test_simple_import_with_package�sz1Test_find_binding.test_simple_import_with_packagecCs8|j|jddd��|j|jddd��|j|jddd��|j|jddd��|j|jddd��|j|jdd	d��|j|jdd
d��|j|jddd��|j|jddd
��|j|jddd
��|j|jddd��dS)Nr,zfrom x import arTzfrom a import azfrom x import *zfrom x import b, c, a, dzfrom x.b import azx.bzfrom x.b import *zfrom x.b import b, c, a, dzfrom a import bzfrom a.d import bza.dzfrom d.a import bzfrom x.y import *za.b)r%rEr')rrrr�test_from_import_with_package�sz/Test_find_binding.test_from_import_with_packagecCsX|j|jddd��|j|jddd��|j|jddd��dS)Nr,zimport b.c as azb.cz
import a as f�f)r'rE)rrrr�test_import_as_with_package�sz-Test_find_binding.test_import_as_with_packagecCs�|j|jddd��|j|jddd��|j|jddd��|j|jddd��|j|jddd��|j|jddd	��|j|jddd
��dS)Nr,zfrom x import b as arTzfrom x import g as a, d as bzfrom x.b import t as azx.bzfrom x.b import g as a, dzfrom a import b as tr-�t)r'rE)rrrr� test_from_import_as_with_package�sz2Test_find_binding.test_from_import_as_with_packagecCs�|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��d	}|j|jd|��dS)
Nr,z
def a(): passzdef a(b, c, d): passzdef a(): b = 7zdef d(b, (c, a), e): passzdef d(a=7): passzdef d(a): passzdef d(): a = 7zG
            def d():
                def a():
                    pass)r%rEr')r�srrr�test_function_def�sz#Test_find_binding.test_function_defcCs|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd	��|j|jdd
��|j|jdd��d}|j|jd|��dS)
Nr,z
class a: passzclass a(): passzclass a(b): passzclass a(b, c=8): passz
class d: passzclass d(a): passzclass d(b, a=7): passzclass d(b, *a): passzclass d(b, **a): passzclass d: a = 7zK
            class d():
                class a():
                    pass)r%rEr')rr{rrr�test_class_def
sz Test_find_binding.test_class_defcCs�|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��|j|jdd��dS)	Nr,zfor a in r: passzfor a, b in r: passzfor (a, b) in r: passzfor c, (a,) in r: passzfor c, (a, b) in r: passzfor c in r: a = czfor c in a: pass)r%rEr')rrrr�test_forszTest_find_binding.test_forcCs�d}|j|jd|��d}|j|jd|��d}|j|jd|��d}|j|jd|��d}|j|jd|��d}|j|jd|��d}|j|jd|��d	}|j|jd|��dS)
NzM
            for b in r:
                for a in b:
                    passr,zP
            for b in r:
                for a, c in b:
                    passzR
            for b in r:
                for (a, c) in b:
                    passzP
            for b in r:
                for (a,) in b:
                    passzU
            for b in r:
                for c, (a, d) in b:
                    passzN
            for b in r:
                for c in b:
                    a = 7zN
            for b in r:
                for c in b:
                    d = azN
            for b in r:
                for c in a:
                    d = 7)r%rEr')rr{rrr�test_for_nested%s z!Test_find_binding.test_for_nestedcCs6|j|jdd��|j|jdd��dS)Nr,zif b in r: a = czif a in r: d = e)r%rEr')rrrr�test_ifVszTest_find_binding.test_ifcCsBd}|j|jd|��d}|j|jd|��dS)NzL
            if b in r:
                if c in d:
                    a = cr,zL
            if b in r:
                if c in d:
                    c = a)r%rEr')rr{rrr�test_if_nestedZsz Test_find_binding.test_if_nestedcCs6|j|jdd��|j|jdd��dS)Nr,zwhile b in r: a = czwhile a in r: d = e)r%rEr')rrrr�
test_whilegszTest_find_binding.test_whilecCsBd}|j|jd|��d}|j|jd|��dS)NzR
            while b in r:
                while c in d:
                    a = cr,zR
            while b in r:
                while c in d:
                    c = a)r%rEr')rr{rrr�test_while_nestedksz#Test_find_binding.test_while_nestedcCs�d}|j|jd|��d}|j|jd|��d}|j|jd|��d}|j|jd|��dS)NzQ
            try:
                a = 6
            except:
                b = 8r,zQ
            try:
                b = 8
            except:
                a = 6z�
            try:
                b = 8
            except KeyError:
                pass
            except:
                a = 6zQ
            try:
                b = 8
            except:
                b = 6)r%rEr')rr{rrr�test_try_exceptxsz!Test_find_binding.test_try_exceptcCs�d}|j|jd|��d}|j|jd|��d}|j|jd|��d}|j|jd|��d}|j|jd|��d}|j|jd|��d}|j|jd|��dS)	Nz�
            try:
                try:
                    a = 6
                except:
                    pass
            except:
                b = 8r,z�
            try:
                b = 8
            except:
                try:
                    a = 6
                except:
                    passz�
            try:
                b = 8
            except:
                try:
                    pass
                except:
                    a = 6z�
            try:
                try:
                    b = 8
                except KeyError:
                    pass
                except:
                    a = 6
            except:
                passz�
            try:
                pass
            except:
                try:
                    b = 8
                except KeyError:
                    pass
                except:
                    a = 6zQ
            try:
                b = 8
            except:
                b = 6a
            try:
                try:
                    b = 8
                except:
                    c = d
            except:
                try:
                    b = 6
                except:
                    t = 8
                except:
                    o = y)r%rEr')rr{rrr�test_try_except_nested�s		z(Test_find_binding.test_try_except_nestedcCs�d}|j|jd|��d}|j|jd|��d}|j|jd|��d}|j|jd|��dS)Nz|
            try:
                c = 6
            except:
                b = 8
            finally:
                a = 9r,zR
            try:
                b = 8
            finally:
                a = 6zR
            try:
                b = 8
            finally:
                b = 6z|
            try:
                b = 8
            except:
                b = 9
            finally:
                b = 6)r%rEr')rr{rrr�test_try_except_finally�sz)Test_find_binding.test_try_except_finallycCsad}|j|jd|��d}|j|jd|��d}|j|jd|��dS)Nz�
            try:
                c = 6
            except:
                b = 8
            finally:
                try:
                    a = 9
                except:
                    b = 9
                finally:
                    c = 9r,z�
            try:
                b = 8
            finally:
                try:
                    pass
                finally:
                    a = 6z�
            try:
                b = 8
            finally:
                try:
                    b = 6
                finally:
                    b = 7)r%rEr')rr{rrr�test_try_except_finally_nesteds		z0Test_find_binding.test_try_except_finally_nested)rr r!rErmrnrorprqrrrsrtrurvrxrzr|r}r~rr�r�r�r�r�r�r�r�rrrrrl�s2
	
	1

M!rlc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�Test_touch_importcCs9td�}tjdd|�|jt|�d�dS)Nz"""foo"""
bar()�fooz"""foo"""
import foo
bar()

)rr�touch_importrr)rrrrr�test_after_docstring*sz&Test_touch_import.test_after_docstringcCs9td�}tjdd|�|jt|�d�dS)Nz"""foo"""
import bar
bar()r�z'"""foo"""
import bar
import foo
bar()

)rrr�rr)rrrrr�test_after_imports/sz$Test_touch_import.test_after_importscCs9td�}tjdd|�|jt|�d�dS)Nzbar()r�zimport foo
bar()

)rrr�rr)rrrrr�test_beginning4sz Test_touch_import.test_beginningcCs9td�}tjdd|�|jt|�d�dS)Nzbar()Zhtml�escapezfrom html import escape
bar()

)rrr�rr)rrrrrrr9sz"Test_touch_import.test_from_importcCs9td�}tjdd|�|jt|�d�dS)Nzbar()Zcgizimport cgi
bar()

)rrr�rr)rrrrr�test_name_import>sz"Test_touch_import.test_name_importN)rr r!r�r�r�rrr�rrrrr�(s
r�c@s(eZdZdd�Zdd�ZdS)�Test_find_indentationcCsQtj}td�}|j||�d�td�}|j||�d�dS)Nznode()�)r�find_indentationrr)r�firrrr�test_nothingEs
	z"Test_find_indentation.test_nothingcCs�tj}td�}|j||�d�|j||jdjdjd�d�td�}|j||jdjdjd�d�dS)Nzdef f():
    x()r�rr=r#z    zdef f():
    x()
    y())rr�rrr
)rr�rrrr�test_simpleLs	+z!Test_find_indentation.test_simpleN)rr r!r�r�rrrrr�Csr�)r�rZos.path�osZlib2to3.pytreerrZlib2to3rZlib2to3.fixer_utilrrr	r
Z
lib2to3.pgen2rrZTestCaserr"r)r+r3r5rDrlr�r�rrrr�<module>s""	,��