a
    §ˆcÄ  ã                   @   s†   d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZ ddlmZmZ g d	¢ZG d
d„ deƒZG dd„ deeƒZdS )é    N)Úrmtree)Úmkdtemp)ÚTestCase)ÚBoolÚobserve)ÚUnittestToolsé   )ÚApplicationExitÚApplication)ZstartingÚstartedZapplication_initializedZstoppingÚstoppedc                       s”   e Zd ZedƒZedƒZedƒZedƒZedƒZedƒZ	edƒZ
edƒZedƒZ‡ fdd„Z‡ fdd„Z‡ fdd„Zed	ƒd
d„ ƒZdd„ Z‡  ZS )Ú
TestingAppTFc                    s   t ƒ  ¡  | jS ©N)ÚsuperÚstartÚstart_cleanly©Úself©Ú	__class__© ú`/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/tests/test_application.pyr   <   s    
zTestingApp.startc                    s   t ƒ  ¡  | jS r   )r   ÚstopÚstop_cleanlyr   r   r   r   r   @   s    
zTestingApp.stopc                    s6   t ƒ  ¡  | jr2| jr tdƒ‚n|  | j¡ d| _dS )Nzerror messageT)r   Ú_runÚdo_exitÚ
error_exitr	   ÚexitÚ
force_exitÚexit_vetoedr   r   r   r   r   D   s    

zTestingApp._runZexitingc                 C   s   |j }| j|_d S r   )ÚnewÚ	veto_exitZveto)r   ÚeventZvetoable_eventr   r   r   Ú_set_veto_on_exiting_eventN   s    z%TestingApp._set_veto_on_exiting_eventc                 C   s   d| _ | jrtdƒ‚d S )NTzExit preparation failed)Úexit_preparedÚexit_prepared_errorÚ	Exceptionr   r   r   r   Ú_prepare_exitS   s    zTestingApp._prepare_exit)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r!   r   r$   r%   r   r   r   r   r#   r'   Ú__classcell__r   r   r   r   r      s   

r   c                   @   st   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S )ÚTestApplicationc                 C   s
   g | _ d S r   )Úapplication_eventsr   r   r   r   ÚsetUpZ   s    zTestApplication.setUpc                 C   s   |j }| j |¡ d S r   )r    r-   Úappend)r   r"   Zapplication_eventr   r   r   Úevent_listener]   s    zTestApplication.event_listenerc                 C   s   t D ]}| | j|¡ qd S r   )ÚEVENTSr   r0   )r   Úappr"   r   r   r   Úconnect_listenersa   s    z!TestApplication.connect_listenersc                 C   sF   ddl m} tƒ }|  |j|j¡ |  |j|j¡ |  |j|j¡ d S )Nr   )Ú	ETSConfig)Ztraits.etsconfig.apir4   r
   ÚassertEqualÚhomeZapplication_homeÚ	user_dataZcompany)r   r4   r2   r   r   r   Útest_defaultse   s
    zTestApplication.test_defaultsc                 C   sT   t ƒ }tj |d¡}t|d�}| ¡  z|  tj |¡¡ W t|ƒ n
t|ƒ 0 d S )NÚtest)r6   )	r   ÚosÚpathÚjoinr
   Zinitialize_application_homeÚ
assertTrueÚexistsr   )r   Údirpathr6   r2   r   r   r   Ú test_initialize_application_homen   s    
z0TestApplication.test_initialize_application_homec                 C   sr   t ƒ }|  |¡ |  |gtg ¡� | ¡ }W d   ƒ n1 s>0    Y  |  |¡ dd„ | jD ƒ}|  |t¡ d S )Nc                 S   s   g | ]
}|j ‘qS r   ©Z
event_type©Ú.0r"   r   r   r   Ú
<listcomp>�   ó    z2TestApplication.test_lifecycle.<locals>.<listcomp>)r
   r3   ÚassertMultiTraitChangesr1   Úrunr=   r-   r5   ©r   r2   ÚresultZevent_orderr   r   r   Útest_lifecycley   s    
&
zTestApplication.test_lifecyclec                 C   sŽ   t dd�}|  |¡ |  |gtg ¡� | ¡ }W d   ƒ n1 sB0    Y  |  |¡ |  |j¡ |  |j¡ dd„ | j	D ƒ}|  
|t¡ d S )NT)r   c                 S   s   g | ]
}|j ‘qS r   rA   rB   r   r   r   rD   Ž   rE   z-TestApplication.test_exit.<locals>.<listcomp>©r   r3   rF   r1   rG   r=   ÚassertFalser   r$   r-   r5   rH   r   r   r   Ú	test_exit„   s    

&
zTestApplication.test_exitc                 C   s�   t ddd�}|  |¡ |  |gtg ¡� | ¡ }W d   ƒ n1 sD0    Y  |  |¡ |  |j¡ |  |j¡ dd„ | j	D ƒ}|  
|t¡ d S )NT)r   r%   c                 S   s   g | ]
}|j ‘qS r   rA   rB   r   r   r   rD   ›   rE   z;TestApplication.test_exit_prepare_error.<locals>.<listcomp>rK   rH   r   r   r   Útest_exit_prepare_error‘   s    
&
z'TestApplication.test_exit_prepare_errorc                 C   s�   t ddd�}|  |¡ |  |gtg ¡� | ¡ }W d   ƒ n1 sD0    Y  |  |¡ |  |j¡ |  |j¡ dd„ | j	D ƒ}|  
|t¡ d S )NT)r   r!   c                 S   s   g | ]
}|j ‘qS r   rA   rB   r   r   r   rD   ¨   rE   z2TestApplication.test_veto_exit.<locals>.<listcomp>)r   r3   rF   r1   rG   r=   r   rL   r$   r-   r5   rH   r   r   r   Útest_veto_exitž   s    
&
zTestApplication.test_veto_exitc                 C   s’   t dddd�}|  |¡ |  |gtg ¡� | ¡ }W d   ƒ n1 sF0    Y  |  |¡ |  |j¡ |  |j¡ dd„ | j	D ƒ}|  
|t¡ d S )NT)r   r   r!   c                 S   s   g | ]
}|j ‘qS r   rA   rB   r   r   r   rD   µ   rE   z3TestApplication.test_force_exit.<locals>.<listcomp>rK   rH   r   r   r   Útest_force_exit«   s    
&
zTestApplication.test_force_exitc                 C   s„   t ddd�}|  |¡ |  |gtg ¡� | ¡ }W d   ƒ n1 sD0    Y  |  |¡ |  |j¡ dd„ | jD ƒ}|  |t¡ d S )NT)r   r   c                 S   s   g | ]
}|j ‘qS r   rA   rB   r   r   r   rD   Á   rE   z3TestApplication.test_error_exit.<locals>.<listcomp>)	r   r3   rF   r1   rG   rL   r   r-   r5   rH   r   r   r   Útest_error_exit¸   s    
&
zTestApplication.test_error_exitc                 C   sŽ   t dd�}|  |¡ |  |gtd d… tdd … ¡� | ¡ }W d   ƒ n1 sR0    Y  |  |¡ dd„ | jD ƒ}|  |td d… ¡ d S )NF)r   é   c                 S   s   g | ]
}|j ‘qS r   rA   rB   r   r   r   rD   Ì   rE   z2TestApplication.test_bad_start.<locals>.<listcomp>©r   r3   rF   r1   rG   rL   r-   r5   rH   r   r   r   Útest_bad_startÄ   s    

"&
zTestApplication.test_bad_startc                 C   sŽ   t dd�}|  |¡ |  |gtd d… tdd … ¡� | ¡ }W d   ƒ n1 sR0    Y  |  |¡ dd„ | jD ƒ}|  |td d… ¡ d S )NF)r   éÿÿÿÿc                 S   s   g | ]
}|j ‘qS r   rA   rB   r   r   r   rD   ×   rE   z1TestApplication.test_bad_stop.<locals>.<listcomp>rS   rH   r   r   r   Útest_bad_stopÏ   s    

"&
zTestApplication.test_bad_stopN)r(   r)   r*   r.   r0   r3   r8   r@   rJ   rM   rN   rO   rP   rQ   rT   rV   r   r   r   r   r,   Y   s   	r,   )r:   Úshutilr   Útempfiler   Zunittestr   Z
traits.apir   r   Ztraits.testing.apir   Zapplicationr	   r
   r1   r   r,   r   r   r   r   Ú<module>   s   	: