U
    ؒ]                     @   s   d Z ddlZdd ZG dd dejZG dd dejZG d	d
 d
eZG dd dejZG dd deZG dd dejZ	G dd dejZ
G dd dejZdS )zAdapter registry tests
    Nc            
   	   C   s   ddl m}  G dd d| }G dd d|}G dd d|}G d	d
 d
||}G dd d||}G dd d| }G dd d|}G dd d| }G dd d|}	|||||||||	f	S )Nr   	Interfacec                   @   s   e Zd ZdS )z_makeInterfaces.<locals>.IB0N__name__
__module____qualname__ r   r   C/usr/lib/python3/dist-packages/zope/interface/tests/test_adapter.pyIB0   s    r
   c                   @   s   e Zd ZdS )z_makeInterfaces.<locals>.IB1Nr   r   r   r   r	   IB1   s    r   c                   @   s   e Zd ZdS )z_makeInterfaces.<locals>.IB2Nr   r   r   r   r	   IB2   s    r   c                   @   s   e Zd ZdS )z_makeInterfaces.<locals>.IB3Nr   r   r   r   r	   IB3   s    r   c                   @   s   e Zd ZdS )z_makeInterfaces.<locals>.IB4Nr   r   r   r   r	   IB4   s    r   c                   @   s   e Zd ZdS )z_makeInterfaces.<locals>.IF0Nr   r   r   r   r	   IF0   s    r   c                   @   s   e Zd ZdS )z_makeInterfaces.<locals>.IF1Nr   r   r   r   r	   IF1   s    r   c                   @   s   e Zd ZdS )z_makeInterfaces.<locals>.IR0Nr   r   r   r   r	   IR0   s    r   c                   @   s   e Zd ZdS )z_makeInterfaces.<locals>.IR1Nr   r   r   r   r	   IR1    s    r   )zope.interfacer   )
r   r
   r   r   r   r   r   r   r   r   r   r   r	   _makeInterfaces   s    r   c                   @   s   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d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7S )8BaseAdapterRegistryTestsc                 C   s<   ddl m} G dd d|}|jD ]}t|j|t  q"|S )Nr   )BaseAdapterRegistryc                   @   s   e Zd ZG dd deZdS )z6BaseAdapterRegistryTests._getTargetClass.<locals>._CUTc                   @   s4   e Zd Zd ZZdd Zdd Zdd Zdd	 Zd
S )zBBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClassr   c                 S   s   d S Nr   )selfregr   r   r	   __init__,   s    zKBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.__init__c                 S   s   |  j |f7  _ d S r   _changed)r   origr   r   r	   changed.   s    zJBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.changedc                 S   s   |  j |f7  _ d S r   )
_extendorsr   providedr   r   r	   add_extendor0   s    zOBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.add_extendorc                    s   t  fdd| jD | _d S )Nc                    s   g | ]}| kr|qS r   r   ).0xr!   r   r	   
<listcomp>3   s    zfBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.remove_extendor.<locals>.<listcomp>)tupler   r    r   r%   r	   remove_extendor2   s    zRBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.remove_extendorN)	r   r   r   r   r   r   r   r"   r(   r   r   r   r	   LookupClass*   s
   r)   N)r   r   r   objectr)   r   r   r   r	   _CUT)   s   r+   )zope.interface.adapterr   
_delegatedsetattrr)   r*   )r   r   r+   namer   r   r	   _getTargetClass'   s
    
z(BaseAdapterRegistryTests._getTargetClassc                 C   s
   |    S r   r0   r   r   r   r	   _makeOne9   s    z!BaseAdapterRegistryTests._makeOnec                 C   s:   |   }| }|jD ] }| t||t|j|k qd S r   )r0   r-   
assertTruegetattr	_v_lookup)r   ZCUTregistryr/   r   r   r	   test_lookup_delegation<   s    
z/BaseAdapterRegistryTests.test_lookup_delegationc                 C   s   |   }| |jd d S N   )r3   assertEqual_generationr   r7   r   r   r	   "test__generation_on_first_creationC   s    z;BaseAdapterRegistryTests.test__generation_on_first_creationc                 C   s>   |   }t }|| | |jd | |jj||f d S N   )r3   r*   r   r;   r<   r6   r   )r   r7   r   r   r   r	   &test__generation_after_calling_changedH   s
    
z?BaseAdapterRegistryTests.test__generation_after_calling_changedc                 C   s2   G dd dt }|  }|f|_| |jd d S )Nc                   @   s   e Zd ZdS )zQBaseAdapterRegistryTests.test__generation_after_changing___bases__.<locals>._BaseNr   r   r   r   r	   _BaseQ   s    rB   r@   )r*   r3   	__bases__r;   r<   )r   rB   r7   r   r   r	   )test__generation_after_changing___bases__P   s    zBBaseAdapterRegistryTests.test__generation_after_changing___bases__c              	   C   sn   t  \	}}}}}}}}}	|  }
|
|g|dd | |
|g|dd | t|
jd | |
jd d S )N A1r@   )r   r3   registerr;   
registeredlen	_adaptersr<   r   r
   r   r   r   r   r   r   r   r   r7   r   r   r	   test_registerV   s    z&BaseAdapterRegistryTests.test_registerc              	   C   sN   t  \	}}}}}}}}}	|  }
| t |
|g|t d W 5 Q R X d S )NrF   )r   r3   assertRaises
ValueErrorrG   r*   rK   r   r   r	   test_register_with_invalid_name^   s    z8BaseAdapterRegistryTests.test_register_with_invalid_namec              	   C   sZ   t  \	}}}}}}}}}	|  }
|
d g|dd |
d g|dd  | t|
jd d S )NrE   rF   r   )r   r3   rG   r;   rI   rJ   rK   r   r   r	   )test_register_with_value_None_unregistersd   s
    zBBaseAdapterRegistryTests.test_register_with_value_None_unregistersc              	   C   sb   t  \	}}}}}}}}}	|  }
t }|
d g|d| |
j}|
d g|d| | |
j| d S NrE   )r   r3   r*   rG   r<   r;   )r   r
   r   r   r   r   r   r   r   r   r7   Z_valueZ_beforer   r   r	   test_register_with_same_valuek   s    z6BaseAdapterRegistryTests.test_register_with_same_valuec                 C   s$   |   }| |d gd dd  d S rQ   )r3   r;   rH   r=   r   r   r	   test_registered_emptyt   s    z.BaseAdapterRegistryTests.test_registered_emptyc              	   C   sN   t  \	}}}}}}}}}	|  }
|
|gd dd | |
|gd dd  d S NrE   rF   )r   r3   rG   r;   rH   rK   r   r   r	   test_registered_non_empty_missx   s    z7BaseAdapterRegistryTests.test_registered_non_empty_missc                 C   s6   |   }|d gd dd | |d gd dd d S rT   )r3   rG   r;   rH   r=   r   r   r	   test_registered_non_empty_hit~   s    z6BaseAdapterRegistryTests.test_registered_non_empty_hitc                 C   s4   |   }|d gd d | |d gd dd  d S rQ   )r3   
unregisterr;   rH   r=   r   r   r	   test_unregister_empty   s    z.BaseAdapterRegistryTests.test_unregister_emptyc              	   C   s^   t  \	}}}}}}}}}	|  }
|
|gd dd |
|gd d | |
|gd dd d S rT   r   r3   rG   rW   r;   rH   rK   r   r   r	   *test_unregister_non_empty_miss_on_required   s
    zCBaseAdapterRegistryTests.test_unregister_non_empty_miss_on_requiredc              	   C   s^   t  \	}}}}}}}}}	|  }
|
|gd dd |
|gd d | |
|gd dd d S )NrE   rF   ZnonesuchrY   rK   r   r   r	   &test_unregister_non_empty_miss_on_name   s
    z?BaseAdapterRegistryTests.test_unregister_non_empty_miss_on_namec              	   C   sn   t  \	}}}}}}}}}	|  }
t }t }|
|gd d| |
|gd d| | |
|gd d|k d S rQ   )r   r3   r*   rG   rW   r4   rH   r   r
   r   r   r   r   r   r   r   r   r7   r   Znomatchr   r   r	   (test_unregister_with_value_not_None_miss   s    zABaseAdapterRegistryTests.test_unregister_with_value_not_None_missc              	   C   s   t  \	}}}}}}}}}	|  }
t }t }|
||gd d| |
||gd d| | ||
jd | k | ||
jd | k |
||gd d| | ||
jd | k | ||
jd | k d S )NrE   r@   )r   r3   r*   rG   r4   rJ   rW   ZassertFalse)r   r
   r   r   r   r   r   r   r   r   r7   ZoneZanotherr   r   r	   .test_unregister_hit_clears_empty_subcomponents   s    zGBaseAdapterRegistryTests.test_unregister_hit_clears_empty_subcomponentsc                 C   s4   |   }|d gd d | |d gd dd  d S rQ   )r3   unsubscriber;   rH   r=   r   r   r	   test_unsubscribe_empty   s    z/BaseAdapterRegistryTests.test_unsubscribe_emptyc              	   C   s\   t  \	}}}}}}}}}	|  }
t }|
|gd | |
|gd | | t|
jd d S Nr   r   r3   r*   	subscriber_   r;   rI   _subscribers)r   r
   r   r   r   r   r   r   r   r   r7   r   r   r   r	   test_unsubscribe_hit   s    z-BaseAdapterRegistryTests.test_unsubscribe_hitc              	   C   s   t  \	}}}}}}}}}	|  }
t }t }t }t }|
|gd | |
|gd | |
|g|| |
|g|| |
|g|| |
|g|| |
|gd | |
|gd | | t|
jd d S ra   rb   )r   r
   r   r   r   r   r   r   r   r   r7   firstsecondthirdZfourthr   r   r	   test_unsubscribe_after_multiple   s    z8BaseAdapterRegistryTests.test_unsubscribe_after_multiplec              	   C   sv   t  \	}}}}}}}}}	|  }
t }t }t }|
|gd | |
|gd | |
|gd  | t|
jd d S ra   rb   )r   r
   r   r   r   r   r   r   r   r   r7   rf   rg   rh   r   r   r	   &test_unsubscribe_w_None_after_multiple   s    z?BaseAdapterRegistryTests.test_unsubscribe_w_None_after_multiplec              	   C   sh   t  \	}}}}}}}}}	|  }
|
|gd d | t|
jd |
|gd d | t|
jd d S )NrF   r@   rE   r   r3   rc   r;   rI   rd   r_   rK   r   r   r	   +test_unsubscribe_non_empty_miss_on_required   s    zDBaseAdapterRegistryTests.test_unsubscribe_non_empty_miss_on_requiredc              	   C   sh   t  \	}}}}}}}}}	|  }
|
|gd d | t|
jd |
|gd d | t|
jd d S )NrF   r@   ZA2rk   rK   r   r   r	   (test_unsubscribe_non_empty_miss_on_value   s    zABaseAdapterRegistryTests.test_unsubscribe_non_empty_miss_on_valuec              	   C   sb   t  \	}}}}}}}}}	|  }
t }t }|
|gd | |
|gd | | t|
jd d S r?   rb   r\   r   r   r	   )test_unsubscribe_with_value_not_None_miss   s    zBBaseAdapterRegistryTests.test_unsubscribe_with_value_not_None_missc                 C   s   |  d d S )Nz*Example method, not intended to be called.Zfailr2   r   r   r	   _instance_method_notify_target   s    z7BaseAdapterRegistryTests._instance_method_notify_targetc              	   C   sl   t  \	}}}}}}}}}	|  }
| t|
jd |
|gd | j |
|gd | j | t|
jd d S ra   )r   r3   r;   rI   rd   rc   rp   r_   rK   r   r   r	    test_unsubscribe_instance_method   s    z9BaseAdapterRegistryTests.test_unsubscribe_instance_methodN)r   r   r   r0   r3   r8   r>   rA   rD   rL   rO   rP   rR   rS   rU   rV   rX   rZ   r[   r]   r^   r`   re   ri   rj   rl   rm   rn   rp   rq   r   r   r   r	   r   %   s6   			r   c                   @   s   e Zd Zdd Zd8ddZdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 ZdS )9LookupBaseFallbackTestsc                 C   s   ddl m} |S Nr   )LookupBaseFallback)r,   rt   )r   rt   r   r   r	   r0      s    z'LookupBaseFallbackTests._getTargetClassNc                    sR    d krdd  d kr dd d kr0dd G  fddd|   }| S )	Nc                 S   s   d S r   r   r   requiredr!   r/   r   r   r	   	uc_lookup  s    z3LookupBaseFallbackTests._makeOne.<locals>.uc_lookupc                 S   s
   t  d S r   NotImplementedErrorr   rv   r!   r   r   r	   uc_lookupAll  s    z6LookupBaseFallbackTests._makeOne.<locals>.uc_lookupAllc                 S   s
   t  d S r   rx   rz   r   r   r	   uc_subscriptions	  s    z:LookupBaseFallbackTests._makeOne.<locals>.uc_subscriptionsc                       s   e Zd Z ZZZdS )z1LookupBaseFallbackTests._makeOne.<locals>.DerivedN)r   r   r   _uncached_lookup_uncached_lookupAll_uncached_subscriptionsr   rw   r{   r|   r   r	   Derived  s   r   r1   )r   rw   r{   r|   r   r   r   r	   r3      s    z LookupBaseFallbackTests._makeOnec              	   C   s>   dd }| j |d}| t |ddt  W 5 Q R X d S )Nc                 S   s   |  d d S NzThis should never be calledro   ru   r   r   r	   _lookup  s    zCLookupBaseFallbackTests.test_lookup_w_invalid_name.<locals>._lookuprw   AB)r3   rM   rN   lookupr*   r   r   lbr   r   r	   test_lookup_w_invalid_name  s    z2LookupBaseFallbackTests.test_lookup_w_invalid_namec                    sJ   g   fdd}| j |d}|ddd}| |d k |  dg d S )Nc                    s     |||f d S r   appendru   _called_withr   r	   r     s    zDLookupBaseFallbackTests.test_lookup_miss_no_default.<locals>._lookupr   r   r   Cr   r   r   )r3   r   r4   r;   r   r   r   foundr   r   r	   test_lookup_miss_no_default  s    z3LookupBaseFallbackTests.test_lookup_miss_no_defaultc                    sR   g  t  } fdd}| j|d}|ddd|}| ||k |  dg d S )Nc                    s     |||f d S r   r   ru   r   r   r	   r   %  s    zCLookupBaseFallbackTests.test_lookup_miss_w_default.<locals>._lookupr   r   r   r   r   r*   r3   r   r4   r;   r   _defaultr   r   r   r   r   r	   test_lookup_miss_w_default"  s    z2LookupBaseFallbackTests.test_lookup_miss_w_defaultc                    s|   g  t  t  t    }}}|||g fdd}| j|d}|ddd}| ||k |  dg | ||g d S )Nc                    s     |||f dS ra   r   popru   r   _resultsr   r	   r   1  s    z?LookupBaseFallbackTests.test_lookup_not_cached.<locals>._lookupr   r   r   r   r   r   r   abcr   r   r   r   r   r	   test_lookup_not_cached-  s    
z.LookupBaseFallbackTests.test_lookup_not_cachedc                    s   g  t  t  t    }}}|||g fdd}| j|d}|ddd}|ddd}| ||k |  dg | ||g d S )Nc                    s     |||f dS ra   r   ru   r   r   r	   r   >  s    z;LookupBaseFallbackTests.test_lookup_cached.<locals>._lookupr   r   r   r   r   r   r   r   r   r	   test_lookup_cached:  s    
z*LookupBaseFallbackTests.test_lookup_cachedc                    s|   g  t  t  t    }}}|||g fdd}| j|d}|ddd}| ||k |  dg | ||g d S )Nc                    s     |||f dS ra   r   ru   r   r   r	   r   L  s    zNLookupBaseFallbackTests.test_lookup_not_cached_multi_required.<locals>._lookupr   r   Dr   r   r   r   r   r   r   r   r   r	   %test_lookup_not_cached_multi_requiredH  s    
z=LookupBaseFallbackTests.test_lookup_not_cached_multi_requiredc                    s   g  t  t  t    }}}|||g fdd}| j|d}|ddd}|ddd}| ||k |  dg | ||g d S )Nc                    s     |||f dS ra   r   ru   r   r   r	   r   Y  s    zJLookupBaseFallbackTests.test_lookup_cached_multi_required.<locals>._lookupr   r   r   r   r   r   r   r   r   r	   !test_lookup_cached_multi_requiredU  s    
z9LookupBaseFallbackTests.test_lookup_cached_multi_requiredc                    s   g  t  t  t    }}}|||g fdd}| j|d}|ddd}|| |ddd}| ||k |  ddg | |g d S )Nc                    s     |||f dS ra   r   ru   r   r   r	   r   g  s    zMLookupBaseFallbackTests.test_lookup_not_cached_after_changed.<locals>._lookupr   r   r   r   r   )r*   r3   r   r   r4   r;   r   r   r   r	   $test_lookup_not_cached_after_changedc  s    

z<LookupBaseFallbackTests.test_lookup_not_cached_after_changedc              	   C   s>   dd }| j |d}| t |ddt  W 5 Q R X d S )Nc                 S   s   |  d d S r   ro   ru   r   r   r	   r   t  s    zDLookupBaseFallbackTests.test_lookup1_w_invalid_name.<locals>._lookupr   r   r   )r3   rM   rN   lookup1r*   r   r   r   r	   test_lookup1_w_invalid_names  s    z3LookupBaseFallbackTests.test_lookup1_w_invalid_namec                    sJ   g   fdd}| j |d}|ddd}| |d k |  dg d S )Nc                    s     |||f d S r   r   ru   r   r   r	   r   }  s    zELookupBaseFallbackTests.test_lookup1_miss_no_default.<locals>._lookupr   r   r   r   r   )r3   r   r4   r;   r   r   r   r	   test_lookup1_miss_no_default{  s    z4LookupBaseFallbackTests.test_lookup1_miss_no_defaultc                    sR   g  t  } fdd}| j|d}|ddd|}| ||k |  dg d S )Nc                    s     |||f d S r   r   ru   r   r   r	   r     s    zDLookupBaseFallbackTests.test_lookup1_miss_w_default.<locals>._lookupr   r   r   r   r   r*   r3   r   r4   r;   r   r   r   r	   test_lookup1_miss_w_default  s    z3LookupBaseFallbackTests.test_lookup1_miss_w_defaultc                    sp   g  t  } fdd}| j|d}|ddd|}| ||k |ddd|}| ||k |  dg d S )Nc                    s     |||f d S r   r   ru   r   r   r	   r     s    zSLookupBaseFallbackTests.test_lookup1_miss_w_default_negative_cache.<locals>._lookupr   r   r   r   r   r   r   r   r   r	   *test_lookup1_miss_w_default_negative_cache  s    zBLookupBaseFallbackTests.test_lookup1_miss_w_default_negative_cachec                    s|   g  t  t  t    }}}|||g fdd}| j|d}|ddd}| ||k |  dg | ||g d S )Nc                    s     |||f dS ra   r   ru   r   r   r	   r     s    z@LookupBaseFallbackTests.test_lookup1_not_cached.<locals>._lookupr   r   r   r   r   r   r   r   r   r	   test_lookup1_not_cached  s    
z/LookupBaseFallbackTests.test_lookup1_not_cachedc                    s   g  t  t  t    }}}|||g fdd}| j|d}|ddd}|ddd}| ||k |  dg | ||g d S )Nc                    s     |||f dS ra   r   ru   r   r   r	   r     s    z<LookupBaseFallbackTests.test_lookup1_cached.<locals>._lookupr   r   r   r   r   r   r   r   r   r	   test_lookup1_cached  s    
z+LookupBaseFallbackTests.test_lookup1_cachedc                    s   g  t  t  t    }}}|||g fdd}| j|d}|ddd}|| |ddd}| ||k |  ddg | |g d S )Nc                    s     |||f dS ra   r   ru   r   r   r	   r     s    zNLookupBaseFallbackTests.test_lookup1_not_cached_after_changed.<locals>._lookupr   r   r   r   r   )r*   r3   r   r   r4   r;   r   r   r   r	   %test_lookup1_not_cached_after_changed  s    

z=LookupBaseFallbackTests.test_lookup1_not_cached_after_changedc              	   C   s@   t  t   }}|  }| t |||t   W 5 Q R X d S r   )r*   r3   rM   rN   adapter_hook)r   reqprvr   r   r   r	    test_adapter_hook_w_invalid_name  s    z8LookupBaseFallbackTests.test_adapter_hook_w_invalid_namec                 C   s6   t  t   }}|  }|||d}| |d k d S rQ   r*   r3   r   r4   )r   r   r   r   r   r   r   r	   !test_adapter_hook_miss_no_default  s    z9LookupBaseFallbackTests.test_adapter_hook_miss_no_defaultc                 C   s@   t  t  t    }}}|  }|||d|}| ||k d S rQ   r   )r   r   r   r   r   r   r   r   r	    test_adapter_hook_miss_w_default  s    z8LookupBaseFallbackTests.test_adapter_hook_miss_w_defaultc                    sn   g   fddfdd}t  t  t    }}}| j|d}|||d|}| ||k |  |g d S )Nc                    s     |  d S r   r   context)_f_called_withr   r	   _factory  s    
zTLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_None.<locals>._factoryc                    s    S r   r   ru   r   r   r	   r     s    zSLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_None.<locals>._lookupr   r   r*   r3   r   r4   r;   r   r   r   r   r   r   adaptedr   )r   r   r	   *test_adapter_hook_hit_factory_returns_None  s    zBLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_Nonec                    sv   g t    fddfdd}t  t  t    }}}| j|d}|||d|}| | k | |g d S )Nc                    s    |   S r   r   r   _adapterr   r   r	   r     s    
zWLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_adapter.<locals>._factoryc                    s    S r   r   ru   r   r   r	   r     s    zVLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_adapter.<locals>._lookupr   r   r   r   r   r   r   r   r	   -test_adapter_hook_hit_factory_returns_adapter  s    zELookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_adapterc                    sv   g t    fddfdd}t  t  t    }}}| j|d}|||d|}| | k | |g d S )Nc                    s    |   S r   r   r   r   r   r	   r     s    
z;LookupBaseFallbackTests.test_queryAdapter.<locals>._factoryc                    s    S r   r   ru   r   r   r	   r     s    z:LookupBaseFallbackTests.test_queryAdapter.<locals>._lookupr   r   )r*   r3   queryAdapterr4   r;   r   r   r   r	   test_queryAdapter  s    z)LookupBaseFallbackTests.test_queryAdapterc                    s\   g  t  t  t  g fdd}| j|d}|dd}| |t |  dg d S )Nc                    s     ||f tS r   r   r'   rz   r   r   r	   
_lookupAll  s    zCLookupBaseFallbackTests.test_lookupAll_uncached.<locals>._lookupAllr{   r   r   r   r   r*   r3   	lookupAllr;   r'   r   r   r   r   r   r   r	   test_lookupAll_uncached  s    z/LookupBaseFallbackTests.test_lookupAll_uncachedc                    sh   g  t  t  t  g fdd}| j|d}|dd}|dd}| |t |  dg d S )Nc                    s     ||f tS r   r   rz   r   r   r	   r     s    zALookupBaseFallbackTests.test_lookupAll_cached.<locals>._lookupAllr   r   r   r   r   r   r   r   r	   test_lookupAll_cached  s    z-LookupBaseFallbackTests.test_lookupAll_cachedc                    s\   g  t  t  t  g fdd}| j|d}|dd}| |t |  dg d S )Nc                    s     ||f tS r   r   rz   r   r   r	   _subscriptions  s    zKLookupBaseFallbackTests.test_subscriptions_uncached.<locals>._subscriptionsr|   r   r   r   r*   r3   subscriptionsr;   r'   r   r   r   r   r   r   r	   test_subscriptions_uncached  s    z3LookupBaseFallbackTests.test_subscriptions_uncachedc                    sh   g  t  t  t  g fdd}| j|d}|dd}|dd}| |t |  dg d S )Nc                    s     ||f tS r   r   rz   r   r   r	   r   (  s    zILookupBaseFallbackTests.test_subscriptions_cached.<locals>._subscriptionsr   r   r   r   r   r   r   r   r	   test_subscriptions_cached%  s    z1LookupBaseFallbackTests.test_subscriptions_cached)NNN)r   r   r   r0   r3   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   rr      s:     


rr   c                   @   s   e Zd Zdd Zdd ZdS )LookupBaseTestsc                 C   s   ddl m} |S )Nr   )
LookupBase)r,   r   )r   r   r   r   r	   r0   4  s    zLookupBaseTests._getTargetClassc                 C   sR   ddl m} zdd l}W n$ tk
r<   | |  | Y nX | |  | d S rs   )r,   rt   -zope.interface._zope_interface_coptimizationsImportErrorassertIsr0   assertIsNot)r   rt   zoper   r   r	   test_optimizations8  s    z"LookupBaseTests.test_optimizationsNr   r   r   r0   r   r   r   r   r	   r   2  s   r   c                   @   sV   e Zd Zdd Zdd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 )VerifyingBaseFallbackTestsc                 C   s   ddl m} |S Nr   )VerifyingBaseFallback)r,   r   )r   r   r   r   r	   r0   D  s    z*VerifyingBaseFallbackTests._getTargetClassNc                    sd   d krdd d kr dd d kr0dd G  fddd|     |}|| |S )	Nc                 S   s
   t  d S r   rx   ru   r   r   r	   rw   K  s    z6VerifyingBaseFallbackTests._makeOne.<locals>.uc_lookupc                 S   s
   t  d S r   rx   rz   r   r   r	   r{   N  s    z9VerifyingBaseFallbackTests._makeOne.<locals>.uc_lookupAllc                 S   s
   t  d S r   rx   rz   r   r   r	   r|   Q  s    z=VerifyingBaseFallbackTests._makeOne.<locals>.uc_subscriptionsc                       s*   e Zd ZZZZ fddZ  ZS )z4VerifyingBaseFallbackTests._makeOne.<locals>.Derivedc                    s   t  |   || _d S r   )superr   	_registryr=   )r   	__class__r   r	   r   W  s    z=VerifyingBaseFallbackTests._makeOne.<locals>.Derived.__init__)r   r   r   r}   r~   r   r   __classcell__r   r   rw   r{   r|   )r   r	   r   S  s   r   )r0   r   )r   r7   rw   r{   r|   Zderivedr   r   r	   r3   H  s    
z#VerifyingBaseFallbackTests._makeOnec                    s*   G dd dt  G  fddd}||S )Nc                   @   s   e Zd ZdZdS )z@VerifyingBaseFallbackTests._makeRegistry.<locals>.WithGenerationr:   N)r   r   r   r<   r   r   r   r	   WithGeneration_  s   r   c                       s   e Zd Z fddZdS )z:VerifyingBaseFallbackTests._makeRegistry.<locals>.Registryc                    s    fddt |D | _d S )Nc                    s   g | ]
}  qS r   r   )r#   ir   r   r	   r&   c  s     zWVerifyingBaseFallbackTests._makeRegistry.<locals>.Registry.__init__.<locals>.<listcomp>)rangero)r   depthr   r   r	   r   b  s    zCVerifyingBaseFallbackTests._makeRegistry.<locals>.Registry.__init__Nr   r   r   r   r   r   r   r	   Registrya  s   r   )r*   )r   r   r   r   r   r	   _makeRegistry^  s    z(VerifyingBaseFallbackTests._makeRegistryc                    s   g  t  t  t    }}}|||g fdd}| d}| j||d}|ddd}|ddd}| ||k |  dg | ||g |jd	  jd	7  _|ddd}| ||k |  ddg | |g d S )
Nc                    s     |||f dS ra   r   ru   r   r   r	   r   j  s    z7VerifyingBaseFallbackTests.test_lookup.<locals>._lookup   r   r   r   r   r   r:   )r*   r   r3   r   r4   r;   r   r<   r   r   r   r   r   r   r   r   r   r   r	   test_lookupf  s$    

z&VerifyingBaseFallbackTests.test_lookupc                    s   g  t  t  t    }}}|||g fdd}| d}| j||d}|ddd}|ddd}| ||k |  dg | ||g |jd	  jd	7  _|ddd}| ||k |  ddg | |g d S )
Nc                    s     |||f dS ra   r   ru   r   r   r	   r     s    z8VerifyingBaseFallbackTests.test_lookup1.<locals>._lookupr   r   r   r   r   r   r:   )r*   r   r3   r   r4   r;   r   r<   r   r   r   r	   test_lookup1{  s$    

z'VerifyingBaseFallbackTests.test_lookup1c                    s   t  t  t  g\}fdd}fdd}fdd}|||g  fdd}t  t  t    }}}d	}	j|	|d
}
|
||d|}|k |
||d|}|k |	jd  jd7  _|
||d|}|k d S )Nc                    s    S r   r   r   r   r   r	   	_factory1  s    z?VerifyingBaseFallbackTests.test_adapter_hook.<locals>._factory1c                    s    S r   r   r   r   r   r	   	_factory2  s    z?VerifyingBaseFallbackTests.test_adapter_hook.<locals>._factory2c                    s     d d S r   ro   r   r2   r   r	   	_factory3  s    z?VerifyingBaseFallbackTests.test_adapter_hook.<locals>._factory3c                    s
     dS ra   r   ru   
_factoriesr   r	   r     s    z=VerifyingBaseFallbackTests.test_adapter_hook.<locals>._lookupr   r   r   r:   )r*   r   r3   r   r4   r   r<   r   Z_cr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   test_adapter_hook  s     

z,VerifyingBaseFallbackTests.test_adapter_hookc                    s   t  t  t  g\}fdd}fdd}fdd}|||g  fdd}t  t  t    }}}d	}	j|	|d
}
|
||d|}|k |
||d|}|k |	jd  jd7  _|
||d|}|k d S )Nc                    s    S r   r   r   r   r   r	   r     s    z?VerifyingBaseFallbackTests.test_queryAdapter.<locals>._factory1c                    s    S r   r   r   r   r   r	   r     s    z?VerifyingBaseFallbackTests.test_queryAdapter.<locals>._factory2c                    s     d d S r   ro   r   r2   r   r	   r     s    z?VerifyingBaseFallbackTests.test_queryAdapter.<locals>._factory3c                    s
     dS ra   r   ru   r   r   r	   r     s    z=VerifyingBaseFallbackTests.test_queryAdapter.<locals>._lookupr   r   r   r:   )r*   r   r3   r   r4   r   r<   r   r   r   r   r	   r     s     

z,VerifyingBaseFallbackTests.test_queryAdapterc                    s   t  t  t  g}t  t  t  g}||g  fdd}| d}| j||d}|dd}| |t| |dd}| |t| |jd  jd7  _|dd}| |t| d S )Nc                    s   t  dS ra   r'   r   rz   r   r   r	   r     s    z=VerifyingBaseFallbackTests.test_lookupAll.<locals>._lookupAllr   r   r   r   r:   )r*   r   r3   r   r;   r'   r   r<   )r   
_results_1
_results_2r   r   r   r   r   r  r	   test_lookupAll  s    
z)VerifyingBaseFallbackTests.test_lookupAllc                    s   t  t  t  g}t  t  t  g}||g  fdd}| d}| j||d}|dd}| |t| |dd}| |t| |jd  jd7  _|dd}| |t| d S )Nc                    s   t  dS ra   r  rz   r  r   r	   r     s    zEVerifyingBaseFallbackTests.test_subscriptions.<locals>._subscriptionsr   r   r   r   r:   )r*   r   r3   r   r;   r'   r   r<   )r   r  r  r   r   r   r   r   r  r	   test_subscriptions  s    
z-VerifyingBaseFallbackTests.test_subscriptions)NNN)r   r   r   r0   r3   r   r   r   r   r   r  r  r   r   r   r	   r   B  s     
r   c                   @   s   e Zd Zdd Zdd ZdS )VerifyingBaseTestsc                 C   s   ddl m} |S )Nr   )VerifyingBase)r,   r  )r   r  r   r   r	   r0     s    z"VerifyingBaseTests._getTargetClassc                 C   sR   ddl m} zdd l}W n$ tk
r<   | |  | Y nX | |  | d S r   )r,   r   r   r   r   r0   r   )r   r   r   r   r   r	   r     s    z%VerifyingBaseTests.test_optimizationsNr   r   r   r   r	   r    s   r  c                   @   s$  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d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGS )HAdapterLookupBaseTestsc                 C   s   ddl m} |S )Nr   )AdapterLookupBase)r,   r
  )r   r
  r   r   r	   r0     s    z&AdapterLookupBaseTests._getTargetClassc                 C   s   |   |S r   r1   r=   r   r   r	   r3     s    zAdapterLookupBaseTests._makeOnec                 G   s   G dd d}| S )Nc                   @   s   e Zd Zdd ZdS )z<AdapterLookupBaseTests._makeSubregistry.<locals>.Subregistryc                 S   s   g | _ g | _d S r   )rJ   rd   r2   r   r   r	   r     s    zEAdapterLookupBaseTests._makeSubregistry.<locals>.Subregistry.__init__Nr   r   r   r   r	   Subregistry  s   r  r   )r   r!   r  r   r   r	   _makeSubregistry  s    z'AdapterLookupBaseTests._makeSubregistryc                 G   s   G dd d}||S )Nc                   @   s   e Zd Zdd ZdS )z6AdapterLookupBaseTests._makeRegistry.<locals>.Registryc                 S   s   || _ g | _d S r   )	_providedr   r    r   r   r	   r     s    z?AdapterLookupBaseTests._makeRegistry.<locals>.Registry.__init__Nr   r   r   r   r	   r     s   r   r   )r   r!   r   r   r   r	   r     s    z$AdapterLookupBaseTests._makeRegistryc                 C   s$   |   }| |}| |ji  d S r   )r   r3   r;   r   )r   r7   albr   r   r	   test_ctor_empty_registry  s    
z/AdapterLookupBaseTests.test_ctor_empty_registryc                 C   s   ddl m} ddlm} |d}|d|}| ||}| |}| t|j	 t|||g | |j| |g | |j| |g | t|j| t||g d S Nr   r   InterfaceClassIFooIBar)
r   r   zope.interface.interfacer  r   r3   r;   sortedr   keysr   r   r  r  r  r7   r  r   r   r	   test_ctor_w_registry_provided	  s    


z4AdapterLookupBaseTests.test_ctor_w_registry_providedc                 C   sD   G dd dt }G dd d|  |}|  }||}|| d S )Nc                   @   s   e Zd Zdd ZdS )zAAdapterLookupBaseTests.test_changed_empty_required.<locals>.Mixinc                 W   s   d S r   r   r   otherr   r   r	   r     s    zIAdapterLookupBaseTests.test_changed_empty_required.<locals>.Mixin.changedNr   r   r   r   r   r   r   r	   Mixin  s   r  c                   @   s   e Zd ZdS )zCAdapterLookupBaseTests.test_changed_empty_required.<locals>.DerivedNr   r   r   r   r	   r     s   r   )r*   r0   r   r   )r   r  r   r7   r  r   r   r	   test_changed_empty_required  s
    z2AdapterLookupBaseTests.test_changed_empty_requiredc                 C   s   G dd dt }G dd d|  |}G dd dt }|d}|d}|  }||}d	|j|< d	|j|< || | t|jd
 | |jd  | |j| d S )Nc                   @   s   e Zd Zdd ZdS )z=AdapterLookupBaseTests.test_changed_w_required.<locals>.Mixinc                 W   s   d S r   r   r  r   r   r	   r   %  s    zEAdapterLookupBaseTests.test_changed_w_required.<locals>.Mixin.changedNr  r   r   r   r	   r  $  s   r  c                   @   s   e Zd ZdS )z?AdapterLookupBaseTests.test_changed_w_required.<locals>.DerivedNr   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S )zCAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakrefNc                 S   s
   || _ d S r   Z_here)r   herer   r   r	   r   +  s    zLAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.__init__c                 S   s   | j r
| S d S r   r  r2   r   r   r	   __call__-  s    zLAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.__call__c                 S   s
   || _ d S r   )_unsub)r   targetr   r   r	   r_   0  s    zOAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.unsubscribe)r   r   r   r"  r   r!  r_   r   r   r   r	   FauxWeakref)  s   r$  FTr:   r   )r*   r0   r   	_requiredr   r;   rI   r"  )r   r  r   r$  Zgoner   r7   r  r   r   r	   test_changed_w_required"  s    	


z.AdapterLookupBaseTests.test_changed_w_requiredc                 C   s   ddl m} ddlm} |d}|d|}|  }| |}||g|_|  | t	|j
 t	|||g | |j
| |g | |j
| |g | t	|j
| t	||g d S r  )r   r   r  r  r   r3   r  Zinit_extendorsr;   r  r   r  r  r   r   r	   )test_init_extendors_after_registry_update=  s     



z@AdapterLookupBaseTests.test_init_extendors_after_registry_updatec                 C   s   ddl m} ddlm} |d}|d|}|  }| |}|| || | t|j	
 t|||g | |j	| |g | |j	| |g | t|j	| t||g d S r  )r   r   r  r  r   r3   r"   r;   r  r   r  r  r   r   r	   test_add_extendorM  s     




z(AdapterLookupBaseTests.test_add_extendorc                 C   s   ddl m} ddlm} |d}|d|}| ||}| |}|| | t|j	
 t|||g | |j	| g  | |j	| |g | t|j	| t|g d S r  )r   r   r  r  r   r3   r(   r;   r  r   r  r  r   r   r	   test_remove_extendor]  s    


z+AdapterLookupBaseTests.test_remove_extendorc                 C   st   ddl m} |d}|d|}|  }| |}||f|}| |d  | t|jd | |	 |jk d S Nr   r  r  r  r:   )
r  r  r   r3   r}   r;   rI   r%  r4   weakrefr   r  r  r  r7   r  resultr   r   r	   test__uncached_lookup_empty_ron  s    

z5AdapterLookupBaseTests.test__uncached_lookup_empty_roc                 C   sf   ddl m} |d}|d|}| ||}|  }|j| | |}||f|}| |d  d S Nr   r  r  r  )	r  r  r   r  r   r   r3   r}   r;   r   r  r  r  r7   subrr  r-  r   r   r	    test__uncached_lookup_order_missy  s    

z7AdapterLookupBaseTests.test__uncached_lookup_order_missc                 C   sr   ddl m} |d}|d|}|  }|  }i i g|_|j| | |}||_|	|f|}| 
|d  d S r/  )r  r  r   r  rJ   r   r   r3   r6   r}   r;   r0  r   r   r	   $test__uncached_lookup_extendors_miss  s    


z;AdapterLookupBaseTests.test__uncached_lookup_extendors_missc           
      C   s   ddl m} |d}|d|}|d}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}	| |	d  d S Nr   r  r  r  IQuxrE   r  r  r   r  r*   rJ   r   r   r3   r6   r}   r;   
r   r  r  r  r5  r7   r1  
irrelevantr  r-  r   r   r	   1test__uncached_lookup_components_miss_wrong_iface  s    

zHAdapterLookupBaseTests.test__uncached_lookup_components_miss_wrong_ifacec           
      C   s   ddl m} |d}|d|}| ||}|  }t }t }i ||d|iiig|_|j| | |}||_	|
|f|}	| |	d  d S Nr   r  r  r  	wrongnamer6  )
r   r  r  r  r7   r1  r8  r;  r  r-  r   r   r	   0test__uncached_lookup_components_miss_wrong_name  s    

zGAdapterLookupBaseTests.test__uncached_lookup_components_miss_wrong_namec           	      C   s   ddl m} |d}|d|}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}| ||k d S Nr   r  r  r  rE   r  r  r   r  r*   rJ   r   r   r3   r6   r}   r4   )	r   r  r  r  r7   r1  	_expectedr  r-  r   r   r	    test__uncached_lookup_simple_hit  s    

z7AdapterLookupBaseTests.test__uncached_lookup_simple_hitc           
      C   s   ddl m} |d}|d|}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}|
|f|}	| ||k | |	|k d S r=  r>  )
r   r  r  r  r7   r1  r?  r  r-  Zresult2r   r   r	   "test__uncached_lookup_repeated_hit  s     

z9AdapterLookupBaseTests.test__uncached_lookup_repeated_hitc                 C   s   ddl m} ddlm} |d}|d|}||G dd dt}| }|  }|  }i i g|_|j	| | 
|}	|	j|	_|	|_t }
|	j|f||
d}| ||
k d S )	Nr   implementerr  r  r  c                   @   s   e Zd ZdS )zFAdapterLookupBaseTests.test_queryMultiAdaptor_lookup_miss.<locals>.FooNr   r   r   r   r	   Foo  s   rD  default)zope.interface.declarationsrC  r  r  r*   r   r  rJ   r   r   r3   r}   r   r6   queryMultiAdapterr4   )r   rC  r  r  r  rD  foor7   r1  r  r   r-  r   r   r	   "test_queryMultiAdaptor_lookup_miss  s&    

z9AdapterLookupBaseTests.test_queryMultiAdaptor_lookup_missc                    s   ddl m} ddlm} |d}|d|}||G dd dt}| }| ||}|  }t }	g   fdd	}
i ||d
|
iiig|_|j	| | 
|}|j|_||_t }|j|f||d}| ||k |  |g d S )Nr   rB  r  r  r  c                   @   s   e Zd ZdS )zGAdapterLookupBaseTests.test_queryMultiAdaptor_factory_miss.<locals>.FooNr   r   r   r   r	   rD    s   rD  c                    s     |  d S r   r   r   r   r   r	   r     s    
zLAdapterLookupBaseTests.test_queryMultiAdaptor_factory_miss.<locals>._factoryrE   rE  rG  rC  r  r  r*   r   r  rJ   r   r   r3   r}   r   r6   rH  r4   r;   )r   rC  r  r  r  rD  rI  r7   r1  r?  r   r  r   r-  r   r   r	   #test_queryMultiAdaptor_factory_miss  s.    

z:AdapterLookupBaseTests.test_queryMultiAdaptor_factory_missc                    s   ddl m} ddlm} |d}|d|}||G dd dt}| }| ||}|  }t g   fdd	}	i ||d
|	iiig|_|j	| | 
|}
|
j|
_|
|_t }|
j|f||d}| |k |  |g d S )Nr   rB  r  r  r  c                   @   s   e Zd ZdS )zFAdapterLookupBaseTests.test_queryMultiAdaptor_factory_hit.<locals>.FooNr   r   r   r   r	   rD    s   rD  c                    s     |  S r   r   r   r   r?  r   r	   r     s    
zKAdapterLookupBaseTests.test_queryMultiAdaptor_factory_hit.<locals>._factoryrE   rE  rK  )r   rC  r  r  r  rD  rI  r7   r1  r   r  r   r-  r   rM  r	   "test_queryMultiAdaptor_factory_hit  s.    

z9AdapterLookupBaseTests.test_queryMultiAdaptor_factory_hitc                 C   st   ddl m} |d}|d|}|  }| |}||f|}| |d | t|jd | |	 |jk d S )Nr   r  r  r  r   r:   )
r  r  r   r3   r~   r;   rI   r%  r4   r+  r,  r   r   r	   !test__uncached_lookupAll_empty_ro,  s    

z8AdapterLookupBaseTests.test__uncached_lookupAll_empty_roc                 C   sl   ddl m} |d}|d|}| ||}|  }|j| | |}||_||f|}| 	|d d S Nr   r  r  r  r   )
r  r  r   r  r   r   r3   r6   r~   r;   r0  r   r   r	   #test__uncached_lookupAll_order_miss7  s    

z:AdapterLookupBaseTests.test__uncached_lookupAll_order_missc                 C   sr   ddl m} |d}|d|}|  }|  }i i g|_|j| | |}||_|	|f|}| 
|d d S rP  )r  r  r   r  rJ   r   r   r3   r6   r~   r;   r0  r   r   r	   'test__uncached_lookupAll_extendors_missC  s    


z>AdapterLookupBaseTests.test__uncached_lookupAll_extendors_missc           
      C   s   ddl m} |d}|d|}|d}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}	| |	d d S )Nr   r  r  r  r5  rE   r   )r  r  r   r  r*   rJ   r   r   r3   r6   r~   r;   r7  r   r   r	   (test__uncached_lookupAll_components_missP  s    

z?AdapterLookupBaseTests.test__uncached_lookupAll_components_missc           
      C   s   ddl m} |d}|d|}| ||}|  }t }t }i ||||diig|_|j| | |}||_	|
|f|}	| t|	d|fd|fg d S Nr   r  r  r  )rE   namedrE   rU  )r  r  r   r  r*   rJ   r   r   r3   r6   r~   r;   r  
r   r  r  r  r7   r1  r?  Z_namedr  r-  r   r   r	   #test__uncached_lookupAll_simple_hitb  s    

z:AdapterLookupBaseTests.test__uncached_lookupAll_simple_hitc           
      C   s   ddl m} |d}|d|}| ||}|  }t }t }i ||||diig|_|j| | |}|j	|_
||_||f|}	| t|	ddg d S rT  )r  r  r   r  r*   rJ   r   r   r3   r~   r   r6   namesr;   r  rV  r   r   r	   
test_namest  s     

z!AdapterLookupBaseTests.test_namesc                 C   st   ddl m} |d}|d|}|  }| |}||f|}| |g  | t|jd | |	 |jk d S r*  )
r  r  r   r3   r   r;   rI   r%  r4   r+  r,  r   r   r	   %test__uncached_subscriptions_empty_ro  s    

z<AdapterLookupBaseTests.test__uncached_subscriptions_empty_roc                 C   sl   ddl m} |d}|d|}| ||}|  }|j| | |}||_||f|}| 	|g  d S r/  )
r  r  r   r  r   r   r3   r6   r   r;   r0  r   r   r	   'test__uncached_subscriptions_order_miss  s    

z>AdapterLookupBaseTests.test__uncached_subscriptions_order_missc                 C   sr   ddl m} |d}|d|}|  }|  }i i g|_|j| | |}||_|	|f|}| 
|g  d S r/  )r  r  r   r  rd   r   r   r3   r6   r   r;   r0  r   r   r	   +test__uncached_subscriptions_extendors_miss  s    


zBAdapterLookupBaseTests.test__uncached_subscriptions_extendors_missc           
      C   s   ddl m} |d}|d|}|d}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}	| |	g  d S r4  r  r  r   r  r*   rd   r   r   r3   r6   r   r;   r7  r   r   r	   8test__uncached_subscriptions_components_miss_wrong_iface  s    

zOAdapterLookupBaseTests.test__uncached_subscriptions_components_miss_wrong_ifacec           	      C   s   ddl m} |d}|d|}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}| |g  d S r:  r]  )	r   r  r  r  r7   r1  r;  r  r-  r   r   r	   7test__uncached_subscriptions_components_miss_wrong_name  s    

zNAdapterLookupBaseTests.test__uncached_subscriptions_components_miss_wrong_namec                 C   s   ddl m} |d}|d|}| ||}|  }G dd dt}| |  }}i ||d||fiiig|_|j| | |}	|	|_	|	
|f|}
| t|
t||g d S )Nr   r  r  r  c                   @   s   e Zd Zdd ZdS )zKAdapterLookupBaseTests.test__uncached_subscriptions_simple_hit.<locals>.Fooc                 S   s   dS )NTr   r  r   r   r	   __lt__  s    zRAdapterLookupBaseTests.test__uncached_subscriptions_simple_hit.<locals>.Foo.__lt__N)r   r   r   r`  r   r   r   r	   rD    s   rD  rE   )r  r  r   r  r*   rd   r   r   r3   r6   r   r;   r  )r   r  r  r  r7   r1  rD  _exp1_exp2r  r-  r   r   r	   'test__uncached_subscriptions_simple_hit  s    

z>AdapterLookupBaseTests.test__uncached_subscriptions_simple_hitc                    s   ddl m} ddlm} |d}|d|}||G dd dt}| }| ||}| ||}|  }i   fdd	}	 fd
d}
i |d d|	|
fiiig|_|j	| | 
|}|j|_||_||fd }| |d |  |g|gd d S )Nr   rB  r  r  r  c                   @   s   e Zd ZdS )z@AdapterLookupBaseTests.test_subscribers_wo_provided.<locals>.FooNr   r   r   r   r	   rD    s   rD  c                    s     dg |  d S Nr   
setdefaultr   r   _calledr   r	   r     s    zFAdapterLookupBaseTests.test_subscribers_wo_provided.<locals>._factory1c                    s     dg |  d S Nr   re  r   rg  r   r	   r     s    zFAdapterLookupBaseTests.test_subscribers_wo_provided.<locals>._factory2rE   r   )r   r   rG  rC  r  r  r*   r   r  rd   r   r   r3   r   r   r6   Zsubscribersr;   )r   rC  r  r  r  rD  rI  r7   r1  r   r   r  r-  r   rg  r	   test_subscribers_wo_provided  s.    

z3AdapterLookupBaseTests.test_subscribers_wo_providedc                    s  ddl m} ddlm} |d}|d|}||G dd dt}| }| ||}| ||}|  }i  t t   fdd	}	 fd
d}
 fdd}i ||d|	|
|fiiig|_|j	| | 
|}|j|_||_||f|}| |g |  |g|g|gd d S )Nr   rB  r  r  r  c                   @   s   e Zd ZdS )z?AdapterLookupBaseTests.test_subscribers_w_provided.<locals>.FooNr   r   r   r   r	   rD    s   rD  c                    s     dg |  S rd  re  r   )rh  ra  r   r	   r     s    zEAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._factory1c                    s     dg |  S ri  re  r   )rh  rb  r   r	   r     s    zEAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._factory2c                    s     dg |  d S )N_side_effect_onlyre  r   rg  r   r	   rl    s    zMAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._side_effect_onlyrE   )r   r   rl  rj  )r   rC  r  r  r  rD  rI  r7   r1  r   r   rl  r  r-  r   )rh  ra  rb  r	   test_subscribers_w_provided  s<    

z2AdapterLookupBaseTests.test_subscribers_w_providedN)&r   r   r   r0   r3   r  r   r  r  r  r&  r'  r(  r)  r.  r2  r3  r9  r<  r@  rA  rJ  rL  rN  rO  rQ  rR  rS  rW  rY  rZ  r[  r\  r^  r_  rc  rk  rm  r   r   r   r	   r	    sF   r	  c                   @   sL   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d Z
dS )AdapterRegistryTestsc                 C   s   ddl m} |S )Nr   )AdapterRegistry)r,   ro  )r   ro  r   r   r	   r0   )  s    z$AdapterRegistryTests._getTargetClassc                 O   s   |   ||S r   r1   )r   argskwr   r   r	   r3   -  s    zAdapterRegistryTests._makeOnec                 C   s   |   }| t|jd d S ra   )r3   r;   rI   _v_subregistries)r   Zarr   r   r	   test_ctor_no_bases0  s    z'AdapterRegistryTests.test_ctor_no_basesc                 C   sL   |   }|  |g}| t|jd | t|jd | ||jk d S Nr   r:   )r3   r;   rI   rr  r4   )r   basesubr   r   r	   test_ctor_w_bases4  s
    z&AdapterRegistryTests.test_ctor_w_basesc                 C   s\   |   }|   }|  |g}|g|_| t|jd | t|jd | ||jk d S rt  r3   rC   r;   rI   rr  r4   r   beforeafterrv  r   r   r	   ,test__setBases_removing_existing_subregistry=  s    zAAdapterRegistryTests.test__setBases_removing_existing_subregistryc                 C   st   |   }|   }|   }|  |g}|jd | |g|_| t|jd | t|jd | ||jk d S )NrC   r   r:   )r3   __dict__r   rC   r;   rI   rr  r4   )r   rz  Zstrayr{  rv  r   r   r	   test__setBases_wo_stray_entryF  s    z2AdapterRegistryTests.test__setBases_wo_stray_entryc                 C   sn   |   }|   }|  |g}||g|_| t|jd | t|jd | ||jk | ||jk d S r9   rx  ry  r   r   r	   *test__setBases_w_existing_entry_continuingQ  s    
z?AdapterRegistryTests.test__setBases_w_existing_entry_continuingc                 C   sn   |   }G dd dt}| |  }}|| || t }|| | |j|k | |j|k d S )Nc                   @   s   e Zd ZdZdd ZdS )zBAdapterRegistryTests.test_changed_w_subregistries.<locals>.DerivedNc                 S   s
   || _ d S r   r   )r   Zoriginally_changedr   r   r	   r   _  s    zJAdapterRegistryTests.test_changed_w_subregistries.<locals>.Derived.changed)r   r   r   r   r   r   r   r   r	   r   ]  s   r   )r3   r*   Z_addSubregistryr   r4   r   )r   ru  r   Zderived1Zderived2r   r   r   r	   test_changed_w_subregistries[  s    


z1AdapterRegistryTests.test_changed_w_subregistriesN)r   r   r   r0   r3   rs  rw  r|  r~  r  r  r   r   r   r	   rn  '  s   		
rn  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )
Test_utilsc                 C   s.   ddl m} ddlm} | |d |k d S )Nr   _convert_None_to_Interfacer   )r,   r  r  r   r4   )r   r  r   r   r   r	   &test__convert_None_to_Interface_w_Nonel  s    z1Test_utils.test__convert_None_to_Interface_w_Nonec                 C   s(   ddl m} t }| |||k d S )Nr   r  )r,   r  r*   r4   )r   r  r  r   r   r	   'test__convert_None_to_Interface_w_otherq  s    z2Test_utils.test__convert_None_to_Interface_w_otherc                 C   sV   dd l }ddlm} d}|jd dk r<| ||t| n| ||t|d d S )Nr   _normalize_names   strr   ascii)sysr,   r  version_infor;   Zunicodestr)r   r  r  ZSTRr   r   r	   test__normalize_name_strv  s    z#Test_utils.test__normalize_name_strc                 C   s$   ddl m} d}| ||| d S )Nr   r  Zustr)r,   r  r;   )r   r  ZUSTRr   r   r	   test__normalize_name_unicode  s    z'Test_utils.test__normalize_name_unicodec                 C   s6   ddl m} dddg i t fD ]}| t|| qd S )Nr   r  r:   g      ?r   )r,   r  r*   rM   	TypeError)r   r  r  r   r   r	   test__normalize_name_other  s    z%Test_utils.test__normalize_name_otherN)r   r   r   r  r  r  r  r  r   r   r   r	   r  j  s
   	r  )__doc__Zunittestr   ZTestCaser   rr   r   r   r  r	  rn  r  r   r   r   r	   <module>   s$    V  :     >C