o
    OZh                     @   s|   d dl Z d dlmZmZmZmZmZ d dlmZm	Z	m
Z
 d dlZG dd de jZG dd de jZedkr<e   dS dS )	    N)
FuncResulttmapWorkerQueueEmptySTOP)threadsSurface	transformc                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )WorkerQueueTypeTestc                 C   sn   dd }dd }t  }t|}t|}||d ||d |  |  | |jd | |jd d S )Nc                 S      | d S N    xr   r   H/var/www/auris/lib/python3.10/site-packages/pygame/tests/threads_test.pyf      zBWorkerQueueTypeTest.test_usage_with_different_functions.<locals>.fc                 S   r   )N   r   r   r   r   r   f2   r   zCWorkerQueueTypeTest.test_usage_with_different_functions.<locals>.f2r   r      )r   r   dowaitstopassertEqualresult)selfr   r   wqfrZfr2r   r   r   #test_usage_with_different_functions
   s   z7WorkerQueueTypeTest.test_usage_with_different_functionsc                 C   s   dS )zSTests function placement on queue and execution after blocking function completion.Nr   r   r   r   r   test_do       zWorkerQueueTypeTest.test_doc                 C   s   t  }| t|jd |jD ]	}| |  qtdD ]
}|dd | q|  |jD ]	}| 	|  q/| 
|j t dS )z$Ensure stop() stops the worker queuer      c                 S   r   r   r   r   r   r   r   <lambda>C       z/WorkerQueueTypeTest.test_stop.<locals>.<lambda>N)r   ZassertGreaterlenpool
assertTrueis_aliveranger   r   assertFalseassertIsqueuegetr   )r   r   tir   r   r   	test_stop9   s   

zWorkerQueueTypeTest.test_stopc                 C   s`   t d}||j g }||jd td | |d d |  | |j	d 
  d S )Nr   g      ?r   )r   r   Z
threadloopappendtimesleepr   r   r+   r'   r)   )r   r   lr   r   r   test_threadloopL   s   
z#WorkerQueueTypeTest.test_threadloopc                 C   sH   t  }tdD ]
}|dd | q|  | t|jj |  d S )Ni  c                 S   r   r   r   r   r   r   r   r$   o   r%   z/WorkerQueueTypeTest.test_wait.<locals>.<lambda>)	r   r*   r   r   assertRaisesr   r-   
get_nowaitr   )r   r   r0   r   r   r   	test_waitg   s   zWorkerQueueTypeTest.test_waitN)__name__
__module____qualname__r   r!   r1   r6   r9   r   r   r   r   r
   	   s    r
   c                   @   sD   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S )ThreadsModuleTestc                 C   sn   	 t  }| |t | d|  kodk n   dd }dd tdddD }t ||}| |t dS )	zfEnsure benchmark_workers performance measure functions properly with both default and specified inputsr   @   c                 S   s   t | d d S )N)   r?   )r	   Zsmoothscale)datar   r   r   smooth_scale_bench   s   zDThreadsModuleTest.test_benchmark_workers.<locals>.smooth_scale_benchc                 S   s   g | ]
}t ||fd dqS )r       )r   .0r   r   r   r   
<listcomp>   s    z<ThreadsModuleTest.test_benchmark_workers.<locals>.<listcomp>   N)r   Zbenchmark_workersassertIsInstanceintr(   r*   )r   Zoptimal_workersrA   Z	surf_dataZbest_num_workersr   r   r   test_benchmark_workersx   s   z(ThreadsModuleTest.test_benchmark_workersc                 C   s$   t d | t jt t   dS )z&Ensure init() sets up the worker queue   N)r   initrG   _wqr   quitr    r   r   r   	test_init   s   
zThreadsModuleTest.test_initc                 C   s"   t d t   | t j dS )z(Ensure quit() cleans up the worker queuerJ   N)r   rK   rM   assertIsNonerL   r    r   r   r   	test_quit   s   
zThreadsModuleTest.test_quitc                 C   sx   dd t d}}tt||}tt||}| || t d}dd }tt||dd}| tdd |D  d S )	Nc                 S   r   r   r   r   r   r   r   r$      r%   z-ThreadsModuleTest.test_tmap.<locals>.<lambda>d   c                 S   s   dd S )Nr   r   r   r   r   r   r   r$      r%   F)Zstop_on_errorc                 s   s    | ]}|d u V  qd S Nr   rC   r   r   r   	<genexpr>   s    z.ThreadsModuleTest.test_tmap.<locals>.<genexpr>)r*   listr   mapr   r(   all)r   funcr@   ZtmappedZmappedZdata2Zalways_exceptsZtmapped2r   r   r   	test_tmap   s   zThreadsModuleTest.test_tmapc                 C   s   |    tdg d}tdg dg d}tdg dg d}tdg dg d}| g d| | g d| | g d| | g d| dS )	z+Using a None as func and multiple sequencesN)r   r   r      )   !   ,   7   )rZ   r[   r\   r]   B   )r   r   r   rY      )r   rZ   r   r[   r   r\   rY   r]   )r`   ra   rb   rc   )Nr^   )r`   ra   rb   rc   )r_   N)Zfailr   r   )r   resZres2Zres3Zres4r   r   r   0todo_test_tmap__None_func_and_multiple_sequences   s   zBThreadsModuleTest.todo_test_tmap__None_func_and_multiple_sequencesc                 C   sN   t d}tdd |ddd\}}|  dd |D }| t|t| d S )	Ni  c                 S   s   | S rR   r   r   r   r   r   r$      r"   z3ThreadsModuleTest.test_tmap__wait.<locals>.<lambda>r_   F)Znum_workersr   c                 s   s    | ]}|j V  qd S rR   )r   rC   r   r   r   rS      s    z4ThreadsModuleTest.test_tmap__wait.<locals>.<genexpr>)r*   r   r   r   rT   )r   rr   resultsr2r   r   r   test_tmap__wait   s
   z!ThreadsModuleTest.test_tmap__waitc                    sf   t dd }|d | |jd | |jd td  fdd}t |}|d	 | |j  d	S )
z:Ensure FuncResult sets its result and exception attributesc                 S   r   r   r   r   r   r   r   r$      r%   z3ThreadsModuleTest.test_FuncResult.<locals>.<lambda>r   r   zno exception should be raisedZrastc                    s    rR   r   )Zsdf	exceptionr   r   r      s   z,ThreadsModuleTest.test_FuncResult.<locals>.xN)r   r   r   rO   rk   
ValueErrorr,   )r   r   r   r   rj   r   test_FuncResult   s   z!ThreadsModuleTest.test_FuncResultN)
r:   r;   r<   rI   rN   rP   rX   re   ri   rm   r   r   r   r   r=   w   s     r=   __main__)ZunittestZpygame.threadsr   r   r   r   r   Zpygamer   r   r	   r3   ZTestCaser
   r=   r:   mainr   r   r   r   <module>   s    nv