o
    b                     @   s   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 dZG dd dZ	d	d
 Z
dd ZG dd dejZG d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d ZdS )Foo
    Helper class.
    c                 C   s
   d| _ d S )N
test-valueinstance_memberself r   D/usr/lib/python3/dist-packages/twisted/persisted/test/test_styles.py__init__   s   
zFoo.__init__c                 C   s   | j S )z 
        Helper method.
        r	   r   r   r   r   method   s   z
Foo.methodN)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdS )Barr   N)r   r   r   r   r   r   r   r   r      s    r   c                   C   s   dS )z)
    A sample function for pickling.
    Nr   r   r   r   r   sampleFunction$       r   c                 C   s   | S )Nr   )xr   r   r   <lambda>*   r   r   c                   @   r   )UniversalPicklingErrorTestsz9
    Tests the L{_UniversalPicklingError} exception.
    c                 C   s   t )z2
        Raise L{UniversalPicklingError}.
        )r   r   r   r   r   raise_UniversalPicklingError2   s   z8UniversalPicklingErrorTests.raise_UniversalPicklingErrorc                 C   s   |  tj| j dS )z^
        Handling L{pickle.PicklingError} handles
        L{_UniversalPicklingError}.
        N)assertRaisespicklePicklingErrorr   r   r   r   r   test_handledByPickleModule8   s   z6UniversalPicklingErrorTests.test_handledByPickleModuleN)r   r   r   r   r   r   r   r   r   r   r   -   s    r   c                   @   s@   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.
    c                 C   s2   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mr   r   r    test_instanceBuildingNamePresentE   s   z4UnpickleMethodTests.test_instanceBuildingNamePresentc                 C   sT   t  }t|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
   r#   r   r   r   test_instanceCopyMethodO   s   z+UnpickleMethodTests.test_instanceCopyMethodc                 C   s2   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"   r#   r   r   r   #test_instanceBuildingNameNotPresent\   s   z7UnpickleMethodTests.test_instanceBuildingNameNotPresentc                 C   s   t  t}| |t dS )zi
        Copying a function returns the same reference, without creating
        an actual copy.
        N)r'   r   r!   )r   fr   r   r   test_copyFunctiong   s   
z%UnpickleMethodTests.test_copyFunctionc                 C   s&   dd }|  tjtdd|d dS )zd
        We do not contaminate normal function pickling with concerns from
        Twisted.
        c                 S   s"   d dt tjd|  dgdS )N
cp.ascii)joinr   r   encode)nr   r   r   expectedu   s
   z9UnpickleMethodTests.test_primeDirective.<locals>.expectedr   )protocol0N)r!   r   dumpsr   )r   r4   r   r   r   test_primeDirectiveo   s   z'UnpickleMethodTests.test_primeDirectivec                 C   s   |  tjtjt dS )zY
        Pickling a C{lambda} function ought to raise a L{pickle.PicklingError}.
        N)r   r   r   r7   lambdaExampler   r   r   r   test_lambdaRaisesPicklingError|   s   z2UnpickleMethodTests.test_lambdaRaisesPicklingErrorN)
r   r   r   r   r&   r(   r)   r+   r8   r:   r   r   r   r   r    @   s    
r    )r   r'   r   twisted.persisted.stylesr   r   twisted.trialr   r   r   r   r9   TestCaser   r    r   r   r   r   <module>   s   