a
    ©ˆcç  ã                   @   s^   d Z ddlZddlmZmZ ddlmZ G dd„ deƒZG dd„ deƒZG d	d
„ d
ej	ƒZ
dS )ú Tests for the plugin manager. é    N)ÚPluginÚPluginManager)ÚBoolc                   @   s0   e Zd ZdZedƒZedƒZdd„ Zdd„ ZdS )ÚSimplePluginz A simple plugin. Fc                 C   s   d| _ d| _dS )ú Start the plugin. TFN©ÚstartedÚstopped©Úself© r   úe/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/envisage/tests/test_plugin_manager.pyÚstart!   s    zSimplePlugin.startc                 C   s   d| _ d| _dS )ú Stop the plugin. FTNr   r   r   r   r   Ústop'   s    zSimplePlugin.stopN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r
   r   r   r   r   r   r   r      s
   r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú	BadPluginz( A plugin that just causes trouble ;^). c                 C   s   dd ‚dS )r   é   r   Nr   r   r   r   r   r   5   s    zBadPlugin.startc                 C   s   dd ‚dS )r   r   r   Nr   r   r   r   r   r   :   s    zBadPlugin.stopN)r   r   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 )ÚPluginManagerTestCaser   c                 C   s@   t ƒ }t|gd�}| |j¡}|  ||¡ |  d| d¡¡ dS )z get plugin ©ÚpluginsNÚbogus)r   r   Ú
get_pluginÚidÚassertEqual)r   Úsimple_pluginÚplugin_managerÚpluginr   r   r   Útest_get_pluginC   s
    z%PluginManagerTestCase.test_get_pluginc                 C   sF   t ƒ }tƒ }t||gd�}g }|D ]}| |¡ q"|  ||g|¡ dS )z iteration over plugins r   N)r   r   r   Úappendr   )r   r   Ú
bad_pluginr    r   r!   r   r   r   Útest_iteration_over_pluginsP   s    z1PluginManagerTestCase.test_iteration_over_pluginsc                 C   sB   t ƒ }t|gd�}| ¡  |  d|j¡ | ¡  |  d|j¡ dS )z start and stop r   TN)r   r   r   r   r	   r   r
   )r   r   r    r   r   r   Útest_start_and_stop_   s    z)PluginManagerTestCase.test_start_and_stopc                 C   sî   t ƒ }tƒ }t||gd�}|  t¡� | ¡  W d  ƒ n1 sB0    Y  |  t¡� | ¡  W d  ƒ n1 st0    Y  |  t¡� |jdd� W d  ƒ n1 sª0    Y  |  t¡� |j	dd� W d  ƒ n1 sà0    Y  dS )z start and stop errors r   Nr   )Z	plugin_id)
r   r   r   ÚassertRaisesÚZeroDivisionErrorr   r   ÚSystemErrorZstart_pluginZstop_plugin)r   r   r$   r    r   r   r   Útest_start_and_stop_errorss   s    &&*z0PluginManagerTestCase.test_start_and_stop_errorsc                 C   sD   ddg}t |tdd�tdd�tdd�gd�}ddg}|  ||¡ d S )NÚfooÚbar©r   Úbaz©Úincluder   ©r   r   Ú_test_start_and_stop©r   r0   r    Úexpectedr   r   r   Ú;test_only_include_plugins_whose_ids_are_in_the_include_listŒ   s    ýþ
zQPluginManagerTestCase.test_only_include_plugins_whose_ids_are_in_the_include_listc                 C   sB   dg}t |tdd�tdd�tdd�gd�}ddg}|  ||¡ d S )Núb*r+   r-   r,   r.   r/   r1   r3   r   r   r   ÚAtest_only_include_plugins_matching_a_wildcard_in_the_include_list¢   s    ýþ
zWPluginManagerTestCase.test_only_include_plugins_matching_a_wildcard_in_the_include_listc                 C   sB   ddg}t |tdd�tdd�tdd�gd�}dg}|  ||¡ d S )Nr+   r.   r-   r,   ©Úexcluder   r1   ©r   r9   r    r4   r   r   r   Ú5test_ignore_plugins_whose_ids_are_in_the_exclude_listº   s    ýþ
zKPluginManagerTestCase.test_ignore_plugins_whose_ids_are_in_the_exclude_listc                 C   s@   dg}t |tdd�tdd�tdd�gd�}dg}|  ||¡ d S )Nr6   r+   r-   r,   r.   r8   r1   r:   r   r   r   Ú;test_ignore_plugins_matching_a_wildcard_in_the_exclude_listÐ   s    ýþ
zQPluginManagerTestCase.test_ignore_plugins_matching_a_wildcard_in_the_exclude_listc                 C   s†   |   |dd„ |D ƒ¡ | ¡  |D ](}| |¡}|  d|¡ |   d|j¡ q"| ¡  |D ](}| |¡}|  d|¡ |   d|j¡ qXdS )zN Make sure the plugin manager starts and stops the expected plugins.

        c                 S   s   g | ]
}|j ‘qS r   r-   )Ú.0r!   r   r   r   Ú
<listcomp>î   ó    z>PluginManagerTestCase._test_start_and_stop.<locals>.<listcomp>NT)r   r   r   ZassertNotEqualr	   r   r
   )r   r    r4   r   r!   r   r   r   r2   è   s    

z*PluginManagerTestCase._test_start_and_stopN)r   r   r   r   r"   r%   r&   r*   r5   r7   r;   r<   r2   r   r   r   r   r   @   s   r   )r   ZunittestZenvisage.apir   r   Z
traits.apir   r   r   ZTestCaser   r   r   r   r   Ú<module>
   s   