Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/__pycache__/ddt.cpython-37.pyc

B

��W: �@sddlZddlZddlZddlZddlmZyddlZWnek
rPdZYnXdZdZ	dZ
dZdZye
d�eeeefZWn&ek
r�e
d�eeeefZYnXd	d
�Zdd�Zd
d�Zdd�Zdd�Zddd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS) �N)�wrapsFTz1.1.1z%valuesz
%file_pathz%unpackcCs.t|t�rdSt|ttf�r*ttt|��SdS)NTF)�
isinstance�
trivial_types�list�tuple�all�map�
is_trivial)�value�r�4/opt/alt/python37/lib/python3.7/site-packages/ddt.pyr	&s

r	cCst|td�|S)z2
    Method decorator to add unpack feature.

    T)�setattr�UNPACK_ATTR)�funcrrr�unpack.srcGst|�S)z
    Method decorator to add to your test methods.

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

    )�idata)�valuesrrr�data7srcs�fdd�}|S)z
    Method decorator to add to your test methods.

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

    cst|t��|S)N)r
�	DATA_ATTR)r)�iterablerr�wrapperHszidata.<locals>.wrapperr)rrr)rrrAsrcs�fdd�}|S)ac
    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.

    cst|t��|S)N)r
�	FILE_ATTR)r)r
rrraszfile_data.<locals>.wrapperr)r
rr)r
r�	file_dataNsrcCsft|�sd�||d�Syt|�}Wn tk
rD|�dd�}YnXd�||d|�}t�dd|�S)a�
    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 ``_``.

    We avoid doing str(value) if dealing with non-trivial values.
    The problem is possible different names with different runs, e.g.
    different order of dictionary keys (see PYTHONHASHSEED) or dealing
    with mock objects.
    Trivial scalar values are passed as is.

    A "trivial" value is a plain scalar, or a tuple or list consisting
    only of trivial values.
    z{0}_{1}��ascii�backslashreplacez{0}_{1}_{2}z
\W|^(?=\d)�_)r	�format�str�UnicodeEncodeError�encode�re�sub)�namer
�index�	test_namerrr�mk_test_namegsr&c	s\t�����fdd��}||_�|_�jrXy�jj���|_Wnttfk
rVYnX|S)zO
    This internal method decorator feeds the test data item to the test.

    cs�|f����S)Nr)�self)�argsr�kwargsrrr�szfeed_data.<locals>.wrapper)r�__name__�__wrapped__�__doc__r�
IndexError�KeyError)r�new_namer(r)rr)r(rr)r�	feed_data�sr0cOst||t||f|�|��dS)z~
    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
r0)�clsr%rr(r)rrr�add_test�sr2c	s�tj�t�|��}tj�tj�|���}�fdd�}tj�|�s`t|d�}t	|||d�d�dS|�
d�}|r�ts�t|d�}t	|||d�d�dSt|�� }	|r�t
�|	�}
n
t�|	�}
WdQRXt||||
�dS)z>
    Process the parameter in the `file_data` decorator.

    cs��fdd�}|S)Ncst����dS)N)�
ValueError)r()�	file_attr�messagerrr�sz:process_file_data.<locals>.create_error_func.<locals>.funcr)r5r)r4)r5r�create_error_func�sz,process_file_data.<locals>.create_error_func�errorz%s does not existN)z.ymlz.yamlz(%s is a YAML file, please install PyYAML)�os�path�abspath�inspect�
getsourcefile�join�dirname�existsr&r2�endswith�
_have_yaml�open�yaml�	safe_load�json�load�_add_tests_from_data)r1r#rr4�cls_path�data_file_pathr6r%�
_is_yaml_file�frr)r4r�process_file_data�s*



rLc	Cs�x~t|�D]r\}}t|t�r8|||}}t|||�}nt|t�rR|}t|||�}t|t�rnt|||f|�q
t||||�q
WdS)zG
    Add tests from data loaded from the data file into the class

    N)�	enumerater�dictr&rr2)	r1r#rr�i�elem�keyr
r%rrrrG�s


rGcCs�x�t|j���D]�\}}t|t�r�x�tt|t��D]n\}}t|t|d|�|�}t|t�r�t	|t
�slt	|t�r�t|||f|��q�t|||f|�q2t||||�q2Wt||�qt|t
�rt|t
�}t||||�t||�qW|S)a�
    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.

    r*)r�__dict__�items�hasattrrrM�getattrr&rrrr2�delattrrrL)r1r#rrO�vr%r4rrr�ddt�s



rX)r) r;rEr8r!�	functoolsrrC�ImportErrorrA�__version__rrr�type�bool�int�float�
basestringr�	NameErrorrr	rrrrr&r0r2rLrGrXrrrr�<module>s8
	


*