o
    $x`‘  ã                   @   sl   d dl mZ G dd„ deƒZG dd„ deƒZzd dlmZ W n ey0   G dd„ deƒZY d	S w 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 )	ÚOptimizationTestMixinzP
    Helper for testing that C optimizations are used
    when appropriate.
    c                 C   ó   t ‚)zq
        Define this to return the implementation in use,
        without the 'Py' or 'Fallback' suffix.
        ©ÚNotImplementedError©Úself© r	   ú?/usr/lib/python3/dist-packages/zope/interface/tests/__init__.pyÚ_getTargetClass
   s   z%OptimizationTestMixin._getTargetClassc                 C   r   )zK
        Define this to return the fallback Python implementation.
        r   r   r	   r	   r
   Ú_getFallbackClass   s   z'OptimizationTestMixin._getFallbackClassc                 C   s6   |   ¡ }|  ¡ }tƒ r|  ||¡ d S |  ||¡ d S ©N)r   r   r   ÚassertIsNotÚ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                   @   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   Úexc_kindÚother_attrsÚdr	   r	   r
   Ú__init__-   s   zMissingSomeAttrs.__init__c                 C   s2   t  | d¡}z|| W S  ty   |d |ƒ‚w )Nr   r   )r   r   ÚKeyError)r   Únamer   r	   r	   r
   r   2   s   
ÿz!MissingSomeAttrs.__getattribute__c           	   
   K   sä   t |tƒsJ ‚||vsJ ‚| jD ]-}| |fi |¤Ž}| |¡�}||ƒ W d  ƒ n1 s.w   Y  | |jjd |¡ q| tfi |¤Ž}z||ƒ W dS  tyh } z| |t|ƒ¡ W Y d}~dS d}~w t	yq   Y dS w )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*.
        Nr   )
Ú
isinstanceÚstrÚEXCEPTION_CLASSESÚassertRaisesÚassertEqualÚ	exceptionÚargsÚAttributeErrorÚassertNotInÚ	Exception)	ÚclsÚunittestÚ	test_funcÚexpected_missingr   ÚexcÚobÚexÚer	   r	   r
   Útest_raisesA   s"   

ÿ€ÿzMissingSomeAttrs.test_raisesN)r   r   r   r   r    r   Ú	TypeErrorÚRuntimeErrorÚBaseExceptionÚ
ValueErrorr%   Úclassmethodr5   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
   ÚcleanUpn   s   zCleanUp.cleanUpN)r   r   r   r=   ÚsetUpÚtearDownr	   r	   r	   r
   r<   m   s    r<   N)	Úzope.interface._compatr   r   r   r   Úzope.testingr;   ÚImportErrorr<   r	   r	   r	   r
   Ú<module>   s     Fÿ
