B
    u9a                 @   sl   d dl Z d dlZd dlZd dlZd dlZd dlmZ dZG dd dZG dd dej	Z	e
dkrhe  dS )	    N)support
   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
Timerc             C   s   t  | _d| _d| _d S )Nr   )	threadingZ	Condition_cond_time_stop)self r
    /usr/lib/python3.7/test_sched.py__init__   s    
zTimer.__init__c          	   C   s   | j  | jS Q R X d S )N)r   r   )r	   r
   r
   r   time   s    z
Timer.timec          	   C   sH   | j 8 || j7 }x | j|k r2| j| _| j   qW || _W d Q R X d S )N)r   r   r   wait)r	   tr
   r
   r   sleep   s    
zTimer.sleepc          	   C   s.   | j  |  j|7  _| j   W d Q R X d S )N)r   r   Z
notify_all)r	   r   r
   r
   r   advance!   s    zTimer.advanceN)__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d Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )TestCasec                sb   g   fdd}t tjtj}xdD ]}||d||f}q&W |  |  ddddd	g d S )
Nc                s
     | S )N)append)x)lr
   r   <lambda>,       z%TestCase.test_enter.<locals>.<lambda>)g      ?g?g333333?g?g?   g?g?g333333?g?g      ?)sched	schedulerr   r   enterrunassertEqual)r	   funr   r   zr
   )r   r   
test_enter*   s    
zTestCase.test_enterc                sb   g   fdd}t tjtj}xdD ]}||d||f}q&W |  |  ddddd	g d S )
Nc                s
     | S )N)r   )r   )r   r
   r   r   5   r   z(TestCase.test_enterabs.<locals>.<lambda>)g?g{Gz?gQ?g{Gz?g{Gz?r   g{Gz?g{Gz?gQ?g{Gz?g?)r   r   r   r   enterabsr   r    )r	   r!   r   r   r"   r
   )r   r   test_enterabs3   s    
zTestCase.test_enterabsc             C   s|  t  }|j}t }t|j|j}|dd|d |dd|d t	j
|jd}|  |d | |jtdd | |  x"dD ]}||d d||f}qW |d | |jtdd | |jtdd | |  |d | |jtdd	 | |  |d | |jtdd
 | |  |d tj|td | |  | | d
 d S )Nr   )r      )r&   )target)timeout)         r+   r)   r*   i  )queueQueueputr   r   r   r   r   r   r   Threadr   startr   r    getTIMEOUT
assertTrueemptyr   join_thread)r	   qr!   timerr   r   r   r"   r
   r
   r   test_enter_concurrent<   s6    





zTestCase.test_enter_concurrentc                sb   g   fdd}t tjtj}xdD ]}|d|||f}q&W |  |  ddddd	g d S )
Nc                s
     | S )N)r   )r   )r   r
   r   r   [   r   z(TestCase.test_priority.<locals>.<lambda>)r   r+   r&   r)   r*   g{Gz?r   r+   r&   r)   r*   )r   r   r   r   r$   r   r    )r	   r!   r   priorityr"   r
   )r   r   test_priorityY   s    
zTestCase.test_priorityc       	         s   g   fdd}t tjtj}t }||d d|d}||d d|d}||d d|d	}||d
 d|d}||d d|d}|| || |  |  ddd
g d S )Nc                s
     | S )N)r   )r   )r   r
   r   r   d   r   z&TestCase.test_cancel.<locals>.<lambda>g{Gz?r   )g{Gz?g{Gz?)g{Gz?gQ?)gQ?g{Gz?)g{Gz?g?)g?)r   r   r   r   r$   cancelr   r    )	r	   r!   r   nowevent1event2event3event4event5r
   )r   r   test_cancelb   s    

zTestCase.test_cancelc             C   s  t  }|j}t }t|j|j}| }||d d|d}||d d|d}||d d|d}||d d|d}	||d	 d|d
}
t	j
|jd}|  |d | |jtdd | |  || ||	 |d | |  |d | |jtdd	 | |  |d | |jtdd | |  |d tj|td | |  | | d d S )Nr   )r   r+   )r+   r)   )r)   r*   )r*   r&   )r&   )r'   )r(   i  )r,   r-   r.   r   r   r   r   r   r$   r   r/   r   r0   r   r    r1   r2   r3   r4   r;   r   r5   )r	   r6   r!   r7   r   r<   r=   r>   r@   rA   r?   r   r
   r
   r   test_cancel_concurrentq   s:    






zTestCase.test_cancel_concurrentc                sv   g   fdd}t tjtj}| |  xdD ]}||d||f}q4W | |  |  | |  d S )Nc                s
     | S )N)r   )r   )r   r
   r   r      r   z%TestCase.test_empty.<locals>.<lambda>)g?g{Gz?gQ?g{Gz?g{Gz?r   )	r   r   r   r   r3   r4   r$   ZassertFalser   )r	   r!   r   r   r"   r
   )r   r   
test_empty   s    
zTestCase.test_emptyc       	         s   g   fdd}t tjtj}t }||d d|}||d d|}||d d|}||d d|}||d d|}| |j|||||g d S )	Nc                s
     | S )N)r   )r   )r   r
   r   r      r   z%TestCase.test_queue.<locals>.<lambda>g?r   g{Gz?g{Gz?g{Gz?gQ?)r   r   r   r   r$   r    r,   )	r	   r!   r   r<   Ze5Ze1Ze2Ze4Ze3r
   )r   r   
test_queue   s    zTestCase.test_queuec          	      s   g   fdd}t   }tt j t j}||d| |j|d|dd |j|d|dd |j|d|dddid	 |  |  d
i fdi fdi fdddifg d S )Nc                 s     | |f d S )N)r   )ab)seqr
   r   r!      s    z&TestCase.test_args_kwargs.<locals>.funr   )r   r+   )argument)rF   rG   Zfoor&   )rI   kwargsr
   )r   r   r   r   r$   r   ZassertCountEqual)r	   r!   r<   r   r
   )rH   r   test_args_kwargs   s    zTestCase.test_args_kwargsc                s\   g   fdd}t tjtj}xdD ]}||d||f q&W |jdd |  g  d S )Nc                s
     | S )N)r   )r   )r   r
   r   r      r   z0TestCase.test_run_non_blocking.<locals>.<lambda>)r   	            r   F)Zblocking)r   r   r   r   r   r   r    )r	   r!   r   r   r
   )r   r   test_run_non_blocking   s    
zTestCase.test_run_non_blockingN)r   r   r   r#   r%   r8   r:   rB   rC   rD   rE   rK   rP   r
   r
   r
   r   r   (   s   			r   __main__)r,   r   r   r   ZunittestZtestr   r2   r   r   r   mainr
   r
   r
   r   <module>   s    