3
NdB
                 @   sb   d dl Z d dlZd dl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j
ZdS )    N)EnumHasStrictTraits)wait_for_conditionc               @   s0   e Zd ZeddddZdddddZdd ZdS )	TrafficLightsGreenAmberRedRedAndAmber)r   r   r   r	   c             C   s6   x0t |D ]$}tjtjdd | j| j | _q
W d S )Ng?g333333?)rangetimesleeprandomuniform_next_colourcolour)selfZchange_count_ r   [/var/www/html/virt/lib64/python3.6/site-packages/traits/util/tests/test_async_trait_wait.pymake_random_changes   s    z!TrafficLights.make_random_changesN)__name__
__module____qualname__r   r   r   r   r   r   r   r   r      s   r   c               @   s$   e Zd Zdd Zdd Zdd ZdS )TestAsyncTraitWaitc             C   sN   t dd}tj|jd
d}|j  tdd |dd | j|jd	 |j  d S )Nr   )r      )targetargsc             S   s
   | j dkS )Nr   )r   )lr   r   r   <lambda>,   s    zDTestAsyncTraitWait.test_wait_for_condition_success.<locals>.<lambda>r   )	conditionobjtraitr   )r   )	r   	threadingThreadr   startr   assertEqualr   join)r   lightstr   r   r   test_wait_for_condition_success&   s    
z2TestAsyncTraitWait.test_wait_for_condition_successc             C   sH   t dd}tj|jd
d}|j  | jttdd |ddd	 |j  d S )Nr   )r   r   )r   r   c             S   s
   | j dkS )Nr	   )r   )r   r   r   r   r   :   s    zDTestAsyncTraitWait.test_wait_for_condition_failure.<locals>.<lambda>r   g      @)r   r    r!   timeout)r   )	r   r"   r#   r   r$   assertRaisesRuntimeErrorr   r&   )r   r'   r(   r   r   r   test_wait_for_condition_failure2   s    
z2TestAsyncTraitWait.test_wait_for_condition_failurec                sN   t dd _tj jjd	d}|j  t fdd jdd  `|j  d S )
Nr   )r      )r   r   c                s    j jdkS )Nr   )r'   r   )r   )r   r   r   r   J   s    zCTestAsyncTraitWait.test_traits_handler_cleaned_up.<locals>.<lambda>r   )r   r    r!   )r.   )r   r'   r"   r#   r   r$   r   r&   )r   r(   r   )r   r   test_traits_handler_cleaned_upA   s    
z1TestAsyncTraitWait.test_traits_handler_cleaned_upN)r   r   r   r)   r-   r/   r   r   r   r   r   %   s   r   )r   r"   r   ZunittestZ
traits.apir   r   Ztraits.util.async_trait_waitr   r   ZTestCaser   r   r   r   r   <module>   s   