o
    >h|:                    @   s"  d Z ddlZddlmZ dd ZG d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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
   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-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   IR00   r   r   c                   @   r   )z_makeInterfaces.<locals>.IR1Nr   r
   r
   r
   r   IR13   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__?      
zCustomDataTypeBase.__getitem__c                 C   s   || j |< d S r   r   )r   r   valuer
   r
   r   __setitem__B      zCustomDataTypeBase.__setitem__c                 C   s   | j |= d S r   r   r   r
   r
   r   __delitem__E      zCustomDataTypeBase.__delitem__c                 C   
   t | jS r   )lenr   r   r
   r
   r   __len__H   r    zCustomDataTypeBase.__len__c                 C   s
   || j v S r   r   r   r
   r
   r   __contains__K   r    zCustomDataTypeBase.__contains__c                 C   s,   || u rdS t |t | urdS |j| jkS )NTF)typer   r   otherr
   r
   r   __eq__N   s
   zCustomDataTypeBase.__eq__c                 C   r&   r   )reprr   r(   r
   r
   r   __repr__V   r    zCustomDataTypeBase.__repr__)r   r   r	   r   r   r"   r$   r)   r*   r.   r0   r
   r
   r
   r   r   <   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__[   s
   
zCustomMapping.__init__r   r   r   r	   r6   r
   r
   r
   r   r2   Z       r2   c                   @   r1   )CustomSequenceNc                 C   s$   g | _ |r| j | | j j| _d S r   )r   extendappendr,   r
   r
   r   r6   d   s   zCustomSequence.__init__r   r7   r
   r
   r
   r   r9   c   r8   r9   c                   @   r   )CustomLeafSequenceNr   r
   r
   r
   r   r<   k   r   r<   c                   @   r   )CustomProvidedNr   r
   r
   r
   r   r=   o   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   _getBaseAdapterRegistryw      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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         zKBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.__init__c                 S      |  j |f7  _ d S r   _changed)r   origr
   r
   r   changed      zJBaseAdapterRegistryTests._getTargetClass.<locals>._CUT.LookupClass.changedc                 S   rI   r   )
_extendorsr   providedr
   r
   r   add_extendor   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   LookupClass   s    rY   N)r   r   r	   rY   r
   r
   r
   r   _CUT~   s    rZ   )rD   
_delegatedsetattrrY   object)r   rA   rZ   r   r
   r
   r   _getTargetClass{   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`   r]   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   s0   G dd d}|   }|f|_| |jd d S )Nc                   @   r   )zQBaseAdapterRegistryTests.test__generation_after_changing___bases__.<locals>._BaseNr   r
   r
   r
   r   _Base   r   rx   rv   )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   s2   

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   addValueP     
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   sf   '

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   r]   r   r   r   r   r   r   r   r   r   r   rm   r
   r
   r   test_register_with_invalid_namea  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_unregistersi  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`   r]   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_valueu  s4   
	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_empty  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_miss  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_hit  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`   r]   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`   r]   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  sJ   


	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`   r]   	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   assertLeafIdentity0  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`   r]   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<  s\   

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`   r]   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_providedr  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_provided  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_empty  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_miss  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`   r]   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`   r]   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_providedK  s   zYBaseAdapterRegistryTests.test_subscribe_multiple_allRegistrations.<locals>.build_providedr   r
   c                 S   r   r   r   r   r
   r
   r   r   p  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  st   $



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>   s   sX    

k,6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     rH   z3CustomTypesBaseAdapterRegistryTests._getMappingTypec                 C   ra   r   )r=   r(   r
   r
   r   re     rH   z4CustomTypesBaseAdapterRegistryTests._getProvidedTypec                 C   ra   r   )r9   r(   r
   r
   r   rg     rH   z7CustomTypesBaseAdapterRegistryTests._getMutableListTypec                 C   ra   r   )r<   r(   r
   r
   r   rh     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     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   CustomAdapterRegistry  s    r  rB   )r   r  r
   r  r   rD     s   z;CustomTypesBaseAdapterRegistryTests._getBaseAdapterRegistryc                 C   s   |  || d S r   )ri   r   r
   r
   r   r     s   z6CustomTypesBaseAdapterRegistryTests.assertLeafIdentityN)
r   r   r	   __doc__rd   re   rg   rh   rD   r   r
   r
   r
   r   r     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   _getFallbackClass  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_lookup  rH   z3LookupBaseFallbackTests._makeOne.<locals>.uc_lookupc                 S      t  r   NotImplementedErrorr   r
  rQ   r
   r
   r   uc_lookupAll     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`     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   lookupr]   r   r  lbr
   r
   r   test_lookup_w_invalid_name  
   "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*  r]   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*  r0  r   abcr  r!  r,  r
   r9  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                    r6  r   r7  r	  r9  r
   r   r    r;  z;LookupBaseFallbackTests.test_lookup_cached.<locals>._lookupr  r  r  r)  r*  r0  r<  r
   r9  r   test_lookup_cached     
z*LookupBaseFallbackTests.test_lookup_cachedc                    r5  )Nc                    r6  r   r7  r	  r9  r
   r   r    r;  zNLookupBaseFallbackTests.test_lookup_not_cached_multi_required.<locals>._lookupr  r  Dr  r)  rE  r  r)  r0  r<  r
   r9  r   %test_lookup_not_cached_multi_required  rA  z=LookupBaseFallbackTests.test_lookup_not_cached_multi_requiredc                    rB  )Nc                    r6  r   r7  r	  r9  r
   r   r  +  r;  zJLookupBaseFallbackTests.test_lookup_cached_multi_required.<locals>._lookupr  rE  r  r)  rG  r0  r<  r
   r9  r   !test_lookup_cached_multi_required&  rD  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                    r6  r   r7  r	  r9  r
   r   r  ;  r;  zMLookupBaseFallbackTests.test_lookup_not_cached_after_changed.<locals>._lookupr  r  r  r)  r*  )r]   r`   r  rM   ri   rq   r<  r
   r9  r   $test_lookup_not_cached_after_changed6     

z<LookupBaseFallbackTests.test_lookup_not_cached_after_changedc                 C   r  )Nc                 S   r   r  r   r	  r
   r
   r   r  J  r#   zDLookupBaseFallbackTests.test_lookup1_w_invalid_name.<locals>._lookupr  r  r  )r`   r   r   lookup1r]   r   r
   r
   r   test_lookup1_w_invalid_nameH  r#  z3LookupBaseFallbackTests.test_lookup1_w_invalid_namec                    r$  )Nc                    r%  r   r&  r	  r'  r
   r   r  T  rN   zELookupBaseFallbackTests.test_lookup1_miss_no_default.<locals>._lookupr  r  r  r)  r*  )r`   rM  r   rq   r+  r
   r'  r   test_lookup1_miss_no_defaultQ  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*  r]   r`   rM  ri   rq   r1  r
   r'  r   test_lookup1_miss_w_default\  r4  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  l  rN   zSLookupBaseFallbackTests.test_lookup1_miss_w_default_negative_cache.<locals>._lookupr  r  r  r)  r*  rP  r1  r
   r'  r   *test_lookup1_miss_w_default_negative_cacheh  s   zBLookupBaseFallbackTests.test_lookup1_miss_w_default_negative_cachec                    r5  )Nc                    r6  r   r7  r	  r9  r
   r   r  {  r;  z@LookupBaseFallbackTests.test_lookup1_not_cached.<locals>._lookupr  r  r  r)  r*  rP  r<  r
   r9  r   test_lookup1_not_cachedv  rA  z/LookupBaseFallbackTests.test_lookup1_not_cachedc                    rB  )Nc                    r6  r   r7  r	  r9  r
   r   r    r;  z<LookupBaseFallbackTests.test_lookup1_cached.<locals>._lookupr  r  r  r)  r*  rP  r<  r
   r9  r   test_lookup1_cached  rD  z+LookupBaseFallbackTests.test_lookup1_cachedc                    rJ  )Nc                    r6  r   r7  r	  r9  r
   r   r    r;  zNLookupBaseFallbackTests.test_lookup1_not_cached_after_changed.<locals>._lookupr  r  r  r)  r*  )r]   r`   rM  rM   ri   rq   r<  r
   r9  r   %test_lookup1_not_cached_after_changed  rL  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   )r]   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   )r]   r`   rV  r   )r   rW  rX  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 r   )r]   r`   rV  ri   )r   rW  rX  r2  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                         |  d S r   r&  context_f_called_withr
   r   _factory  r#   zTLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_None.<locals>._factoryc                        S r   r
   r	  ra  r
   r   r    rH   zSLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_None.<locals>._lookupr  r)  r]   r`   rV  ri   rq   r   r  rW  rX  r2  r!  adaptedr
   r`  ra  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 r   r&  r]  _adapterr`  r
   r   ra       
zWLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_adapter.<locals>._factoryc                    rb  r   r
   r	  rc  r
   r   r    rH   zVLookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_adapter.<locals>._lookupr  r)  rd  re  r
   rk  r`  ra  r   -test_adapter_hook_hit_factory_returns_adapter     zELookupBaseFallbackTests.test_adapter_hook_hit_factory_returns_adapterc                    s`   g   fdddfdd	}t  }t }| j|d}|||}| ||  |  | g d S )Nc                    s     |  | S r   r&  r]  r_  r
   r   ra    rl  zILookupBaseFallbackTests.test_adapter_hook_super_unwraps.<locals>._factoryr   c                    rb  r   r
   r	  rc  r
   r   r    rH   zHLookupBaseFallbackTests.test_adapter_hook_super_unwraps.<locals>._lookupr  )r   )superr]   r`   rV  ri   rq   )r   r  r
  rQ   r!  rf  	__class__rg  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                    ri  r   r&  r]  rj  r
   r   ra    rl  z;LookupBaseFallbackTests.test_queryAdapter.<locals>._factoryc                    rb  r   r
   r	  rc  r
   r   r    rH   z:LookupBaseFallbackTests.test_queryAdapter.<locals>._lookupr  r)  )r]   r`   queryAdapterri   rq   re  r
   rm  r   test_queryAdapter  ro  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  r9  r
   r   
_lookupAll     zCLookupBaseFallbackTests.test_lookupAll_uncached.<locals>._lookupAllr  r  r  r  r  r]   r`   	lookupAllrq   rW   r   ry  r!  r,  r
   r9  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                    rw  r   rx  r  r9  r
   r   ry    rz  zALookupBaseFallbackTests.test_lookupAll_cached.<locals>._lookupAllr{  r  r  r|  r}  r  r
   r9  r   test_lookupAll_cached     z-LookupBaseFallbackTests.test_lookupAll_cachedc                    rv  )Nc                    rw  r   rx  r  r9  r
   r   _subscriptions  rz  zKLookupBaseFallbackTests.test_subscriptions_uncached.<locals>._subscriptionsr  r  r  r|  r]   r`   subscriptionsrq   rW   r   r  r!  r,  r
   r9  r   test_subscriptions_uncached  r  z3LookupBaseFallbackTests.test_subscriptions_uncachedc                    r  )Nc                    rw  r   rx  r  r9  r
   r   r  '  rz  zILookupBaseFallbackTests.test_subscriptions_cached.<locals>._subscriptionsr  r  r  r|  r  r  r
   r9  r   test_subscriptions_cached#  r  z1LookupBaseFallbackTests.test_subscriptions_cachedNNN)!r   r   r	   r  r^   r`   r"  r-  r3  r@  rC  rH  rI  rK  rN  rO  rQ  rR  rS  rT  rU  rY  rZ  r[  rh  rn  rs  ru  r  r  r  r  __classcell__r
   r
   rq  r   r    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^   5  rE   zLookupBaseTests._getTargetClassNr   r   r	   r^   r
   r
   r
   r   r  2      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                    sb    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  G  r  z6VerifyingBaseFallbackTests._makeOne.<locals>.uc_lookupc                 S   r  r   r  r  r
   r
   r   r  L  r  z9VerifyingBaseFallbackTests._makeOne.<locals>.uc_lookupAllc                 S   r  r   r  r  r
   r
   r   r  Q  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   )rp  r6   	_registryrs   rq  r
   r   r6   Y  s   

z=VerifyingBaseFallbackTests._makeOne.<locals>.Derived.__init__)r   r   r	   r  r  r  r6   r  r
   r  rq  r   r  T  s
    r  )r^   rM   )r   rm   r  r  r  r  derivedr
   r  r   r`   B  s   	
z#VerifyingBaseFallbackTests._makeOnec                    s(   G dd d 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   WithGenerationc  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   h  s    zWVerifyingBaseFallbackTests._makeRegistry.<locals>.Registry.__init__.<locals>.<listcomp>)rangero)r   depthr  r
   r   r6   g  s   zCVerifyingBaseFallbackTests._makeRegistry.<locals>.Registry.__init__Nr7   r
   r  r
   r   Registryf  s    r  r
   )r   r  r  r
   r  r   _makeRegistrya  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                    r6  r   r7  r	  r9  r
   r   r  q  r;  z7VerifyingBaseFallbackTests.test_lookup.<locals>._lookupr   r  r  r  r)  r*  rp   )r]   r  r`   r  ri   rq   r  rr   r   r=  r>  r?  r  rG   r!  r,  r
   r9  r   test_lookupl  $   

z&VerifyingBaseFallbackTests.test_lookupc                    r  )
Nc                    r6  r   r7  r	  r9  r
   r   r    r;  z8VerifyingBaseFallbackTests.test_lookup1.<locals>._lookupr   r  r  r  r)  r*  rp   )r]   r  r`   rM  ri   rq   r  rr   r  r
   r9  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                    rb  r   r
   r]  r=  r
   r   	_factory1  rH   z?VerifyingBaseFallbackTests.test_adapter_hook.<locals>._factory1c                    rb  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   r8  r	  
_factoriesr
   r   r    r    z=VerifyingBaseFallbackTests.test_adapter_hook.<locals>._lookupr   r  r)  rp   )r]   r  r`   rV  ri   r  rr   r   _cr  r  r  r  rW  rX  r2  rG   r!  rf  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                    rb  r   r
   r]  r  r
   r   r    rH   z?VerifyingBaseFallbackTests.test_queryAdapter.<locals>._factory1c                    rb  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   )r]   r  r`   rt  ri   r  rr   rV  r  r
   r  r   ru    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   r8  r  r:  r
   r   ry    r#   z=VerifyingBaseFallbackTests.test_lookupAll.<locals>._lookupAllr   r{  r  r  rp   )r]   r  r`   r~  rq   rW   r  rr   )r   
_results_1
_results_2ry  rG   r!  r,  r
   r  r   test_lookupAll     
z)VerifyingBaseFallbackTests.test_lookupAllc                    r  )Nc                    r  r   r  r  r  r
   r   r    r#   zEVerifyingBaseFallbackTests.test_subscriptions.<locals>._subscriptionsr   r  r  r  rp   )r]   r  r`   r  rq   rW   r  rr   )r   r  r  r  rG   r!  r,  r
   r  r   test_subscriptions  r  z-VerifyingBaseFallbackTests.test_subscriptionsr  )r   r   r	   r  r^   r`   r  r  r  r  ru  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    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^     rE   z&AdapterLookupBaseTests._getTargetClassc                 C   s   |   |S r   r_   rs   r
   r
   r   r`     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        
zEAdapterLookupBaseTests._makeSubregistry.<locals>.Subregistry.__init__Nr7   r
   r
   r
   r   Subregistry
      r  r
   )r   rQ   r  r
   r
   r   _makeSubregistry  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     r  z?AdapterLookupBaseTests._makeRegistry.<locals>.Registry.__init__Nr7   r
   r
   r
   r   r    r  r  r
   )r   rQ   r  r
   r
   r   r    s   z$AdapterLookupBaseTests._makeRegistryc                 C   s$   |   }| |}| |ji  d S r   )r  r`   rq   rO   )r   rm   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  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   sB   G dd d}G dd d|   |}|  }||}|| d S )Nc                   @   r  )zAAdapterLookupBaseTests.test_changed_empty_required.<locals>.Mixinc                 W   rF   r   r
   r,   r
   r
   r   rM   1  rH   zIAdapterLookupBaseTests.test_changed_empty_required.<locals>.Mixin.changedNr   r   r	   rM   r
   r
   r
   r   Mixin0  r  r  c                   @   r   )zCAdapterLookupBaseTests.test_changed_empty_required.<locals>.DerivedNr   r
   r
   r
   r   r  4  r   r  )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}G dd d|   |}G dd d}|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  B  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   H  r    zLAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.__init__c                 S   s   | j r| S d S r   r  r(   r
   r
   r   __call__K  r#   zLAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.__call__c                 S   r  r   )_unsub)r   targetr
   r
   r   r   N  r    zOAdapterLookupBaseTests.test_changed_w_required.<locals>.FauxWeakref.unsubscribe)r   r   r	   r  r6   r  r   r
   r
   r
   r   FauxWeakrefE  s
    r  FTrp   r   )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_extendorl  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  r]   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  r]   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}| }|  }|  }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   Foo      r   default)zope.interface.declarationsr  r  r  r  r  r|   r  r;   r`   r  r  rk   r]   queryMultiAdapterri   )r   r  r  r  r  r   foorm   r  r  r2  r  r
   r
   r   "test_queryMultiAdaptor_lookup_miss   s&   
z9AdapterLookupBaseTests.test_queryMultiAdaptor_lookup_missc                    s\   ddl m} ddlm} |d |  }| |j_ fdd}|j| |dd d S )	Nr   r  )MissingSomeAttrsr  c                    s    | f S r   )r  )obr  r  r
   r   test'  s   zVAdapterLookupBaseTests.test_queryMultiAdapter_errors_on_attribute_access.<locals>.testrr  )expected_missing)	r  r  zope.interface.testsr  r  r`   r  r  test_raises)r   r  r  rm   r  r
   r
  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}| }| ||}|  }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   5  r  r   c                    r\  r   r&  r]  r'  r
   r   ra  >  r#   zLAdapterLookupBaseTests.test_queryMultiAdaptor_factory_miss.<locals>._factoryr   r  )r  r  r  r  r  r  r|   r  r;   r`   r  r  rk   r]   r  ri   rq   r   r  r  r  r  r   r  rm   r  ra  r  r2  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 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   T  r  r   c                    s     |  S r   r&  r]  r(  r  r
   r   ra  ^  rl  zKAdapterLookupBaseTests.test_queryMultiAdaptor_factory_hit.<locals>._factoryr   r  )r  r  r  r  r  r  r]   r|   r  r;   r`   r  r  rk   r  ri   rq   r  r
   r  r   "test_queryMultiAdaptor_factory_hitN  s.   
z9AdapterLookupBaseTests.test_queryMultiAdaptor_factory_hitc                    s\   |  |  } fdd}dd  ||_t ddt g}||d }| || dd| f d S )Nc                     rb  r   r
   r   factoryr
   r   r  r  rH   zKAdapterLookupBaseTests.test_queryMultiAdapter_super_unwraps.<locals>.lookupc                  W   s   | S r   r
   r  r
   r
   r   r  u  rH   zLAdapterLookupBaseTests.test_queryMultiAdapter_super_unwraps.<locals>.factory*   abc)r`   r  r  rp  r  rq   )r   r  r  objectsr  rq  r  r   $test_queryMultiAdapter_super_unwrapso  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  r]   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  r]   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  r]   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_miss  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  r]   r   r  r;   r`   rk   r  rq   r  r
   r
   r   8test__uncached_subscriptions_components_miss_wrong_iface  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  r,  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}| | }}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__4  rH   zRAdapterLookupBaseTests.test__uncached_subscriptions_simple_hit.<locals>.Foo.__lt__N)r   r   r	   r/  r
   r
   r
   r   r   2  s    r   r   )r  r  r  r  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_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}| }| ||}| ||}|  }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   H  r  r   c                         dg |  d S Nr  
setdefaultr;   r]  _calledr
   r   r  R     zFAdapterLookupBaseTests.test_subscribers_wo_provided.<locals>._factory1c                    r3  Nr  r5  r]  r7  r
   r   r  U  r9  zFAdapterLookupBaseTests.test_subscribers_wo_provided.<locals>._factory2r   r
   )r  r  )r  r  r  r  r  r  r   r  r;   r`   r  r  rk   subscribersrq   )r   r  r  r  r  r   r  rm   r  r  r  r  r  r
   r7  r   test_subscribers_wo_providedB  s.   
z3AdapterLookupBaseTests.test_subscribers_wo_providedc                    s  ddl m} ddlm} |d}|d|f}||G dd d}| }| ||}| ||}|  }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   j  r  r   c                         dg |  S r4  r5  r]  )r8  r0  r
   r   r  u     zEAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._factory1c                    r=  r:  r5  r]  )r8  r1  r
   r   r  y  r>  zEAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._factory2c                    r3  )N_side_effect_onlyr5  r]  r7  r
   r   r?  }  r9  zMAdapterLookupBaseTests.test_subscribers_w_provided.<locals>._side_effect_onlyr   )r  r  r?  )r  r  r  r  r  r  r]   r   r  r;   r`   r  r  rk   r;  rq   )r   r  r  r  r  r   r  rm   r  r  r  r?  r  r  r
   )r8  r0  r1  r   test_subscribers_w_providedd  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+  r-  r.  r2  r<  r@  r  r
   r
   rq  r   r    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   rB  )r   rB  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   )IAdapterRegistry)verifyObject)zope.interface.interfacesrD  zope.interface.verifyrE  r`   )r   rD  rE  rm   r
   r
   r   ,test_verify_object_provides_IAdapterRegistry  s   zJVerifyingAdapterRegistryTests.test_verify_object_provides_IAdapterRegistryN)r   r   r	   r^   r`   rH  r
   r
   r
   r   rA    s    rA  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   rJ  )r   rJ  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'   rK  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'   rK  r   r   beforeafterrO  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'   rK  r   )r   rS  strayrT  rO  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   rQ  rR  r
   r
   r   *test__setBases_w_existing_entry_continuing  s   
z?AdapterRegistryTests.test__setBases_w_existing_entry_continuingc                 C   sh   |   }G dd d}| | }}|| || 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`   _addSubregistryr]   rM   ri   rK   )r   rN  r  derived1derived2rL   r
   r
   r   test_changed_w_subregistries  s   


z1AdapterRegistryTests.test_changed_w_subregistriesN)
r   r   r	   r^   rM  rP  rU  rX  rY  r^  r
   r
   r
   r   rI    s    		
rI  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   ra  r  r   ri   )r   ra  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`  )rC   ra  r]   ri   )r   ra  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   strstr)rC   re  rq   r}   r+   )r   re  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   rd  ustr)rC   re  rq   )r   re  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   rd  rp   g      ?r
   )rC   re  r]   r   	TypeError)r   re  r-   r
   r
   r   test__normalize_name_other	  s   z%Test_utils.test__normalize_name_otherN)r   r   r	   rb  rc  rj  rm  ro  r
   r
   r
   r   r_    s    r_  )r  unittestr  r   r   r   r2   r9   r<   r=   TestCaser>   r   r  r  r  r  r  rA  rI  r_  r
   r
   r
   r   <module>   sJ   $	      3  ~ >     C