
\K]c           @` s  d  d l  m Z m Z m Z d  d l j Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z m Z m Z m Z m Z d d l m Z d  d l m Z m Z d  d l m Z y d  d l m Z Wn! e k
 r>d  d	 l m  Z n Xd
   Z! d e" f d     YZ# d e j$ f d     YZ% d e j& f d     YZ' d   Z( d d  Z) d   Z* d   Z+ d e, f d     YZ- d e j. f d     YZ/ d e j0 f d     YZ1 d e j2 f d     YZ3 d e j0 f d     YZ4 d  e" f d!     YZ5 d" e" f d#     YZ6 d$ e" f d%     YZ7 d&   Z8 d' e j2 f d(     YZ9 d S()   i    (   t   print_functiont   divisiont   absolute_importN(   t   resultt   runnert   signalst   suitet   loadert   casei   (   t
   TestLoader(   t	   PYVERSIONt   StringIO(   t   config(   t   TimeoutError(   t   Emptyc         ` s     f d   } | S(   sO   
    Create a decorator allowing tests to be tagged with the *known_tags*.
    c          ` sF   x0   D]( } |  k r t  d | f   q q W  f d   } | S(   s   
        Tag a test method with the given tags.
        Can be used in conjunction with the --tags command-line argument
        for runtests.py.
        s   unknown tag: %rc         ` s   t  |   s/ t |  t  s/ |  j j d  r> t d   n  y |  j } Wn! t k
 rn t   } |  _ n X| j	    |  S(   Nt   test_s(   @tag(...) should be used on test methods(
   t   callablet
   isinstancet   typet   __name__t
   startswitht	   TypeErrort   tagst   AttributeErrort   sett   update(   t   funct   s(   R   (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   decorate+   s    (   t
   ValueError(   R   t   tR   (   t
   known_tags(   R   s1   lib/python2.7/site-packages/numba/testing/main.pyt   tag!   s
    
(    (   R   R    (    (   R   s1   lib/python2.7/site-packages/numba/testing/main.pyt   make_tag_decorator   s    t
   TestListerc           B` s    e  Z d  Z d   Z d   Z RS(   s5   Simply list available tests rather than running them.c         C` s   d  S(   N(    (   t   self(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   __init__<   s    c         C` sl   t  j t j d t d d } t |  |  _ x! |  j D] } t | j    q7 Wt d t	 |  j   | S(   Nt   descriptionst	   verbosityi   s   %d tests found(
   R   t   TextTestResultt   syst   stderrt   Truet   _flatten_suitet
   _test_listt   printt   idt   len(   R#   t   testR   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   run?   s    (   R   t
   __module__t   __doc__R$   R1   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR"   :   s   	t   SerialSuitec           B` s   e  Z d  Z d   Z RS(   sA  A simple marker to make sure tests in this suite are run serially.

    Note: As the suite is going through internals of unittest,
          it may get unpacked and stuffed into a plain TestSuite.
          We need to set an attribute on the TestCase objects to
          remember they should not be run in parallel.
    c         C` sV   t  | t j  s3 x= | D] } |  j |  q Wn t | _ t t |   j |  d  S(   N(   R   t   unittestt   TestCaset   addTestt   Falset   _numba_parallel_test_t   superR4   (   R#   R0   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR7   Q   s
    	(   R   R2   R3   R7   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR4   H   s   t   NumbaTestProgramc           B` sw   e  Z d  Z e Z e Z e Z e Z d Z	 d Z
 d Z d Z d   Z d   Z d   Z d   Z d d  Z d   Z RS(	   s3  
    A TestProgram subclass adding the following options:
    * a -R option to enable reference leak detection
    * a --profile option to enable profiling of the test run
    * a -m option for parallel execution
    * a -l option to (only) list tests

    Currently the options are only added in 3.4+.
    i*   c         O` s   t  j r" t j d  t t  _ n  | j d d   } t |  | d <t j	 j
 d  | j d t  |  _ t t |   j | |   d  S(   Ns   Unset INTERPRETER_FALLBACKt   topleveldirt
   testLoaders   :xt   nomultiproc(   R   t   COMPATIBILITY_MODEt   warningst   warnR8   t   popt   NoneR	   R(   t   warnoptionst   appendR>   R:   R;   R$   (   R#   t   argst   kwargsR<   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR$   s   s    	c         C` s  t  t |   j   } |  j d  k rI | j d d d d d d d d n  | j d	 d
 d d d d d t d t j   d d | j d d d d d d d d | j d d d d t	 d d | j d d d d t	 d d | j d d d d t
 d d | j d d d d d d d  | S(!   Ns   -Rs	   --refleakt   destt   refleakt   actiont
   store_truet   helps   Detect reference / memory leakss   -ms   --multiprocesst   multiprocesst   nargst   ?R   t   consts   Parallelize testss   -ls   --listt   lists   List tests without running thems   --tagsR   sA   Comma-separated list of tags to select a subset of the test suites   --exclude-tagst   exclude_tagssD   Comma-separated list of tags to de-select a subset of the test suites   --randomt   random_selects$   Random proportion of tests to selects	   --profilet   profiles   Profile the test run(   R:   R;   t   _getParentArgParsert
   testRunnerRC   t   add_argumentt   intt   multiprocessingt	   cpu_countt   strt   float(   R#   t   parser(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyRU      s.    
c   	      C` su  d  } xB | D]: } | | k r | d  k r4 | } qG t d |   q q W| d  k	 rq| j |  } yh | | k r | | d j   } | j |  n4 d | k r | j d  d j   } n t d   Wn' t k
 r d } t | |   n X| j d  rt d   n  d | k r;d } t | |   n  | d	 j	 d d
  } t
 |  | |  | j |  n  d  S(   Ns   argument %s supplied repeatedlyi   t   =t   unreachables,   %s requires at least one tag to be specifiedt   -s,   tag starts with '-', probably a syntax errors1   %s argument contains '=', probably a syntax errori   t   _(   RC   R   t   indext   stript   removet   splitt   AssertionErrort
   IndexErrorR   t   replacet   setattr(	   R#   t   argvt   tagstrt   foundt   xt   posnt   tag_argst   msgt   attr(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   _handle_tags   s4    	c         C` sO  d | k r% | j  d  t |  _ n  t d k  rd | k r | j d  } t j   } yh | | d } | d k r y t |  } Wn' t k
 r d } t	 | |   n X| j  |  n  Wn t
 k
 r n X| |  _ | j  d  n  |  j | d  |  j | d	  n  t t |   j |  t |  d
  sF|  j j   rb|  j f |  _ |  j   n  |  j rg  |  j j d  D] } | j   ^ q~} t |  j | d d |  _ n  |  j rg  |  j j d  D] } | j   ^ q} t |  j | d d |  _ n  |  j r0t |  j |  j |  j  |  _ n  |  j d k rKt |  _ n  d  S(   Ns   -li   i   s   -mi   s   --s7   Expected an integer argument to option `-m`, found "%s"s   --tagss   --exclude-tagsR0   t   ,t   modet   includet   excludei    (   i   i   (    Rd   R*   RQ   R
   Rb   RY   RZ   RX   t   BaseExceptionR   Rg   RM   Rr   R:   R;   t	   parseArgst   hasattrR0   t   countTestCasest   defaultTestt	   testNamest   createTestsR   Re   Rc   t   _choose_tagged_testsRR   RS   t   _choose_random_testst   random_seedR&   t   buffer(   R#   Rj   t
   dashm_posnt   nprocst   m_optionRp   R   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyRx      sJ    	 	+	+	c         C` s   d  S(   N(    (   R#   Rj   t   Loader(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   _do_discovery  s    c      	   ` s    j  r4 t   _ t t d  sj t j d  qj n6   j rL t     _ n   j d  k rj t
 j   _ n    j r   j r   j d k  r d } t |   n  t   j   j d   j d   j d   j   _ n    f d   }   j r~t j j t j j t j d	 j   d
 d } t j d t j  } | j   z | j |  Wd  | j    t! d | f  | j" |  Xn |   d  S(   Nt   gettotalrefcounts^   detecting reference leaks requires a debug build of Python, only memory leaks will be detectedi   sS   Value specified for the number of processes to use in running the suite must be > 0R&   t   failfastR   c           ` s   t  t    j   d  S(   N(   R:   R;   t   runTests(    (   R#   (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   run_tests_real#  s    t   __main__i    s   .proft   timers!   Writing test profile data into %r(#   RI   t   RefleakTestRunnerRV   Ry   R(   R@   RA   RQ   R"   RC   R5   t   TextTestRunnerRM   R>   R   t   ParallelTestRunnerR&   R   R   RT   t   ost   patht   splitextt   basenamet   modulest   __file__t   cProfilet   Profilet   timet   perf_countert   enablet   runcallt   disableR-   t
   dump_stats(   R#   Rp   R   t   filenamet   p(    (   R#   s1   lib/python2.7/site-packages/numba/testing/main.pyR   
  s<    									

N(   R   R2   R3   R8   RI   RT   RM   RQ   RC   R   RR   RS   R   R$   RU   Rr   Rx   R   R   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR;   _   s   				%	>c         C` sT   t  |  t j t t f  rI g  } x! |  D] } | j t |   q( W| S|  g Sd S(   s6   
    Expand nested suite into list of test cases.
    N(   R   R5   t	   TestSuiteRQ   t   tuplet   extendR+   (   R0   t   testsRm   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR+   6  s    Ru   c         C` s  g  } t  |  } x t |   D] } t | t j  s= t  t | | j  } y | j } Wn t	 k
 ro n Xt | d d  } | d k r | d k	 r | | @r | j |  q q | d k r | d k s | | @r | j |  q q t d |   q Wt j |  S(   s   
    Select tests that are tagged/not tagged with at least one of the given tags.
    Set mode to 'include' to include the tests with tags, or 'exclude' to
    exclude the tests with the tags.
    R   Ru   Rv   s   Invalid 'mode' supplied: %s.N(   R   R+   R   R5   R6   Rf   t   getattrt   _testMethodNamet   im_funcR   RC   RE   R   R   (   R   R   Rt   t   selectedR0   R   t
   found_tags(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR~   C  s$    c         C` s~   t  j   } | j |  t |  t j  r: t |   }  n  | j |  t t	 |   |   }  t
 |  d d   }  t j |   S(   s7   
    Choose a given proportion of tests at random.
    t   keyc         S` s
   |  j    S(   N(   R.   (   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   <lambda>k  t    (   t   randomt   Randomt   seedR   R5   R   R+   t   sampleRX   R/   t   sorted(   R   t   ratioR   t   rnd(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR   b  s    "c          C` s   t  j }  y t  j } Wn t k
 r2 d   } n Xx? t  j t  j t  j t  j f D] } | d  k	 rR | j	   qR qR Wt  j
   t j   |    |   f S(   Nc           S` s   d S(   Ni*   (    (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR   x  R   (   R(   t   getallocatedblocksR   R   t   stdoutR)   t
   __stdout__t
   __stderr__RC   t   flusht   _clear_type_cachet   gct   collect(   t   func1t   func2t   stream(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   _refleak_cleanupr  s    	%

t   ReferenceLeakErrorc           B` s   e  Z RS(    (   R   R2   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR     s   t   IntPoolc           B` s   e  Z d    Z RS(   c         C` s   | S(   N(    (   R#   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   __missing__  s    (   R   R2   R   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR     s   t   RefleakTestResultc           B` s&   e  Z d  Z d Z d   Z d   Z RS(   i   i   c         C` s;  |  j  j   |  j } |  j } d g | | } d g | | } t   } x t d d  D] } | | qZ Wx t |  D] } t j   } | j |  | j	   s |  j
 j | j
  |  j j | j  t  n  ~ t   \ }	 }
 | | k r | |
 | | | | <| |	 | | | | <n  |	 |
 } } qy W| | f S(   Ni    i8i   (   R   R   t   repetitionst   warmupR   t   rangeR   t
   TestResultR1   t   wasSuccessfult   failuresR   t   errorsRf   R   (   R#   R0   t   repcountt   nwarmupt	   rc_deltast   alloc_deltast	   _int_poolt   it   rest   alloc_aftert   rc_aftert	   rc_beforet   alloc_before(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt
   _huntLeaks  s,    				c         C` sE  y |  j  |  \ } } Wn% t k
 r@ |  j   s< t  d  SXd   } d   } t } x | d | f | d | f g D] \ } } }	 |	 |  rx d | | | t |  f }
 t } y t |
   Wn t k
 r t j	   } n X|  j
 r|  j j d | | f  n  |  j | |  qx qx W| sAt t |   j |  n  d  S(   Nc         S` s
   t  |   S(   N(   t   any(   t   deltas(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   check_rc_deltas  s    c         S` sC   d |  j  d  t |   k  r# t St |   t d  k s? t St S(   Ni   i    i   i(   i   i    i(   t   countR/   R*   R   R8   (   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   check_alloc_deltas  s
    t
   referencess   memory blockss   %s leaked %s %s, sum=%ss   %s = %r (   R   Rf   R   R8   t   sumR*   R   t	   ExceptionR(   t   exc_infot   showAllR   t   writet
   addFailureR:   R   t
   addSuccess(   R#   R0   R   R   R   R   t   failedR   t	   item_namet   checkerRp   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR     s0    				(   R   R2   R   R   R   R   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR     s   	R   c           B` s   e  Z e Z RS(    (   R   R2   R   t   resultclass(    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR     s   t   ParallelTestResultc           B` s   e  Z d  Z d   Z RS(   sA   
    A TestResult able to inject results from other results.
    c         C` s   |  j  j | j  j    |  j  j   |  j | j 7_ |  j j | j  |  j j | j  |  j j | j  |  j	 j | j	  |  j
 j | j
  d S(   sI   
        Add the results from the other *result* to this result.
        N(   R   R   t   getvalueR   t   testsRunR   R   R   t   skippedt   expectedFailurest   unexpectedSuccesses(   R#   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   add_results  s    (   R   R2   R3   R   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR     s   t   _MinimalResultc        	   B` s)   e  Z d  Z d Z d
   Z d d  Z RS(   s7   
    A minimal, picklable TestResult-alike object.
    R   R   R   R   R   R   t
   shouldStopR   t   test_idc         C` s   d | _ d S(   sR   
        Remove any unpicklable attributes from TestCase instance *case*.
        N(   RC   t   _outcomeForDoCleanups(   R#   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt
   fixup_case  s    c         C` s   x- |  j  D]" } t |  | t | | d    q
 Wx$ |  j D] \ } } |  j |  q: Wx$ |  j D] \ } } |  j |  qa Wx$ |  j D] \ } } |  j |  q W| |  _ d  S(   N(	   t	   __slots__Ri   R   RC   R   R   R   R   R   (   R#   t   original_resultR   Rq   R   Ra   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR$     s     (	   R   R   R   R   R   R   R   R   R   N(   R   R2   R3   R   R   RC   R$   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR     s     	t   _FakeStringIOc           B` s    e  Z d  Z d   Z d   Z RS(   s:   
    A trivial picklable StringIO-alike for Python 2.
    c         C` s   | |  _  d  S(   N(   t   _value(   R#   t   value(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR$     s    c         C` s   |  j  S(   N(   R   (   R#   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR     s    (   R   R2   R3   R$   R   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR     s   	t   _MinimalRunnerc           B` s2   e  Z d  Z d   Z d   Z e j d    Z RS(   su   
    A minimal picklable object able to instantiate a runner in a
    child process and run a test case with it.
    c         C` s   | |  _  | |  _ d  S(   N(   t
   runner_clst   runner_args(   R#   R   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR$   $  s    	c         C` s   |  j  } t   | d <|  j |   } | j   } t j   t j |  | j | _ | j | _ |  j	 |   | |  Wd  QXt
 | j j    | _ t | | j    S(   NR   (   R   R   R   t   _makeResultR   t   installHandlert   registerResultR   R   t   cleanup_objectR   R   R   R   R.   (   R#   R0   RG   R   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   __call__+  s    	
c         c` sN   t  | j  } z	 | VWd t  | j  | } x | D] } | j | =q5 WXd S(   su   
        A context manager which cleans up unwanted attributes on a test case
        (or any other object).
        N(   R   t   __dict__(   R#   R0   t   vanilla_attrst   spurious_attrst   name(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR   >  s    	(   R   R2   R3   R$   R   t
   contextlibt   contextmanagerR   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR     s   		c         C` s   g  } g  } d   } t  |  t j  rg xa |  D]2 } t |  \ } } | j |  | j |  q. Wn$ | |   r |  g } n t |   } | | f S(   s:   
    Split test suite into parallel and serial tests.
    c         S` sJ   |  j  } t |  |  } | j | k r: | j d k r: t St |  d t  S(   Nt   testFailureR9   (   R   R   R   R8   R*   (   R0   t   method_namet   method(    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   is_parallelizable_test_caseT  s
    	(   R   R5   R   t   _split_nonparallel_testsR   R+   (   R0   t   ptestst   stestsR	  R   R   R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR
  M  s    	
R   c           B` s>   e  Z d  Z e Z d Z d   Z d   Z d   Z d   Z	 RS(   s\   
    A test runner which delegates the actual running to a pool of child
    processes.
    i,  c         K` s2   t  j j |  |  | |  _ | |  _ | |  _ d  S(   N(   R   R   R$   R   R   R   (   R#   R   R   RG   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR$   w  s    		c   	      C` s  t  |  j |  j  } d } g  t d t |  j  |  D] } |  j | | | !^ q7 } x | D]| } t j |  j  } zV y |  j	 | | | |  Wn | j
     n" X| j r | j
   Pn
 | j   Wd  | j   Xq^ W| j st |  j  } | j |  | Sd  S(   Ni  i    (   R   R   R   R   R/   t   _ptestsRY   t   PoolR   t   _run_parallel_testst	   terminateR   t   closet   joinR4   t   _stestsR1   (	   R#   R   t   child_runnert
   chunk_sizeR   t   splitted_testsR   t   poolR  (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt
   _run_inner}  s*    9 
	
	c   
      C` s   t  d   | D  } | j | |  } x t r y | j |  j  } Wnd t k
 r[ d  St k
 r } d d j d   t |  D  }	 |	 f | j	 d | _	 |  q+ X| j
 |  | j | j  | j r+ t | _ d  Sq+ Wd  S(   Nc         s` s   |  ] } | j    Vq d  S(   N(   R.   (   t   .0R   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pys	   <genexpr>  s    s3   Tests didn't finish before timeout (or crashed):
%sR   c         s` s   |  ] } d  | Vq d S(   s   - %r
N(    (   R  t   tid(    (    s1   lib/python2.7/site-packages/numba/testing/main.pys	   <genexpr>  s    i   (   R   t   imap_unorderedR*   t   __next__t   timeoutt   StopIterationR   R  R   RF   R   t   discardR   R   (
   R#   R   R  R  R   t   remaining_idst   itt   child_resultt   eRp   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR    s"    	 
		c         C` s1   t  |  \ |  _ |  _ t t |   j |  j  S(   N(   R
  R  R  R:   R   R1   R  (   R#   R0   (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR1     s    (
   R   R2   R3   R   R   R  R$   R  R  R1   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyR   m  s   		"	(:   t
   __future__R    R   R   t   numba.unittest_supportt   unittest_supportR5   t   collectionsR  R   R   RY   R   R   R(   R   R@   R   R   R   R   R   R   R	   t   numba.utilsR
   R   t   numbaR   R   t   ImportErrort   QueueR   R!   t   objectR"   R   R4   t   mainR;   R+   R~   R   R   t   RuntimeErrorR   t   defaultdictR   R'   R   R   R   R   R   R   R   R
  R   (    (    (    s1   lib/python2.7/site-packages/numba/testing/main.pyt   <module>   sJ   .				N/	 