a
    _                     @   s   d Z ddlZddlmZ dd ZG dd dejZG dd	 d	ejZG d
d deeZG dd dejZ	G dd de	e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dS )zAdapter registry tests
    N)OptimizationTestMixinc            
   	   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__9   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_extendor=   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>@   s   zfBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.remove_extendor.<locals>.<listcomp>)tupler    r!   r	   r&   r
   remove_extendor?   s    zRBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.remove_extendorN)	r   r   r   r   r    r   r   r#   r)   r	   r	   r	   r
   LookupClass7   s
   r*   N)r   r   r   objectr*   r	   r	   r	   r
   _CUT6   s   r,   )zope.interface.adapterr   
_delegatedsetattrr*   r+   )r   r   r,   namer	   r	   r
   _getTargetClass4   s
    
z(BaseAdapterRegistryTests._getTargetClassc                 C   s
   |    S r   r1   r   r	   r	   r
   _makeOneF   s    z!BaseAdapterRegistryTests._makeOnec                 C   s:   |   }| }|jD ] }| t||t|j|u  qd S r   )r1   r.   Z
assertTruegetattr	_v_lookup)r   ZCUTregistryr0   r	   r	   r
   test_lookup_delegationI   s    
z/BaseAdapterRegistryTests.test_lookup_delegationc                 C   s   |   }| |jd d S N   )r4   assertEqual_generationr   r7   r	   r	   r
   "test__generation_on_first_creationP   s    z;BaseAdapterRegistryTests.test__generation_on_first_creationc                 C   s>   |   }t }|| | |jd | |jj||f d S N   )r4   r+   r   r;   r<   r6   r   )r   r7   r   r	   r	   r
   &test__generation_after_calling_changedU   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
   _Base^   s   rB   r@   )r+   r4   	__bases__r;   r<   )r   rB   r7   r	   r	   r
   )test__generation_after_changing___bases__]   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   r4   registerr;   
registeredlen	_adaptersr<   r   r   r   r   r   r   r   r   r   r   r7   r	   r	   r
   test_registerd   s    z&BaseAdapterRegistryTests.test_registerc              	   C   sb   t  \	}}}}}}}}}	|  }
| t$ |
|g|t d W d    n1 sT0    Y  d S )NrF   )r   r4   assertRaises
ValueErrorrG   r+   rK   r	   r	   r
   test_register_with_invalid_namel   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   r4   rG   r;   rI   rJ   rK   r	   r	   r
   )test_register_with_value_None_unregistersr   s
    zBBaseAdapterRegistryTests.test_register_with_value_None_unregistersc              	   C   sb   t  \	}}}}}}}}}	|  }
t }|
d g|d| |
j}|
d g|d| | |
j| d S NrE   )r   r4   r+   rG   r<   r;   )r   r   r   r   r   r   r   r   r   r   r7   Z_valueZ_beforer	   r	   r
   test_register_with_same_valuey   s    z6BaseAdapterRegistryTests.test_register_with_same_valuec                 C   s$   |   }| |d gd dd  d S rQ   )r4   r;   rH   r=   r	   r	   r
   test_registered_empty   s    z.BaseAdapterRegistryTests.test_registered_emptyc              	   C   sN   t  \	}}}}}}}}}	|  }
|
|gd dd | |
|gd dd  d S NrE   rF   )r   r4   rG   r;   rH   rK   r	   r	   r
   test_registered_non_empty_miss   s    z7BaseAdapterRegistryTests.test_registered_non_empty_missc                 C   s6   |   }|d gd dd | |d gd dd d S rT   )r4   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   )r4   
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   r4   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   sl   t  \	}}}}}}}}}	|  }
t }t }|
|gd d| |
|gd d| | |
|gd d| d S rQ   )r   r4   r+   rG   rW   assertIsrH   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 |  | ||
jd |  |
||gd d| | ||
jd |  | ||
jd |  d S )NrE   r@   )r   r4   r+   rG   assertInrJ   rW   ZassertNotIn)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   )r4   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   r4   r+   	subscribera   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 rc   rd   )r   r   r   r   r   r   r   r   r   r   r7   firstsecondZthirdZfourthr	   r	   r
   test_unsubscribe_after_multiple   s    z8BaseAdapterRegistryTests.test_unsubscribe_after_multiplec              	   C   sp   t  \	}}}}}}}}}	|  }
t }t }|
|gd | |
|gd | |
|gd  | t|
jd d S rc   rd   )r   r   r   r   r   r   r   r   r   r   r7   rh   ri   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   r4   re   r;   rI   rf   ra   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A2rl   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?   rd   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failr3   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 rc   )r   r4   r;   rI   rf   re   rq   ra   rK   r	   r	   r
    test_unsubscribe_instance_method   s    z9BaseAdapterRegistryTests.test_unsubscribe_instance_methodN)r   r   r   r1   r4   r8   r>   rA   rD   rL   rO   rP   rR   rS   rU   rV   rX   rZ   r[   r^   r`   rb   rg   rj   rk   rm   rn   ro   rq   rr   r	   r	   r	   r
   r   2   s6   			r   c                       s   e Zd Zdd Ze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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 fd.d/Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Z  Z S );LookupBaseFallbackTestsc                 C   s   ddl m} |S )Nr   )LookupBaseFallback)r-   rt   )r   rt   r	   r	   r
   _getFallbackClass
  s    z)LookupBaseFallbackTests._getFallbackClassNc                    sR    d u rdd  d u r dd d u r0dd G  fddd|   }| S )	Nc                 S   s   d S r   r	   r   requiredr"   r0   r	   r	   r
   	uc_lookup  s    z3LookupBaseFallbackTests._makeOne.<locals>.uc_lookupc                 S   s
   t  d S r   NotImplementedErrorr   rw   r"   r	   r	   r
   uc_lookupAll  s    z6LookupBaseFallbackTests._makeOne.<locals>.uc_lookupAllc                 S   s
   t  d S r   ry   r{   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	   rx   r|   r}   r	   r
   Derived  s   r   r2   )r   rx   r|   r}   r   r	   r   r
   r4     s    z LookupBaseFallbackTests._makeOnec                 C   sR   dd }| j |d}| t  |ddt  W d    n1 sD0    Y  d S )Nc                 S   s   |  d d S NzThis should never be calledrp   rv   r	   r	   r
   _lookup#  s    zCLookupBaseFallbackTests.test_lookup_w_invalid_name.<locals>._lookuprx   AB)r4   rM   rN   lookupr+   r   r   lbr	   r	   r
   test_lookup_w_invalid_name"  s    z2LookupBaseFallbackTests.test_lookup_w_invalid_namec                    sF   g   fdd}| j |d}|ddd}| | |  dg d S )Nc                    s     |||f d S r   appendrv   _called_withr	   r
   r   +  s    zDLookupBaseFallbackTests.test_lookup_miss_no_default.<locals>._lookupr   r   r   Cr   r   r   )r4   r   assertIsNoner;   r   r   r   foundr	   r   r
   test_lookup_miss_no_default)  s    
z3LookupBaseFallbackTests.test_lookup_miss_no_defaultc                    sP   g  t  } fdd}| j|d}|ddd|}| || |  dg d S )Nc                    s     |||f d S r   r   rv   r   r	   r
   r   6  s    zCLookupBaseFallbackTests.test_lookup_miss_w_default.<locals>._lookupr   r   r   r   r   r+   r4   r   r\   r;   r   _defaultr   r   r   r	   r   r
   test_lookup_miss_w_default3  s    z2LookupBaseFallbackTests.test_lookup_miss_w_defaultc                    sz   g  t  t  t    }}}|||g fdd}| j|d}|ddd}| || |  dg | ||g d S )Nc                    s     |||f dS rc   r   poprv   r   _resultsr	   r
   r   B  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}| || |  dg | ||g d S )Nc                    s     |||f dS rc   r   rv   r   r	   r
   r   O  s    z;LookupBaseFallbackTests.test_lookup_cached.<locals>._lookupr   r   r   r   r   r   r   r	   r   r
   test_lookup_cachedK  s    
z*LookupBaseFallbackTests.test_lookup_cachedc                    sz   g  t  t  t    }}}|||g fdd}| j|d}|ddd}| || |  dg | ||g d S )Nc                    s     |||f dS rc   r   rv   r   r	   r
   r   ]  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_requiredY  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}| || |  dg | ||g d S )Nc                    s     |||f dS rc   r   rv   r   r	   r
   r   j  s    zJLookupBaseFallbackTests.test_lookup_cached_multi_required.<locals>._lookupr   r   r   r   r   r   r   r	   r   r
   !test_lookup_cached_multi_requiredf  s    
z9LookupBaseFallbackTests.test_lookup_cached_multi_requiredc                    s   g  t  t  t    }}}|||g fdd}| j|d}|ddd}|| |ddd}| || |  ddg | |g d S )Nc                    s     |||f dS rc   r   rv   r   r	   r
   r   x  s    zMLookupBaseFallbackTests.test_lookup_not_cached_after_changed.<locals>._lookupr   r   r   r   r   )r+   r4   r   r   r\   r;   r   r	   r   r
   $test_lookup_not_cached_after_changedt  s    

z<LookupBaseFallbackTests.test_lookup_not_cached_after_changedc                 C   sR   dd }| j |d}| t  |ddt  W d    n1 sD0    Y  d S )Nc                 S   s   |  d d S r   rp   rv   r	   r	   r
   r     s    zDLookupBaseFallbackTests.test_lookup1_w_invalid_name.<locals>._lookupr   r   r   )r4   rM   rN   lookup1r+   r   r	   r	   r
   test_lookup1_w_invalid_name  s    z3LookupBaseFallbackTests.test_lookup1_w_invalid_namec                    sF   g   fdd}| j |d}|ddd}| | |  dg d S )Nc                    s     |||f d S r   r   rv   r   r	   r
   r     s    zELookupBaseFallbackTests.test_lookup1_miss_no_default.<locals>._lookupr   r   r   r   r   )r4   r   r   r;   r   r	   r   r
   test_lookup1_miss_no_default  s    
z4LookupBaseFallbackTests.test_lookup1_miss_no_defaultc                    sP   g  t  } fdd}| j|d}|ddd|}| || |  dg d S )Nc                    s     |||f d S r   r   rv   r   r	   r
   r     s    zDLookupBaseFallbackTests.test_lookup1_miss_w_default.<locals>._lookupr   r   r   r   r   r+   r4   r   r\   r;   r   r	   r   r
   test_lookup1_miss_w_default  s    z3LookupBaseFallbackTests.test_lookup1_miss_w_defaultc                    sl   g  t  } fdd}| j|d}|ddd|}| || |ddd|}| || |  dg d S )Nc                    s     |||f d S r   r   rv   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                    sz   g  t  t  t    }}}|||g fdd}| j|d}|ddd}| || |  dg | ||g d S )Nc                    s     |||f dS rc   r   rv   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}| || |  dg | ||g d S )Nc                    s     |||f dS rc   r   rv   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}| || |  ddg | |g d S )Nc                    s     |||f dS rc   r   rv   r   r	   r
   r     s    zNLookupBaseFallbackTests.test_lookup1_not_cached_after_changed.<locals>._lookupr   r   r   r   r   )r+   r4   r   r   r\   r;   r   r	   r   r
   %test_lookup1_not_cached_after_changed  s    

z=LookupBaseFallbackTests.test_lookup1_not_cached_after_changedc                 C   sT   t  t   }}|  }| t  |||t   W d    n1 sF0    Y  d S r   )r+   r4   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   s2   t  t   }}|  }|||d}| | d S rQ   )r+   r4   r   r   )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|}| || d S rQ   )r+   r4   r   r\   )r   r   r   r   r   r   r	   r	   r
    test_adapter_hook_miss_w_default  s    z8LookupBaseFallbackTests.test_adapter_hook_miss_w_defaultc                    sl   g   fddfdd}t  t  t    }}}| j|d}|||d|}| || |  |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	   rv   r   r	   r
   r     s    zSLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_None.<locals>._lookupr   r   r+   r4   r   r\   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                    st   g t    fddfdd}t  t  t    }}}| j|d}|||d|}| |  | |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	   rv   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                    sd   g   fdddfdd	}t t| }t }| j|d}|||}| ||  |  | g d S )Nc                    s     |  | S r   r   r   r   r	   r
   r     s    
zILookupBaseFallbackTests.test_adapter_hook_super_unwraps.<locals>._factoryrE   c                    s    S r   r	   rv   r   r	   r
   r     s    zHLookupBaseFallbackTests.test_adapter_hook_super_unwraps.<locals>._lookupr   )rE   )superrs   r+   r4   r   r\   r;   )r   r   rw   r"   r   r   	__class__r   r
   test_adapter_hook_super_unwraps  s    
z7LookupBaseFallbackTests.test_adapter_hook_super_unwrapsc                    st   g t    fddfdd}t  t  t    }}}| j|d}|||d|}| |  | |g d S )Nc                    s    |   S r   r   r   r   r	   r
   r     s    
z;LookupBaseFallbackTests.test_queryAdapter.<locals>._factoryc                    s    S r   r	   rv   r   r	   r
   r     s    z:LookupBaseFallbackTests.test_queryAdapter.<locals>._lookupr   r   )r+   r4   queryAdapterr\   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(   r{   r   r	   r
   
_lookupAll%  s    zCLookupBaseFallbackTests.test_lookupAll_uncached.<locals>._lookupAllr|   r   r   r   r   r+   r4   	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   r{   r   r	   r
   r   0  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   r{   r   r	   r
   _subscriptions<  s    zKLookupBaseFallbackTests.test_subscriptions_uncached.<locals>._subscriptionsr}   r   r   r   r+   r4   subscriptionsr;   r(   r   r   r   r   r	   r   r
   test_subscriptions_uncached9  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   r{   r   r	   r
   r   G  s    zILookupBaseFallbackTests.test_subscriptions_cached.<locals>._subscriptionsr   r   r   r   r   r   r	   r   r
   test_subscriptions_cachedD  s    z1LookupBaseFallbackTests.test_subscriptions_cached)NNN)!r   r   r   ru   r1   r4   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   __classcell__r	   r	   r   r
   rs     s>     


rs   c                   @   s   e Zd Zdd ZdS )LookupBaseTestsc                 C   s   ddl m} |S )Nr   )
LookupBase)r-   r   )r   r   r	   r	   r
   r1   T  s    zLookupBaseTests._getTargetClassNr   r   r   r1   r	   r	   r	   r
   r   Q  s   r   c                   @   sZ   e Zd Zdd Ze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
   ru   [  s    z,VerifyingBaseFallbackTests._getFallbackClassNc                    sd   d u rdd d u r dd d u r0dd G  fddd|     |}|| |S )	Nc                 S   s
   t  d S r   ry   rv   r	   r	   r
   rx   e  s    z6VerifyingBaseFallbackTests._makeOne.<locals>.uc_lookupc                 S   s
   t  d S r   ry   r{   r	   r	   r
   r|   h  s    z9VerifyingBaseFallbackTests._makeOne.<locals>.uc_lookupAllc                 S   s
   t  d S r   ry   r{   r	   r	   r
   r}   k  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   )r   r   	_registryr=   )r   r   r	   r
   r   q  s    z=VerifyingBaseFallbackTests._makeOne.<locals>.Derived.__init__)r   r   r   r~   r   r   r   r   r	   r   rx   r|   r}   r   r
   r   m  s   r   )r1   r   )r   r7   rx   r|   r}   Zderivedr	   r   r
   r4   a  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
   WithGenerationy  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'   }      zWVerifyingBaseFallbackTests._makeRegistry.<locals>.Registry.__init__.<locals>.<listcomp>)rangero)r   depthr   r	   r
   r   |  s    zCVerifyingBaseFallbackTests._makeRegistry.<locals>.Registry.__init__Nr   r   r   r   r	   r   r	   r
   Registry{  s   r   )r+   )r   r   r   r	   r   r
   _makeRegistryx  s    z(VerifyingBaseFallbackTests._makeRegistryc                    s   g  t  t  t    }}}|||g fdd}| d}| j||d}|ddd}|ddd}| || |  dg | ||g |jd	  jd	7  _|ddd}| || |  ddg | |g d S )
Nc                    s     |||f dS rc   r   rv   r   r	   r
   r     s    z7VerifyingBaseFallbackTests.test_lookup.<locals>._lookup   r   r   r   r   r   r:   )r+   r   r4   r   r\   r;   r   r<   r   r   r   r   r   r   r   r   r	   r   r
   test_lookup  s$    

z&VerifyingBaseFallbackTests.test_lookupc                    s   g  t  t  t    }}}|||g fdd}| d}| j||d}|ddd}|ddd}| || |  dg | ||g |jd	  jd	7  _|ddd}| || |  ddg | |g d S )
Nc                    s     |||f dS rc   r   rv   r   r	   r
   r     s    z8VerifyingBaseFallbackTests.test_lookup1.<locals>._lookupr   r   r   r   r   r   r:   )r+   r   r4   r   r\   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|}| |
||d|}| |	jd  jd7  _|
||d|}| 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   rp   r   r3   r	   r
   	_factory3  s    z?VerifyingBaseFallbackTests.test_adapter_hook.<locals>._factory3c                    s
     dS rc   r   rv   
_factoriesr	   r
   r     s    z=VerifyingBaseFallbackTests.test_adapter_hook.<locals>._lookupr   r   r   r:   )r+   r   r4   r   r\   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|}| |
||d|}| |	jd  jd7  _|
||d|}| 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   rp   r   r3   r	   r
   r     s    z?VerifyingBaseFallbackTests.test_queryAdapter.<locals>._factory3c                    s
     dS rc   r   rv   r   r	   r
   r     s    z=VerifyingBaseFallbackTests.test_queryAdapter.<locals>._lookupr   r   r   r:   )r+   r   r4   r   r\   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 rc   r(   r   r{   r   r	   r
   r     s    z=VerifyingBaseFallbackTests.test_lookupAll.<locals>._lookupAllr   r   r   r   r:   )r+   r   r4   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 rc   r   r{   r  r	   r
   r     s    zEVerifyingBaseFallbackTests.test_subscriptions.<locals>._subscriptionsr   r   r   r   r:   )r+   r   r4   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   ru   r1   r4   r   r   r   r   r   r  r  r	   r	   r	   r
   r   Y  s     
r   c                   @   s   e Zd Zdd ZdS )VerifyingBaseTestsc                 C   s   ddl m} |S )Nr   )VerifyingBase)r-   r  )r   r  r	   r	   r
   r1     s    z"VerifyingBaseTests._getTargetClassNr   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 f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%dGdH Z&dIdJ Z'  Z(S )KAdapterLookupBaseTestsc                 C   s   ddl m} |S )Nr   )AdapterLookupBase)r-   r	  )r   r	  r	   r	   r
   r1     s    z&AdapterLookupBaseTests._getTargetClassc                 C   s   |   |S r   r2   r=   r	   r	   r
   r4     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   rf   r3   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   r4   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|f}| ||}| |}| 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   r4   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+   r1   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   7  s    zEAdapterLookupBaseTests.test_changed_w_required.<locals>.Mixin.changedNr  r	   r	   r	   r
   r  6  s   r  c                   @   s   e Zd ZdS )z?AdapterLookupBaseTests.test_changed_w_required.<locals>.DerivedNr   r	   r	   r	   r
   r   9  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  r3   r	   r	   r
   __call__?  s    zLAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.__call__c                 S   s
   || _ d S r   )_unsub)r   targetr	   r	   r
   ra   A  s    zOAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.unsubscribe)r   r   r   r!  r   r   ra   r	   r	   r	   r
   FauxWeakref;  s   r#  FTr:   r   )r+   r1   r   	_requiredr   r;   rI   r!  )r   r  r   r#  Zgoner  r7   r  r	   r	   r
   test_changed_w_required4  s    


z.AdapterLookupBaseTests.test_changed_w_requiredc                 C   s   ddl m} ddlm} |d}|d|f}|  }| |}||g|_|  | t	|j
 t	|||g | |j
| ||g | |j
| |g | t	|j
| t	||g d S r  )r   r   r  r  r   r4   r  Zinit_extendorsr;   r  r    r  r  r	   r	   r
   )test_init_extendors_after_registry_updateN  s     


z@AdapterLookupBaseTests.test_init_extendors_after_registry_updatec                 C   s   ddl m} ddlm} |d}|d|f}|  }| |}|| || | t|j	
 t|||g | |j	| ||g | |j	| |g | t|j	| t||g d S r  )r   r   r  r  r   r4   r#   r;   r  r    r  r  r	   r	   r
   test_add_extendor^  s     



z(AdapterLookupBaseTests.test_add_extendorc                 C   s   ddl m} ddlm} |d}|d|f}| ||}| |}|| | t|j	
 t|||g | |j	| |g | |j	| |g | t|j	| t|g d S r  )r   r   r  r  r   r4   r)   r;   r  r    r  r  r	   r	   r
   test_remove_extendorn  s    

z+AdapterLookupBaseTests.test_remove_extendorc                 C   st   ddl m} |d}|d|f}|  }| |}||f|}| |d  | t|jd | |	 |j d S Nr   r  r  r  r:   )
r  r  r   r4   r~   r;   rI   r$  r_   weakrefr   r  r  r  r7   r  resultr	   r	   r
   test__uncached_lookup_empty_ro  s    
z5AdapterLookupBaseTests.test__uncached_lookup_empty_roc                 C   sh   ddl m} |d}|d|f}| ||}|  }|j| | |}||f|}| |d  d S Nr   r  r  r  )	r  r  r   r  r   r   r4   r~   r;   r   r  r  r  r7   subrr  r,  r	   r	   r
    test__uncached_lookup_order_miss  s    
z7AdapterLookupBaseTests.test__uncached_lookup_order_missc                 C   st   ddl m} |d}|d|f}|  }|  }i i g|_|j| | |}||_|	|f|}| 
|d  d S r.  )r  r  r   r  rJ   r   r   r4   r6   r~   r;   r/  r	   r	   r
   $test__uncached_lookup_extendors_miss  s    

z;AdapterLookupBaseTests.test__uncached_lookup_extendors_missc           
      C   s   ddl m} |d}|d|f}|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   r4   r6   r~   r;   
r   r  r  r  r4  r7   r0  Z
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|f}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}| |d  d S Nr   r  r  r  	wrongnamer5  	r   r  r  r  r7   r0  r9  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|f}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}| || d S Nr   r  r  r  rE   r  r  r   r  r+   rJ   r   r   r4   r6   r~   r\   )	r   r  r  r  r7   r0  	_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|f}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}|
|f|}	| || | |	| d S r<  r=  )
r   r  r  r  r7   r0  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|f}||G dd dt}| }|  }|  }i i g|_|j	| | 
|}	|	j|	_|	|_t }
|	j|f||
d}| ||
 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   rC  default)zope.interface.declarationsrB  r  r  r+   r   r  rJ   r   r   r4   r~   r   r6   queryMultiAdapterr\   )r   rB  r  r  r  rC  foor7   r0  r  r   r,  r	   r	   r
   "test_queryMultiAdaptor_lookup_miss  s&    
z9AdapterLookupBaseTests.test_queryMultiAdaptor_lookup_missc                    sl   ddl m} ddlm} |d |  }| |j_ fdd}tt	u}|j
| ||r`dndd	 d S )
Nr   r  )MissingSomeAttrsr  c                    s    | f S r   )rG  )obr  r  r	   r
   test  s    zVAdapterLookupBaseTests.test_queryMultiAdapter_errors_on_attribute_access.<locals>.testr   Z__providedBy__)Zexpected_missing)r  r  zope.interface.testsrJ  r   r4   r~   r   strbytesZtest_raises)r   r  rJ  r7   rM  ZPY3r	   rL  r
   1test_queryMultiAdapter_errors_on_attribute_access  s    

zHAdapterLookupBaseTests.test_queryMultiAdapter_errors_on_attribute_accessc                    s   ddl m} ddlm} |d}|d|f}||G dd dt}| }| ||}|  }t }	g   fdd	}
i ||d
|
iiig|_|j	| | 
|}|j|_||_t }|j|f||d}| || |  |g d S )Nr   rA  r  r  r  c                   @   s   e Zd ZdS )zGAdapterLookupBaseTests.test_queryMultiAdaptor_factory_miss.<locals>.FooNr   r	   r	   r	   r
   rC    s   rC  c                    s     |  d S r   r   r   r   r	   r
   r   '  s    zLAdapterLookupBaseTests.test_queryMultiAdaptor_factory_miss.<locals>._factoryrE   rD  rF  rB  r  r  r+   r   r  rJ   r   r   r4   r~   r   r6   rG  r\   r;   )r   rB  r  r  r  rC  rH  r7   r0  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|f}||G dd dt}| }| ||}|  }t g   fdd	}	i ||d
|	iiig|_|j	| | 
|}
|
j|
_|
|_t }|
j|f||d}| | |  |g d S )Nr   rA  r  r  r  c                   @   s   e Zd ZdS )zFAdapterLookupBaseTests.test_queryMultiAdaptor_factory_hit.<locals>.FooNr   r	   r	   r	   r
   rC  <  s   rC  c                    s     |  S r   r   r   r   r>  r	   r
   r   D  s    
zKAdapterLookupBaseTests.test_queryMultiAdaptor_factory_hit.<locals>._factoryrE   rD  rR  )r   rB  r  r  r  rC  rH  r7   r0  r   r  r   r,  r	   rT  r
   "test_queryMultiAdaptor_factory_hit7  s.    
z9AdapterLookupBaseTests.test_queryMultiAdaptor_factory_hitc                    sd   |  |  } fdd}dd  ||_tt| ddtt| g}||d }| || dd| f d S )Nc                     s    S r   r	   argsfactoryr	   r
   r   V  s    zKAdapterLookupBaseTests.test_queryMultiAdapter_super_unwraps.<locals>.lookupc                  W   s   | S r   r	   rV  r	   r	   r
   rY  X  s    zLAdapterLookupBaseTests.test_queryMultiAdapter_super_unwraps.<locals>.factory*   abc)r4   r   r   r   r  rG  r;   )r   r  r   Zobjectsr,  r   rX  r
   $test_queryMultiAdapter_super_unwrapsT  s     z;AdapterLookupBaseTests.test_queryMultiAdapter_super_unwrapsc                 C   st   ddl m} |d}|d|f}|  }| |}||f|}| |d | t|jd | |	 |j d S )Nr   r  r  r  r	   r:   )
r  r  r   r4   r   r;   rI   r$  r_   r*  r+  r	   r	   r
   !test__uncached_lookupAll_empty_rok  s    
z8AdapterLookupBaseTests.test__uncached_lookupAll_empty_roc                 C   sn   ddl m} |d}|d|f}| ||}|  }|j| | |}||_||f|}| 	|d d S Nr   r  r  r  r	   )
r  r  r   r  r   r   r4   r6   r   r;   r/  r	   r	   r
   #test__uncached_lookupAll_order_missv  s    
z:AdapterLookupBaseTests.test__uncached_lookupAll_order_missc                 C   st   ddl m} |d}|d|f}|  }|  }i i g|_|j| | |}||_|	|f|}| 
|d d S r^  )r  r  r   r  rJ   r   r   r4   r6   r   r;   r/  r	   r	   r
   'test__uncached_lookupAll_extendors_miss  s    

z>AdapterLookupBaseTests.test__uncached_lookupAll_extendors_missc           
      C   s   ddl m} |d}|d|f}|d}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}	| |	d d S )Nr   r  r  r  r4  rE   r	   )r  r  r   r  r+   rJ   r   r   r4   r6   r   r;   r6  r	   r	   r
   (test__uncached_lookupAll_components_miss  s    
z?AdapterLookupBaseTests.test__uncached_lookupAll_components_missc           
      C   s   ddl m} |d}|d|f}| ||}|  }t }t }i ||||diig|_|j| | |}||_	|
|f|}	| t|	d|fd|fg d S Nr   r  r  r  )rE   namedrE   rc  )r  r  r   r  r+   rJ   r   r   r4   r6   r   r;   r  
r   r  r  r  r7   r0  r>  Z_namedr  r,  r	   r	   r
   #test__uncached_lookupAll_simple_hit  s    
z:AdapterLookupBaseTests.test__uncached_lookupAll_simple_hitc           
      C   s   ddl m} |d}|d|f}| ||}|  }t }t }i ||||diig|_|j| | |}|j	|_
||_||f|}	| t|	ddg d S rb  )r  r  r   r  r+   rJ   r   r   r4   r   r   r6   namesr;   r  rd  r	   r	   r
   
test_names  s     
z!AdapterLookupBaseTests.test_namesc                 C   st   ddl m} |d}|d|f}|  }| |}||f|}| |g  | t|jd | |	 |j d S r)  )
r  r  r   r4   r   r;   rI   r$  r_   r*  r+  r	   r	   r
   %test__uncached_subscriptions_empty_ro  s    
z<AdapterLookupBaseTests.test__uncached_subscriptions_empty_roc                 C   sn   ddl m} |d}|d|f}| ||}|  }|j| | |}||_||f|}| 	|g  d S r.  )
r  r  r   r  r   r   r4   r6   r   r;   r/  r	   r	   r
   'test__uncached_subscriptions_order_miss  s    
z>AdapterLookupBaseTests.test__uncached_subscriptions_order_missc                 C   st   ddl m} |d}|d|f}|  }|  }i i g|_|j| | |}||_|	|f|}| 
|g  d S r.  )r  r  r   r  rf   r   r   r4   r6   r   r;   r/  r	   r	   r
   +test__uncached_subscriptions_extendors_miss  s    

zBAdapterLookupBaseTests.test__uncached_subscriptions_extendors_missc           
      C   s   ddl m} |d}|d|f}|d}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}	| |	g  d S r3  r  r  r   r  r+   rf   r   r   r4   r6   r   r;   r6  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|f}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}| |g  d S r8  rk  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|f}| ||}|  }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   rn  r	   r	   r	   r
   rC    s   rC  rE   )r  r  r   r  r+   rf   r   r   r4   r6   r   r;   r  )r   r  r  r  r7   r0  rC  _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|f}||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   rA  r  r  r  c                   @   s   e Zd ZdS )z@AdapterLookupBaseTests.test_subscribers_wo_provided.<locals>.FooNr   r	   r	   r	   r
   rC  &  s   rC  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   rs  r   ru  r	   r
   r   0  s    zFAdapterLookupBaseTests.test_subscribers_wo_provided.<locals>._factory2rE   r	   )r   r   rF  rB  r  r  r+   r   r  rf   r   r   r4   r   r   r6   Zsubscribersr;   )r   rB  r  r  r  rC  rH  r7   r0  r   r   r  r,  r	   ru  r
   test_subscribers_wo_provided!  s.    
z3AdapterLookupBaseTests.test_subscribers_wo_providedc                    s   ddl m} ddlm} |d}|d|f}||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   rA  r  r  r  c                   @   s   e Zd ZdS )z?AdapterLookupBaseTests.test_subscribers_w_provided.<locals>.FooNr   r	   r	   r	   r
   rC  C  s   rC  c                    s     dg |  S rr  rs  r   )rv  ro  r	   r
   r   L  s    zEAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._factory1c                    s     dg |  S rw  rs  r   )rv  rp  r	   r
   r   O  s    zEAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._factory2c                    s     dg |  d S )N_side_effect_onlyrs  r   ru  r	   r
   rz  R  s    zMAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._side_effect_onlyrE   )r   r   rz  rx  )r   rB  r  r  r  rC  rH  r7   r0  r   r   rz  r  r,  r	   )rv  ro  rp  r
   test_subscribers_w_provided>  s<    
z2AdapterLookupBaseTests.test_subscribers_w_provided))r   r   r   r1   r4   r  r   r  r  r  r%  r&  r'  r(  r-  r1  r2  r7  r;  r?  r@  rI  rQ  rS  rU  r\  r]  r_  r`  ra  re  rg  rh  ri  rj  rl  rm  rq  ry  r{  r   r	   r	   r   r
   r    sJ   r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )VerifyingAdapterRegistryTestsc                 C   s   ddl m} |S )Nr   )VerifyingAdapterRegistry)r-   r}  )r   r}  r	   r	   r
   r1   m  s    z-VerifyingAdapterRegistryTests._getTargetClassc                 O   s   |   |i |S r   r2   )r   rW  kwr	   r	   r
   r4   q  s    z&VerifyingAdapterRegistryTests._makeOnec                 C   s.   ddl m} ddlm} |  }||| d S )Nr   )verifyObject)IAdapterRegistry)Zzope.interface.verifyr  Zzope.interface.interfacesr  r4   )r   r  r  r7   r	   r	   r
   ,test_verify_object_provides_IAdapterRegistryt  s    zJVerifyingAdapterRegistryTests.test_verify_object_provides_IAdapterRegistryN)r   r   r   r1   r4   r  r	   r	   r	   r
   r|  f  s   r|  c                   @   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 )AdapterRegistryTestsc                 C   s   ddl m} |S )Nr   )AdapterRegistry)r-   r  )r   r  r	   r	   r
   r1   }  s    z$AdapterRegistryTests._getTargetClassc                 C   s   |   }| t|jd d S rc   )r4   r;   rI   _v_subregistries)r   Zarr	   r	   r
   test_ctor_no_bases  s    z'AdapterRegistryTests.test_ctor_no_basesc                 C   sJ   |   }|  |g}| t|jd | t|jd | ||j d S Nr   r:   )r4   r;   rI   r  r_   )r   basesubr	   r	   r
   test_ctor_w_bases  s
    z&AdapterRegistryTests.test_ctor_w_basesc                 C   sZ   |   }|   }|  |g}|g|_| t|jd | t|jd | ||j d S r  r4   rC   r;   rI   r  r_   r   beforeafterr  r	   r	   r
   ,test__setBases_removing_existing_subregistry  s    zAAdapterRegistryTests.test__setBases_removing_existing_subregistryc                 C   sr   |   }|   }|   }|  |g}|jd | |g|_| t|jd | t|jd | ||j d S )NrC   r   r:   )r4   __dict__r   rC   r;   rI   r  r_   )r   r  Zstrayr  r  r	   r	   r
   test__setBases_wo_stray_entry  s    z2AdapterRegistryTests.test__setBases_wo_stray_entryc                 C   sj   |   }|   }|  |g}||g|_| t|jd | t|jd | ||j | ||j d S r9   r  r  r	   r	   r
   *test__setBases_w_existing_entry_continuing  s    
z?AdapterRegistryTests.test__setBases_w_existing_entry_continuingc                 C   sj   |   }G dd dt}| |  }}|| || t }|| | |j| | |j| 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   )r4   r+   Z_addSubregistryr   r\   r   )r   r  r   Zderived1Zderived2r   r	   r	   r
   test_changed_w_subregistries  s    


z1AdapterRegistryTests.test_changed_w_subregistriesN)
r   r   r   r1   r  r  r  r  r  r  r	   r	   r	   r
   r  {  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_utilsc                 C   s,   ddl m} ddlm} | |d | d S )Nr   _convert_None_to_Interfacer   )r-   r  r  r   r\   )r   r  r   r	   r	   r
   &test__convert_None_to_Interface_w_None  s    z1Test_utils.test__convert_None_to_Interface_w_Nonec                 C   s&   ddl m} t }| ||| d S )Nr   r  )r-   r  r+   r\   )r   r  r  r	   r	   r
   'test__convert_None_to_Interface_w_other  s    z2Test_utils.test__convert_None_to_Interface_w_otherc                 C   s<   ddl m} d}d}||}| || | |t| d S )Nr   _normalize_names   strrO  )r-   r  r;   ZassertIsInstancetype)r   r  ZSTRUNICODEZnormr	   r	   r
   test__normalize_name_str  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    s
   r  )__doc__ZunittestrN  r   r   ZTestCaser   rs   r   r   r  r  r|  r  r  r	   r	   r	   r
   <module>   s0    W  K     k@