ó
\K]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 m Z d Z d Z d Z	 d Z
 d „  Z d „  Z d	 „  Z d
 „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿN(   t   wrapss   1.0.0s   %valuess
   %file_paths   %unpackc         C   s   t  |  t t ƒ |  S(   s2   
    Method decorator to add unpack feature.

    (   t   setattrt   UNPACK_ATTRt   True(   t   func(    (    s0   lib/python2.7/site-packages/numba/testing/ddt.pyt   unpack   s    c             s   ‡  f d †  } | S(   s   
    Method decorator to add to your test methods.

    Should be added to methods of instances of ``unittest.TestCase``.

    c            s   t  |  t ˆ  ƒ |  S(   N(   R   t	   DATA_ATTR(   R   (   t   values(    s0   lib/python2.7/site-packages/numba/testing/ddt.pyt   wrapper*   s    (    (   R   R   (    (   R   s0   lib/python2.7/site-packages/numba/testing/ddt.pyt   data#   s    c            s   ‡  f d †  } | S(   sc  
    Method decorator to add to your test methods.

    Should be added to methods of instances of ``unittest.TestCase``.

    ``value`` should be a path relative to the directory of the file
    containing the decorated ``unittest.TestCase``. The file
    should contain JSON encoded data, that can either be a list or a
    dict.

    In case of a list, each value in the list will correspond to one
    test case, and the value will be concatenated to the test method
    name.

    In case of a dict, keys will be used as suffixes to the name of the
    test case, and values will be fed as test data.

    c            s   t  |  t ˆ  ƒ |  S(   N(   R   t	   FILE_ATTR(   R   (   t   value(    s0   lib/python2.7/site-packages/numba/testing/ddt.pyR   C   s    (    (   R   R   (    (   R   s0   lib/python2.7/site-packages/numba/testing/ddt.pyt	   file_data0   s    c           C   sF   t  j d k r t  j d k  s- t  j d k oE t  j j oE d t j k S(   Ni i   i t   PYTHONHASHSEED(   t   syst
   hexversiont   flagst   hash_randomizationt   ost   environ(    (    (    s0   lib/python2.7/site-packages/numba/testing/ddt.pyt   is_hash_randomizedI   s
    i    c            sÞ   t  d	 ƒ t t t t f ‰ y ˆ t f 7‰ Wn t k
 r? n X‡  ‡ f d †  ‰  t ƒ  r| ˆ  | ƒ r| d j	 |  | d ƒ Sy t | ƒ } Wn# t
 k
 r± | j d d ƒ } n Xd j	 |  | d | ƒ } t j d d | ƒ S(
   sÜ  
    Generate a new name for a test case.

    It will take the original test name and append an ordinal index and a
    string representation of the value, and convert the result into a valid
    python identifier by replacing extraneous characters with ``_``.

    If hash randomization is enabled (a feature available since 2.7.3/3.2.3
    and enabled by default since 3.3) and a "non-trivial" value is passed
    this will omit the name argument by default. Set `PYTHONHASHSEED`
    to a fixed value before running tests in these cases to get the
    names back consistently or use the `__name__` attribute on data values.

    A "trivial" value is a plain scalar, or a tuple or list consisting
    only of trivial values.

    c            s?   t  |  ˆ ƒ r t St  |  t t f ƒ r; t t ˆ  |  ƒ ƒ St S(   N(   t
   isinstanceR   t   listt   tuplet   allt   mapt   False(   R   (   t
   is_trivialt   trivial_types(    s0   lib/python2.7/site-packages/numba/testing/ddt.pyR   v   s
    s   {0}_{1}i   t   asciit   backslashreplaces   {0}_{1}_{2}s
   \W|^(?=\d)t   _N(   t   typet   Nonet   boolt   strt   intt   floatt   unicodet	   NameErrorR   t   formatt   UnicodeEncodeErrort   encodet   ret   sub(   t   nameR   t   indext	   test_name(    (   R   R   s0   lib/python2.7/site-packages/numba/testing/ddt.pyt   mk_test_nameQ   s    	c            sp   t  ˆ ƒ ‡  ‡ ‡ f d †  ƒ } | | _ ˆ j rl y ˆ j j ˆ  ˆ Ž  | _ Wql t t f k
 rh ql Xn  | S(   sO   
    This internal method decorator feeds the test data item to the test.

    c            s   ˆ |  ˆ  ˆ Ž S(   N(    (   t   self(   t   argsR   t   kwargs(    s0   lib/python2.7/site-packages/numba/testing/ddt.pyR      s    (   R    t   __name__t   __doc__R(   t
   IndexErrort   KeyError(   R   t   new_nameR2   R3   R   (    (   R2   R   R3   s0   lib/python2.7/site-packages/numba/testing/ddt.pyt	   feed_data‹   s    !		c         O   s#   t  |  | t | | | | Ž ƒ d S(   s~   
    Add a test case to this class.

    The test will be based on an existing function but will give it a new
    name.

    N(   R   R9   (   t   clsR/   R   R2   R3   (    (    s0   lib/python2.7/site-packages/numba/testing/ddt.pyt   add_test    s    c            s[  t  j j t j |  ƒ ƒ } t  j j t  j j | ƒ ˆ  ƒ } ‡  f d †  } t  j j | ƒ t k rˆ t	 | d ƒ } t
 |  | | d ƒ nÏ t j t | ƒ j ƒ  ƒ } x± t | ƒ D]£ \ }	 }
 t | t ƒ rñ |
 | |
 } } t	 | | |	 ƒ } n* t | t ƒ r|
 } t	 | | |	 ƒ } n  t | t ƒ r@t
 |  | | |  q° t
 |  | | | ƒ q° Wd S(   s>   
    Process the parameter in the `file_data` decorator.

    c             s   t  d ˆ  ƒ ‚ d  S(   Ns   %s does not exist(   t
   ValueError(   R2   (   t	   file_attr(    s0   lib/python2.7/site-packages/numba/testing/ddt.pyt	   _raise_ve³   s    t   errorN(   R   t   patht   abspatht   inspectt   getsourcefilet   joint   dirnamet   existsR   R0   R;   R!   t   jsont   loadst   opent   readt	   enumerateR   t   dictR   (   R:   R-   R   R=   t   cls_patht   data_file_pathR>   R/   R	   t   it   elemt   keyR   (    (   R=   s0   lib/python2.7/site-packages/numba/testing/ddt.pyt   process_file_data«   s"    !c         C   s:  x3t  |  j j ƒ  ƒ D]\ } } t | t ƒ rñ x­ t t | t ƒ ƒ D]– \ } } t | t | d | ƒ | ƒ } t | t ƒ rÊ t	 | t
 ƒ sž t	 | t  ƒ r´ t |  | | | Œ qÝ t |  | | |  qG t |  | | | ƒ qG Wt |  | ƒ q t | t ƒ r t | t ƒ } t |  | | | ƒ t |  | ƒ q q W|  S(   sÉ  
    Class decorator for subclasses of ``unittest.TestCase``.

    Apply this decorator to the test case class, and then
    decorate test methods with ``@data``.

    For each method decorated with ``@data``, this will effectively create as
    many methods as data items are passed as parameters to ``@data``.

    The names of the test methods follow the pattern
    ``original_test_name_{ordinal}_{data}``. ``ordinal`` is the position of the
    data argument, starting with 1.

    For data we use a string representation of the data value converted into a
    valid python identifier.  If ``data.__name__`` exists, we use that instead.

    For each method decorated with ``@file_data('test_data.json')``, the
    decorator will try to load the test_data.json file located relative
    to the python file containing the method that is decorated. It will,
    for each ``test_name`` key create as many methods in the list of values
    from the ``data`` key.

    R4   (   R   t   __dict__t   itemst   hasattrR   RK   t   getattrR0   R   R   R   R;   t   delattrR
   RR   (   R:   R-   R   RO   t   vR/   R=   (    (    s0   lib/python2.7/site-packages/numba/testing/ddt.pyt   ddtÈ   s    ""(   RB   RG   R   R+   R   t	   functoolsR    t   __version__R   R
   R   R   R	   R   R   R0   R9   R;   RR   RY   (    (    (    s0   lib/python2.7/site-packages/numba/testing/ddt.pyt   <module>   s$   					:			