3
6ßL]B7  ã               @   sþ   d Z ddlZddlZddlZddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZmZmZ ddlmZ dd	„ 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	ƒZG dd„ dejƒZedkrúejƒ  dS )z% Tests for applications and plugins. é    N)Ú	ETSConfig)ÚApplicationÚExtensionPoint)ÚPluginÚPluginManager)ÚBoolÚIntÚList)ÚEventTrackerc             C   s   | t _|t _|t _|t _dS )z, A useful trait change handler for testing! N)ÚlistenerÚobjÚ
trait_nameÚoldÚnew)r   r   r   r   © r   úJ/tmp/pip-install-5sebvq2j/envisage/envisage/tests/application_test_case.pyr      s
    r   c             C   s
   d| _ dS )z% A function that will veto an event. TN)Zveto)Úeventr   r   r   Úvetoer   s    r   c               @   s   e Zd ZdZdZdS )ÚTestApplicationz, The type of application used in the tests. ÚtestN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úidr   r   r   r   r   '   s   r   c               @   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 )z Start the plugin. TFN)ÚstartedÚstopped)Úselfr   r   r   Ústart9   s    zSimplePlugin.startc             C   s   d| _ d| _dS )z Stop the plugin. FTN)r   r   )r   r   r   r   ÚstopA   s    zSimplePlugin.stopN)	r   r   r   r   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 )z Start the plugin. é   r   Nr   )r   r   r   r   r   Q   s    zBadPlugin.startc             C   s   dd ‚dS )z Stop the plugin. r"   r   Nr   )r   r   r   r   r    V   s    zBadPlugin.stopN)r   r   r   r   r   r    r   r   r   r   r!   J   s   r!   c               @   s    e Zd ZdZdZeedd�ZdS )ÚPluginAz* A plugin that offers an extension point. ÚAza.x)r   N)r   r   r   r   r   r   r	   Úxr   r   r   r   r#   \   s   r#   c               @   s(   e Zd ZdZdZeedddgdd�ZdS )	ÚPluginBz2 A plugin that contributes to an extension point. ÚBr"   é   é   za.x)Úcontributes_toN)r   r   r   r   r   r	   r   r%   r   r   r   r   r&   c   s   r&   c               @   s(   e Zd ZdZdZeedddgdd�ZdS )	ÚPluginCz8 Another plugin that contributes to an extension point! ÚCéb   éc   éd   za.x)r*   N)r   r   r   r   r   r	   r   r%   r   r   r   r   r+   j   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dd„ Zdd„ ZdS )ÚApplicationTestCasez% Tests for applications and plugins. c             C   s   dt _dt _dt _dt _dS )z> Prepares the test fixture before each test method is called. N)r   r   r   r   r   )r   r   r   r   ÚsetUpx   s
    zApplicationTestCase.setUpc             C   s   dS )z< Called immediately after each test method has been called. Nr   )r   r   r   r   ÚtearDownƒ   s    zApplicationTestCase.tearDownc             C   sL   t ƒ }| jtj|jƒ tj|jƒ t ƒ }| jtj	j
|jƒƒ tj|jƒ dS )z home N)r   ÚassertEqualr   Zapplication_homeÚhomeÚshutilÚrmtreeÚ
assertTrueÚosÚpathÚexists)r   Úapplicationr   r   r   Ú	test_homeŒ   s    zApplicationTestCase.test_homec             C   s|   t ƒ }t|df|df|df|dfgd�}|jƒ }| jd|ƒ | jddg|jƒ |jƒ }| jd|ƒ | jddddg|jƒ dS )z no plugins Ústartingr   Ústoppingr   )ÚsubscriptionsTN)r   r
   r   r3   Úevent_namesr    )r   r;   Útrackerr   r   r   r   r   Útest_no_plugins¢   s    z#ApplicationTestCase.test_no_pluginsc             C   s\   t ƒ }|jtdƒ t|df|df|df|dfgd�}|jƒ }| jd|ƒ | jd|jkƒ dS )z veto starting r=   r   r>   r   )r?   FN)r   Úon_trait_changer   r
   r   r3   r7   r@   )r   r;   rA   r   r   r   r   Útest_veto_starting¾   s    z&ApplicationTestCase.test_veto_startingc             C   s‚   t ƒ }|jtdƒ t|df|df|df|dfgd�}|jƒ }| jddg|jƒ | jd|ƒ |jƒ }| jd|ƒ | jd|jkƒ dS )	z veto stopping r>   r=   r   r   )r?   TFN)	r   rC   r   r
   r   r3   r@   r    r7   )r   r;   rA   r   r   r   r   r   Útest_veto_stoppingÖ   s    z&ApplicationTestCase.test_veto_stoppingc             C   s^   t ƒ }tƒ }t||gd�}| jt|jƒ | jt|jƒ | jt|jdd� | jt|j	dd� dS )z start and stop errors )ÚpluginsZbogus)Z	plugin_idN)
r   r!   r   ZassertRaisesÚZeroDivisionErrorr   r    ÚSystemErrorZstart_pluginZstop_plugin)r   Zsimple_pluginZ
bad_pluginr;   r   r   r   Útest_start_and_stop_errorsó   s    z.ApplicationTestCase.test_start_and_stop_errorsc             C   sŽ   t ƒ }tƒ }tƒ }t|||gd�}|jƒ  |jdƒ}| jdt|ƒƒ | jdddddd	g|ƒ |j}| jdt|ƒƒ | jdddddd	g|ƒ d
S )z extension point )rF   za.xé   r"   r(   r)   r-   r.   r/   N)	r#   r&   r+   r   r   Úget_extensionsr3   Úlenr%   )r   ÚaÚbÚcr;   Ú
extensionsr   r   r   Útest_extension_point  s    
z(ApplicationTestCase.test_extension_pointc                sª   t ƒ }tƒ }tƒ }t||gd�}|jƒ  ‡ fdd„‰ |jdƒ}| jdt|ƒƒ | jdddg|ƒ |jˆ dƒ |j	|ƒ | jdˆ j
ƒ | jg ˆ jƒ | jdd	d
gˆ jƒ dS )z add extension point listener )rF   c                s   |j ˆ _ |jˆ _|jˆ _dS )z An extension point listener. N)Úextension_point_idÚaddedÚremoved)Úextension_registryr   )r   r   r   r   -  s    zGApplicationTestCase.test_add_extension_point_listener.<locals>.listenerza.xr)   r"   r(   r-   r.   r/   N)r#   r&   r+   r   r   rK   r3   rL   Úadd_extension_point_listenerÚ
add_pluginrR   rT   rS   )r   rM   rN   rO   r;   rP   r   )r   r   Ú!test_add_extension_point_listener"  s    


z5ApplicationTestCase.test_add_extension_point_listenerc                sÀ   t ƒ }tƒ }tƒ }t|gd�}|jƒ  ‡ fdd„‰ |jdƒ}| jdt|ƒƒ |jˆ dƒ |j	|ƒ | jdˆ j
ƒ | jg ˆ jƒ | jdddgˆ jƒ d	ˆ _
|jˆ dƒ |j	|ƒ | jd	ˆ j
ƒ d	S )
z! remove extension point listener )rF   c                s   |j ˆ _ |jˆ _|jˆ _dS )z An extension point listener. N)rR   rS   rT   )rU   r   )r   r   r   r   S  s    zJApplicationTestCase.test_remove_extension_point_listener.<locals>.listenerza.xr   r"   r(   r)   N)r#   r&   r+   r   r   rK   r3   rL   rV   rW   rR   rT   rS   Zremove_extension_point_listener)r   rM   rN   rO   r;   rP   r   )r   r   Ú$test_remove_extension_point_listenerH  s$    



z8ApplicationTestCase.test_remove_extension_point_listenerc             C   sê   t ƒ }tƒ }tƒ }t||gd�}|jƒ  |jdƒ}| jdt|ƒƒ | jdddg|ƒ |j}| jdt|ƒƒ | jdddg|ƒ |j	|ƒ |jdƒ}| jdt|ƒƒ | jdddddd	g|ƒ |j}| jdt|ƒƒ | jdddddd	g|ƒ d
S )z add plugin )rF   za.xr)   r"   r(   rJ   r-   r.   r/   N)
r#   r&   r+   r   r   rK   r3   rL   r%   rW   )r   rM   rN   rO   r;   rP   r   r   r   Útest_add_pluginw  s&    


z#ApplicationTestCase.test_add_pluginc             C   sv   t ƒ }tƒ }tƒ }t|||gd�}|jƒ  | j||jdƒƒ | j||jdƒƒ | j||jdƒƒ | jd|jdƒƒ dS )z get plugin )rF   r$   r'   r,   NÚBOGUS)r#   r&   r+   r   r   r3   Ú
get_plugin)r   rM   rN   rO   r;   r   r   r   Útest_get_plugin›  s    z#ApplicationTestCase.test_get_pluginc             C   sì   t ƒ }tƒ }tƒ }t|||gd�}|jƒ  |jdƒ}| jdt|ƒƒ | jdddddd	g|ƒ |j}| jdt|ƒƒ | jdddddd	g|ƒ |j	|ƒ |jdƒ}| jdt|ƒƒ | jddd	g|ƒ |j}| jdt|ƒƒ | jddd	g|ƒ d
S )z remove plugin )rF   za.xrJ   r"   r(   r)   r-   r.   r/   N)
r#   r&   r+   r   r   rK   r3   rL   r%   Zremove_plugin)r   rM   rN   rO   r;   rP   r   r   r   Útest_remove_plugin°  s&    


z&ApplicationTestCase.test_remove_pluginc             C   s|   t ƒ }tƒ }tƒ }tt|||gd�d�}|jƒ  | j||jdƒƒ | j||jdƒƒ | j||jdƒƒ | jd|jdƒƒ dS )z( set plugin manager at construction time)rF   )Zplugin_managerr$   r'   r,   Nr[   )r#   r&   r+   r   r   r   r3   r\   )r   rM   rN   rO   r;   r   r   r   Ú+test_set_plugin_manager_at_contruction_timeÓ  s    z?ApplicationTestCase.test_set_plugin_manager_at_contruction_timeN)r   r   r   r   r1   r2   r<   rB   rD   rE   rI   rQ   rX   rY   rZ   r]   r^   r_   r   r   r   r   r0   q   s   	&/$#r0   Ú__main__)r   r8   r5   ZunittestZtraits.etsconfig.apir   Zenvisage.apir   r   r   r   Z
traits.apir   r   r	   Zenvisage.tests.event_trackerr
   r   r   r   r   r!   r#   r&   r+   ZTestCaser0   r   Úmainr   r   r   r   Ú<module>   s&     }