ó
¦V]c           @   sö   d  d l  Z  d  d l m Z d  d l Td  d l Td  d l m Z m Z d e f d „  ƒ  YZ d e	 f d „  ƒ  YZ
 d	 e f d
 „  ƒ  YZ e r± d  d l m Z d  d l m Z n e	 Z d e f d „  ƒ  YZ e d k rò d  d l Z e j ƒ  n  d S(   iÿÿÿÿN(   t   TransformTest(   t   *(   t   Maint   Symtabt   TestNormalizeTreec           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s/   |  j  d ƒ j } |  j d |  j | ƒ ƒ d  S(   Nu   if x: yu—   
(root): StatListNode
  stats[0]: IfStatNode
    if_clauses[0]: IfClauseNode
      condition: NameNode
      body: ExprStatNode
        expr: NameNode
(   t   fragmentt   roott   assertLinest	   treetypes(   t   selft   t(    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt)   test_parserbehaviour_is_what_we_coded_for
   s    c         C   s8   |  j  t d  ƒ g d ƒ } |  j d |  j | ƒ ƒ d  S(   Nu   if x: yu¸   
(root): StatListNode
  stats[0]: IfStatNode
    if_clauses[0]: IfClauseNode
      condition: NameNode
      body: StatListNode
        stats[0]: ExprStatNode
          expr: NameNode
(   t   run_pipelinet   NormalizeTreet   NoneR   R   (   R	   R
   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   test_wrap_singlestat   s    c         C   s8   |  j  t d  ƒ g d ƒ } |  j d |  j | ƒ ƒ d  S(   Nu?   
            if z:
                x
                y
        uð   
(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   R   R   R   (   R	   R
   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   test_wrap_multistat!   s    	
c         C   s8   |  j  t d  ƒ g d ƒ } |  j d |  j | ƒ ƒ d  S(   Nu!   
            a, b = x, y
        u½   
(root): StatListNode
  stats[0]: SingleAssignmentNode
    lhs: TupleNode
      args[0]: NameNode
      args[1]: NameNode
    rhs: TupleNode
      args[0]: NameNode
      args[1]: NameNode
(   R   R   R   R   R   (   R	   R
   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   test_statinexpr3   s    		c         C   s8   |  j  t d  ƒ g d ƒ } |  j d |  j | ƒ ƒ d  S(   NuI   
            x
            y
            if z:
                x
        u  
(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   R   R   R   (   R	   R
   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   test_wrap_offagainB   s    	c         C   s;   |  j  t d  ƒ g d ƒ } |  j t | j ƒ d k ƒ d  S(   Nu   passi    (   R   R   R   t   assert_t   lent   stats(   R	   R
   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   test_pass_eliminatedX   s    (   t   __name__t
   __module__R   R   R   R   R   R   (    (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyR   	   s   					t   TestWithTransformc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s/   |  j  t d  ƒ g d ƒ } |  j d | ƒ d  S(   Nu0   
        with x:
            y = z ** 3
        ux  

        $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   t   WithTransformR   t
   assertCode(   R	   R
   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   test_simplified^   s    	c         C   s/   |  j  t d  ƒ g d ƒ } |  j d | ƒ d  S(   Nu5   
        with x as y:
            y = z ** 3
        u˜  

        $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   R   R   (   R	   R
   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt
   test_basicx   s    	(   R   R   R   R   (    (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyR   \   s   	t   TestInterpretCompilerDirectivesc           B   so   e  Z d  Z d Z i d d 6d d 6d d 6d d 6d d 6d d	 6d
 d 6Z d „  Z d „  Z d „  Z d „  Z RS(   sO   
    This class tests the parallel directives AST-rewriting and importing.
    u?  
        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
    u   cython.parallelu   paru   par2u   parallelu   cython.parallel.threadidu   tidu   cython.parallel.threadavailableu   tavailu   cython.parallel.prangeu   prangec         C   sw   t  t |  ƒ j ƒ  t j t j ƒ } | j ƒ  } t | | j ƒ } t	 j
 d d  | ƒ | _ | g |  _ t j |  _ d  S(   Nt   __main__(   t   superR   t   setUpR   t   CompilationOptionst   default_optionst   create_contextt   InterpretCompilerDirectivest   compiler_directivesR   t   ModuleScopeR   t   module_scopet   pipelinet
   DebugFlagst   debug_exception_on_error(   R	   t   compilation_optionst   ctxt	   transform(    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyR!   ±   s    c         C   s   |  j  t _  d  S(   N(   R+   R*   (   R	   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   tearDown½   s    c         C   s=   |  j  |  j |  j ƒ |  j d j } |  j | |  j ƒ d  S(   Ni    (   R   R)   t   import_codet   parallel_directivest   assertEqualt   expected_directives_dict(   R	   R1   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt!   test_parallel_directives_cimportsÀ   s    c         C   sI   |  j  |  j |  j j d d ƒ ƒ |  j d j } |  j | |  j ƒ d  S(   Nu   cimportu   importi    (   R   R)   R0   t   replaceR1   R2   R3   (   R	   R1   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt    test_parallel_directives_importsÅ   s    (	   R   R   t   __doc__R0   R3   R!   R/   R4   R6   (    (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyR   “   s   
			(   t   DebugWriter(   t   DebuggerTestCaset   TestDebugTransformc           B   s   e  Z d  „  Z d „  Z RS(   c            s   t  ‡  f d †  | Dƒ ƒ S(   Nc         3   s   |  ] } | ˆ  j  k Vq d  S(   N(   t   attrib(   t   .0t   attr(   t   elem(    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pys	   <genexpr>Ø   s    (   t   all(   R	   R>   t   attrs(    (   R>   sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   elem_hasattrs×   s    c            s  yÞt  j j |  j ƒ s t ‚ t j j |  j ƒ } t | j	 d ƒ ƒ } | sT t ‚ t
 d „  | Dƒ ƒ } |  j t | ƒ t | ƒ ƒ t | j	 d ƒ ƒ } | s§ t ‚ t
 d „  | Dƒ ƒ ‰  |  j t | ƒ t ˆ  ƒ ƒ |  j d | j d ƒ ƒ |  j d | j d ƒ ƒ d } d } t ‡  f d †  | Dƒ ƒ s9t ‚ g  | D] } ˆ  | ^ q@\ } } }	 |  j | j d d ƒ |  j d | j d ƒ |  j | | ƒ s¥t ‚ t | j	 d ƒ ƒ }
 |
 sÆt ‚ |
 j d d „  ƒ g  |
 D] } | j d ^ qà} |  j t d ƒ | ƒ |  j |
 d | ƒ s+t ‚ t | j	 d ƒ ƒ } | sLt ‚ |  j d t t | ƒ ƒ ƒ | j	 d ƒ } g  | D] } | j d ^ q~} | s£t ‚ |  j d t | ƒ ƒ d | k sËt ‚ d | k sÝt ‚ Wn6 t |  j ƒ } z | j ƒ  GHWd  | j ƒ  X‚  n Xd  S(    Ns   /Module/Globalsc         s   s)   |  ] } | j  d  | j  d f Vq d S(   t   namet   typeN(   R;   (   R<   t   e(    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pys	   <genexpr>ã   s    s   /Module/Functionsc         s   s"   |  ] } | j  d  | f Vq d S(   t   qualified_nameN(   R;   (   R<   RD   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pys	   <genexpr>è   s    t   CObjectt   c_vart   PythonObjectt
   python_vars   codefile.spams   codefile.hams   codefile.eggss   codefile.closures   codefile.innerRB   t   cnameRE   c         3   s   |  ] } | ˆ  k Vq d  S(   N(    (   R<   t   f(   t	   xml_funcs(    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pys	   <genexpr>ó   s    t   spamt   Localst   keyc         S   s   |  j  d S(   NRB   (   R;   (   RD   (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   <lambda>ý   t    t   abcdi    t	   Argumentsi   t   StepIntoFunctionsi   t   putst   some_c_function(   s   codefile.spams   codefile.hams   codefile.eggss   codefile.closures   codefile.inner(   RB   RJ   RE   (   t   ost   patht   existst
   debug_destt   AssertionErrorR8   t   etreet   parset   listt   findt   dictR2   R   t   getR?   R;   t   assertNotEqualRA   t   sortt   opent   readt   close(   R	   R
   t   Lt   xml_globalst	   funcnamest   required_xml_attrst   funcnameRM   t   hamt   eggst   spam_localsRD   t   namest   spam_argumentst	   step_intot   xt   spam_stepintoRK   (    (   RL   sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   test_debug_infoÚ   sT     "&  (   R   R   RA   Rt   (    (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyR:   Õ   s   	R   (   RW   t   Cython.TestUtilsR    t#   Cython.Compiler.ParseTreeTransformst   Cython.Compiler.Nodest   Cython.CompilerR   R   R   t   objectR   R   t   Falset   Cython.DebuggerR8   t#   Cython.Debugger.Tests.TestLibCythonR9   R:   R   t   unittestt   main(    (    (    sL   lib/python2.7/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.pyt   <module>   s   

S7:C