a
    ©ˆc"  ã                   @   sf   d Z ddlZddlmZmZ ddlmZ ddlmZmZm	Z	m
Z
 G dd„ deƒZG dd	„ d	ejƒZdS )
ú Tests for extension points. é    N)ÚApplicationÚExtensionPoint)ÚExtensionRegistry)Ú	HasTraitsÚIntÚListÚ
TraitErrorc                   @   s   e Zd ZdZdZdS )ÚTestBasezE Base class for all test classes that use the 'ExtensionPoint' type. N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úextension_registry© r   r   úf/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/envisage/tests/test_extension_point.pyr
      s   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d„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedfdd„ZdS )ÚExtensionPointTestCaser   c                 C   s   t tƒ d�| _| jt_dS )z> Prepares the test fixture before each test method is called. )r   N)r   r   Úregistryr
   r   ©Úselfr   r   r   ÚsetUp   s    zExtensionPointTestCase.setUpc                 C   s8   |   t¡� ttdƒ W d  ƒ n1 s*0    Y  dS )z invalid extension point type úmy.epN)ÚassertRaisesÚ	TypeErrorr   r   r   r   r   r   Ú!test_invalid_extension_point_type(   s    z8ExtensionPointTestCase.test_invalid_extension_point_typec                 C   sp   | j }| |  d¡¡ | dd¡ G dd„ dtƒ}|ƒ }|  t¡� t|dƒ W d  ƒ n1 sb0    Y  dS )z$ no reference to extension registry r   Úxxxc                   @   s   e Zd Zeeeƒdd�ZdS )zKExtensionPointTestCase.test_no_reference_to_extension_registry.<locals>.Foor   ©ÚidN©r   r   r   r   r   r   Úxr   r   r   r   ÚFoo<   s   r    r   N)r   Úadd_extension_pointÚ_create_extension_pointÚset_extensionsr   r   Ú
ValueErrorÚgetattr©r   r   r    Úfr   r   r   Ú'test_no_reference_to_extension_registry0   s    z>ExtensionPointTestCase.test_no_reference_to_extension_registryc                 C   s¨   | j }| |  d¡¡ G dd„ dtƒ}|ƒ }t |¡ | dg d¢¡ |  dt|j	ƒ¡ |  g d¢|j	¡ |  
|j¡ d|_t |¡ | dg d¢¡ |  d|j¡ dS )	z extension point changed r   c                   @   s   e Zd Zedd�Zdd„ ZdS )z@ExtensionPointTestCase.test_extension_point_changed.<locals>.Foor   r   c                 S   s
   d| _ dS )z Static trait change handler. TN)Úx_changed_calledr   r   r   r   Ú
_x_changedQ   s    zKExtensionPointTestCase.test_extension_point_changed.<locals>.Foo._x_changedN)r   r   r   r   r   r*   r   r   r   r   r    N   s   
r    ©é*   za stringTé   F)éb   éc   éd   N)r   r!   r"   r
   r   Zconnect_extension_point_traitsr#   ÚassertEqualÚlenr   Ú
assertTruer)   Z!disconnect_extension_point_traitsr&   r   r   r   Útest_extension_point_changedE   s    

z3ExtensionPointTestCase.test_extension_point_changedc                 C   st   | j }| |  d¡¡ | dg d¢¡ G dd„ dtƒ}|ƒ }|j d¡ |  | d¡g d¢¡ |  |jg d¢¡ dS )z: Extension point is recomputed so mutation has no effect. r   )é   é   r-   c                   @   s   e Zd Zeeeƒdd�ZdS )zIExtensionPointTestCase.test_mutate_extension_point_no_effect.<locals>.Foor   r   Nr   r   r   r   r   r    ~   s   r    r,   N)	r   r!   r"   r#   r
   r   Úappendr1   Úget_extensionsr&   r   r   r   Ú%test_mutate_extension_point_no_effectr   s    z<ExtensionPointTestCase.test_mutate_extension_point_no_effectc                 C   sŽ   | j }| |  d¡¡ | dg d¢¡ G dd„ dtƒ}|ƒ }|  dt|jƒ¡ |  g d¢|j¡ |ƒ }|  dt|jƒ¡ |  g d¢|j¡ dS )z untyped extension point r   r+   c                   @   s   e Zd Zedd�ZdS )z@ExtensionPointTestCase.test_untyped_extension_point.<locals>.Foor   r   N©r   r   r   r   r   r   r   r   r   r    —   s   r    r-   N©r   r!   r"   r#   r
   r1   r2   r   ©r   r   r    r'   Úgr   r   r   Útest_untyped_extension_point‹   s    z3ExtensionPointTestCase.test_untyped_extension_pointc                 C   sŽ   | j }| |  d¡¡ | dg d¢¡ G dd„ dtƒ}|ƒ }|  dt|jƒ¡ |  g d¢|j¡ |ƒ }|  dt|jƒ¡ |  g d¢|j¡ dS )z typed extension point r   )r,   é+   é,   c                   @   s   e Zd Zeeeƒdd�ZdS )z>ExtensionPointTestCase.test_typed_extension_point.<locals>.Foor   r   Nr   r   r   r   r   r    ¯   s   r    r-   Nr;   r<   r   r   r   Útest_typed_extension_point£   s    z1ExtensionPointTestCase.test_typed_extension_pointc                 C   sp   | j }| |  d¡¡ | dd¡ G dd„ dtƒ}|ƒ }|  t¡� t|dƒ W d  ƒ n1 sb0    Y  dS )z invalid extension point r   r   c                   @   s   e Zd Zeeeƒdd�ZdS )z@ExtensionPointTestCase.test_invalid_extension_point.<locals>.Foor   r   Nr   r   r   r   r   r    Ç   s   r    r   N)r   r!   r"   r#   r
   r   r	   r%   r&   r   r   r   Útest_invalid_extension_point»   s    z3ExtensionPointTestCase.test_invalid_extension_pointc                 C   s<   dd„ }|   t¡� |ƒ  W d  ƒ n1 s.0    Y  dS )z extension point with no Id c                  S   s   G dd„ dt ƒ} d S )Nc                   @   s   e Zd ZeeeƒƒZdS )zTExtensionPointTestCase.test_extension_point_with_no_id.<locals>.factory.<locals>.FooNr   r   r   r   r   r    Ô   s   r    )r
   )r    r   r   r   ÚfactoryÓ   s    zGExtensionPointTestCase.test_extension_point_with_no_id.<locals>.factoryN)r   r$   )r   rC   r   r   r   Útest_extension_point_with_no_idÐ   s    z6ExtensionPointTestCase.test_extension_point_with_no_idc                 C   sL   | j }| |  d¡¡ G dd„ dtƒ}|ƒ }dg|_|  dg| d¡¡ dS )z set untyped extension point r   c                   @   s   e Zd Zedd�ZdS )zDExtensionPointTestCase.test_set_untyped_extension_point.<locals>.Foor   r   Nr:   r   r   r   r   r    ã   s   r    r,   N©r   r!   r"   r
   r   r1   r8   r&   r   r   r   Ú test_set_untyped_extension_pointÚ   s    z7ExtensionPointTestCase.test_set_untyped_extension_pointc                 C   sL   | j }| |  d¡¡ G dd„ dtƒ}|ƒ }dg|_|  dg| d¡¡ dS )z set typed extension point r   c                   @   s   e Zd Zeeeƒdd�ZdS )zBExtensionPointTestCase.test_set_typed_extension_point.<locals>.Foor   r   Nr   r   r   r   r   r    ö   s   r    r,   NrE   r&   r   r   r   Útest_set_typed_extension_pointí   s    z5ExtensionPointTestCase.test_set_typed_extension_pointc                 C   s>   d}|   d¡}|  | d¡t|ƒ¡ |  | d¡t|ƒ¡ dS )z7 test the string representation of the extension point zExtensionPoint(id={!r})r   N)r"   r1   ÚformatÚstrÚrepr)r   Zep_reprÚepr   r   r   Ú'test_extension_point_str_representation   s    
z>ExtensionPointTestCase.test_extension_point_str_representationÚ c                 C   s   t |||d�S )z Create an extension point. )r   Ú
trait_typeÚdesc)r   )r   r   rN   rO   r   r   r   r"     s    z.ExtensionPointTestCase._create_extension_pointN)r   r   r   r   r   r   r(   r4   r9   r>   rA   rB   rD   rF   rG   rL   r   r"   r   r   r   r   r      s   
-
r   )r   ZunittestZenvisage.apir   r   r   Z
traits.apir   r   r   r	   r
   ZTestCaser   r   r   r   r   Ú<module>
   s   