
    i                         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e j                        Z G d de j                        Zedk(  r e j                           yy)	    N)
FuncResulttmapWorkerQueueEmptySTOP)threadsSurface	transformc                   *    e Zd Zd Zd Zd Zd Zd Zy)WorkerQueueTypeTestc                 H   d }d }t               }t        |      }t        |      }|j                  |d       |j                  |d       |j                          |j	                          | j                  |j                  d       | j                  |j                  d       y )Nc                     | dz   S N    xs    c/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/pygame/tests/threads_test.pyfzBWorkerQueueTypeTest.test_usage_with_different_functions.<locals>.f       q5L    c                     | dz   S )N   r   r   s    r   f2zCWorkerQueueTypeTest.test_usage_with_different_functions.<locals>.f2   r   r   r   r      )r   r   dowaitstopassertEqualresult)selfr   r   wqfrfr2s         r   #test_usage_with_different_functionsz7WorkerQueueTypeTest.test_usage_with_different_functions
   s{    		 ]]n
b!
c1
	
	A&Q'r   c                      y)zSTests function placement on queue and execution after blocking function completion.Nr   r!   s    r   test_dozWorkerQueueTypeTest.test_do   s    r   c                    t               }| j                  t        |j                        d       |j                  D ]!  }| j	                  |j                                # t        d      D ]  }|j                  d |        |j                          |j                  D ]!  }| j                  |j                                # | j                  |j                  j                         t               y)z$Ensure stop() stops the worker queuer      c                     | dz   S r   r   r   s    r   <lambda>z/WorkerQueueTypeTest.test_stop.<locals>.<lambda>C   
    AE r   N)r   assertGreaterlenpool
assertTrueis_aliveranger   r   assertFalseassertIsqueuegetr   )r!   r"   tis       r   	test_stopzWorkerQueueTypeTest.test_stop9   s    ]3rww<+ 	*AOOAJJL)	* s 	&AEE/1%	& 		 	+AQZZ\*	+ 	bhhllnd+r   c                 X   t        d      }|j                  |j                         g }|j                  |j                  d       t	        j
                  d       | j                  |d   d       |j                          | j                  |j                  d   j                                y )Nr   g      ?r   )r   r   
threadloopappendtimesleepr   r   r4   r0   r2   )r!   r"   ls      r   test_threadloopz#WorkerQueueTypeTest.test_threadloopL   s     ^ 	bmm 
ahh

31q! 		 	,,./r   c                     t               }t        d      D ]  }|j                  d |        |j                          | j	                  t
        |j                  j                         |j                          y )Ni  c                     | dz   S r   r   r   s    r   r,   z/WorkerQueueTypeTest.test_wait.<locals>.<lambda>o   r-   r   )	r   r3   r   r   assertRaisesr   r6   
get_nowaitr   )r!   r"   r9   s      r   	test_waitzWorkerQueueTypeTest.test_waitg   sX    
 ]t 	&AEE/1%	&
	%!4!45
	r   N)__name__
__module____qualname__r%   r(   r:   rA   rF   r   r   r   r   r   	   s    ($b:,&06r   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	ThreadsModuleTestc                 N   	 t        j                         }| j                  |t               | j	                  d|cxk  xr dk  nc        d }t        ddd      D cg c]  }t        ||fdd       }}t        j                  ||      }| j                  |t               yc c}w )zfEnsure benchmark_workers performance measure functions properly with both default and specified inputsr   @   c                 0    t        j                  | d       y )N)   rO   )r
   smoothscale)datas    r   smooth_scale_benchzDThreadsModuleTest.test_benchmark_workers.<locals>.smooth_scale_bench   s    !!$
3r          N)r   benchmark_workersassertIsInstanceintr1   r3   r	   )r!   optimal_workersrR   r   	surf_databest_num_workerss         r   test_benchmark_workersz(ThreadsModuleTest.test_benchmark_workersx   s     "335os3_1r12	4 6;2r25FGWaVQ+G	G"445GS.4 Hs   B"c                     t        j                  d       | j                  t         j                  t               t        j
                          y)z&Ensure init() sets up the worker queue   N)r   initrV   _wqr   quitr'   s    r   	test_initzThreadsModuleTest.test_init   s*    Qgkk;7r   c                     t        j                  d       t        j                          | j                  t         j                         y)z(Ensure quit() cleans up the worker queuer]   N)r   r^   r`   assertIsNoner_   r'   s    r   	test_quitzThreadsModuleTest.test_quit   s(    Q'++&r   c                 $   d t        d      }}t        t        ||            }t        t        ||            }| j	                  ||       t        d      }d }t        t        ||d            }| j                  t        d |D                     y )Nc                     | dz   S r   r   r   s    r   r,   z-ThreadsModuleTest.test_tmap.<locals>.<lambda>   s
    q1u r   d   c                     ddz  S )Nr   r   r   r   s    r   r,   z-ThreadsModuleTest.test_tmap.<locals>.<lambda>   s
    1q5 r   F)stop_on_errorc              3   $   K   | ]  }|d u  
 y wNr   .0r   s     r   	<genexpr>z.ThreadsModuleTest.test_tmap.<locals>.<genexpr>   s     8!AI8s   )r3   listr   mapr   r1   all)r!   funcrQ   tmappedmappeddata2always_exceptstmapped2s           r   	test_tmapzThreadsModuleTest.test_tmap   s~     %eCjdtD$'(c$o&&) c
(^U%HI 	8x889r   c                 F   | j                          t        dg d      }t        dg dg d      }t        dg dg d      }t        dg dg d      }| j                  g d|       | j                  g d|       | j                  g d|       | j                  g d|       y)	z+Using a None as func and multiple sequencesN)r   r   r      )   !   ,   7   )r{   r|   r}   r~   B   )r   r   r   rz      )r   r{   r   r|   r   r}   rz   r~   )r   r   r   r   )Nr   )r   r   r   r   )r   N)failr   r   )r!   resres2res3res4s        r   0todo_test_tmap__None_func_and_multiple_sequenceszBThreadsModuleTest.todo_test_tmap__None_func_and_multiple_sequences   s    		4&D,(89D,(<=D/+;<s+=tDI4PH$Or   c                     t        d      }t        d |dd      \  }}|j                          d |D        }| j                  t	        |      t	        |             y )Ni  c                     | S rk   r   r   s    r   r,   z3ThreadsModuleTest.test_tmap__wait.<locals>.<lambda>   s    Q r   r   F)num_workersr   c              3   4   K   | ]  }|j                     y wrk   )r    rl   s     r   rn   z4ThreadsModuleTest.test_tmap__wait.<locals>.<genexpr>   s     (1ahh(s   )r3   r   r   r   ro   )r!   rr"   resultsr2s        r   test_tmap__waitz!ThreadsModuleTest.test_tmap__wait   sJ    $K;quEG
	((a$r(+r   c                    t        d       } |d       | j                  |j                  d       | j                  |j                  d       t        d      fd}t        |      } |d       | j                  |j                         y)z:Ensure FuncResult sets its result and exception attributesc                     | dz   S r   r   r   s    r   r,   z3ThreadsModuleTest.test_FuncResult.<locals>.<lambda>   s
    !a% r   r   r   zno exception should be raisedrastc                     rk   r   )sdf	exceptions    r   r   z,ThreadsModuleTest.test_FuncResult.<locals>.x   s    Or   N)r   r   r    rc   r   
ValueErrorr5   )r!   r#   r   r   s      @r   test_FuncResultz!ThreadsModuleTest.test_FuncResult   st     (
1A& 	",,(GHv&		 ]
4bllI.r   N)
rG   rH   rI   r[   ra   rd   rx   r   r   r   r   r   r   rK   rK   w   s'    52':@P,/r   rK   __main__)unittestpygame.threadsr   r   r   r   r   pygamer   r	   r
   r>   TestCaser   rK   rG   mainr   r   r   <module>r      s]     E E . . k(++ k\q/)) q/l zHMMO r   