a
    zej                     @   s   d dl Z d dlmZ d dlZd dlZd dlZd dlmZ dZdZ	e
 ZG dd dejZG dd	 d	ejZed
kr|e  dS )    N)start_threads)	print_exc   2   c                   @   s   e Zd ZdZdZdd ZdS )TempFileGreedyr   c                 C   sp   t  | _t  ttD ]P}ztd}|	  W n&   |  j
d7  _
t| jd Y q0 |  jd7  _qd S )Nzw+b   )file)ioStringIOerrors
startEventwaitrangeFILES_PER_THREADtempfileTemporaryFilecloseerror_countr   ok_count)selfif r   0/usr/lib/python3.9/test/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    n1 s40    Y  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>4       z2ThreadedTempFileTest.test_main.<locals>.<listcomp>c                 s   s   | ]}|j V  qd S )N)r   r   tr   r   r   	<genexpr>7   r!   z1ThreadedTempFileTest.test_main.<locals>.<genexpr>c                 S   s*   g | ]"}|j rt|jt|j  qS r   )r   strnamer   getvaluer"   r   r   r   r    8   s   zErrors: errors %d ok %d
%s
)
r   NUM_THREADSr   r   setsumlenjoinZassertEqualr   )r   threadsokr   msgr   r   r   	test_main3   s    
zThreadedTempFileTest.test_mainN)r   r   r   r1   r   r   r   r   r   2   s   r   __main__)r   Ztest.supportr   Zunittestr	   	threading	tracebackr   r)   r   Eventr   Threadr   ZTestCaser   r   mainr   r   r   r   <module>   s   