o
    i                     @   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   S/home/kim/smarthome/.venv/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   ZassertRaisesr   r-   
get_nowaitr   )r   r   r0   r   r   r   	test_waitg   s   zWorkerQueueTypeTest.test_waitN)__name__
__module____qualname__r   r!   r1   r6   r8   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_workersr@   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   initrF   _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 queuerI   N)r   rJ   rL   assertIsNonerK   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   rB   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   )rY   rZ   r[   r\   B   )r   r   r   rX      )r   rY   r   rZ   r   r[   rX   r\   )r_   r`   ra   rb   )Nr]   )r_   r`   ra   rb   )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 rQ   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 rQ   )r   rB   r   r   r   rR      s    z4ThreadsModuleTest.test_tmap__wait.<locals>.<genexpr>)r*   r   r   r   rS   )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    rQ   r   )Zsdf	exceptionr   r   r      s   z,ThreadsModuleTest.test_FuncResult.<locals>.xN)r   r   r   rN   rj   
ValueErrorr,   )r   r   r   r   ri   r   test_FuncResult   s   z!ThreadsModuleTest.test_FuncResultN)
r9   r:   r;   rH   rM   rO   rW   rd   rh   rl   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<   r9   mainr   r   r   r   <module>   s    nv