B
    u9av                 @   s   d Z dZddlZddlmZmZ ddlZddlZddlZddl	m
Z
 e ZG dd dejZG dd	 d	ejZed
kre  dS )   2       N)start_threadsimport_module)	print_excc               @   s   e Zd ZdZdZdd ZdS )TempFileGreedyr   c             C   st   t  | _t  x\ttD ]P}ytd}|	  W n&   |  j
d7  _
t| jd Y qX |  jd7  _qW d S )Nzw+b   )file)ioStringIOerrors
startEventwaitrangeFILES_PER_THREADtempfileZTemporaryFilecloseerror_countr   ok_count)selfif r   +/usr/lib/python3.7/test_threadedtempfile.pyrun!   s    

zTempFileGreedy.runN)__name__
__module____qualname__r   r   r   r   r   r   r   r      s   r   c               @   s   e Zd Zdd ZdS )ThreadedTempFileTestc          	   C   s   dd t tD }t|tj W d Q R X tdd |D }dd |D }dt||d|f }| |g | | |tt	  d S )Nc             S   s   g | ]
}t  qS r   )r   ).0r   r   r   r   
<listcomp>1   s    z2ThreadedTempFileTest.test_main.<locals>.<listcomp>c             s   s   | ]}|j V  qd S )N)r   )r   tr   r   r   	<genexpr>4   s    z1ThreadedTempFileTest.test_main.<locals>.<genexpr>c             S   s*   g | ]"}|j rt|jt|j  qS r   )r   strnamer   getvalue)r   r!   r   r   r   r    5   s   zErrors: errors %d ok %d
%s
)
r   NUM_THREADSr   r   setsumlenjoinZassertEqualr   )r   Zthreadsokr   msgr   r   r   	test_main0   s    

zThreadedTempFileTest.test_mainN)r   r   r   r.   r   r   r   r   r   /   s   r   __main__)r'   r   r   Ztest.supportr   r   Zunittestr
   Z	threading	tracebackr   ZEventr   ZThreadr   ZTestCaser   r   mainr   r   r   r   <module>   s   