
    -Ph!                     "   d dl Zd dlZd dlmZ d dlT d dlmZ d dlT d dlm	Z	m
Z
mZ  G d de          Z G d d	          Z G d
 de          Z	 eZ G d de          Z G d dej                  Zedk    rd dlZ ej                     dS dS )    N)TransformTest)*)_calculate_pickle_checksums)MainSymtabOptionsc                   ,    e Zd Zd Zd Zd Zd Zd ZdS )TestNormalizeTreec                     |                      d          j        }|                     d|                     |                     d S )Nif x: yz
(root): StatListNode
  stats[0]: IfStatNode
    if_clauses[0]: IfClauseNode
      condition: NameNode
      body: ExprStatNode
        expr: NameNode
)fragmentrootassertLines	treetypesselfts     m/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.py)test_parserbehaviour_is_what_we_coded_forz;TestNormalizeTree.test_parserbehaviour_is_what_we_coded_for   sN    MM)$$)  
^^A	 	 	 	 	    c                     |                      t          d           gd          }|                     d|                     |                     d S )Nr   z
(root): StatListNode
  stats[0]: IfStatNode
    if_clauses[0]: IfClauseNode
      condition: NameNode
      body: StatListNode
        stats[0]: ExprStatNode
          expr: NameNode
run_pipelineNormalizeTreer   r   r   s     r   test_wrap_singlestatz&TestNormalizeTree.test_wrap_singlestat   sZ    }T223Y??  
^^A	 	 	 	 	r   c                     |                      t          d           gd          }|                     d|                     |                     d S )Nz?
            if z:
                x
                y
        z
(root): StatListNode
  stats[0]: IfStatNode
    if_clauses[0]: IfClauseNode
      condition: NameNode
      body: StatListNode
        stats[0]: ExprStatNode
          expr: NameNode
        stats[1]: ExprStatNode
          expr: NameNode
r   r   s     r   test_wrap_multistatz%TestNormalizeTree.test_wrap_multistat#   sc    }T223 6  
 	 
 
^^A
	 
	 
	 
	 
	r   c                     |                      t          d           gd          }|                     d|                     |                     d S )Nz!
            a, b = x, y
        z
(root): StatListNode
  stats[0]: SingleAssignmentNode
    lhs: TupleNode
      args[0]: NameNode
      args[1]: NameNode
    rhs: TupleNode
      args[0]: NameNode
      args[1]: NameNode
r   r   s     r   test_statinexprz!TestNormalizeTree.test_statinexpr5   sc    }T223 6   	 	 
^^A		 		 		 		 		r   c                     |                      t          d           gd          }|                     d|                     |                     d S )NzI
            x
            y
            if z:
                x
        a  
(root): StatListNode
  stats[0]: ExprStatNode
    expr: NameNode
  stats[1]: ExprStatNode
    expr: NameNode
  stats[2]: IfStatNode
    if_clauses[0]: IfClauseNode
      condition: NameNode
      body: StatListNode
        stats[0]: ExprStatNode
          expr: NameNode
r   r   s     r   test_wrap_offagainz$TestNormalizeTree.test_wrap_offagainD   sc    }T223 6   	  
^^A	 	 	 	 	r   N)__name__
__module____qualname__r   r   r   r   r!    r   r   r
   r
      s_        	 	 	
 
 
  $      r   r
   c                       e Zd Zd Zd ZdS )TestWithTransformc                 z    |                      t          d           gd          }|                     d|           d S )Nz0
        with x:
            y = z ** 3
        ax  

        $0_0 = x
        $0_2 = $0_0.__exit__
        $0_0.__enter__()
        $0_1 = True
        try:
            try:
                $1_0 = None
                y = z ** 3
            except:
                $0_1 = False
                if (not $0_2($1_0)):
                    raise
        finally:
            if $0_1:
                $0_2(None, None, None)

        r   WithTransform
assertCoder   s     r   test_simplifiedz!TestWithTransform.test_simplified\   sU    }T223 6  
 	 $ %	 	 	 	 	r   c                 z    |                      t          d           gd          }|                     d|           d S )Nz5
        with x as y:
            y = z ** 3
        a  

        $0_0 = x
        $0_2 = $0_0.__exit__
        $0_3 = $0_0.__enter__()
        $0_1 = True
        try:
            try:
                $1_0 = None
                y = $0_3
                y = z ** 3
            except:
                $0_1 = False
                if (not $0_2($1_0)):
                    raise
        finally:
            if $0_1:
                $0_2(None, None, None)

        r)   r   s     r   
test_basiczTestWithTransform.test_basicv   sU    }T223 6   	 & '	 	 	 	 	r   N)r"   r#   r$   r,   r.   r%   r   r   r'   r'   Z   s2          4    r   r'   c                   L     e Zd ZdZdZddddddddZ fdZd	 Zd
 Zd Z	 xZ
S )TestInterpretCompilerDirectiveszO
    This class tests the parallel directives AST-rewriting and importing.
    a?  
        cimport cython.parallel
        cimport cython.parallel as par
        from cython cimport parallel as par2
        from cython cimport parallel

        from cython.parallel cimport threadid as tid
        from cython.parallel cimport threadavailable as tavail
        from cython.parallel cimport prange
    cython.parallelzcython.parallel.threadidzcython.parallel.threadavailablezcython.parallel.prange)r1   parpar2paralleltidtavailprangec                 T   t                                                       t          j        t          j                  }t
          j                            |          }t          ||j	                  }t          j        dd |          |_        |g| _        t          j        | _        d S )N__main__)supersetUpr   CompilationOptionsdefault_optionsr   Contextfrom_optionsInterpretCompilerDirectivescompiler_directivesr   ModuleScopemodule_scopepipeline
DebugFlagsdebug_exception_on_error)r   compilation_optionsctx	transform	__class__s       r   r;   z%TestInterpretCompilerDirectives.setUp   s    %89PQQl''(;<</S5LMM	!'!3Jc!J!J	"(2(K%%%r   c                 (    | j         t          _         d S N)rF   rE   )r   s    r   tearDownz(TestInterpretCompilerDirectives.tearDown   s    .2.K
+++r   c                     |                      | j        | j                   | j        d         j        }|                     || j                   d S )Nr   )r   rD   import_codeparallel_directivesassertEqualexpected_directives_dictr   rP   s     r   !test_parallel_directives_cimportszATestInterpretCompilerDirectives.test_parallel_directives_cimports   sM    $-)9:::"mA.B,d.KLLLLLr   c                     |                      | j        | j                            dd                     | j        d         j        }|                     || j                   d S )Ncimportimportr   )r   rD   rO   replacerP   rQ   rR   rS   s     r    test_parallel_directives_importsz@TestInterpretCompilerDirectives.test_parallel_directives_imports   sg    $-*229hGG	I 	I 	I"mA.B,d.KLLLLLr   )r"   r#   r$   __doc__rO   rR   r;   rM   rT   rY   __classcell__)rJ   s   @r   r0   r0      s         	K - !%)3*	  	 
L 
L 
L 
L 
LL L LM M M
M M M M M M Mr   r0   F)DebugWriter)DebuggerTestCasec                       e Zd Zd Zd ZdS )TestDebugTransformc                 :    t          fd|D                       S )Nc              3   *   K   | ]}|j         v V  d S rL   attrib).0attrelems     r   	<genexpr>z3TestDebugTransform.elem_hasattrs.<locals>.<genexpr>   s*      99444;&999999r   )all)r   rf   attrss    ` r   elem_hasattrsz TestDebugTransform.elem_hasattrs   s&    99995999999r   c                     	 t           j                            | j                  sJ t          j                            | j                  }t          |                    d                    }|sJ d |D             }| 	                    t          |          t          |                     t          |                    d                    }|sJ d |D             | 	                    t          |          t                               | 	                    d|                    d                     | 	                    d|                    d                     d	}d
}t          fd|D                       sJ fd|D             \  }}}| 	                    |j        d         d           |                     d|j        d                    |                     ||          sJ t          |                    d                    }	|	sJ |	                    d            d |	D             }
| 	                    t          d          |
           |                     |	d         |          sJ t          |                    d                    }|sJ | 	                    dt          t          |                               |                    d          }d |D             }|sJ | 	                    dt          |                     d|v sJ d|v sJ d S #  t#          | j                  }	 t%          |                                           |                                 n# |                                 w xY w xY w)Nz/Module/Globalsc                 @    i | ]}|j         d          |j         d         S )nametyperb   rd   es     r   
<dictcomp>z6TestDebugTransform.test_debug_info.<locals>.<dictcomp>   s(    III!18F+QXf-=IIIr   z/Module/Functionsc                 *    i | ]}|j         d          |S )qualified_namerb   ro   s     r   rq   z6TestDebugTransform.test_debug_info.<locals>.<dictcomp>   s"    BBB1"23QBBBr   CObjectc_varPythonObject
python_var)zcodefile.spamzcodefile.hamzcodefile.eggszcodefile.closurezcodefile.inner)rm   cnamers   c              3       K   | ]}|v V  	d S rL   r%   )rd   f	xml_funcss     r   rg   z5TestDebugTransform.test_debug_info.<locals>.<genexpr>   s'      99!qI~999999r   c                      g | ]
}|         S r%   r%   )rd   funcnamer{   s     r   
<listcomp>z6TestDebugTransform.test_debug_info.<locals>.<listcomp>   s    MMMxy2MMMr   rm   spamrx   Localsc                     | j         d         S )Nrm   rb   )rp   s    r   <lambda>z4TestDebugTransform.test_debug_info.<locals>.<lambda>   s    18F+; r   )keyc                 (    g | ]}|j         d          S rm   rb   ro   s     r   r~   z6TestDebugTransform.test_debug_info.<locals>.<listcomp>   s    ;;;!QXf%;;;r   abcdr   	Arguments   StepIntoFunctionsc                 (    g | ]}|j         d          S r   rb   )rd   xs     r   r~   z6TestDebugTransform.test_debug_info.<locals>.<listcomp>  s    AAA!QXf-AAAr      putssome_c_function)ospathexists
debug_destr\   etreeparselistfindrQ   lengetrh   rc   assertNotEqualrj   sortopenprintreadclose)r   r   Lxml_globals	funcnamesrequired_xml_attrsr   hameggsspam_localsnamesspam_arguments	step_intospam_stepintorz   r{   s                  @r   test_debug_infoz"TestDebugTransform.test_debug_info   s   9	7>>$/22222!''88A QVV-..//AHHHIIqIIIKSVVS%5%5666QVV/0011AHHHBBBBBISVVS^^444 Y(@(@AAA^[__\-J-JKKK?I!B9999y99999999MMMM9MMMOD#tT[0&999G(<===%%d,>????? tyy2233K!;!;<<<;;{;;;ET&\\5111%%k!n6HIIIII "$))K"8"899N!!!!QD$8$8 9 9::: 		"566IAAyAAAM    QM 2 2333]****$555555	T_%%Aaffhh								s$   L!L& &N=!M3N3N		NN)r"   r#   r$   rj   r   r%   r   r   r_   r_      s2        : : :: : : : :r   r_   c                       e Zd Zd ZdS ) TestAnalyseDeclarationsTransformc                 t    t          g d          }dt          |          cxk    rdk    sn J |            d S )N)member1member2member3r      )r   r   )r   	checksumss     r   test_calculate_pickle_checksumsz@TestAnalyseDeclarationsTransform.test_calculate_pickle_checksums  sO    /0Q0Q0QRR	C	NN''''a''''''''''r   N)r"   r#   r$   r   r%   r   r   r   r     s#        3 3 3 3 3r   r   r9   )os.pathr   unittestCython.TestUtilsr   #Cython.Compiler.ParseTreeTransformsr   Cython.Compiler.NodesCython.Compilerr   r   r   r
   r'   r0   Cython.Debuggerr\   #Cython.Debugger.Tests.TestLibCythonr]   objectr_   TestCaser   r"   mainr%   r   r   <module>r      s     * * * * * * 1 1 1 1 K K K K K K # # # # 1 1 1 1 1 1 1 1 1 1L L L L L L L L^4 4 4 4 4 4 4 4n6M 6M 6M 6M 6Mm 6M 6M 6Mt
 ? ? ? ? ?) ? ? ?D3 3 3 3 3x'8 3 3 3 zOOOHMOOOOO r   