o
    $x`7                    @   s$  d Z ddlZddlmZ dd ZG dd deZG dd	 d	eZG d
d deZG dd de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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                   @      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       r   c                   @   r   )z_makeInterfaces.<locals>.IB1Nr   r
   r
   r
   r   IB1   r   r   c                   @   r   )z_makeInterfaces.<locals>.IB2Nr   r
   r
   r
   r   IB2   r   r   c                   @   r   )z_makeInterfaces.<locals>.IB3Nr   r
   r
   r
   r   IB3    r   r   c                   @   r   )z_makeInterfaces.<locals>.IB4Nr   r
   r
   r
   r   IB4"   r   r   c                   @   r   )z_makeInterfaces.<locals>.IF0Nr   r
   r
   r
   r   IF0%   r   r   c                   @   r   )z_makeInterfaces.<locals>.IF1Nr   r
   r
   r
   r   IF1'   r   r   c                   @   r   )z_makeInterfaces.<locals>.IR0Nr   r
   r
   r
   r   IR0*   r   r   c                   @   r   )z_makeInterfaces.<locals>.IR1Nr   r
   r
   r
   r   IR1,   r   r   )zope.interfacer   )
r   r   r   r   r   r   r   r   r   r   r
   r
   r   _makeInterfaces   s   r   c                   @   sH   e Zd 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 )CustomDataTypeBaseNc                 C   s
   | j | S N_dataselfnamer
   r
   r   __getitem__7      
zCustomDataTypeBase.__getitem__c                 C   s   || j |< d S r   r   )r   r   valuer
   r
   r   __setitem__:      zCustomDataTypeBase.__setitem__c                 C   s   | j |= d S r   r   r   r
   r
   r   __delitem__=      zCustomDataTypeBase.__delitem__c                 C   
   t | jS r   )lenr   r   r
   r
   r   __len__@   r    zCustomDataTypeBase.__len__c                 C   s
   || j v S r   r   r   r
   r
   r   __contains__C   r    zCustomDataTypeBase.__contains__c                 C   s,   || u rdS t |t | krdS |j| jkS )NTF)typer   r   otherr
   r
   r   __eq__F   s
   zCustomDataTypeBase.__eq__c                 C   r&   r   )reprr   r(   r
   r
   r   __repr__N   r    zCustomDataTypeBase.__repr__)r   r   r	   r   r   r"   r$   r)   r*   r.   r0   r
   r
   r
   r   r   5   s    r   c                   @      e Zd ZdddZdS )CustomMappingNc                 C   s.   i | _ |r| j | | j j| _| j j| _d S r   )r   updategetitemsr,   r
   r
   r   __init__R   s
   
zCustomMapping.__init__r   r   r   r	   r6   r
   r
   r
   r   r2   Q       r2   c                   @   r1   )CustomSequenceNc                 C   s$   g | _ |r| j | | j j| _d S r   )r   extendappendr,   r
   r
   r   r6   [   s   zCustomSequence.__init__r   r7   r
   r
   r
   r   r9   Z   r8   r9   c                   @   r   )CustomLeafSequenceNr   r
   r
   r
   r   r<   a   r   r<   c                   @   r   )CustomProvidedNr   r
   r
   r
   r   r=   d   r   r=   c                   @   sd  e Zd 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dWddZdWd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%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dS )XBaseAdapterRegistryTestsNc                 C      ddl m} |S )Nr   BaseAdapterRegistryzope.interface.adapterrA   )r   rA   r
   r
   r   _getBaseAdapterRegistryl      z0BaseAdapterRegistryTests._getBaseAdapterRegistryc                 C   s8   |   }G dd d|}|jD ]
}t|j|t  q|S )Nc                   @   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      d S r   r
   )r   regr
   r
   r   r6   u      zKBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.__init__c                 S      |  j |f7  _ d S r   _changed)r   origr
   r
   r   changedw      zJBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.changedc                 S   rI   r   )
_extendorsr   providedr
   r
   r   add_extendory   rN   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rQ   r
   r   
<listcomp>|   s    
zfBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.remove_extendor.<locals>.<listcomp>)tuplerO   rP   r
   rU   r   remove_extendor{   s   zRBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.remove_extendorN)	r   r   r	   rK   rO   r6   rM   rR   rX   r
   r
   r
   r   LookupClasss   s    rY   N)r   r   r	   objectrY   r
   r
   r
   r   _CUTr   s    r[   )rD   
_delegatedsetattrrY   rZ   )r   rA   r[   r   r
   r
   r   _getTargetClassp   s
   
z(BaseAdapterRegistryTests._getTargetClassc                 C   s
   |    S r   r^   r(   r
   r
   r   _makeOne   r    z!BaseAdapterRegistryTests._makeOnec                 C      t S r   dictr(   r
   r
   r   _getMappingType   rH   z(BaseAdapterRegistryTests._getMappingTypec                 C   ra   r   rb   r(   r
   r
   r   _getProvidedType   rH   z)BaseAdapterRegistryTests._getProvidedTypec                 C   ra   r   )listr(   r
   r
   r   _getMutableListType   rH   z,BaseAdapterRegistryTests._getMutableListTypec                 C   ra   r   )rW   r(   r
   r
   r   _getLeafSequenceType   rH   z-BaseAdapterRegistryTests._getLeafSequenceTypec                 C   s8   |   }| }|jD ]}| t||t|j| q
d S r   )r^   r\   assertIsgetattr	_v_lookup)r   CUTregistryr   r
   r
   r   test_lookup_delegation   s
   
z/BaseAdapterRegistryTests.test_lookup_delegationc                 C   s   |   }| |jd d S N   )r`   assertEqual_generationr   rm   r
   r
   r   "test__generation_on_first_creation   s   z;BaseAdapterRegistryTests.test__generation_on_first_creationc                 C   s>   |   }t }|| | |jd | |jj||f d S N   )r`   rZ   rM   rq   rr   rk   rK   )r   rm   rL   r
   r
   r   &test__generation_after_calling_changed   s
   
z?BaseAdapterRegistryTests.test__generation_after_calling_changedc                 C   s2   G dd dt }|  }|f|_| |jd d S )Nc                   @   r   )zQBaseAdapterRegistryTests.test__generation_after_changing___bases__.<locals>._BaseNr   r
   r
   r
   r   _Base   r   rx   rv   )rZ   r`   	__bases__rq   rr   )r   rx   rm   r
   r
   r   )test__generation_after_changing___bases__   s   zBBaseAdapterRegistryTests.test__generation_after_changing___bases__rv   c                 C   s   |  t|j| | |j|   |  }|jD ]}| || q|  |jd |  | |jd | |  t|j|d  d d S Nr   rp   )rq   r'   	_adaptersassertIsInstancerg   rd   r   rm   expected_orderMTmappingr
   r
   r   _check_basic_types_of_adapters   s   
z7BaseAdapterRegistryTests._check_basic_types_of_adaptersc                 C   s   |  t|j| | |j|   |  }|jD ]}| || q|rF|  |jd |  | |jd | |  t|j|d  d d S d S r{   )rq   r'   _subscribersr}   rg   rd   r~   r
   r
   r   !_check_basic_types_of_subscribers   s   
z:BaseAdapterRegistryTests._check_basic_types_of_subscribersc              
   C   s   t  \	}}}}}}}}}	|  }
|
|g|dd | |
|g|dd | |
jd | |
 |  }| |
jd |||||ddiii | 	 }| |
j
||di t|
 }| ||f|ddfg d S )N A1rv   rp   )r   r`   registerrq   
registeredrr   r   rd   r|   re   	_providedrf   allRegistrations)r   r   r   r   r   r   r   r   r   r   rm   r   PTr   r
   r
   r   test_register   s.   

z&BaseAdapterRegistryTests.test_registerc           
         s$  t  \	 }}}|  }|g dd |g dd | gdd | gdd | gdd | gdd | gdd | gdd | gd	d | gdd  fd
d}| |j||  |  d t| }| |dddfdddf fddf fddf fddf fddf fddf fddf fd	df fddfg
 |  }|D ]}|j|  q| |j|j | |j	|j	 t
|_t|_t|_t|_dd }	|	|_|  | |j|tt
d d S )Nr   r   name1A2name2A3name3A4name4c                    s   | ||dddi| ||ddd|dddii| |||ddii||d	di|d
dii||ddiiiigS )Nr   r   )r   r   )r   r   r   r   )r   r   r   r   r   r
   Lr   r   r   r   r   r   r   r
   r   build_adapters   sD   zXBaseAdapterRegistryTests.test_register_multiple_allRegistrations.<locals>.build_adaptersr   r
   c                 S       | d ur| nt  } | | | S r   r<   r;   existingnewr
   r
   r   addValue1     
zRBaseAdapterRegistryTests.test_register_multiple_allRegistrations.<locals>.addValue)r   r`   r   rq   r|   rg   rd   sortedr   r   r2   _mappingTyper<   _leafSequenceTyper9   _sequenceTyper=   _providedType_addValueToLeafrebuild)
r   r   r   r   rm   r   r   	registry2argsr   r
   r   r   'test_register_multiple_allRegistrations   sb   '

z@BaseAdapterRegistryTests.test_register_multiple_allRegistrationsc              	   C   sd   t  \	}}}}}}}}}	|  }
| t |
|g|t d W d    d S 1 s+w   Y  d S Nr   )r   r`   assertRaises
ValueErrorr   rZ   r   r   r   r   r   r   r   r   r   r   rm   r
   r
   r   test_register_with_invalid_name?  s
   "z8BaseAdapterRegistryTests.test_register_with_invalid_namec              	   C   s   t  \	}}}}}}}}}	|  }
|
d g|dd |
d g|dd  | t|
jd | |
j|   t|
	 }| |g  d S )Nr   r   r   )
r   r`   r   rq   r'   r|   r}   rg   rf   r   )r   r   r   r   r   r   r   r   r   r   rm   r   r
   r
   r   )test_register_with_value_None_unregistersE  s   zBBaseAdapterRegistryTests.test_register_with_value_None_unregistersc              
   C   s   ddl m} t \	}}}}}}}}	}
|  }t }|d g|	d| |j}|d g|	d| | |j| | | | 	 }| |j
d ||||	|d|iii t| }| ||f|	d|fg d S )Nr   r   r   rp   )r   r   r   r`   rZ   r   rr   rq   r   rd   r|   rf   r   )r   r   r   r   r   r   r   r   r   r   r   rm   _value_beforer   r   r
   r
   r   test_register_with_same_valueO  s0   
	z6BaseAdapterRegistryTests.test_register_with_same_valuec                 C   s<   |   }| |d gd dd  t| }| |g  d S Nr   )r`   rq   r   rf   r   )r   rm   r   r
   r
   r   test_registered_emptyl  s   z.BaseAdapterRegistryTests.test_registered_emptyc              	   C   sN   t  \	}}}}}}}}}	|  }
|
|gd dd | |
|gd dd  d S Nr   r   )r   r`   r   rq   r   r   r
   r
   r   test_registered_non_empty_missr  s   z7BaseAdapterRegistryTests.test_registered_non_empty_missc                 C   s6   |   }|d gd dd | |d gd dd d S r   )r`   r   rq   r   rs   r
   r
   r   test_registered_non_empty_hitx  s   z6BaseAdapterRegistryTests.test_registered_non_empty_hitc                 C   sF   |   }|d gd d | |d gd dd  | t|jd d S )Nr   r   )r`   
unregisterrq   r   r'   r   rs   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 | |
 |  }| |
jd |||d |ddiii | 	 }| |
j
|d di d S )Nr   r   rp   r   r`   r   r   rq   r   r   rd   r|   re   r   r   r   r   r   r   r   r   r   r   r   rm   r   r   r
   r
   r   *test_unregister_non_empty_miss_on_required  $   
	
zCBaseAdapterRegistryTests.test_unregister_non_empty_miss_on_requiredc              
   C   s   t  \	}}}}}}}}}	|  }
|
|gd dd |
|gd d | |
|gd dd | |
 |  }| |
jd |||d |ddiii | 	 }| |
j
|d di d S )Nr   r   nonesuchrp   r   r   r
   r
   r   &test_unregister_non_empty_miss_on_name  r   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 r   )r   r`   rZ   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   rm   rL   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d | ||
jd |  | ||
jd |  |  }| |
jd |||||d |d|ii||d |d|iiii | 	 }| |
j
|d di |
||gd d| | ||
jd |  | ||
jd |  | |
jd |||||d |d|iiii | |
j
|d di d S )Nr      r   rv   rp   )r   r`   rZ   r   r   assertInr|   rd   rq   re   r   r   assertNotIn)r   r   r   r   r   r   r   r   r   r   rm   oneanotherr   r   r
   r
   r   .test_unregister_hit_clears_empty_subcomponents  sF   


	zGBaseAdapterRegistryTests.test_unregister_hit_clears_empty_subcomponentsc                 C   sB   |   }|d gd d | |d gd dd  | j|dd d S )Nr   r   r   )r`   unsubscriberq   r   r   rs   r
   r
   r   test_unsubscribe_empty  s   z/BaseAdapterRegistryTests.test_unsubscribe_emptyc                 C   s   t  \	}}}}}}}}}	|  }
t }|
|gd | |  }|  }|  }| |
 | |
j	d |||d |d||fiii | |
j
|i  |
|gd | | t|
j	d | |
j
|i  d S )Nrp   r   r   )r   r`   rZ   	subscriberd   rh   re   r   rq   r   r   r   r'   )r   r   r   r   r   r   r   r   r   r   rm   rL   r   r   r   r
   r
   r   test_unsubscribe_hit  s&   

z-BaseAdapterRegistryTests.test_unsubscribe_hitc                 C   s   |  || dS )a  
        Implementations may choose to use new, immutable objects
        instead of mutating existing subscriber leaf objects, or vice versa.

        The default implementation uses immutable tuples, so they are never
        the same. Other implementations may use persistent lists so they should be
        the same and mutated in place. Subclasses testing this behaviour need to
        override this method.
        N)assertIsNotr   leaf1leaf2r
   r
   r   assertLeafIdentity  s   
z+BaseAdapterRegistryTests.assertLeafIdentityc                 C   s*  t  \	}}}}}}}}}	|  }
t }t }t }t }|
|gd | |
|gd | |
|g|| |
|g|| | j|
dd |  }|  }|  }| |
j	d |||d |d|||fi||d|||fiii | |
j
||di |
j	d | | d }|
j	d | d  d }|
|gd | |
|g|| | |
j	d |||d |d||fi||d||fiii | |
j
||di |
j	d | | d }|
j	d | d  d }| || | || |
|gd | |
|g|| | t|
j	d | t|
j
d d S )Nrv   r   rp   r   r   )r   r`   rZ   r   r   rd   rh   re   rq   r   r   r   r   r'   )r   r   r   r   r   r   r   r   r   r   rm   firstsecondthirdfourthr   r   r   IR0_leaf_origNon_leaf_origIR0_leaf_newNon_leaf_newr
   r
   r   test_unsubscribe_after_multiple	  sX   

z8BaseAdapterRegistryTests.test_unsubscribe_after_multiplec                 C   s   t  \	}}}}}}}}}	|  }
t }|
|g|| |
|g|| |  }|  }|  }| |
jd |||||d|||fiii | |
j	||di |

|g|| |

|g|| | t|
jd | |
j	|  d S Nrp   r   rv   r   r   r`   rZ   r   rd   rh   re   rq   r   r   r   r'   )r   r   r   r   r   r   r   r   r   r   rm   r   r   r   r   r
   r
   r   5test_subscribe_unsubscribe_identical_objects_provided=  s(   
zNBaseAdapterRegistryTests.test_subscribe_unsubscribe_identical_objects_providedc                 C   s   t  \	}}}}}}}}}	|  }
t }t }|
|g|| |
|g|| |  }|  }|  }| |
jd |||||d|||fiii | |
j	||di |

|g|| |

|g|| | t|
jd | |
j	|  d S r   r   )r   r   r   r   r   r   r   r   r   r   rm   r   r   r   r   r   r
   r
   r   4test_subscribe_unsubscribe_nonequal_objects_providedV  s*   
zMBaseAdapterRegistryTests.test_subscribe_unsubscribe_nonequal_objects_providedc                 C   s:   |   }| |d gd d t| }| |g  d S r   )r`   assertIsNone
subscribedrf   allSubscriptionsrq   )r   rm   r   r
   r
   r   test_subscribed_emptyp  s   z.BaseAdapterRegistryTests.test_subscribed_emptyc              	   C   sv   t  \	}}}}}}}}}	|  }
|
|g|d | |
|g|d | |
|g|d | |
|g|d d S )Nr   r   )r   r`   r   r   r   r   r
   r
   r   test_subscribed_non_empty_missv  s   z7BaseAdapterRegistryTests.test_subscribed_non_empty_missc              	   C   sL   t  \	}}}}}}}}}	|  }
|
|g|d | |
|g|dd d S r   )r   r`   r   rq   r   r   r
   r
   r   test_subscribed_non_empty_hit  s   z6BaseAdapterRegistryTests.test_subscribed_non_empty_hitc              	   C   s~   t  \	}}}}}}}}}	|  }
t }t }|
|gd | |
|gd | | j|
dd |
|gd  | t|
jd d S )Nrv   r   r   )	r   r`   rZ   r   r   r   rq   r'   r   )r   r   r   r   r   r   r   r   r   r   rm   r   r   r
   r
   r   &test_unsubscribe_w_None_after_multiple  s   z?BaseAdapterRegistryTests.test_unsubscribe_w_None_after_multiplec                 C   s   t  \	}}}}}}}}}	|  }
|
|gd d | j|
dd |
|gd d | t|
jd |  }| 	 }| |
jd |||d |d|diii d S )Nr   rv   r   r   rp   r   
r   r`   r   r   r   rq   r'   r   rd   rh   r   r   r   r   r   r   r   r   r   r   rm   r   r   r
   r
   r   +test_unsubscribe_non_empty_miss_on_required     zDBaseAdapterRegistryTests.test_unsubscribe_non_empty_miss_on_requiredc                 C   s   t  \	}}}}}}}}}	|  }
|
|gd d | j|
dd |
|gd d | t|
jd |  }| 	 }| |
jd |||d |d|diii d S )Nr   rv   r   r   rp   r   r   r   r   r
   r
   r   (test_unsubscribe_non_empty_miss_on_value  r   zABaseAdapterRegistryTests.test_unsubscribe_non_empty_miss_on_valuec              	   C   sb   t  \	}}}}}}}}}	|  }
t }t }|
|gd | |
|gd | | t|
jd d S ru   )r   r`   rZ   r   r   rq   r'   r   r   r
   r
   r   )test_unsubscribe_with_value_not_None_miss  s   zBBaseAdapterRegistryTests.test_unsubscribe_with_value_not_None_missc                 C      |  d d S )Nz*Example method, not intended to be called.failr(   r
   r
   r   _instance_method_notify_target  r#   z7BaseAdapterRegistryTests._instance_method_notify_targetc              	   C   sl   t  \	}}}}}}}}}	|  }
| t|
jd |
|gd | j |
|gd | j | t|
jd d S Nr   )r   r`   rq   r'   r   r   r   r   r   r
   r
   r    test_unsubscribe_instance_method  s   z9BaseAdapterRegistryTests.test_unsubscribe_instance_methodc                    s*  t  \	 }}}|  }|g d |g d | gd | gd | gd | gd | gd | gd | gd | gd  fdd}| |j||  |  |  d fdd	}| |j|| 	 d
 t
| }| |ddfddf fdf fdf fdf fdf fdf fdf fdf fdfg
 |  }|D ]}	|j|	  q| |j|j | |j|j t|_t|_t|_t|_dd }
|
|_|  | |j|tttd d S )Nr   r   r   r   c                    s   | ||d|ddgii| ||d|ddgi|d|ddgiii| |||d|dgii||d|dgi|d|dgii||d|dgiiiigS )Nr   r   r   r   r   r
   r   Fr   r   r
   r   build_subscribers  s>   z\BaseAdapterRegistryTests.test_subscribe_multiple_allRegistrations.<locals>.build_subscribersr   c                    s   |  ddiS )N      r
   P)r   r   r
   r   build_provided  s   zYBaseAdapterRegistryTests.test_subscribe_multiple_allRegistrations.<locals>.build_providedr   r
   c                 S   r   r   r   r   r
   r
   r   r   (  r   zSBaseAdapterRegistryTests.test_subscribe_multiple_allRegistrations.<locals>.addValue)r   r`   r   rq   r   rg   rh   rd   r   re   r   r   r2   r   r<   r   r9   r   r=   r   r   r   )r   r   r   r   rm   r   r   r   r   r   r   r
   r   r   (test_subscribe_multiple_allRegistrations  sp   $



zABaseAdapterRegistryTests.test_subscribe_multiple_allRegistrations)rv   ).r   r   r	   maxDiffrD   r^   r`   rd   re   rg   rh   rn   rt   rw   rz   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   r   r   r
   r
   r
   r   r>   h   sX    


e
	*4		r>   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )#CustomTypesBaseAdapterRegistryTestsz
    This class may be extended by other packages to test their own
    adapter registries that use custom types. (So be cautious about
    breaking changes.)

    One known user is ``zope.component.persistentregistry``.
    c                 C   ra   r   )r2   r(   r
   r
   r   rd   A  rH   z3CustomTypesBaseAdapterRegistryTests._getMappingTypec                 C   ra   r   )r=   r(   r
   r
   r   re   D  rH   z4CustomTypesBaseAdapterRegistryTests._getProvidedTypec                 C   ra   r   )r9   r(   r
   r
   r   rg   G  rH   z7CustomTypesBaseAdapterRegistryTests._getMutableListTypec                 C   ra   r   )r<   r(   r
   r
   r   rh   J  rH   z8CustomTypesBaseAdapterRegistryTests._getLeafSequenceTypec                    s&   ddl m  G  fddd }|S )Nr   r@   c                       s@   e Zd Z Z Z Z	 Z
dd Z fddZdS )zZCustomTypesBaseAdapterRegistryTests._getBaseAdapterRegistry.<locals>.CustomAdapterRegistryc                 S   s   |s|   }|| |S r   )r   r;   )r   existing_leaf_sequencenew_itemr
   r
   r   r   U  s   
zjCustomTypesBaseAdapterRegistryTests._getBaseAdapterRegistry.<locals>.CustomAdapterRegistry._addValueToLeafc                    s*     | ||}||d d < ||vsJ |S r   )_removeValueFromLeaf)r   r   	to_removewithout_removedr@   r
   r   r   [  s   zoCustomTypesBaseAdapterRegistryTests._getBaseAdapterRegistry.<locals>.CustomAdapterRegistry._removeValueFromLeafN)r   r   r	   rd   r   rg   r   rh   r   re   r   r   r   r
   rA   r   r
   r   CustomAdapterRegistryO  s    r  rB   )r   r  r
   r  r   rD   M  s   z;CustomTypesBaseAdapterRegistryTests._getBaseAdapterRegistryc                 C   s   |  || d S r   )ri   r   r
   r
   r   r   f  s   z6CustomTypesBaseAdapterRegistryTests.assertLeafIdentityN)
r   r   r	   __doc__rd   re   rg   rh   rD   r   r
   r
   r
   r   r   8  s    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   r?   )Nr   )LookupBaseFallback)rC   r  )r   r  r
   r
   r   _getFallbackClassl  rE   z)LookupBaseFallbackTests._getFallbackClassNc                    sR    d u rdd  d u rdd d u rdd G  fddd|   }| S )	Nc                 S   rF   r   r
   r   requiredrQ   r   r
   r
   r   	uc_lookupv  rH   z3LookupBaseFallbackTests._makeOne.<locals>.uc_lookupc                 S      t  r   NotImplementedErrorr   r
  rQ   r
   r
   r   uc_lookupAlly     z6LookupBaseFallbackTests._makeOne.<locals>.uc_lookupAllc                 S   r  r   r  r  r
   r
   r   uc_subscriptions|  r  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
   r  r  r  r
   r   Derived~  s    r  r_   )r   r  r  r  r  r
   r  r   r`   r  s   z LookupBaseFallbackTests._makeOnec                 C   T   dd }| j |d}| t |ddt  W d    d S 1 s#w   Y  d S )Nc                 S   r   NzThis should never be calledr   r	  r
   r
   r   _lookup  r#   zCLookupBaseFallbackTests.test_lookup_w_invalid_name.<locals>._lookupr  AB)r`   r   r   lookuprZ   r   r  lbr
   r
   r   test_lookup_w_invalid_name  s
   "z2LookupBaseFallbackTests.test_lookup_w_invalid_namec                    F   g   fdd}| j |d}|ddd}| | |  dg d S )Nc                         |||f d S r   r;   r	  _called_withr
   r   r    rN   zDLookupBaseFallbackTests.test_lookup_miss_no_default.<locals>._lookupr  r  r  Cr  r  r(  )r`   r  r   rq   r   r  r!  foundr
   r&  r   test_lookup_miss_no_default     
z3LookupBaseFallbackTests.test_lookup_miss_no_defaultc                    P   g  t  } fdd}| j|d}|ddd|}| || |  dg d S )Nc                    r$  r   r%  r	  r&  r
   r   r    rN   zCLookupBaseFallbackTests.test_lookup_miss_w_default.<locals>._lookupr  r  r  r(  r)  rZ   r`   r  ri   rq   r   _defaultr  r!  r+  r
   r&  r   test_lookup_miss_w_default     z2LookupBaseFallbackTests.test_lookup_miss_w_defaultc                    z   g  t  t  t  }}}|||g fdd}| j|d}|ddd}| || |  dg | ||g d S )Nc                         |||f dS r   r;   popr	  r'  _resultsr
   r   r       
z?LookupBaseFallbackTests.test_lookup_not_cached.<locals>._lookupr  r  r  r(  r)  r/  r   abcr  r!  r+  r
   r8  r   test_lookup_not_cached     
z.LookupBaseFallbackTests.test_lookup_not_cachedc                       g  t  t  t  }}}|||g fdd}| j|d}|ddd}|ddd}| || |  dg | ||g d S )Nc                    r5  r   r6  r	  r8  r
   r   r    r:  z;LookupBaseFallbackTests.test_lookup_cached.<locals>._lookupr  r  r  r(  r)  r/  r;  r
   r8  r   test_lookup_cached     
z*LookupBaseFallbackTests.test_lookup_cachedc                    r4  )Nc                    r5  r   r6  r	  r8  r
   r   r    r:  zNLookupBaseFallbackTests.test_lookup_not_cached_multi_required.<locals>._lookupr  r  Dr  r(  rD  r  r(  r/  r;  r
   r8  r   %test_lookup_not_cached_multi_required  r@  z=LookupBaseFallbackTests.test_lookup_not_cached_multi_requiredc                    rA  )Nc                    r5  r   r6  r	  r8  r
   r   r    r:  zJLookupBaseFallbackTests.test_lookup_cached_multi_required.<locals>._lookupr  rD  r  r(  rF  r/  r;  r
   r8  r   !test_lookup_cached_multi_required  rC  z9LookupBaseFallbackTests.test_lookup_cached_multi_requiredc                       g  t  t  t  }}}|||g fdd}| j|d}|ddd}|| |ddd}| || |  ddg | |g d S )Nc                    r5  r   r6  r	  r8  r
   r   r    r:  zMLookupBaseFallbackTests.test_lookup_not_cached_after_changed.<locals>._lookupr  r  r  r(  r)  )rZ   r`   r  rM   ri   rq   r;  r
   r8  r   $test_lookup_not_cached_after_changed     

z<LookupBaseFallbackTests.test_lookup_not_cached_after_changedc                 C   r  )Nc                 S   r   r  r   r	  r
   r
   r   r    r#   zDLookupBaseFallbackTests.test_lookup1_w_invalid_name.<locals>._lookupr  r  r  )r`   r   r   lookup1rZ   r   r
   r
   r   test_lookup1_w_invalid_name  s
   "z3LookupBaseFallbackTests.test_lookup1_w_invalid_namec                    r#  )Nc                    r$  r   r%  r	  r&  r
   r   r    rN   zELookupBaseFallbackTests.test_lookup1_miss_no_default.<locals>._lookupr  r  r  r(  r)  )r`   rL  r   rq   r*  r
   r&  r   test_lookup1_miss_no_default  r-  z4LookupBaseFallbackTests.test_lookup1_miss_no_defaultc                    r.  )Nc                    r$  r   r%  r	  r&  r
   r   r    rN   zDLookupBaseFallbackTests.test_lookup1_miss_w_default.<locals>._lookupr  r  r  r(  r)  rZ   r`   rL  ri   rq   r0  r
   r&  r   test_lookup1_miss_w_default  r3  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                    r$  r   r%  r	  r&  r
   r   r    rN   zSLookupBaseFallbackTests.test_lookup1_miss_w_default_negative_cache.<locals>._lookupr  r  r  r(  r)  rO  r0  r
   r&  r   *test_lookup1_miss_w_default_negative_cache  s   zBLookupBaseFallbackTests.test_lookup1_miss_w_default_negative_cachec                    r4  )Nc                    r5  r   r6  r	  r8  r
   r   r    r:  z@LookupBaseFallbackTests.test_lookup1_not_cached.<locals>._lookupr  r  r  r(  r)  rO  r;  r
   r8  r   test_lookup1_not_cached  r@  z/LookupBaseFallbackTests.test_lookup1_not_cachedc                    rA  )Nc                    r5  r   r6  r	  r8  r
   r   r  !  r:  z<LookupBaseFallbackTests.test_lookup1_cached.<locals>._lookupr  r  r  r(  r)  rO  r;  r
   r8  r   test_lookup1_cached  rC  z+LookupBaseFallbackTests.test_lookup1_cachedc                    rI  )Nc                    r5  r   r6  r	  r8  r
   r   r  /  r:  zNLookupBaseFallbackTests.test_lookup1_not_cached_after_changed.<locals>._lookupr  r  r  r(  r)  )rZ   r`   rL  rM   ri   rq   r;  r
   r8  r   %test_lookup1_not_cached_after_changed+  rK  z=LookupBaseFallbackTests.test_lookup1_not_cached_after_changedc                 C   sV   t  t  }}|  }| t |||t   W d    d S 1 s$w   Y  d S r   )rZ   r`   r   r   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 r   )rZ   r`   rU  r   )r   rV  rW  r!  r+  r
   r
   r   !test_adapter_hook_miss_no_defaultA  s   z9LookupBaseFallbackTests.test_adapter_hook_miss_no_defaultc                 C   s>   t  t  t  }}}|  }|||d|}| || d S r   )rZ   r`   rU  ri   )r   rV  rW  r1  r!  r+  r
   r
   r    test_adapter_hook_miss_w_defaultG  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                         |  d S r   r%  context_f_called_withr
   r   _factoryO  r#   zTLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_None.<locals>._factoryc                        S r   r
   r	  r`  r
   r   r  R  rH   zSLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_None.<locals>._lookupr  r(  rZ   r`   rU  ri   rq   r   r  rV  rW  r1  r!  adaptedr
   r_  r`  r   *test_adapter_hook_hit_factory_returns_NoneM  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 r   r%  r\  _adapterr_  r
   r   r`  ]     
zWLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_adapter.<locals>._factoryc                    ra  r   r
   r	  rb  r
   r   r  `  rH   zVLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_adapter.<locals>._lookupr  r(  rc  rd  r
   rj  r_  r`  r   -test_adapter_hook_hit_factory_returns_adapterZ     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`  j  rk  zILookupBaseFallbackTests.test_adapter_hook_super_unwraps.<locals>._factoryr   c                    ra  r   r
   r	  rb  r
   r   r  m  rH   zHLookupBaseFallbackTests.test_adapter_hook_super_unwraps.<locals>._lookupr  )r   )superr  rZ   r`   rU  ri   rq   )r   r  r
  rQ   r!  re  	__class__rf  r   test_adapter_hook_super_unwrapsh  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                    rh  r   r%  r\  ri  r
   r   r`  y  rk  z;LookupBaseFallbackTests.test_queryAdapter.<locals>._factoryc                    ra  r   r
   r	  rb  r
   r   r  |  rH   z:LookupBaseFallbackTests.test_queryAdapter.<locals>._lookupr  r(  )rZ   r`   queryAdapterri   rq   rd  r
   rl  r   test_queryAdapterv  rn  z)LookupBaseFallbackTests.test_queryAdapterc                    \   g  t  t  t  g fdd}| j|d}|dd}| |t |  dg d S )Nc                         ||f tS r   r;   rW   r  r8  r
   r   
_lookupAll     zCLookupBaseFallbackTests.test_lookupAll_uncached.<locals>._lookupAllr  r  r  r  r  rZ   r`   	lookupAllrq   rW   r   rx  r!  r+  r
   r8  r   test_lookupAll_uncached     z/LookupBaseFallbackTests.test_lookupAll_uncachedc                    h   g  t  t  t  g fdd}| j|d}|dd}|dd}| |t |  dg d S )Nc                    rv  r   rw  r  r8  r
   r   rx    ry  zALookupBaseFallbackTests.test_lookupAll_cached.<locals>._lookupAllrz  r  r  r{  r|  r~  r
   r8  r   test_lookupAll_cached     z-LookupBaseFallbackTests.test_lookupAll_cachedc                    ru  )Nc                    rv  r   rw  r  r8  r
   r   _subscriptions  ry  zKLookupBaseFallbackTests.test_subscriptions_uncached.<locals>._subscriptionsr  r  r  r{  rZ   r`   subscriptionsrq   rW   r   r  r!  r+  r
   r8  r   test_subscriptions_uncached  r  z3LookupBaseFallbackTests.test_subscriptions_uncachedc                    r  )Nc                    rv  r   rw  r  r8  r
   r   r    ry  zILookupBaseFallbackTests.test_subscriptions_cached.<locals>._subscriptionsr  r  r  r{  r  r  r
   r8  r   test_subscriptions_cached  r  z1LookupBaseFallbackTests.test_subscriptions_cachedNNN)!r   r   r	   r  r^   r`   r"  r,  r2  r?  rB  rG  rH  rJ  rM  rN  rP  rQ  rR  rS  rT  rX  rY  rZ  rg  rm  rr  rt  r  r  r  r  __classcell__r
   r
   rp  r   r  j  s@    


r  c                   @      e Zd Zdd ZdS )LookupBaseTestsc                 C   r?   )Nr   )
LookupBase)rC   r  )r   r  r
   r
   r   r^     rE   zLookupBaseTests._getTargetClassNr   r   r	   r^   r
   r
   r
   r   r        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S )VerifyingBaseFallbackTestsc                 C   r?   )Nr   )VerifyingBaseFallback)rC   r  )r   r  r
   r
   r   r    rE   z,VerifyingBaseFallbackTests._getFallbackClassNc                    sd   d u rdd d u rdd d u rdd G  fddd|     |}|| |S )	Nc                 S   r  r   r  r	  r
   r
   r   r    r  z6VerifyingBaseFallbackTests._makeOne.<locals>.uc_lookupc                 S   r  r   r  r  r
   r
   r   r    r  z9VerifyingBaseFallbackTests._makeOne.<locals>.uc_lookupAllc                 S   r  r   r  r  r
   r
   r   r    r  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   )ro  r6   	_registryrs   )r  rq  r
   r   r6     s   
z=VerifyingBaseFallbackTests._makeOne.<locals>.Derived.__init__)r   r   r	   r  r  r  r6   r  r
   r  r  r  r  rp  r   r    s
    r  )r^   rM   )r   rm   r  r  r  derivedr
   r  r   r`     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>.WithGenerationrp   N)r   r   r	   rr   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
   )rS   ir  r
   r   rV     s    zWVerifyingBaseFallbackTests._makeRegistry.<locals>.Registry.__init__.<locals>.<listcomp>)rangero)r   depthr  r
   r   r6     s   zCVerifyingBaseFallbackTests._makeRegistry.<locals>.Registry.__init__Nr7   r
   r  r
   r   Registry  s    r  )rZ   )r   r  r  r
   r  r   _makeRegistry  s   z(VerifyingBaseFallbackTests._makeRegistryc                       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                    r5  r   r6  r	  r8  r
   r   r    r:  z7VerifyingBaseFallbackTests.test_lookup.<locals>._lookupr   r  r  r  r(  r)  rp   )rZ   r  r`   r  ri   rq   r  rr   r   r<  r=  r>  r  rG   r!  r+  r
   r8  r   test_lookup  $   

z&VerifyingBaseFallbackTests.test_lookupc                    r  )
Nc                    r5  r   r6  r	  r8  r
   r   r    r:  z8VerifyingBaseFallbackTests.test_lookup1.<locals>._lookupr   r  r  r  r(  r)  rp   )rZ   r  r`   rL  ri   rq   r  rr   r  r
   r8  r   test_lookup1  r  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                    ra  r   r
   r\  r<  r
   r   	_factory1  rH   z?VerifyingBaseFallbackTests.test_adapter_hook.<locals>._factory1c                    ra  r   r
   r\  r=  r
   r   	_factory2  rH   z?VerifyingBaseFallbackTests.test_adapter_hook.<locals>._factory2c                         d d S r  r   r\  r(   r
   r   	_factory3  r#   z?VerifyingBaseFallbackTests.test_adapter_hook.<locals>._factory3c                    
     dS r   r7  r	  
_factoriesr
   r   r    r    z=VerifyingBaseFallbackTests.test_adapter_hook.<locals>._lookupr   r  r(  rp   )rZ   r  r`   rU  ri   r  rr   r   _cr  r  r  r  rV  rW  r1  rG   r!  re  r
   r  r<  r=  r   r   test_adapter_hook      

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                    ra  r   r
   r\  r  r
   r   r  $  rH   z?VerifyingBaseFallbackTests.test_queryAdapter.<locals>._factory1c                    ra  r   r
   r\  r  r
   r   r  &  rH   z?VerifyingBaseFallbackTests.test_queryAdapter.<locals>._factory2c                    r  r  r   r\  r(   r
   r   r  (  r#   z?VerifyingBaseFallbackTests.test_queryAdapter.<locals>._factory3c                    r  r   r  r	  r  r
   r   r  +  r    z=VerifyingBaseFallbackTests.test_queryAdapter.<locals>._lookupr   r  r(  rp   )rZ   r  r`   rs  ri   r  rr   rU  r  r
   r  r   rt  "  r  z,VerifyingBaseFallbackTests.test_queryAdapterc                       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                       t  dS r   rW   r7  r  r9  r
   r   rx  <  r#   z=VerifyingBaseFallbackTests.test_lookupAll.<locals>._lookupAllr   rz  r  r  rp   )rZ   r  r`   r}  rq   rW   r  rr   )r   
_results_1
_results_2rx  rG   r!  r+  r
   r  r   test_lookupAll8     
z)VerifyingBaseFallbackTests.test_lookupAllc                    r  )Nc                    r  r   r  r  r  r
   r   r  L  r#   zEVerifyingBaseFallbackTests.test_subscriptions.<locals>._subscriptionsr   r  r  r  rp   )rZ   r  r`   r  rq   rW   r  rr   )r   r  r  r  rG   r!  r+  r
   r  r   test_subscriptionsH  r  z-VerifyingBaseFallbackTests.test_subscriptionsr  )r   r   r	   r  r^   r`   r  r  r  r  rt  r  r  r
   r
   r
   r   r    s    
r  c                   @   r  )VerifyingBaseTestsc                 C   r?   )Nr   )VerifyingBase)rC   r  )r   r  r
   r
   r   r^   \  rE   z"VerifyingBaseTests._getTargetClassNr  r
   r
   r
   r   r  Y  r  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   r?   )Nr   )AdapterLookupBase)rC   r  )r   r  r
   r
   r   r^   c  rE   z&AdapterLookupBaseTests._getTargetClassc                 C   s   |   |S r   r_   rs   r
   r
   r   r`   g  r%   zAdapterLookupBaseTests._makeOnec                 G   s   G dd d}| S )Nc                   @   r  )z<AdapterLookupBaseTests._makeSubregistry.<locals>.Subregistryc                 S   s   g | _ g | _d S r   )r|   r   r(   r
   r
   r   r6   l     
zEAdapterLookupBaseTests._makeSubregistry.<locals>.Subregistry.__init__Nr7   r
   r
   r
   r   Subregistryk      r  r
   )r   rQ   r  r
   r
   r   _makeSubregistryj  s   z'AdapterLookupBaseTests._makeSubregistryc                 G   s   G dd d}||S )Nc                   @   r  )z6AdapterLookupBaseTests._makeRegistry.<locals>.Registryc                 S   s   || _ g | _d S r   )r   r  rP   r
   r
   r   r6   s  r  z?AdapterLookupBaseTests._makeRegistry.<locals>.Registry.__init__Nr7   r
   r
   r
   r   r  r  r  r  r
   )r   rQ   r  r
   r
   r   r  q  s   z$AdapterLookupBaseTests._makeRegistryc                 C   s$   |   }| |}| |ji  d S r   )r  r`   rq   rO   )r   rm   albr
   r
   r   test_ctor_empty_registryx  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  r`   rq   r   rO   keysr   r   r  r  r  rm   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                   @   r  )zAAdapterLookupBaseTests.test_changed_empty_required.<locals>.Mixinc                 W   rF   r   r
   r,   r
   r
   r   rM     rH   zIAdapterLookupBaseTests.test_changed_empty_required.<locals>.Mixin.changedNr   r   r	   rM   r
   r
   r
   r   Mixin  r  r  c                   @   r   )zCAdapterLookupBaseTests.test_changed_empty_required.<locals>.DerivedNr   r
   r
   r
   r   r    r   r  )rZ   r^   r  rM   )r   r  r  rm   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                   @   r  )z=AdapterLookupBaseTests.test_changed_w_required.<locals>.Mixinc                 W   rF   r   r
   r,   r
   r
   r   rM     rH   zEAdapterLookupBaseTests.test_changed_w_required.<locals>.Mixin.changedNr  r
   r
   r
   r   r    r  r  c                   @   r   )z?AdapterLookupBaseTests.test_changed_w_required.<locals>.DerivedNr   r
   r
   r
   r   r    r   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   
   || _ d S r   _here)r   herer
   r
   r   r6     r    zLAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.__init__c                 S   s   | j r| S d S r   r  r(   r
   r
   r   __call__  r#   zLAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.__call__c                 S   r  r   )_unsub)r   targetr
   r
   r   r     r    zOAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.unsubscribe)r   r   r	   r  r6   r  r   r
   r
   r
   r   FauxWeakref  s
    r  FTrp   r   )rZ   r^   r  	_requiredrM   rq   r'   r  )r   r  r  r  goner  rm   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|f}|  }| |}||g|_|  | t	|j
 t	|||g | |j
| ||g | |j
| |g | t	|j
| t	||g d S r  )r   r   r  r  r  r`   r   init_extendorsrq   r   rO   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|f}|  }| |}|| || | t|j	
 t|||g | |j	| ||g | |j	| |g | t|j	| t||g d S r  )r   r   r  r  r  r`   rR   rq   r   rO   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  r`   rX   rq   r   rO   r  r  r
   r
   r   test_remove_extendor  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  rp   )
r  r  r  r`   r  rq   r'   r  r   weakrefr   r  r  r  rm   r  resultr
   r
   r   test__uncached_lookup_empty_ro     
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;   r`   r  rq   r   r  r  r  rm   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  r|   r  r;   r`   rk   r  rq   r  r
   r
   r   $test__uncached_lookup_extendors_miss     

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  IQuxr   r  r  r  r  rZ   r|   r  r;   r`   rk   r  rq   
r   r  r  r  r  rm   r  
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  	wrongnamer  	r   r  r  r  rm   r  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|f}| ||}|  }t }i ||d|iiig|_|j| | |}||_	|
|f|}| || d S Nr   r  r  r  r   r  r  r  r  rZ   r|   r  r;   r`   rk   r  ri   )	r   r  r  r  rm   r  	_expectedr  r  r
   r
   r    test__uncached_lookup_simple_hit*     
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  rm   r  r  r  r  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                   @   r   )zFAdapterLookupBaseTests.test_queryMultiAdaptor_lookup_miss.<locals>.FooNr   r
   r
   r
   r   FooS      r   default)zope.interface.declarationsr  r  r  rZ   r  r  r|   r  r;   r`   r  r  rk   queryMultiAdapterri   )r   r  r  r  r  r   foorm   r  r  r1  r  r
   r
   r   "test_queryMultiAdaptor_lookup_missN  s&   
z9AdapterLookupBaseTests.test_queryMultiAdaptor_lookup_missc                    sl   ddl m} ddlm} |d |  }| |j_ fdd}tt	u}|j
| ||r0dndd	 d S )
Nr   r  )MissingSomeAttrsr  c                    s    | f S r   )r  )obr  r  r
   r   testr  s   zVAdapterLookupBaseTests.test_queryMultiAdapter_errors_on_attribute_access.<locals>.testrq  __providedBy__)expected_missing)r  r  zope.interface.testsr  r  r`   r  r  strbytestest_raises)r   r  r  rm   r  PY3r
   r
  r   1test_queryMultiAdapter_errors_on_attribute_accesse  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   r  r  r  r  c                   @   r   )zGAdapterLookupBaseTests.test_queryMultiAdaptor_factory_miss.<locals>.FooNr   r
   r
   r
   r   r     r  r   c                    r[  r   r%  r\  r&  r
   r   r`    r#   zLAdapterLookupBaseTests.test_queryMultiAdaptor_factory_miss.<locals>._factoryr   r  r  r  r  r  rZ   r  r  r|   r  r;   r`   r  r  rk   r  ri   rq   )r   r  r  r  r  r   r  rm   r  r  r`  r  r1  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   r  r  r  r  c                   @   r   )zFAdapterLookupBaseTests.test_queryMultiAdaptor_factory_hit.<locals>.FooNr   r
   r
   r
   r   r     r  r   c                    s     |  S r   r%  r\  r'  r  r
   r   r`    rk  zKAdapterLookupBaseTests.test_queryMultiAdaptor_factory_hit.<locals>._factoryr   r  r  )r   r  r  r  r  r   r  rm   r  r`  r  r1  r  r
   r  r   "test_queryMultiAdaptor_factory_hit  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                     ra  r   r
   r   factoryr
   r   r    rH   zKAdapterLookupBaseTests.test_queryMultiAdapter_super_unwraps.<locals>.lookupc                  W   s   | S r   r
   r  r
   r
   r   r    rH   zLAdapterLookupBaseTests.test_queryMultiAdapter_super_unwraps.<locals>.factory*   abc)r`   r  r  ro  r  r  rq   )r   r  r  objectsr  rp  r  r   $test_queryMultiAdapter_super_unwraps  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
   rp   )
r  r  r  r`   r  rq   r'   r  r   r  r  r
   r
   r   !test__uncached_lookupAll_empty_ro  r  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;   r`   rk   r  rq   r  r
   r
   r   #test__uncached_lookupAll_order_miss     
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  r|   r  r;   r`   rk   r  rq   r  r
   r
   r   'test__uncached_lookupAll_extendors_miss  r  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  r  r   r
   )r  r  r  r  rZ   r|   r  r;   r`   rk   r  rq   r  r
   r
   r   (test__uncached_lookupAll_components_miss     
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  )r   namedr   r'  )r  r  r  r  rZ   r|   r  r;   r`   rk   r  rq   r   
r   r  r  r  rm   r  r  _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 r&  )r  r  r  r  rZ   r|   r  r;   r`   r  r}  rk   namesrq   r   r(  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  r`   r  rq   r'   r  r   r  r  r
   r
   r   %test__uncached_subscriptions_empty_ro(  r  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;   r`   rk   r  rq   r  r
   r
   r   'test__uncached_subscriptions_order_miss3  r"  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  r   r  r;   r`   rk   r  rq   r  r
   r
   r   +test__uncached_subscriptions_extendors_miss?  r  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 r  r  r  r  r  rZ   r   r  r;   r`   rk   r  rq   r  r
   r
   r   8test__uncached_subscriptions_components_miss_wrong_ifaceL  r%  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 r  r0  r  r
   r
   r   7test__uncached_subscriptions_components_miss_wrong_name^  r  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                   @   r  )zKAdapterLookupBaseTests.test__uncached_subscriptions_simple_hit.<locals>.Fooc                 S   s   dS )NTr
   r,   r
   r
   r   __lt__v  rH   zRAdapterLookupBaseTests.test__uncached_subscriptions_simple_hit.<locals>.Foo.__lt__N)r   r   r	   r3  r
   r
   r
   r   r   u  r  r   r   )r  r  r  r  rZ   r   r  r;   r`   rk   r  rq   r   )r   r  r  r  rm   r  r   _exp1_exp2r  r  r
   r
   r   'test__uncached_subscriptions_simple_hito  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   r  r  r  r  c                   @   r   )z@AdapterLookupBaseTests.test_subscribers_wo_provided.<locals>.FooNr   r
   r
   r
   r   r     r  r   c                         dg |  d S Nr  
setdefaultr;   r\  _calledr
   r   r       zFAdapterLookupBaseTests.test_subscribers_wo_provided.<locals>._factory1c                    r7  Nr  r9  r\  r;  r
   r   r    r=  zFAdapterLookupBaseTests.test_subscribers_wo_provided.<locals>._factory2r   r
   )r  r  r  r  r  r  rZ   r  r  r   r  r;   r`   r  r  rk   subscribersrq   )r   r  r  r  r  r   r  rm   r  r  r  r  r  r
   r;  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   r  r  r  r  c                   @   r   )z?AdapterLookupBaseTests.test_subscribers_w_provided.<locals>.FooNr   r
   r
   r
   r   r     r  r   c                         dg |  S r8  r9  r\  )r<  r4  r
   r   r       zEAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._factory1c                    rB  r>  r9  r\  )r<  r5  r
   r   r    rC  zEAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._factory2c                    r7  )N_side_effect_onlyr9  r\  r;  r
   r   rD    r=  zMAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._side_effect_onlyr   )r  r  rD  r?  )r   r  r  r  r  r   r  rm   r  r  r  rD  r  r  r
   )r<  r4  r5  r   test_subscribers_w_provided  s<   
z2AdapterLookupBaseTests.test_subscribers_w_provided))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#  r$  r*  r,  r-  r.  r/  r1  r2  r6  rA  rE  r  r
   r
   rp  r   r  a  sL    r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )VerifyingAdapterRegistryTestsc                 C   r?   )Nr   )VerifyingAdapterRegistry)rC   rG  )r   rG  r
   r
   r   r^     rE   z-VerifyingAdapterRegistryTests._getTargetClassc                 O   s   |   |i |S r   r_   )r   r   kwr
   r
   r   r`     s   z&VerifyingAdapterRegistryTests._makeOnec                 C   s.   ddl m} ddlm} |  }||| d S )Nr   )verifyObject)IAdapterRegistry)zope.interface.verifyrI  zope.interface.interfacesrJ  r`   )r   rI  rJ  rm   r
   r
   r   ,test_verify_object_provides_IAdapterRegistry  s   zJVerifyingAdapterRegistryTests.test_verify_object_provides_IAdapterRegistryN)r   r   r	   r^   r`   rM  r
   r
   r
   r   rF    s    rF  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   r?   )Nr   )AdapterRegistry)rC   rO  )r   rO  r
   r
   r   r^     rE   z$AdapterRegistryTests._getTargetClassc                 C   s   |   }| t|jd d S r   )r`   rq   r'   _v_subregistries)r   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 r{   )r`   rq   r'   rP  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{   r`   ry   rq   r'   rP  r   r   beforeafterrT  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 )Nry   r   rp   )r`   __dict__r;   ry   rq   r'   rP  r   )r   rX  strayrY  rT  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 ro   rV  rW  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   r  r   rJ   )r   originally_changedr
   r
   r   rM     r    zJAdapterRegistryTests.test_changed_w_subregistries.<locals>.Derived.changed)r   r   r	   rK   rM   r
   r
   r
   r   r    s    r  )r`   rZ   _addSubregistryrM   ri   rK   )r   rS  r  derived1derived2rL   r
   r
   r   test_changed_w_subregistries  s   


z1AdapterRegistryTests.test_changed_w_subregistriesN)
r   r   r	   r^   rR  rU  rZ  r]  r^  rc  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 | d S )Nr   _convert_None_to_Interfacer   )rC   rf  r  r   ri   )r   rf  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   re  )rC   rf  rZ   ri   )r   rf  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   strr  )rC   rj  rq   r}   r+   )r   rj  STRUNICODE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   ri  ustr)rC   rj  rq   )r   rj  USTRr
   r
   r   test__normalize_name_unicode1  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   ri  rp   g      ?r
   )rC   rj  rZ   r   	TypeError)r   rj  r-   r
   r
   r   test__normalize_name_other7  s   z%Test_utils.test__normalize_name_otherN)r   r   r	   rg  rh  rn  rq  rs  r
   r
   r
   r   rd    s    rd  )r  unittestr  r   r   rZ   r   r2   r9   r<   r=   TestCaser>   r   r  r  r  r  r  rF  rN  rd  r
   r
   r
   r   <module>   sF   	     U2  K     k@