ó
C]c           @   s  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 d d l m Z d e j f d „  ƒ  YZ e e _ d „  Z d e f d	 „  ƒ  YZ d
 e  j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d „  Z d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ  y d  d l! Z! Wn e" k
 rÐnD Xy e! j# ƒ  Wn2 e$ k
 rZ% d Z& e	 j' e& j( d e% ƒ ƒ n Xd S(   iÿÿÿÿN(   t   resultt   runnert   signalsi   (   t   StringIOt   NumbaTestProgramc           B   sM   e  Z d  Z e Z e Z e Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(   sã   
    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

    Currently the options are only added in 3.4+.
    c         O   sB   | j  d d  ƒ |  _ t j j d ƒ t t |  ƒ j | | Ž  d  S(   Nt   suites   :x(	   t   popt   Nonet   discovered_suitet   syst   warnoptionst   appendt   superR   t   __init__(   t   selft   argst   kwargs(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR   "   s    c         C   s5   |  j  d  k	 r |  j  |  _ n t t |  ƒ j ƒ  d  S(   N(   R   R   t   testR   R   t   createTests(   R   (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR   *   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 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   multiprocesss   Parallelize testss	   --profilet   profiles   Profile the test run(   R   R   t   _getParentArgParsert
   testRunnerR   t   add_argument(   R   t   parser(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR   0   s    
c         C   s‘   t  j d k  r\ d | k r4 | j d ƒ t |  _ n  d | k r\ | j d ƒ t |  _ q\ n  t t |  ƒ j | ƒ |  j	 d k r t |  _
 n  d  S(   Ni   i   s   -Rs   -mi    (   i   i   (   R	   t   version_infot   removet   TrueR   R   R   R   t	   parseArgst	   verbosityt   buffer(   R   t   argv(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR!   A   s    c            s8  ˆ  j  r4 t ˆ  _ t t d ƒ sR t j d ƒ qR n ˆ  j d  k rR t j	 ˆ  _ n  ˆ  j
 r‹ t ˆ  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 ƒ  d | f GH| j | ƒ Xn | ƒ  d  S(   Nt   gettotalrefcounts^   detecting reference leaks requires a debug build of Python, only memory leaks will be detectedR"   t   failfastR#   c              s   t  t ˆ  ƒ j ƒ  d  S(   N(   R   R   t   runTests(    (   R   (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyt   run_tests_reala   s    t   __main__i    s   .proft   timers!   Writing test profile data into %r(   R   t   RefleakTestRunnerR   t   hasattrR	   t   warningst   warnR   t   unittestt   TextTestRunnerR   t   ParallelTestRunnerR"   R&   R#   R   t   ost   patht   splitextt   basenamet   modulest   __file__t   cProfilet   Profilet   timet   perf_countert   enablet   runcallt   disablet
   dump_stats(   R   R(   t   filenamet   p(    (   R   s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR'   P   s0    							

(   t   __name__t
   __module__t   __doc__t   FalseR   R   R   R   R   R   R!   R'   (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR      s   				c          C   sº   y t  j }  Wn t k
 r) d „  }  n Xy t  j } Wn t k
 rS d „  } n Xx? t  j t  j t  j t  j f D] } | d  k	 rs | j	 ƒ  qs qs Wt  j
 ƒ  t j ƒ  |  ƒ  | ƒ  f S(   Nc           S   s   d S(   Ni*   (    (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyt   <lambda>   t    c           S   s   d S(   Ni*   (    (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyRF   …   RG   (   R	   t   getallocatedblockst   AttributeErrorR%   t   stdoutt   stderrt
   __stdout__t
   __stderr__R   t   flusht   _clear_type_cachet   gct   collect(   t   func1t   func2t   stream(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyt   _refleak_cleanup|   s    %

t   ReferenceLeakErrorc           B   s   e  Z RS(    (   RB   RC   (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyRV   “   s   t   IntPoolc           B   s   e  Z d  „  Z RS(   c         C   s   | S(   N(    (   R   t   key(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyt   __missing__™   s    (   RB   RC   RY   (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyRW   —   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    i8ÿÿÿiÈ   (   RT   RN   t   repetitionst   warmupRW   t   rangeR    t
   TestResultt   runt   wasSuccessfult   failurest   extendt   errorst   AssertionErrorRU   (   R   R   t   repcountt   nwarmupt	   rc_deltast   alloc_deltast	   _int_poolt   it   rest   alloc_aftert   rc_aftert	   rc_beforet   alloc_before(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.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(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.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   countt   lenR    t   setRE   (   Rr   (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyt   check_alloc_deltasÌ   s
    t
   referencess   memory blockss   %s leaked %s %s, sum=%ss   %s = %r (   Rp   Rd   R`   RE   t   sumR    RV   t	   ExceptionR	   t   exc_infot   showAllRT   t   writet
   addFailureR   RZ   t
   addSuccess(   R   R   Rg   Rh   Rs   Rw   t   failedRr   t	   item_namet   checkert   msgR{   (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR   Á   s0    				(   RB   RC   R\   R[   Rp   R   (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyRZ      s   	R+   c           B   s   e  Z e Z RS(    (   RB   RC   RZ   t   resultclass(    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR+   ê   s   c         C   sK   t  |  t j ƒ r@ g  } x! |  D] } | j t | ƒ ƒ q W| S|  g Sd S(   s$   Expand suite into list of tests
    N(   t
   isinstanceR/   t	   TestSuiteRb   t   _flatten_suite(   R   t   testst   x(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.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(   RT   R}   t   getvalueRN   t   testsRunRa   Rb   Rc   t   skippedt   expectedFailurest   unexpectedSuccesses(   R   R    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyt   add_resultsÿ   s    (   RB   RC   RD   R   (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyRŠ   ú   s   t   _MinimalResultc           B   s&   e  Z d  Z d Z d	 „  Z d
 „  Z RS(   s7   
    A minimal, picklable TestResult-alike object.
    Ra   Rc   R   RŽ   R   RT   t
   shouldStopRŒ   c         C   s   d | _ d S(   sR   
        Remove any unpicklable attributes from TestCase instance *case*.
        N(   R   t   _outcomeForDoCleanups(   R   t   case(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyt
   fixup_case  s    c         C   s¦   x* |  j  D] } t |  | t | | ƒ ƒ q
 Wx$ |  j D] \ } } |  j | ƒ q7 Wx$ |  j D] \ } } |  j | ƒ q^ Wx$ |  j D] \ } } |  j | ƒ q… Wd  S(   N(   t	   __slots__t   setattrt   getattrRŽ   R•   Rc   Ra   (   R   t   original_resultt   attrR”   t   _(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR     s    (   Ra   Rc   R   RŽ   R   RT   R’   RŒ   (   RB   RC   RD   R–   R•   R   (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.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(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR   -  s    c         C   s   |  j  S(   N(   R   (   R   (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR‹   0  s    (   RB   RC   RD   R   R‹   (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.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¡   (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR   :  s    	c         C   s¢   |  j  } t ƒ  | d <|  j |   } | j ƒ  } t j ƒ  t j | ƒ | j | _ | j | _ |  j	 | ƒ  | | ƒ Wd  QXt
 | j j ƒ  ƒ | _ t | ƒ S(   NRT   (   R¡   R   R    t   _makeResultR   t   installHandlert   registerResultR&   R#   t   cleanup_objectRœ   RT   R‹   R‘   (   R   R   R   R   R    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyt   __call__A  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(   Rv   t   __dict__(   R   R   t   vanilla_attrst   spurious_attrst   name(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR¥   T  s    	(   RB   RC   RD   R   R¦   t
   contextlibt   contextmanagerR¥   (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyRŸ   4  s   		R1   c           B   s/   e  Z d  Z e Z d „  Z d „  Z d „  Z RS(   s\   
    A test runner which delegates the actual running to a pool of child
    processes.
    c         K   s)   t  j j |  |  | |  _ | |  _ d  S(   N(   R   R0   R   R    R¡   (   R   R    R   (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR   k  s    	c         C   s…   t  |  j |  j ƒ } t j ƒ  } | j } z? x4 | | |  j ƒ D]  } | j | ƒ | j r@ Pq@ q@ W| SWd  | j	 ƒ  | j
 ƒ  Xd  S(   N(   RŸ   R    R¡   t   multiprocessingt   Poolt   imap_unorderedt
   _test_listR   R’   t	   terminatet   join(   R   R    t   child_runnert   poolt   imapt   child_result(    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyt
   _run_innerp  s    		
c         C   s(   t  | ƒ |  _ t t |  ƒ j |  j ƒ S(   N(   R‡   R°   R   R1   R_   R·   (   R   R   (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR_     s    (   RB   RC   RD   RŠ   R„   R   R·   R_   (    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyR1   c  s
   		s+   Failed to enable faulthandler due to:
{err}t   err()   t   collectionsR«   R8   RP   R2   R­   R	   R:   R/   R-   R    R   R   t   sixR   t   mainR   RU   t   RuntimeErrorRV   t   defaultdictRW   t   TextTestResultRZ   R0   R+   R‡   RŠ   t   objectR‘   Rœ   RŸ   R1   t   faulthandlert   ImportErrorR<   t   BaseExceptiont   eRƒ   R.   t   format(    (    (    s7   lib/python2.7/site-packages/llvmlite/tests/customize.pyt   <module>   sB   a		M	/%