U
    j5{i’  ã                   @   st   d dl mZ G dd„ dƒZG dd„ dƒZG dd„ dƒZzd dlmZ W n" ek
rh   G d	d
„ d
ƒZY nX ejZdS )é    )Ú_should_attempt_c_optimizationsc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚOptimizationTestMixinzBMixin testing that C optimizations are used when appropriate.
    c                 C   s   t ‚dS )zMReturn the implementation in use, without 'Py' or 'Fallback' suffix.
        N©ÚNotImplementedError©Úself© r   úA/tmp/pip-unpacked-wheel-jkvlexts/zope/interface/tests/__init__.pyÚ_getTargetClass   s    z%OptimizationTestMixin._getTargetClassc                 C   s   t ‚dS )z3Return the fallback Python implementation.
        Nr   r   r   r   r	   Ú_getFallbackClass   s    z'OptimizationTestMixin._getFallbackClassc                 C   s4   |   ¡ }|  ¡ }tƒ r$|  ||¡ n|  ||¡ d S ©N)r
   r   r   ZassertIsNotZassertIs)r   ÚusedÚfallbackr   r   r	   Útest_optimizations   s
    z(OptimizationTestMixin.test_optimizationsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r   r	   r      s   r   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚSubclassableMixinc                 C   s   t ‚dS )zLReturn the implementation in use without 'Py' or 'Fallback' suffix.
        Nr   r   r   r   r	   r
   !   s    z!SubclassableMixin._getTargetClassc                 C   s   |   ¡ }G dd„ d|ƒ}d S )Nc                   @   s   e Zd ZdS )z4SubclassableMixin.test_can_subclass.<locals>.DerivedN)r   r   r   r   r   r   r	   ÚDerived)   s   r   )r
   )r   Úklassr   r   r   r	   Útest_can_subclass&   s    z#SubclassableMixin.test_can_subclassN)r   r   r   r
   r   r   r   r   r	   r      s   r   c                   @   s8   e Zd ZdZdd„ Zdd„ Zeeee	fZ
edd„ ƒZdS )	ÚMissingSomeAttrsa  
    Helper for tests that raises a specific exception
    for attributes that are missing. This is usually not
    an AttributeError, and this object is used to test that
    those errors are not improperly caught and treated like
    an AttributeError.
    c                 K   s    || _ t | d¡}| |¡ d S )NÚ__dict__)Ú_MissingSomeAttrs__exc_kindÚobjectÚ__getattribute__Úupdate)r   Zexc_kindÚother_attrsÚdr   r   r	   Ú__init__6   s    zMissingSomeAttrs.__init__c                 C   s<   t  | d¡}z
|| W S  tk
r6   |d |ƒ‚Y nX d S )Nr   r   )r   r   ÚKeyError)r   Únamer   r   r   r	   r   ;   s
    
z!MissingSomeAttrs.__getattribute__c           	   
   K   sÆ   t |tƒst‚||kst‚| jD ]B}| |f|Ž}| |¡�}||ƒ W 5 Q R X | |jjd |¡ q | tf|Ž}z||ƒ W nD tk
r® } z| 	|t|ƒ¡ W 5 d}~X Y n t
k
rÀ   Y nX dS )a  
        Loop through various exceptions, calling *test_func* inside a
        ``assertRaises`` block.

        :param test_func: A callable of one argument, the instance of this
            class.
        :param str expected_missing: The attribute that should fail with the
            exception.  This is used to ensure that we're testing the path we
            think we are.
        :param other_attrs: Attributes that should be provided on the test
            object.  Must not contain *expected_missing*.
        r   N)Ú
isinstanceÚstrÚAssertionErrorÚEXCEPTION_CLASSESÚassertRaisesÚassertEqualÚ	exceptionÚargsÚAttributeErrorZassertNotInÚ	Exception)	ÚclsZunittestZ	test_funcZexpected_missingr   ÚexcÚobÚexÚer   r   r	   Útest_raisesJ   s    
 zMissingSomeAttrs.test_raisesN)r   r   r   r   r    r   Ú	TypeErrorÚRuntimeErrorÚBaseExceptionÚ
ValueErrorr&   Úclassmethodr2   r   r   r   r	   r   -   s   	ür   )Úcleanupc                   @   s   e Zd Zdd„ Ze ZZdS )ÚCleanUpc                 C   s   d S r   r   r   r   r   r	   ÚcleanUp}   s    zCleanUp.cleanUpN)r   r   r   r:   ZsetUpZtearDownr   r   r   r	   r9   |   s   r9   N)	Zzope.interface._compatr   r   r   r   Zzope.testingr8   ÚImportErrorr9   r   r   r   r	   Ú<module>   s   K