
    
3j;                        S SK r S SKrS SKrS SKrS SKrS SKJrJr  S SKJ	r	   S SK
r
SrS SKJr  SrSrS	rS
rSrSr " S S\5      r " S S\5      r\" S5      \\\\\4r \\4-  r\ " S S\5      5       r!S r"S r#S r$S"S jr%S"S jr&S S\!RN                  4S jr(S r)S r*S r+S r,S r-S r.S"S  jr/S! r0g! \ a    Sr Nf = f! \ a	    \\ 4-  r Nlf = f)#    N)Enumunique)wrapsTF)Sequencez1.7.2z%valuesz
%file_pathz%yaml_loaderz%unpackz
%index_lenc                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )_NamedDataList(   c                 8   > [         [        U ]  U5        Xl        g N)superr   __init__name)selfr   args	__class__s      =/home/wildlama/miniconda3/lib/python3.13/site-packages/ddt.pyr   _NamedDataList.__init__)   s    nd,T2	    c                 ,    [        U R                  5      $ r   strr   r   s    r   __str___NamedDataList.__str__-       499~r   r   __name__
__module____qualname____firstlineno__r   r   __static_attributes____classcell__r   s   @r   r   r   (   s     r   r   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )_NamedDataDict1   c                    > SUR                  5       ;  a  [        S5      eUR                  S5      U l        [        [
        U ]  U5        g )Nr   z3@named_data expects a dictionary with a 'name' key.)keysKeyErrorpopr   r   r&   r   )r   kwargsr   s     r   r   _NamedDataDict.__init__2   s<    &PQQJJv&	nd,V4r   c                 ,    [        U R                  5      $ r   r   r   s    r   r   _NamedDataDict.__str__8   r   r   r   r   r$   s   @r   r&   r&   1   s    5 r   r&   c                        \ rS rSrSrSrSrSrg)TestNameFormatC   ao  
An enum to configure how ``mk_test_name()`` to compose a test name.  Given
the following example:

.. code-block:: python

    @data("a", "b")
    def testSomething(self, value):
        ...

if using just ``@ddt`` or together with ``DEFAULT``:

* ``testSomething_1_a``
* ``testSomething_2_b``

if using ``INDEX_ONLY``:

* ``testSomething_1``
* ``testSomething_2``

r       N)r   r   r    r!   __doc__DEFAULT
INDEX_ONLYr"   r4   r   r   r1   r1   C   s    * GJr   r1   c                     [        U [        5      (       a  g[        U [        [        45      (       a  [	        [        [        U 5      5      $ g)NTF)
isinstancetrivial_typeslisttupleallmap
is_trivial)values    r   r?   r?   ^   s8    %''	ED%=	)	)3z5)**r   c                 (    [        U [        S5        U $ )z*
Method decorator to add unpack feature.

T)setattrUNPACK_ATTR)funcs    r   unpackrE   f   s    
 D+t$Kr   c                      [        U 5      $ )zs
Method decorator to add to your test methods.

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

)idata)valuess    r   datarI   o   s     =r   c                 n   ^ ^ Tc(  [        T 5      m [        [        [        T 5      5      5      mUU 4S jnU$ )a  
Method decorator to add to your test methods.

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

:param iterable: iterable of the values to provide to the test function.
:param index_len: an optional integer specifying the width to zero-pad the
    test identifier indices to.  If not provided, this will add the fewest
    zeros necessary to make all identifiers the same length.
c                 L   > [        U [        T5        [        U [        T5        U $ r   )rB   	DATA_ATTR	INDEX_LEN)rD   	index_leniterables    r   wrapperidata.<locals>.wrapper   s     i*i+r   )r<   lenr   )rO   rN   rP   s   `` r   rG   rG   y   s3     ?CM*+	
 Nr   c                    ^ ^ U U4S jnU$ )a  
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.

``yaml_loader`` can be used to customize yaml deserialization.
The default is ``None``, which results in using the ``yaml.safe_load``
method.
c                 Z   > [        U [        T5        T(       a  [        U [        T5        U $ r   )rB   	FILE_ATTRYAML_LOADER_ATTR)rD   r@   yaml_loaders    r   rP   file_data.<locals>.wrapper   s$    i'D*K8r   r4   )r@   rW   rP   s   `` r   	file_datarY      s    ,
 Nr      c                 D   SR                  US-   U5      nU[        R                  L d  [        U5      (       d  SR                  X5      $  [	        U5      nSR                  XU5      n[        R                  " SSU5      $ ! [
         a    UR                  SS5      n NHf = f)	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.

The test name format is controlled by enum ``TestNameFormat`` as well. See
the enum documentation for further details.
z{0:0{1}}r3   z{0}_{1}asciibackslashreplacez{0}_{1}_{2}z
\W|^(?=\d)_)	formatr1   r7   r?   r   UnicodeEncodeErrorencoderesub)r   r@   indexrN   name_fmt	test_names         r   mk_test_namerg      s    , eai3E>,,,Ju4E4E,,:E
 $$T%8I66-i00	  :W&89:s   B   BBc                 d  ^ ^^ [         R                  " T 5      (       a  [        T 5      UU U4S j5       nO[        T 5      UU U4S j5       nXl        T Ul        Ub  X%l        U$ T R
                  (       a$   T R
                  R                  " T0 TD6Ul        U$ U$ ! [        [        4 a     U$ f = f)zG
This internal method decorator feeds the test data item to the test.

c                 8   >#    T" U /TQ70 TD6I S h  vN $  N7fr   r4   r   r   rD   r,   s    r   rP   feed_data.<locals>.wrapper   s!     d4T4V4444s   c                    > T" U /TQ70 TD6$ r   r4   rj   s    r   rP   rk      s    .t.v..r   )	inspectiscoroutinefunctionr   r   __wrapped__r5   r_   
IndexErrorr*   )rD   new_nametest_data_docstringr   r,   rP   s   `  `` r   	feed_datars      s    
 ""4((	t	5 
	5 
t	/ 
	/  G&- N <<"&,,"5"5t"Fv"F N7N ) 
 Ns   6!B B/.B/c           	      8    [        X[        X1U/UQ70 UD65        g)zn
Add a test case to this class.

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

N)rB   rs   )clsrf   test_docstringrD   r   r,   s         r   add_testrw      s)     CId~  r   c                 h  ^ [         R                  R                  [        R                  " U 5      5      n[         R                  R                  [         R                  R                  U5      T5      nU4S jn[         R                  R                  U5      (       d#  [        US5      nSn[        XUU" S5      S5        gUR                  S5      n	U	(       a/  [        (       d$  [        US5      nSn[        U UUU" S5      S5        g[        R                  " USS	5       n
U	(       aQ  [        U[        5      (       a%  [!        U[        5      n["        R$                  " XS
9nO-["        R&                  " U
5      nO[(        R$                  " U
5      nSSS5        [+        XUW5        g! , (       d  f       N= f)z5
Process the parameter in the `file_data` decorator.
c                    >^  UU 4S jnU$ )Nc                      > [        TT-  5      er   )
ValueError)r   	file_attrmessages    r   rD   :process_file_data.<locals>.create_error_func.<locals>.func  s    Wy011r   r4   )r}   rD   r|   s   ` r   create_error_func,process_file_data.<locals>.create_error_func  s    	2r   errorzError!z%s does not existN)z.ymlz.yamlz(%s is a YAML file, please install PyYAMLrzutf-8)Loader)ospathabspathrm   getsourcefilejoindirnameexistsrg   rw   endswith
_have_yamlcodecsopenhasattrrV   getattryamlload	safe_loadjson_add_tests_from_data)ru   r   rD   r|   cls_pathdata_file_pathr   rf   rv   _is_yaml_filefrW   rI   s      `         r   process_file_datar      sJ    www44S9:HWW\\"''//(";YGN 77>>.)) w/	%"#67	?"++,=>M ZZ w/	%HI	
 		^S'	2at-..%d,<=yy7~~a(99Q<D 
3 D$/ 
3	2s   A/F##
F1c                 `   [        [        [        U5      5      5      n[        U5       H  u  pV[        U[        5      (       a  XcU   p[        XXT5      n	O#[        U[        5      (       a  Un[        XXT5      n	[        W[        5      (       a  [        U W	X40 UD6  Mt  [        U W	XU5        M     g)z>
Add tests from data loaded from the data file into the class
N)rR   r   	enumerater9   dictrg   r;   rw   )
ru   r   rD   rI   rN   ielemkeyr@   rf   s
             r   r   r   /  s     CD	N#IT?dD!!Dz$T=Id##E$T!?IeT""S)Y>>S)Ye< #r   c                 $    [        U S5      (       + $ )zNFinds out if the obj is a "primitive". It is somewhat hacky but it works.
    __dict__)r   )objs    r   _is_primitiver   A  s     sJ'''r   c                 ^    [        U5      (       d  UR                  (       a  UR                  $ g)zReturns a docstring based on the following resolution strategy:
1. Passed value is not a "primitive" and has a docstring, then use it.
2. In all other cases return None, i.e the test name is used.
N)r   r5   )rD   r@   s     r   _get_test_data_docstringr   G  s"    
 EMM}}r   c                    ^ UR                  S[        R                  5      mU4S jn[        R                  " U 5      (       a  U" U 5      $ U$ )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.

Decorating with the keyword argument ``testNameFormat`` can control the
format of the generated test names.  For example:

- ``@ddt(testNameFormat=TestNameFormat.DEFAULT)`` will be index and values.

- ``@ddt(testNameFormat=TestNameFormat.INDEX_ONLY)`` will be index only.

- ``@ddt`` is the same as DEFAULT.

testNameFormatc           
        > [        U R                  R                  5       5       GH,  u  p[        U[        5      (       a  [        U[        5      n[        [        U[        5      5       H  u  pE[        U[        USU5      UUT	5      n[        X%5      n[        U[        5      (       aL  [        U[        5      (       d  [        U[         5      (       a  [        U UUU/UQ76   Mz  [        U UUU40 UD6  M  [        XXrU5        M     [        X5        M  [        U[        5      (       d  GM  [        U[        5      n[!        XX(5        [        X5        GM/     U $ )Nr   )r;   r   itemsr   rL   r   rM   r   rg   r   rC   r9   r<   rw   delattrrU   r   )
ru   r   rD   rN   r   vrf   rr   r|   fmt_test_names
            r   rP   ddt.<locals>.wrapperu  s4   s||1134JDtY''#D)4	%gdI&>?DA ,:q1!%!I +C4*K't[11%a//:a3F3F$ # ) 3 $	
 "# % # ) 3 $	
 #$ !1DAN9 @: "y))#D)4	!#T="I 5J 
r   )getr1   r6   rm   isclass)argr,   rP   r   s      @r   ddtr   R  sB    B JJ/1G1GHM&T #??3//73<<W<r   c                  :  ^ / mU  H  n[        U[        [        45      (       d#  [        SR	                  [        U5      5      5      e[        U[        5      (       a  [        S0 UD6O[        US   /USS Q76 nSUl        TR                  U5        M     U4S jnU$ )a  
This decorator is to allow for meaningful names to be given to tests that would otherwise use @ddt.data and
@ddt.unpack.

Example of original ddt usage:
    @ddt.ddt
    class TestExample(TemplateTest):
        @ddt.data(
            [0, 1],
            [10, 11]
        )
        @ddt.unpack
        def test_values(self, value1, value2):
            ...

Example of new usage:
    @ddt.ddt
    class TestExample(TemplateTest):
        @named_data(
            ['LabelA', 0, 1],
            ['LabelB', 10, 11],
        )
        def test_values(self, value1, value2):
            ...

Note that @unpack is not used.

:param Sequence[Any] | dict[Any,Any] named_values: Each named_value should be a Sequence (e.g. list or tuple) with
    the name as the first element, or a dictionary with 'name' as one of the keys. The name will be coerced to a
    string and all other values will be passed unchanged to the test.
zI@named_data expects a Sequence (list, tuple) or dictionary, and not '{}'.r   r3   Nc                 6   > [        T6 " [        U 5      5        U $ r   )rI   rE   )rD   rH   s    r   rP   named_data.<locals>.wrapper  s    ffTl#r   r4   )
r9   r   r   	TypeErrorr_   typer&   r   r5   append)named_valuesnamed_valuer@   rP   rH   s       @r   
named_datar     s    @ F#+$'788[bbcghsctu  2<K1N1N--AAQRA 	 e $ Nr   r   )1r   rm   r   r   rb   enumr   r   	functoolsr   r   r   ImportErrorcollections.abcr   __version__rL   rU   rV   rC   rM   r;   r   r   r&   r   boolintfloatr:   
basestring	NameErrorr   r1   r?   rE   rI   rG   rY   r6   rg   rs   rw   r   r   r   r   r   r   r4   r   r   <module>r      s;      	 	   J $  		! 	T T  dT3~~Nj^#M
 T  40< %&^=S=S 1DB	.0b=$(M=`3a  JZ  cWMs#   B7 !C 7CCCC