
    Yf                         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dS )z(
Tests for L{twisted.persisted.styles}.
    N)_UniversalPicklingErrorunpickleMethod)unittestc                        e Zd ZdZddZd ZdS )Foo
    Helper class.
    returnNc                     d| _         d S )N
test-valueinstance_memberselfs    T/var/www/html/env/lib/python3.11/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   r	   N)__name__
__module____qualname____doc__r   r    r   r   r   r      sA         , , , ,$ $ $ $ $r   r   c                       e Zd ZdZdS )Barr   N)r   r   r   r   r   r   r   r   r      s           r   r   r	   c                      dS )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dS )UniversalPicklingErrorTestsz9
    Tests the L{_UniversalPicklingError} exception.
    c                     t           )z2
        Raise L{UniversalPicklingError}.
        )r   r   s    r   raise_UniversalPicklingErrorz8UniversalPicklingErrorTests.raise_UniversalPicklingError2   s
     &%r   r	   Nc                 P    |                      t          j        | j                   dS )z^
        Handling L{pickle.PicklingError} handles
        L{_UniversalPicklingError}.
        N)assertRaisespicklePicklingErrorr%   r   s    r   test_handledByPickleModulez6UniversalPicklingErrorTests.test_handledByPickleModule8   s&    
 	&.0QRRRRRr   r   )r   r   r   r   r%   r*   r   r   r   r#   r#   -   sG         & & &S S S S S Sr   r#   c                   B    e Zd ZdZd
dZd
dZd
dZd
dZd
dZd
d	Z	dS )UnpickleMethodTestsz0
    Tests for the unpickleMethod function.
    r	   Nc                     t                      }t          d|t                     }|                     ||j                   |                     ||j                   dS )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   sT    
 ee8S#..CJ'''CJ'''''r   c                 F   t                      }t          j        |j                  }|                     ||j                   |                     ||j                   |                     d |                       d|_        |                     d |                       dS )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   s    
 eeIcj!!CJ'''CJ'''qqss+++)aacc*****r   c                     t                      }t          d|t                    }|                     ||j                   |                     ||j                   dS )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\   sT     ee8S#..CJ'''CJ'''''r   c                 n    t          j         t                    }|                     |t                     dS )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/    
 In%%N+++++r   c                 |    d }|                      t          j        t          d           |d                     dS )zd
        We do not contaminate normal function pickling with concerns from
        Twisted.
        c                     d                     dt          z   t          j        d| z   dg                              d          S )N
cp.ascii)joinr   r   encode)ns    r   expectedz9UnpickleMethodTests.test_primeDirective.<locals>.expectedu   s:    99x!8#'3G fWoor   r   )protocol0N)r.   r(   dumpsr   )r   rF   s     r   test_primeDirectivez'UnpickleMethodTests.test_primeDirectiveo   sF    	 	 	
 	nqAAA88C==QQQQQr   c                 f    |                      t          j        t          j        t                     dS )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LLLLLr   r   )
r   r   r   r   r3   r6   r8   r;   rJ   rM   r   r   r   r,   r,   @   s         ( ( ( (+ + + +	( 	( 	( 	(, , , ,R R R RM M M M M Mr   r,   r   )r   r5   r(   twisted.persisted.stylesr   r   twisted.trialr   r   r   r   rL   TestCaser#   r,   r   r   r   <module>rQ      s:      L L L L L L L L " " " " " "$ $ $ $ $ $ $ $           S S S S S("3 S S S&@M @M @M @M @M(+ @M @M @M @M @Mr   