ó
\K]c           @   s"  d  Z  d d l m Z d d l m Z m Z m Z m Z d d l m Z	 d d l m
 Z
 m Z d d l Z d d l m Z d d	 d
 d g Z e j j e e ƒ Z d e	 j f d „  ƒ  YZ d e	 j f d „  ƒ  YZ d e	 j f d „  ƒ  YZ d e	 j f d „  ƒ  YZ e d k re	 j ƒ  n  d S(   s"   
Unspecified error handling tests
iÿÿÿÿ(   t   division(   t   jitt   njitt   typedt   int64(   t   unittest_support(   t   errorst   utilsNi   (   t   skip_parfors_unsupportedi   i   i   t   TestErrorHandlingBeforeLoweringc           B   s    e  Z d  Z d „  Z d „  Z RS(   sW   Numba encountered the use of a language feature it does not support in this context: %sc         C   su   d „  } xe t  t f D]W } |  j t j ƒ  } | | ƒ d ƒ Wd  QX|  j d } |  j | t | j ƒ ƒ q Wd  S(   Nc         S   s   d „  } d  S(   Nc         S   s   |  S(   N(    (   t   x(    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   <lambda>   t    (    (   R
   t   f(    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   func   s    i   s   <lambda>(	   R   R   t   assertRaisesR   t   UnsupportedErrort   expected_msgt   assertInt   strt	   exception(   t   selfR   t   pipelinet   raisest   expected(    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt%   test_unsupported_make_function_lambda   s    	c         C   su   d „  } xe t  t f D]W } |  j t j ƒ  } | | ƒ d ƒ Wd  QX|  j d } |  j | t | j ƒ ƒ q Wd  S(   Nc            s   |  d ‰  ‡  f d †  } | S(   s    return the closure i   c            s   |  ˆ  S(   N(    (   R
   (   t   z(    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   inner&   s    (    (   R
   R   (    (   R   s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyR   "   s    
i   s$   <creating a function from a closure>(	   R   R   R   R   R   R   R   R   R   (   R   R   R   R   R   (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt0   test_unsupported_make_function_return_inner_func!   s    	(   t   __name__t
   __module__R   R   R   (    (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyR	      s   	t   TestUnsupportedReportingc           B   s   e  Z d  „  Z RS(   c         C   sT   t  d „  ƒ } |  j t j ƒ  } | ƒ  Wd  QXd } |  j | t | j ƒ ƒ d  S(   Nc           S   s   t  j d d d g ƒ d  S(   Ni   i   i   (   t   npt
   asanyarray(    (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyR   7   s    s4   Use of unsupported NumPy function 'numpy.asanyarray'(   R   R   R   t   TypingErrorR   R   R   (   R   R   R   R   (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   test_unsupported_numpy_function5   s
    (   R   R   R#   (    (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyR   3   s   t   TestMiscErrorHandlingc           B   sM   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z	 RS(   c         C   s8   t  d „  ƒ } t j d g d t j ƒ} | | ƒ d  S(   Nc         S   s   d |  S(   Ni
   (    (   R
   (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   fnI   s    g      ð?t   dtype(   R   R    t   arrayt   float64(   R   R%   t   a(    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt&   test_use_of_exception_for_flow_controlD   s    c         C   se   d „  } d „  } xL | | f D]> } |  j  t ƒ  } | ƒ  Wd  QX|  j d t | j ƒ ƒ q Wd  S(   Nc           S   s   t  d ƒ ‚ d  S(   Nt   test_string(   t	   Exception(    (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   foo_commentedV   s    c           S   s   t  d ƒ ‚ d S(   s>    def docstring containing def might match function definition!R+   N(   R,   (    (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   foo_docstringZ   s    R+   (   R   R,   R   R   R   (   R   R-   R.   R   R   (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt2   test_commented_func_definition_is_not_a_definitionP   s    		c            s   d d  l  ‰  d ˆ  j j f ‡  f d †  ƒ  Y} ˆ  j d | ƒ d „  ƒ } |  j t j ƒ  } | t d d g ƒ ƒ Wd  QXd } |  j | t	 | j
 ƒ ƒ d  S(	   Niÿÿÿÿt   TestPipelinec              s    e  Z d  „  Z ‡  f d †  Z RS(   c         S   s’   | j  d ƒ |  j | ƒ |  j | ƒ |  j | ƒ | j |  j d ƒ |  j | ƒ |  j | ƒ | j |  j d ƒ |  j	 | ƒ |  j
 | ƒ d  S(   Nt   test_locs-   remove dead before type inference for testings$   ensure IR is legal prior to lowering(   t   create_pipelinet   add_preprocessing_staget   add_with_handling_staget   add_pre_typing_staget	   add_staget   rm_dead_staget   add_typing_staget   add_optimization_staget   stage_ir_legalizationt   add_lowering_staget   add_cleanup_stage(   R   t   pm(    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   define_pipelinesh   s    c            s)   ˆ  j  j |  j j |  j j |  j ƒ d  S(   N(   t   ir_utilst   remove_deadt   func_irt   blockst	   arg_names(   R   (   t   numba(    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyR7   x   s    	(   R   R   R>   R7   (    (   RD   (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyR0   g   s   	t   pipeline_classc         S   s   d S(   Ni    (    (   R)   (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyR   |   s    i   i   s    File "unknown location", line 0:(   RD   t   compilert   BasePipelineR   R   R   R"   t   iterR   R   R   (   R   R0   R   R   R   (    (   RD   s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   test_use_of_ir_unknown_locd   s    "c         C   s\   |  j  t j ƒ  } | ƒ  Wd  QXd d g } x' | D] } |  j | t | j ƒ ƒ q5 Wd  S(   Ns   The use of as'   in globals, is not supported as globals(   R   R   R"   R   R   R   (   R   R   R   R   t   ex(    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   check_write_to_globals†   s
    c         C   s    t  d „  ƒ } |  j | ƒ d  S(   Nc           S   s   d t  d <d  S(   Ni
   i    (   t   _global_list(    (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   foo   s    (   R   RK   (   R   RM   (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt*   test_handling_of_write_to_reflected_global   s    c         C   s    t  d „  ƒ } |  j | ƒ d  S(   Nc           S   s   d t  d <d  S(   Ni
   i    (   t   _global_dict(    (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyRM   —   s    (   R   RK   (   R   RM   (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt+   test_handling_of_write_to_typed_dict_global–   s    c         C   s]   t  d t ƒ d „  ƒ } |  j t j ƒ  } | ƒ  Wd  QXd } |  j | t | j ƒ ƒ d  S(   Nt   parallelc          S   s   x t  d ƒ D] }  q Wd  S(   Ni
   (   t   prange(   t   i(    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyRM   Ÿ   s    sC   'prange' looks like a Numba internal function, has it been imported(   R   t   TrueR   R   R"   R   R   R   (   R   RM   R   R   (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt-   test_handling_forgotten_numba_internal_import   s
    (
   R   R   R*   R/   RI   RK   RN   RP   R   RU   (    (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyR$   B   s   			"				t"   TestConstantInferenceErrorHandlingc           B   s   e  Z d  „  Z RS(   c         C   sy   t  d „  ƒ } |  j t j ƒ  } | d d ƒ Wd  QXd } d } |  j | t | j ƒ ƒ |  j | t | j ƒ ƒ d  S(   Nc         S   s)   |  | k r! t  d |  | ƒ ‚ n  |  | S(   Ns   Equal numbers: %i %i(   R,   (   R)   t   b(    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   problem°   s    i   i   s3   Constant inference not possible for: arg(0, name=a)s-   raise Exception("Equal numbers: %i %i", a, b)(   R   R   R   t   ConstantInferenceErrorR   R   R   (   R   RX   R   t   msg1t   msg2(    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   test_basic_error®   s    (   R   R   R\   (    (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyRV   ¬   s   t   __main__(   t   __doc__t
   __future__R    RD   R   R   R   R   R   t   unittestR   R   t   numpyR    t   supportR   RL   t   Dictt   emptyRO   t   TestCaseR	   R   R$   RV   R   t   main(    (    (    s=   lib/python2.7/site-packages/numba/tests/test_errorhandling.pyt   <module>   s   ""j