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   