3
7ßL]Ñ  ã               @   s    d dl mZmZmZmZ d dlZd dlmZ d dlm	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dddgZG dd„ deƒZG dd„ deeƒZdS )é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literalsN)Úrmtree)Úmkdtemp)ÚTestCase)ÚBool)ÚUnittestToolsé   )ÚApplicationExitÚApplicationZ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d	d
„ Zdd„ Z‡  ZS )Ú
TestingAppTFc                s   t t| ƒjƒ  | jS )N)Úsuperr   ÚstartÚstart_cleanly)Úself)Ú	__class__© úA/tmp/pip-install-5sebvq2j/pyface/pyface/tests/test_application.pyr   :   s    zTestingApp.startc                s   t t| ƒjƒ  | jS )N)r   r   ÚstopÚstop_cleanly)r   )r   r   r   r   >   s    zTestingApp.stopc                s:   t t| ƒjƒ  | jr6| jr$tdƒ‚n| j| jƒ d| _dS )Nzerror messageT)	r   r   Ú_runÚdo_exitÚ
error_exitr   ÚexitÚ
force_exitÚexit_vetoed)r   )r   r   r   r   B   s    
zTestingApp._runc             C   s   | j |_d S )N)Ú	veto_exitZveto)r   Úeventr   r   r   Ú_exiting_firedL   s    zTestingApp._exiting_firedc             C   s   d| _ | jrtdƒ‚d S )NTzExit preparation failed)Úexit_preparedÚexit_prepared_errorÚ	Exception)r   r   r   r   Ú_prepare_exitO   s    zTestingApp._prepare_exit)Ú__name__Ú
__module__Ú__qualname__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 )N)Úapplication_events)r   r   r   r   ÚsetUpV   s    zTestApplication.setUpc             C   s   | j j|ƒ d S )N)r,   Úappend)r   r!   r   r   r   Úevent_listenerY   s    zTestApplication.event_listenerc             C   s    xt D ]}|j| j|ƒ qW d S )N)ÚEVENTSZon_trait_changer/   )r   Úappr!   r   r   r   Úconnect_listeners\   s    
z!TestApplication.connect_listenersc             C   sF   ddl m} tƒ }| j|j|jƒ | j|j|jƒ | j|j|jƒ d S )Nr   )Ú	ETSConfig)Ztraits.etsconfig.apir3   r   ÚassertEqualÚhomeZapplication_homeÚ	user_dataZcompany)r   r3   r1   r   r   r   Útest_defaults`   s
    zTestApplication.test_defaultsc             C   sL   t ƒ }tjj|dƒ}t|d�}|jƒ  z| jtjj|ƒƒ W d t|ƒ X d S )NÚtest)r5   )	r   ÚosÚpathÚjoinr   Zinitialize_application_homeÚ
assertTrueÚexistsr   )r   Údirpathr5   r1   r   r   r   Ú test_initialize_application_homei   s    
z0TestApplication.test_initialize_application_homec          
   C   s^   t ƒ }| j|ƒ | j|gtg ƒ� |jƒ }W d Q R X | j|ƒ dd„ | jD ƒ}| j|tƒ d S )Nc             S   s   g | ]
}|j ‘qS r   )Ú
event_type)Ú.0r!   r   r   r   ú
<listcomp>|   s    z2TestApplication.test_lifecycle.<locals>.<listcomp>)r   r2   ÚassertMultiTraitChangesr0   Úrunr<   r,   r4   )r   r1   ÚresultÚevent_orderr   r   r   Útest_lifecyclet   s    

zTestApplication.test_lifecyclec          
   C   sz   t dd�}| j|ƒ | j|gtg ƒ� |jƒ }W d Q R X | j|ƒ | j|jƒ | j|jƒ dd„ | j	D ƒ}| j
|tƒ d S )NT)r   c             S   s   g | ]
}|j ‘qS r   )r@   )rA   r!   r   r   r   rB   ‰   s    z-TestApplication.test_exit.<locals>.<listcomp>)r   r2   rC   r0   rD   r<   ÚassertFalser   r#   r,   r4   )r   r1   rE   rF   r   r   r   Ú	test_exit   s    


zTestApplication.test_exitc          
   C   s|   t ddd�}| j|ƒ | j|gtg ƒ� |jƒ }W d Q R X | j|ƒ | j|jƒ | j|jƒ dd„ | j	D ƒ}| j
|tƒ d S )NT)r   r$   c             S   s   g | ]
}|j ‘qS r   )r@   )rA   r!   r   r   r   rB   –   s    z;TestApplication.test_exit_prepare_error.<locals>.<listcomp>)r   r2   rC   r0   rD   r<   rH   r   r#   r,   r4   )r   r1   rE   rF   r   r   r   Útest_exit_prepare_errorŒ   s    

z'TestApplication.test_exit_prepare_errorc          
   C   s|   t ddd�}| j|ƒ | j|gtg ƒ� |jƒ }W d Q R X | j|ƒ | j|jƒ | j|jƒ dd„ | j	D ƒ}| j
|tƒ d S )NT)r   r    c             S   s   g | ]
}|j ‘qS r   )r@   )rA   r!   r   r   r   rB   £   s    z2TestApplication.test_veto_exit.<locals>.<listcomp>)r   r2   rC   r0   rD   r<   r   rH   r#   r,   r4   )r   r1   rE   rF   r   r   r   Útest_veto_exit™   s    

zTestApplication.test_veto_exitc          
   C   s~   t dddd�}| j|ƒ | j|gtg ƒ� |jƒ }W d Q R X | j|ƒ | j|jƒ | j|jƒ dd„ | j	D ƒ}| j
|tƒ d S )NT)r   r   r    c             S   s   g | ]
}|j ‘qS r   )r@   )rA   r!   r   r   r   rB   °   s    z3TestApplication.test_force_exit.<locals>.<listcomp>)r   r2   rC   r0   rD   r<   rH   r   r#   r,   r4   )r   r1   rE   rF   r   r   r   Útest_force_exit¦   s    

zTestApplication.test_force_exitc          
   C   sp   t ddd�}| j|ƒ | j|gtg ƒ� |jƒ }W d Q R X | j|ƒ | j|jƒ dd„ | jD ƒ}| j|tƒ d S )NT)r   r   c             S   s   g | ]
}|j ‘qS r   )r@   )rA   r!   r   r   r   rB   ¼   s    z3TestApplication.test_error_exit.<locals>.<listcomp>)	r   r2   rC   r0   rD   rH   r   r,   r4   )r   r1   rE   rF   r   r   r   Útest_error_exit³   s    

zTestApplication.test_error_exitc             C   sz   t dd�}| j|ƒ | j|gtd d… tdd … ƒ� |jƒ }W d Q R X | j|ƒ dd„ | jD ƒ}| j|td d… ƒ d S )NF)r   é   c             S   s   g | ]
}|j ‘qS r   )r@   )rA   r!   r   r   r   rB   Ç   s    z2TestApplication.test_bad_start.<locals>.<listcomp>)r   r2   rC   r0   rD   rH   r,   r4   )r   r1   rE   rF   r   r   r   Útest_bad_start¿   s    

"
zTestApplication.test_bad_startc             C   sz   t dd�}| j|ƒ | j|gtd d… tdd … ƒ� |jƒ }W d Q R X | j|ƒ dd„ | jD ƒ}| j|td d… ƒ d S )	NF)r   rN   c             S   s   g | ]
}|j ‘qS r   )r@   )rA   r!   r   r   r   rB   Ò   s    z1TestApplication.test_bad_stop.<locals>.<listcomp>éÿÿÿÿrP   rP   )r   r2   rC   r0   rD   rH   r,   r4   )r   r1   rE   rF   r   r   r   Útest_bad_stopÊ   s    

"
zTestApplication.test_bad_stopN)r'   r(   r)   r-   r/   r2   r7   r?   rG   rI   rJ   rK   rL   rM   rO   rQ   r   r   r   r   r+   U   s   	r+   )Ú
__future__r   r   r   r   r9   Úshutilr   Útempfiler   Zunittestr   Z
traits.apir	   Ztraits.testing.unittest_toolsr
   Zapplicationr   r   r0   r   r+   r   r   r   r   Ú<module>
   s   8