
    dafR                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
mZmZ ddlmZ ddZ G d	 d
ej                         Z G d dej                         Z G d dej                         Z G d de      Z G d de      Z G d de      Z G d dej                         Z G d dej                         Z G d dej                         Z G d dej                         Zy)z' Test suite for the code in fixer_util    )support    )NodeLeaf)
fixer_util)AttrNameCallComma)tokenc                 |    t        j                  |       }t        |      D ]  }|j                  d   } d |_        |S )Nr   )r   parse_stringrangechildrenparent)codestrip_levelstreeis       6/root/Python-3.12.4/Lib/test/test_lib2to3/test_util.pyparser      sB     %D<   }}Q DKK    c                       e Zd Zd Zy)MacroTestCasec                     t        |t        t        f      r$t        t        j
                  j                  |      }| j                  t        |      |       y N)	
isinstancetuplelistr   r   symssimple_stmtassertEqualstr)selfnodestrings      r   	assertStrzMacroTestCase.assertStr   s:    dUDM*
33T:DTF+r   N)__name__
__module____qualname__r'    r   r   r   r      s    ,r   r   c                       e Zd Zd Zd Zd Zy)Test_is_tuplec                 B    t        j                  t        |d            S N   r   )r   is_tupler   r$   r&   s     r   r2   zTest_is_tuple.is_tuple   s    ""5a#@AAr   c                 D   | j                  | j                  d             | j                  | j                  d             | j                  | j                  d             | j                  | j                  d             | j                  | j                  d             y )Nz(a, b)z(a, (b, c))z((a, (b, c)),)z(a,)z())
assertTruer2   r$   s    r   
test_validzTest_is_tuple.test_valid    sl    h/0m45&678f-.d+,r   c                     | j                  | j                  d             | j                  | j                  d             y )Nz(a)z('foo') % (b, c))assertFalser2   r6   s    r   test_invalidzTest_is_tuple.test_invalid'   s1    u-.'9:;r   N)r(   r)   r*   r2   r7   r:   r+   r   r   r-   r-      s    B-<r   r-   c                       e Zd Zd Zd Zd Zy)Test_is_listc                 B    t        j                  t        |d            S r/   )r   is_listr   r3   s     r   r>   zTest_is_list.is_list-   s    !!%Q"?@@r   c                 D   | j                  | j                  d             | j                  | j                  d             | j                  | j                  d             | j                  | j                  d             | j                  | j                  d             y )Nz[]z[a]z[a, b]z[a, [b, c]]z[[a, [b, c]],])r5   r>   r6   s    r   r7   zTest_is_list.test_valid0   sl    T*+U+,X./]34%567r   c                 D    | j                  | j                  d             y )Nz[]+[])r9   r>   r6   s    r   r:   zTest_is_list.test_invalid7   s    g./r   N)r(   r)   r*   r>   r7   r:   r+   r   r   r<   r<   ,   s    A80r   r<   c                       e Zd Zd Zd Zy)	Test_Attrc                     t        dd      }| j                  t        t        d      t        d            d       | j                  t        |t        d            d       y )Nzfoo()r0   r1   aba.bzfoo().b)r   r'   r   r	   )r$   calls     r   testzTest_Attr.test<   sD    W1-tDItCy159tD$s),i8r   c                 ~    t        t        d      t        d            }| j                  t        |      t               y )NrD   rE   )r   r	   r"   typer   )r$   attrs     r   test_returnszTest_Attr.test_returnsB   s*    DItCy)dT*r   N)r(   r)   r*   rH   rL   r+   r   r   rB   rB   ;   s    9+r   rB   c                       e Zd Zd Zy)	Test_Namec                     | j                  t        d      d       | j                  t        d      d       | j                  t        dd      d       y )NrD   zfoo.foo().barrE   prefixba)r'   r	   r6   s    r   rH   zTest_Name.testH   s<    tCy#&tO,o>tC,d3r   N)r(   r)   r*   rH   r+   r   r   rN   rN   G   s    4r   rN   c                       e Zd ZddZd Zy)	Test_CallNc                     g }t        |t              rA|D ],  }|j                  |       |j                  t                      . |j	                          t        t        |      ||      S )zHelp the next test)r   r   appendr   popr
   r	   )r$   nameargsrQ   r   args         r   _CallzTest_Call._CallO   sX    dD! )$() LLNDJ&11r   c           	         d t        t        j                  d      t        t        j                  d      t        t        j                  d      gt        t        j                  d      t        t        j                  d      t        t        j                  d      t        t        j                  d      gt        t        j                  d      t        t        j                  dd      gg}| j	                  | j                  d	      d
       | j	                  | j                  d|d         d       | j	                  | j                  d|d         d       | j	                  | j                  d|d   d      d       y )Nr   r0         rE   j rP   AzA()zb(1,2,3)za.b().cza.b().c(1,3,2,4)dz d(b, j))r   r   NUMBERSTRINGr'   r[   )r$   kidss     r   rH   zTest_Call.testY   s	   ellA&U\\1(=ellA&(ellA&U\\1(=ellA&U\\1(=?ellC($u||S*MN 	tzz#.tzz#tAw/<tzz)T!W57IJtzz#tAwsz;ZHr   )NN)r(   r)   r*   r[   rH   r+   r   r   rT   rT   N   s    2Ir   rT   c                   $    e Zd Zd Zd Zd Zd Zy)Test_does_tree_importc                     t        j                  ||      }|r|S |j                  D ]  }| j                  ||      }|s|c S  y r   )r   find_bindingr   _find_bind_rec)r$   rX   r%   cchilds        r   rj   z$Test_does_tree_import._find_bind_rech   sI     ##D$/Qh]] 	E##D%0A(	r   c                 j    t        |      }| j                  d|      }t        j                  |||      S )Nstart)r   rj   r   does_tree_import)r$   packagerX   r&   r%   s        r   ro   z&Test_does_tree_import.does_tree_importq   s2    V}""7D1**7D$??r   c                    d}|D ]Z  \  }}}| j                  |||dz   |z         }| j                  |       | j                  |||dz   |z         }| j                  |       \ d}|D ]Z  \  }}}| j                  |||dz   |z         }| j                  |       | j                  |||dz   |z         }| j                  |       \ y )N))rD   rD   from a import b)a.drD   from a.d import b)zd.arD   from d.a import b)NrD   import b)NrD   import b, c, d
))rD   rD   from a import a)xrD   from x import a)rz   rD   from x import b, c, a, d)x.brD   from x.b import a)r}   rD   from x.b import b, c, a, d)NrD   import a)NrD   import b, c, a, d)ro   r9   r5   )r$   r&   failing_testsrp   rX   import_npassing_testss           r   try_withzTest_does_tree_import.try_withw   s    8
 '4 	 "GT7%%gtWt^f5LMAQ%%gtVd]W5LMAQ		 ; '4 	"GT7%%gtWt^f5LMAOOA%%gtVd]W5LMAOOA		r   c                 &    | j                  d       y )Nzdef foo():
	bar.baz()
	start=3)r   r6   s    r   test_in_functionz&Test_does_tree_import.test_in_function   s    :;r   N)r(   r)   r*   rj   ro   r   r   r+   r   r   rg   rg   g   s    @2<r   rg   c                       e Zd ZddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)Test_find_bindingNc                 B    t        j                  |t        |      |      S r   )r   ri   r   )r$   rX   r&   rp   s       r   ri   zTest_find_binding.find_binding   s    &&tU6]GDDr   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             y )NrD   za = bza = [b, c, d]z	a = foo()za = foo().foo.foo[6][foo]zfoo = azfoo = (a, b, c)r5   ri   r9   r6   s    r   test_simple_assignmentz(Test_find_binding.test_simple_assignment   s    ))#w78))#?@))#{;<))#/JKL**3	:;**30ABCr   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             y )NrD   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   r6   s    r   test_tuple_assignmentz'Test_find_binding.test_tuple_assignment   s    ))#z:;))#/FGH))#/GHI))#/KLM**30CDE**30KLMr   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             y )NrD   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   r6   s    r   test_list_assignmentz&Test_find_binding.test_list_assignment   s    ))#y9:))#/FGH))#/GHI))#/KLM**30CDE**30KLMr   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             y )NrD   z	foo.a = 5z
foo[a] = 5z
foo(a) = 5zfoo(a, b) = 5r9   ri   r6   s    r   test_invalid_assignmentsz*Test_find_binding.test_invalid_assignments   sn    **3<=**3=>**3=>**3@Ar   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             y )NrD   r   r   rv   rw   r   r6   s    r   test_simple_importz$Test_find_binding.test_simple_import   sl    ))#z:;))#/BCD**3
;<**30@ABr   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd	             y )
NrD   r{   ry   r|   r~   r   rr   rt   ru   r   r6   s    r   test_from_importz"Test_find_binding.test_from_import   s    ))#/@AB))#/@AB))#/IJK))#/BCD))#/KLM**30ABC**30CDE**30CDEr   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             y )NrD   zimport b as azimport b as a, c, a as f, dimport a as fzimport b, c as f, d as er   r6   s    r   test_import_asz Test_find_binding.test_import_as   sl    ))#?@))#/LMN**3@A**30JKLr   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             y )	NrD   from x import b as afrom x import g as a, d as bfrom x.b import t as afrom x.b import g as a, dfrom a import b as tzfrom a.d import b as tzfrom d.a import b as tr   r6   s    r   test_from_import_asz%Test_find_binding.test_from_import_as   s    ))#/EFG))#/MNO))#/GHI))#/JKL**30FGH**30HIJ**30HIJr   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  ddd             | j                  | j                  ddd             y )NrE   rv   rw   rk   r   r6   s    r   test_simple_import_with_packagez1Test_find_binding.test_simple_import_with_package   sp    ))#z:;))#/?@A**3
C@A**30@#FGr   c                    | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  dd	d             | j                  | j                  dd
d             | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  ddd             y )NrD   r{   rz   ry   zfrom x import *r|   r~   r}   zfrom x.b import *r   rr   rt   rs   ru   zfrom x.y import *rF   r   r6   s    r   test_from_import_with_packagez/Test_find_binding.test_from_import_with_package   s>   ))#/@#FG))#/@#FG))#/@#FG))#/I3OP))#/BEJK))#/BEJK))#/KUST**30A3GH**30CUKL**30CUKL**30CUKLr   c                     | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  ddd             y )NrD   zimport b.c as azb.cr   fr   r6   s    r   test_import_as_with_packagez-Test_find_binding.test_import_as_with_package   sZ    **30A5IJ**3EF**3EFr   c                    | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  ddd             | j                  | j                  ddd	             | j                  | j                  ddd
             y )NrD   r   rz   r   r   r}   r   r   rE   tr   r6   s    r    test_from_import_as_with_packagez2Test_find_binding.test_from_import_as_with_package   s     	**30FLM**30NPSTU**30H%PQ**30KUST**30FLM**30FLM**30FLMr   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             d	}| j                  | j                  d|             y )
NrD   zdef a(): passzdef a(b, c, d): passzdef a(): b = 7zdef d(b, (c, a), e): passzdef d(a=7): passzdef d(a): passzdef d(): a = 7zG
            def d():
                def a():
                    passr   r$   ss     r   test_function_defz#Test_find_binding.test_function_def   s    ))#?@))#/EFG))#/?@A**30KLM**30BCD**30@AB**30@AB 	**323r   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd	             | j                  | j                  dd
             | j                  | j                  dd             d}| j                  | j                  d|             y )NrD   zclass a: passzclass a(): passzclass a(b): passzclass a(b, c=8): passzclass d: passzclass d(a): passzclass d(b, a=7): passzclass d(b, *a): passzclass d(b, **a): passzclass d: a = 7zK
            class d():
                class a():
                    passr   r   s     r   test_class_defz Test_find_binding.test_class_def  s4   ))#?@))#/@AB))#/ABC))#/FGH**3@A**30BCD**30GHI**30FGH**30GHI**30@AB 	**323r   c                    | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             | j                  | j                  dd             y )	NrD   zfor a in r: passzfor a, b in r: passzfor (a, b) in r: passzfor c, (a,) in r: passzfor c, (a, b) in r: passzfor c in r: a = czfor c in a: passr   r6   s    r   test_forzTest_find_binding.test_for  s    ))#/ABC))#/DEF))#/FGH))#/GHI))#/IJK))#/BCD**30BCDr   c                 4   d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d	}| j                  | j                  d|             y )
NzM
            for b in r:
                for a in b:
                    passrD   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 = 7r   r   s     r   test_for_nestedz!Test_find_binding.test_for_nested"  s    	))#q12 	))#q12 	))#q12 	))#q12 	))#q12 	))#q12 	**323 	**323r   c                     | j                  | j                  dd             | j                  | j                  dd             y )NrD   zif b in r: a = czif a in r: d = er   r6   s    r   test_ifzTest_find_binding.test_ifS  s8    ))#/ABC**30BCDr   c                     d}| j                  | j                  d|             d}| j                  | j                  d|             y )NzL
            if b in r:
                if c in d:
                    a = crD   zL
            if b in r:
                if c in d:
                    c = ar   r   s     r   test_if_nestedz Test_find_binding.test_if_nestedW  H     	))#q12 	**323r   c                     | j                  | j                  dd             | j                  | j                  dd             y )NrD   zwhile b in r: a = czwhile a in r: d = er   r6   s    r   
test_whilezTest_find_binding.test_whiled  s8    ))#/DEF**30EFGr   c                     d}| j                  | j                  d|             d}| j                  | j                  d|             y )NzR
            while b in r:
                while c in d:
                    a = crD   zR
            while b in r:
                while c in d:
                    c = ar   r   s     r   test_while_nestedz#Test_find_binding.test_while_nestedh  r   r   c                    d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             y )NzQ
            try:
                a = 6
            except:
                b = 8rD   zQ
            try:
                b = 8
            except:
                a = 6z
            try:
                b = 8
            except KeyError:
                pass
            except:
                a = 6Q
            try:
                b = 8
            except:
                b = 6r   r   s     r   test_try_exceptz!Test_find_binding.test_try_exceptu  s    
 	))#q12
 	))#q12 	))#q12
 	**323r   c                    d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             y )	Nz
            try:
                try:
                    a = 6
                except:
                    pass
            except:
                b = 8rD   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 = 6r   a  
            try:
                try:
                    b = 8
                except:
                    c = d
            except:
                try:
                    b = 6
                except:
                    t = 8
                except:
                    o = yr   r   s     r   test_try_except_nestedz(Test_find_binding.test_try_except_nested  s     	))#q12 	))#q12 	))#q12	 	))#q12	 	))#q12
 	**323 	**323r   c                    d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             y )Nz|
            try:
                c = 6
            except:
                b = 8
            finally:
                a = 9rD   zR
            try:
                b = 8
            finally:
                a = 6zR
            try:
                b = 8
            finally:
                b = 6z|
            try:
                b = 8
            except:
                b = 9
            finally:
                b = 6r   r   s     r   test_try_except_finallyz)Test_find_binding.test_try_except_finally  s     	))#q12
 	))#q12
 	**323 	**323r   c                     d}| j                  | j                  d|             d}| j                  | j                  d|             d}| j                  | j                  d|             y )Nz
            try:
                c = 6
            except:
                b = 8
            finally:
                try:
                    a = 9
                except:
                    b = 9
                finally:
                    c = 9rD   z
            try:
                b = 8
            finally:
                try:
                    pass
                finally:
                    a = 6z
            try:
                b = 8
            finally:
                try:
                    b = 6
                finally:
                    b = 7r   r   s     r   test_try_except_finally_nestedz0Test_find_binding.test_try_except_finally_nested  sj     	))#q12 	))#q12 	**323r   r   )r(   r)   r*   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r+   r   r   r   r      s    EDNNBCFMKHMG

N44$E/4bE4H44>K4Z4B!4r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)Test_touch_importc                 ~    t        d      }t        j                  d d|       | j                  t	        |      d       y )Nz"""foo"""
bar()fooz"""foo"""
import foo
bar()

r   r   touch_importr"   r#   r$   r%   s     r   test_after_docstringz&Test_touch_import.test_after_docstring'  s4    '(eT2T$FGr   c                 ~    t        d      }t        j                  d d|       | j                  t	        |      d       y )Nz"""foo"""
import bar
bar()r   z'"""foo"""
import bar
import foo
bar()

r   r   s     r   test_after_importsz$Test_touch_import.test_after_imports,  s4    34eT2T$RSr   c                 ~    t        d      }t        j                  d d|       | j                  t	        |      d       y )Nbar()r   zimport foo
bar()

r   r   s     r   test_beginningz Test_touch_import.test_beginning1  2    W~eT2T$;<r   c                 ~    t        d      }t        j                  dd|       | j                  t	        |      d       y )Nr   htmlescapezfrom html import escape
bar()

r   r   s     r   r   z"Test_touch_import.test_from_import6  s2    W~$7T$HIr   c                 ~    t        d      }t        j                  d d|       | j                  t	        |      d       y )Nr   cgizimport cgi
bar()

r   r   s     r   test_name_importz"Test_touch_import.test_name_import;  r   r   N)r(   r)   r*   r   r   r   r   r   r+   r   r   r   r   %  s    H
T
=
J
=r   r   c                       e Zd Zd Zd Zy)Test_find_indentationc                     t         j                  }t        d      }| j                   ||      d       t        d      }| j                   ||      d       y )Nznode() )r   find_indentationr   r"   r$   fir%   s      r   test_nothingz"Test_find_indentation.test_nothingB  sG    ((XD2&RyD2&r   c                 |   t         j                  }t        d      }| j                   ||      d       | j                   ||j                  d   j                  d   j                  d         d       t        d      }| j                   ||j                  d   j                  d   j                  d         d       y )Nzdef f():
    x()r   r   r^   r0   z    zdef f():
    x()
    y())r   r   r   r"   r   r   s      r   test_simplez!Test_find_indentation.test_simpleI  s    ((()D2&DMM!,55a8AA!DEvN12DMM!,55a8AA!DEvNr   N)r(   r)   r*   r   r   r+   r   r   r   r   @  s    'Or   r   N)r   )__doc__r   r   lib2to3.pytreer   r   lib2to3r   lib2to3.fixer_utilr   r	   r
   r   lib2to3.pgen2r   r   TestCaser   r-   r<   rB   rN   rT   rg   r   r   r   r+   r   r   <module>r      s    -  &  6 6 ,G$$ ,<G$$ < 07## 0	+ 	+4 4I I2*<G,, *<XP4(( P4d=(( =6OG,, Or   