a
    §ˆc8%  ã                   @   sJ   d Z ddlZddlmZ ddlmZmZ G dd„ dƒZG dd„ deƒZdS )	zw Define the registry object responsible for collecting and reporting
implementations for testing various GUI elements.
é    N)ÚAbstractTargetRegistry)ÚInteractionNotSupportedÚLocationNotSupportedc                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú_TargetToKeyRegistryz±Perform the mapping from target to a key to a callable.

    Internally this is a dict(type, dict(type, callable)), but expose a few
    methods for better error reporting.
    c                 C   s   i | _ || _dS )a	  Initializer

        Parameters
        ----------
        exception_maker : callable(target_class, key, available_keys)
            A callable that return an exception for when no values are referred
            to by a given pair of target_class and key.
        N)Ú_target_to_key_to_valueÚexception_maker)Úselfr   © r	   új/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/testing/tester/target_registry.pyÚ__init__"   s    	z_TargetToKeyRegistry.__init__c                 C   s2   | j  |i ¡}||v r&td ||¡ƒ‚|||< d S )Nz4A value for target {!r} and key {!r} already exists.)r   Ú
setdefaultÚ
ValueErrorÚformat)r   Útarget_classÚkeyÚvalueÚaction_to_handlerr	   r	   r
   Úregister.   s    ÿÿÿz_TargetToKeyRegistry.registerc                 C   s2   | j  |g ¡}||vr*| j||t|ƒd�‚|| S )N©r   r   Zavailable_keys)r   Úgetr   Úlist)r   r   r   r   r	   r	   r
   Ú	get_value9   s    ýz_TargetToKeyRegistry.get_valuec                 C   s   t | j |g ¡ƒS )zìReturn all the keys for the given target.

        Parameters
        ----------
        target_class : subclass of type
            The type of a UI target being operated on.

        Returns
        -------
        keys : set
        )Úsetr   r   )r   r   r	   r	   r
   Úget_keysC   s    z_TargetToKeyRegistry.get_keysN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r	   r	   r	   r
   r      s
   
r   c                   @   sX   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S )ÚTargetRegistryaÎ  An object for registering interaction and location resolution logic
    for different UI target types.

    ``register_interaction`` supports extending ``UIWrapper.perform`` and
    ``UIWrapper.inspect`` for a given UI target type and interaction type.

    ``register_location`` supports extending ``UIWrapper.locate`` for a given
    UI target type and location type.

    See :ref:`testing-how-extension-works` in the User Manual for further
    details.
    c                 C   s$   t dd„ d�| _t dd„ d�| _d S )Nc                 S   s   t | ||d�S )N)r   Úinteraction_classÚ	supported)r   r   r	   r	   r
   Ú<lambda>c   s
    ýz)TargetRegistry.__init__.<locals>.<lambda>)r   c                 S   s   t | ||d�S )N)r   Úlocator_classr    )r   r   r	   r	   r
   r!   n   s   ý)r   Ú_interaction_registryÚ_location_registry)r   r	   r	   r
   r   `   s    þþzTargetRegistry.__init__c                 C   s   | j j|||d� dS )a…  Register a handler for a given target type and interaction type.

        Parameters
        ----------
        target_class : subclass of type
            The type of a UI target being operated on.
        interaction_class : subclass of type
            Any class.
        handler : callable(UIWrapper, interaction) -> any
            The function to handle the particular interaction on a target.
            ``interaction`` should be an instance of ``interaction_class``.

        Raises
        ------
        ValueError
            If a handler has already be registered for the same target type
            and interaction class.
        ©r   r   r   N)r#   r   )r   r   r   Úhandlerr	   r	   r
   Úregister_interactionv   s
    ýz#TargetRegistry.register_interactionc                 C   s   | j j|j|jd�S )a7  Return a callable for handling an interaction for a given target.

        Parameters
        ----------
        target : any
            The UI target being operated on.
        interaction : any
            Any interaction object.

        Returns
        -------
        handler : callable(UIWrapper, interaction) -> any
            The function to handle the given interaction on a target.

        Raises
        ------
        InteractionNotSupported
            If the given target and interaction types are not supported
            by this registry.
        ©r   r   )r#   r   Ú	__class__)r   ÚtargetZinteractionr	   r	   r
   Ú_get_handler�   s    þzTargetRegistry._get_handlerc                 C   s   | j j|jd�S )aO  Returns all the interactions supported for the given target.

        Parameters
        ----------
        target : any
            The UI target for which supported interactions are queried.

        Returns
        -------
        interaction_classes : set
            Supported interaction types for the given target type.
        ©r   )r#   r   r)   ©r   r*   r	   r	   r
   Ú_get_interactions©   s    ÿz TargetRegistry._get_interactionsc                 C   s   | j j|j|d� t |¡S )aé  Return the documentation for the given target and interaction type.

        Parameters
        ----------
        target : any
            The UI target for which the interaction will be applied.
        interaction_class : subclass of type
            Any class.

        Returns
        -------
        doc : str

        Raises
        ------
        InteractionNotSupported
            If the given target and interaction types are not supported
            by this registry.
        r(   )r#   r   r)   ÚinspectÚgetdoc)r   r*   r   r	   r	   r
   Ú_get_interaction_docº   s
    þz#TargetRegistry._get_interaction_docc                 C   s   | j j|||d� dS )a”  Register a solver for resolving the next UI target for the given
        target type and locator type.

        Parameters
        ----------
        target_class : subclass of type
            The type of a UI target being operated on.
        locator_class : subclass of type
            Any class.
        solver : callable(UIWrapper, location) -> any
            A callable for resolving a location into a new target.
            The location argument will be an instance of locator_class.

        Raises
        ------
        ValueError
            If a solver has already been registered for the given target
            type and locator type.
        r%   N)r$   r   )r   r   r"   Zsolverr	   r	   r
   Úregister_locationÕ   s
    ýz TargetRegistry.register_locationc                 C   s   | j j|j|jd�S )a®  Return a callable registered for resolving a location for the
        given target and location.

        Parameters
        ----------
        target : any
            The UI target being operated on.
        location : subclass of type
            The location to be resolved on the target.

        Raises
        ------
        LocationNotSupported
            If the given locator and target types are not supported.
        r(   )r$   r   r)   )r   r*   Úlocationr	   r	   r
   Ú_get_solverï   s    þzTargetRegistry._get_solverc                 C   s   | j j|jd�S )aL  Returns all the location types supported for the given target.

        Parameters
        ----------
        target : any
            The UI target for which supported location types are queried.

        Returns
        -------
        locators_classes : set
            Supported locator types for the given target type.
        r,   )r$   r   r)   r-   r	   r	   r
   Ú_get_locations  s    zTargetRegistry._get_locationsc                 C   s   | j j|j|d� t |¡S )a¥  Return the documentation for the given target and locator type.

        Parameters
        ----------
        target : any
            The UI target being operated on.
        locator_class : subclass of type
            Any class.

        Returns
        -------
        doc : str

        Raises
        ------
        LocationNotSupported
            If the given locator and target types are not supported.
        r(   )r$   r   r)   r/   r0   )r   r*   r"   r	   r	   r
   Ú_get_location_doc  s
    þz TargetRegistry._get_location_docN)r   r   r   r   r   r'   r+   r.   r1   r2   r4   r5   r6   r	   r	   r	   r
   r   R   s   r   )	r   r/   Z1traitsui.testing.tester._abstract_target_registryr   Z"traitsui.testing.tester.exceptionsr   r   r   r   r	   r	   r	   r
   Ú<module>   s
   7