U
    ,W                     @   sN   d Z ddlZG dd dejZG dd dejZG dd dejZd	d
 ZdS )z!Test adapter declaration helpers
    Nc                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )Test_adapterc                 C   s   ddl m} |S )Nr   )adapter)zope.component._declarationr   )selfr    r   H/usr/lib/python3/dist-packages/zope/component/tests/test__declaration.py_getTargetClass   s    zTest_adapter._getTargetClassc                 G   s   |   | S N)r   )r   
interfacesr   r   r   _makeOne   s    zTest_adapter._makeOnec                 C   s   |   }| t|jg  d S r	   )r   assertEquallistr
   )r   decor   r   r   test_ctor_no_interfaces   s    z$Test_adapter.test_ctor_no_interfacesc                 C   sR   ddl m} G dd d|}G dd d|}| ||}| t|j||g d S )Nr   	Interfacec                   @   s   e Zd ZdS )z1Test_adapter.test_ctor_w_interfaces.<locals>.IFooN__name__
__module____qualname__r   r   r   r   IFoo!   s   r   c                   @   s   e Zd ZdS )z1Test_adapter.test_ctor_w_interfaces.<locals>.IBarNr   r   r   r   r   IBar#   s   r   )zope.interfacer   r   r   r   r
   )r   r   r   r   r   r   r   r   test_ctor_w_interfaces   s
    z#Test_adapter.test_ctor_w_interfacesc                 C   s^   ddl m} G dd d|}G dd d|}| ||G dd dt}| |j||f d S )	Nr   r   c                   @   s   e Zd ZdS )z/Test_adapter.test__call___w_class.<locals>.IFooNr   r   r   r   r   r   *   s   r   c                   @   s   e Zd ZdS )z/Test_adapter.test__call___w_class.<locals>.IBarNr   r   r   r   r   r   ,   s   r   c                   @   s   e Zd ZdS )z.Test_adapter.test__call___w_class.<locals>.BazNr   r   r   r   r   Baz.   s   r   )r   r   r   objectr   __component_adapts__)r   r   r   r   r   r   r   r   test__call___w_class(   s    
z!Test_adapter.test__call___w_classc                 C   sb   ddl m} G dd d|}G dd d|}| ||G dd dt}| }| tt|d	 d S )
Nr   r   c                   @   s   e Zd ZdS )zATest_adapter.test__call___w_inst_of_decorated_class.<locals>.IFooNr   r   r   r   r   r   5   s   r   c                   @   s   e Zd ZdS )zATest_adapter.test__call___w_inst_of_decorated_class.<locals>.IBarNr   r   r   r   r   r   7   s   r   c                   @   s   e Zd ZdS )z@Test_adapter.test__call___w_inst_of_decorated_class.<locals>.BazNr   r   r   r   r   r   9   s   r   Z__component_adapts_)r   r   r   r   assertRaisesAttributeErrorgetattrr   r   r   r   r   bazr   r   r   &test__call___w_inst_of_decorated_class3   s    
  z3Test_adapter.test__call___w_inst_of_decorated_classc                 C   sh   ddl m} G dd d|}G dd d|}G dd dt}| ||}|| }| |j||f d S )	Nr   r   c                   @   s   e Zd ZdS )z3Test_adapter.test__call___w_non_class.<locals>.IFooNr   r   r   r   r   r   B   s   r   c                   @   s   e Zd ZdS )z3Test_adapter.test__call___w_non_class.<locals>.IBarNr   r   r   r   r   r   D   s   r   c                   @   s   e Zd ZdS )z2Test_adapter.test__call___w_non_class.<locals>.BazNr   r   r   r   r   r   F   s   r   )r   r   r   r   r   r   )r   r   r   r   r   r   r"   r   r   r   test__call___w_non_class@   s    
z%Test_adapter.test__call___w_non_classN)
r   r   r   r   r   r   r   r   r#   r$   r   r   r   r   r      s   	r   c                   @   s6   e Zd ZdddZdd Zdd Zdd	 Zd
d ZdS )Test_adaptsTc              	   C   s   dd l }d}|jdd|}|  |sPt||| | t|d W 5 Q R  dS zt||| W n  tk
r   Y W 5 Q R  dS X |r| d W 5 Q R X d S )Nr   FTrecordDidn't raise TypeError)warningscatch_warningsresetwarningsexecr   len	TypeErrorfail)r   codeglobslocsZfails_under_py3kr)   PYTHON3logr   r   r   _run_generated_codeO   s    zTest_adapts._run_generated_codec                    sJ   ddl m G fdddt |  jd  fdd}| t| d S )Nr   adaptsc                       s   e Zd Z   dS )z2Test_adapts.test_instances_not_affected.<locals>.CNr   r   r6   r   r   Cf   s   r8   r   c                      s     j S r	   )r   r   )r8   r   r   _tryj   s    z5Test_adapts.test_instances_not_affected.<locals>._try)r   r7   r   r   r   r   r   )r   r9   r   )r8   r7   r   test_instances_not_affectedd   s
    z'Test_adapts.test_instances_not_affectedc           
   	   C   s   dd l }ddlm} ddlm} G dd d|}||d}i }ddd	g}| |||d
r|d }|jdd*}	|  | 	t
| | t|	d W 5 Q R X d S )Nr   r6   r   c                   @   s   e Zd ZdS )z3Test_adapts.test_called_from_function.<locals>.IFooNr   r   r   r   r   r   r   s   r   r7   r   
z
def foo():    adapts(IFoo)FfooTr&   )r)   r   r7   r   r   joinr5   r*   r+   r   r.   r   r-   )
r   r)   r7   r   r   r1   r2   CODEr>   r4   r   r   r   test_called_from_functionn   s     
z%Test_adapts.test_called_from_functionc              	   C   s   dd l }ddlm} ddlm} ddlm} G dd d|}G dd d|}|||d	}i }d
dddg}	|jddR}
|	  zt
|	|| W n( tk
r   |s| t|
d Y nX | d W 5 Q R X d S )Nr   r6   r   )r3   c                   @   s   e Zd ZdS )z6Test_adapts.test_called_twice_from_class.<locals>.IFooNr   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )z6Test_adapts.test_called_twice_from_class.<locals>.IBarNr   r   r   r   r   r      s   r   )r7   r   r   r<   class Foo(object):r=   z    adapts(IBar)Tr&   r(   )r)   r   r7   r   r   Zzope.interface._compatr3   r?   r*   r+   r,   r.   r   r-   r/   )r   r)   r7   r   r3   r   r   r1   r2   r@   r4   r   r   r   test_called_twice_from_class   s*    z(Test_adapts.test_called_twice_from_classc           	      C   sv   ddl m} ddlm} G dd d|}||d}i }ddd	g}| |||rr|d
 }|j}| t||g d S )Nr   r6   r   c                   @   s   e Zd ZdS )z5Test_adapts.test_called_once_from_class.<locals>.IFooNr   r   r   r   r   r      s   r   r;   r<   rB   r=   Foo)	r   r7   r   r   r?   r5   r   r   r   )	r   r7   r   r   r1   r2   r@   rD   specr   r   r   test_called_once_from_class   s    
z'Test_adapts.test_called_once_from_classN)T)r   r   r   r5   r:   rA   rC   rF   r   r   r   r   r%   M   s    

r%   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )Test_adaptedByc                 C   s   ddl m} ||S )Nr   )	adaptedBy)r   rH   )r   objrH   r   r   r   _callFUT   s    zTest_adaptedBy._callFUTc                 C   s   |  | t d  d S r	   )r   rJ   r   )r   r   r   r   test_obj_w_no_attr   s    z!Test_adaptedBy.test_obj_w_no_attrc                    s\   ddl m} G dd d|G dd d| G  fdddt}| | | f d S )	Nr   r   c                   @   s   e Zd ZdS )z1Test_adaptedBy.test__call___w_class.<locals>.IFooNr   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )z1Test_adaptedBy.test__call___w_class.<locals>.IBarNr   r   r   r   r   r      s   r   c                       s   e Zd Z fZdS )z0Test_adaptedBy.test__call___w_class.<locals>.BazNr   r   r   r   r   r   r   r   r   r      s   r   )r   r   r   r   rJ   )r   r   r   r   rM   r   r      s
    z#Test_adaptedBy.test__call___w_classc                    sl   ddl m} ddlm G dd d|G dd d| G  fdd	d	t}| }| | |d  d S )
Nr   r   )_adapts_descrc                   @   s   e Zd ZdS )zCTest_adaptedBy.test__call___w_inst_of_decorated_class.<locals>.IFooNr   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )zCTest_adaptedBy.test__call___w_inst_of_decorated_class.<locals>.IBarNr   r   r   r   r   r      s   r   c                       s   e Zd Z fZdS )zBTest_adaptedBy.test__call___w_inst_of_decorated_class.<locals>.BazNrL   r   r   r   rN   r   r   r      s   r   )r   r   r   rN   r   r   rJ   )r   r   r   r"   r   rO   r   r#      s    z5Test_adaptedBy.test__call___w_inst_of_decorated_classc                 C   sf   ddl m} G dd d|}G dd d|}G dd dt}| }||f|_| | |||f d S )	Nr   r   c                   @   s   e Zd ZdS )z5Test_adaptedBy.test__call___w_non_class.<locals>.IFooNr   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )z5Test_adaptedBy.test__call___w_non_class.<locals>.IBarNr   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )z4Test_adaptedBy.test__call___w_non_class.<locals>.BazNr   r   r   r   r   r      s   r   )r   r   r   r   r   rJ   r!   r   r   r   r$      s    
z'Test_adaptedBy.test__call___w_non_classN)r   r   r   rJ   rK   r   r#   r$   r   r   r   r   rG      s
   
rG   c                   C   s"   t t tt tt tfS r	   )unittestZ	TestSuiteZ	makeSuiter   r%   rG   r   r   r   r   
test_suite   s
    rQ   )__doc__rP   ZTestCaser   r%   rG   rQ   r   r   r   r   <module>   s
   ;_,