
    daf                         d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d Zd Z G d d	ej                        Zd
 Zy)    N)Message)compat32)load_package_tests)__file__c                  \    t        t        j                  j                  t              g|  S N)r   ospathdirnamer   )argss    3/root/Python-3.12.4/Lib/test/test_email/__init__.py
load_testsr      s    bggooh7?$??    c                     t         j                  j                  t         j                  j                  t              d|       }t        |g|i |S )Ndata)r	   r
   joinr   landmarkopen)filenamer   kwsr
   s       r   openfiler      s:    77<<168DD#t#s##r   c                        e Zd ZdZeZeZ fdZe	j                  j                  Zd Zd
dZd
dZd Zd Zd Zd	 Z xZS )TestEmailBaseNc                 d    t        |   |i | | j                  t        | j                         y r   )super__init__addTypeEqualityFuncbytesassertBytesEqual)selfr   kw	__class__s      r   r   zTestEmailBase.__init__!   s+    $%"%  (=(=>r   c                     t        |d      5 }t        j                  || j                        cd d d        S # 1 sw Y   y xY w)Nzutf-8)encodingpolicy)r   emailmessage_from_filer&   )r    r   fps      r   _msgobjzTestEmailBase._msgobj(   s;    h1 	CR**2dkkB	C 	C 	Cs	   !9Ac                 j    || j                   }|| j                  }t        j                  |||      S Nr%   )r&   messager'   message_from_string)r    stringr-   r&   s       r   _str_msgzTestEmailBase._str_msg,   s3    >[[F?llG((HHr   c                 j    || j                   }|| j                  }t        j                  |||      S r,   )r&   r-   r'   message_from_bytes)r    
bytestringr-   r&   s       r   
_bytes_msgzTestEmailBase._bytes_msg3   s3    >[[F?llG''
GFKKr   c                 :    | j                  | j                        S r,   )r-   r&   )r    s    r   _make_messagezTestEmailBase._make_message:   s    ||4;;|//r   c                 ^    |j                  d      D cg c]  }t        |       c}S c c}w )NT)keepends)
splitlinesrepr)r    bxs      r   _bytes_reprzTestEmailBase._bytes_repr=   s%    !"t!<=AQ===s   *c                 d    | j                  | j                  |      | j                  |             y)z@Our byte strings are really encoded strings; improve diff outputN)assertEqualr=   )r    firstsecondmsgs       r   r   zTestEmailBase.assertBytesEqual@   s(    ))%0$2B2B62JKr   c                     | j                  t        |      t        |      |       t        t        |            D ]*  }| j                  ||   ||   dj	                  |             , y )Nzitem {})r?   lenrangeassertIsInstanceformat)r    actualexpectedis       r   assertDefectsEqualz TestEmailBase.assertDefectsEqualD   s\    Vc(mV<s6{# 	9A!!&)Xa[$-$4$4Q$79	9r   )NN)__name__
__module____qualname__maxDiffr   r&   r   r-   r   unittestTestCaser?   ndiffAssertEqualr*   r0   r4   r6   r=   r   rK   __classcell__)r"   s   @r   r   r      sT    G FG?
  ((44CIL0>L9r   r   c                    i }t        j                  t              }| j                  j	                         D ]  \  }}|j                  d      r^t        |d      sGi }|D ]>  }t        |d      s|f}dj                  d |D              j                  dd      }|||<   @ |}|||dd d	z   <   d	|v sz||j                  d	      d
   d	z      j                  |        i }|D ]   }||vst        dj                  |             |D ]   }||vst        dj                  |             | j                  j	                         D ]  \  }}|j	                         D ]m  \  }	}
|j                  |	      sd|t        |	      d z   }|
j	                         D ]2  \  }}t        |d      r||fd}n||fd}|dz   |z   }||_        |||<   4 o  |j	                         D ]  \  }}t!        | ||        | S )a2  A test method parameterization class decorator.

    Parameters are specified as the value of a class attribute that ends with
    the string '_params'.  Call the portion before '_params' the prefix.  Then
    a method to be parameterized must have the same prefix, the string
    '_as_', and an arbitrary suffix.

    The value of the _params attribute may be either a dictionary or a list.
    The values in the dictionary and the elements of the list may either be
    single values, or a list.  If single values, they are turned into single
    element tuples.  However derived, the resulting sequence is passed via
    *args to the parameterized test function.

    In a _params dictionary, the keys become part of the name of the generated
    tests.  In a _params list, the values in the list are converted into a
    string by joining the string values of the elements of the tuple by '_' and
    converting any blanks into '_'s, and this become part of the name.
    The  full name of a generated test is a 'test_' prefix, the portion of the
    test function name after the  '_as_' separator, plus an '_', plus the name
    derived as explained above.

    For example, if we have:

        count_params = range(2)

        def count_as_foo_arg(self, foo):
            self.assertEqual(foo+1, myfunc(foo))

    we will get parameterized test methods named:
        test_foo_arg_0
        test_foo_arg_1
        test_foo_arg_2

    Or we could have:

        example_params = {'foo': ('bar', 1), 'bing': ('bang', 2)}

        def example_as_myfunc_input(self, name, count):
            self.assertEqual(name+str(count), myfunc(name, count))

    and get:
        test_myfunc_input_foo
        test_myfunc_input_bing

    Note: if and only if the generated test name is a valid identifier can it
    be used to select the test individually from the unittest command line.

    The values in the params dict can be a single value, a tuple, or a
    dict.  If a single value of a tuple, it is passed to the test function
    as positional arguments.  If a dict, it is a passed via **kw.

    _paramskeys__iter___c              3   2   K   | ]  }t        |        y wr   )str).0vs     r   	<genexpr>zparameterize.<locals>.<genexpr>   s      3AQ 3s    Ni_as_r   zNo tester found for {}zNo params found for {}test_c                 &     t        | |      di |S )N getattrr    nameparamss      r   <lambda>zparameterize.<locals>.<lambda>   s    $7GD$$7$A&$A r   c                       t        | |      | S r   rc   re   s      r   rh   zparameterize.<locals>.<lambda>   s    (;d(;V(D r   )collectionsdefaultdictlist__dict__itemsendswithhasattrr   replacesplitappend
ValueErrorrG   
startswithrD   rL   setattr)cls
paramdictstestersrf   attrdr<   n	testfuncs
paramsname
paramsdicttestnameroot	paramnamerg   testtestnamekeyvalues                     r   parameterizer   K   sD   j J%%d+Gll((* A
d==#4( A"1j1D 3 33;;CEAAaD	
 -1JtCRy6)*T>DJJv&q)F23::4@A I Dw5<<TBCCD  Dz!5<<TBCCD ll((* /
d&0&6&6&8 	/"J
z*&c*o.>)??)3)9)9); 	/%Ivvv.26v !B 37v !E+c1I=H$,DM*.Ih'	/	//  oo' !
US% !Jr   )r	   rP   rj   r'   email.messager   email._policybaser   test.supportr   test.test_emailr   r   r   r   rQ   r   r   rb   r   r   <module>r      sA    	    ! & + 0@$19H%% 19h[r   