
    Vh                         d Z ddlZddlZddlmZmZ ddlmZ  G d d      Z G d d      Z	dd	Z
d
 Z G d dej                        Z G d dej                        Zy)z(
Tests for L{twisted.persisted.styles}.
    N)_UniversalPicklingErrorunpickleMethod)unittestc                       e Zd ZdZddZd Zy)Foo
    Helper class.
    Nc                     d| _         y )N
test-valueinstance_memberselfs    R/home/dcms/DCMS/lib/python3.12/site-packages/twisted/persisted/test/test_styles.py__init__zFoo.__init__   s
    +    c                     | j                   S )z 
        Helper method.
        r   r   s    r   methodz
Foo.method   s     ###r   returnN)__name__
__module____qualname____doc__r   r    r   r   r   r      s    ,$r   r   c                       e Zd ZdZy)Barr   N)r   r   r   r   r   r   r   r   r      s    r   r   c                       y)z)
    A sample function for pickling.
    Nr   r   r   r   sampleFunctionr   $   s    r   c                     | S )Nr   )xs    r   <lambda>r!   *   s    ! r   c                       e Zd ZdZd ZddZy)UniversalPicklingErrorTestsz9
    Tests the L{_UniversalPicklingError} exception.
    c                     t         )z2
        Raise L{UniversalPicklingError}.
        )r   r   s    r   raise_UniversalPicklingErrorz8UniversalPicklingErrorTests.raise_UniversalPicklingError2   s
     &%r   Nc                 X    | j                  t        j                  | j                         y)z^
        Handling L{pickle.PicklingError} handles
        L{_UniversalPicklingError}.
        N)assertRaisespicklePicklingErrorr%   r   s    r   test_handledByPickleModulez6UniversalPicklingErrorTests.test_handledByPickleModule8   s     
 	&..0Q0QRr   r   )r   r   r   r   r%   r*   r   r   r   r#   r#   -   s    &Sr   r#   c                   @    e Zd ZdZd	dZd	dZd	dZd	dZd	dZd	dZ	y)
UnpickleMethodTestsz0
    Tests for the unpickleMethod function.
    Nc                     t               }t        d|t               }| j                  ||j                         | j	                  ||j                         y)zj
        L{unpickleMethod} returns an instance method bound to the
        instance passed to it.
        r   N)r   r   assertEqualr   assertIsNotr   fooms      r    test_instanceBuildingNamePresentz4UnpickleMethodTests.test_instanceBuildingNamePresentE   sA    
 e8S#.CJJ'CJJ'r   c                 0   t               }t        j                  |j                        }| j                  ||j                         | j	                  ||j                         | j                  d |              d|_        | j                  d |              y)za
        Copying an instance method returns a new method with the same
        behavior.
        r
   z	new-valueN)r   copyr   r.   r/   r   r0   s      r   test_instanceCopyMethodz+UnpickleMethodTests.test_instanceCopyMethodO   sq    
 eIIcjj!CJJ'CJJ'qs+)ac*r   c                     t               }t        d|t              }| j                  ||j                         | j                  ||j                         y)z
        If the named method is not present in the class,
        L{unpickleMethod} finds a method on the class of the instance
        and returns a bound method from there.
        r   N)r   r   r   r.   r   r/   r0   s      r   #test_instanceBuildingNameNotPresentz7UnpickleMethodTests.test_instanceBuildingNameNotPresent\   sA     e8S#.CJJ'CJJ'r   c                 b    t        j                   t              }| j                  |t               y)zi
        Copying a function returns the same reference, without creating
        an actual copy.
        N)r5   r   r.   )r   fs     r   test_copyFunctionz%UnpickleMethodTests.test_copyFunctiong   s"    
 IIn%N+r   c                 l    d }| j                  t        j                  t        d       |d             y)zd
        We do not contaminate normal function pickling with concerns from
        Twisted.
        c                 z    dj                  dt        z   t        j                  d| z   dg      j                  d      S )N
cp.ascii)joinr   r   encode)ns    r   expectedz9UnpickleMethodTests.test_primeDirective.<locals>.expectedu   s6    99x!8!8#'3GfWor   r   )protocol0N)r.   r(   dumpsr   )r   rF   s     r   test_primeDirectivez'UnpickleMethodTests.test_primeDirectiveo   s(    	
 	nqA8C=Qr   c                 j    | j                  t        j                  t        j                  t               y)zY
        Pickling a C{lambda} function ought to raise a L{pickle.PicklingError}.
        N)r'   r(   r)   rI   lambdaExampler   s    r   test_lambdaRaisesPicklingErrorz2UnpickleMethodTests.test_lambdaRaisesPicklingError|   s      	&..mLr   r   )
r   r   r   r   r3   r6   r8   r;   rJ   rM   r   r   r   r,   r,   @   s'    (+	(,RMr   r,   r   )r   r5   r(   twisted.persisted.stylesr   r   twisted.trialr   r   r   r   rL   TestCaser#   r,   r   r   r   <module>rQ      sb      L "$ $  S("3"3 S&@M(++ @Mr   