
    &h>                         S SK r S SKrS SKrS SKrS SKr\R                  R
                  r " S S\R                  5      r " S S\R                  5      r\	S:X  a  \R                  " 5         gg)    Nc                      \ rS rSrS/rS rS rS rS r\	R                  " \R                  " 5       S:H  S5      \	R                  " \R                  R                  S	S
5      S5      S 5       5       r\	R                  " \R                  " 5       S:H  S5      \	R                  " \R                  R                  S	S
5      S5      S 5       5       rS rSrg
)ClockTypeTest
   timingc                 <    [        5       nU R                  US5        g)z$Ensure a Clock object can be createdzClock cannot be constructedN)Clock
assertTrue)selfcs     N/var/www/auris/envauris/lib/python3.13/site-packages/pygame/tests/time_test.pytest_constructionClockTypeTest.test_construction   s    G89    c                 ,   [        5       nU R                  UR                  5       S5        U R                  [	        UR                  5       5      [
        :H  5        SnU R                  USU5        U R                  USU5        U R                  USU5        g)z(test_get_fps tests pygame.time.get_fps()r   333333?d   <      N)r   assertEqualget_fpsr	   typefloat	_fps_test)r
   r   deltas      r   test_get_fpsClockTypeTest.test_get_fps   sr     Ga(QYY[)U23q#u%q"e$q"e$r   c                     SU-  n[        U5       H)  nUR                  5         [        R                  " U5        M+     U R	                  UR                  5       X"U-  S9  g)z>ticks fps times each second, hence get_fps() should return fpsg      ?r   N)rangeticktimesleepassertAlmostEqualr   )r
   clockfpsr   delay_per_framefs         r   r   ClockTypeTest._fps_test!   sM    )sAJJLJJ'  	u}};Gr   c                    SnSnUS-  nSnSn[        5       nU R                  UR                  5       S5        [        U5       HJ  n[        R
                  " U5        UR                  U5        UR                  5       nU R                  X8US9  ML     [        U5       HY  n[        R
                  " U5        UR                  5         UR                  5       nUR                  5       n	U R                  XUS9  M[     g )Nr   皙?     2   r   r   )	r   r   get_rawtimer   r!   r"   r    r#   get_time)
r
   
iterationsdelaydelay_milisecondsframerate_limitr   r   r'   c1c2s
             r   test_get_rawtimeClockTypeTest.test_get_rawtime*   s    
!UO G!, z"AJJuFF?#B""#4"F	 # z"AJJuFFHBB""2"7 #r   s390xFails on s390xCIN'CI can have variable time slices, slow.c                 0   SnUS-  nSnSn[        5       nU R                  UR                  5       S5        [        U5       HI  n[        R
                  " U5        UR                  5         UR                  5       nU R                  X'US9  MK     [        U5       Hz  n[        R                  " 5       n[        R
                  " U5        UR                  5         [        R                  " 5       n	UR                  5       nX-
  S-  n
U R                  XUS9  M|     g )Nr*   r+   r   r-   r   r   )r   r   r/   r   r!   r"   r    r#   )r
   r1   r2   r0   r   r   ir4   t0t1d0s              r   test_get_timeClockTypeTest.test_get_timeD   s     !UO
 Gq) z"AJJuFFHB""#4"F	 # z"ABJJuFFHBB'B ""2"7 #r   c                     SnSnSnSnSn/ n[        5       nUR                  5         [        S5       H;  n[        R                  " US-  5        UR                  UR                  5       5        M=     [        U5      [        U5      4 H  n	X:w  d  M
  UR                  U	5        M     [        [        U5      5      [        U5      -  n
U R                  XUS9  [        5       n/ n[        R                  " 5       n[        U5       H#  nUR                  UR                  U5      5        M%     [        U5      [        U5      4 H(  n	U	[        SU-  5      :w  d  M  UR                  U	5        M*     [        R                  " 5       nU R                  X-
  S	US9  [        [        U5      5      [        U5      -  nU R                  SU-  XCS9  g
)zTests time.Clock.tick()r,   r      r   g      @r   r+   r      N)r   r    r   r!   r"   appendminmaxremover   sumlenr#   round)r
   epsilonepsilon2epsilon3testing_frameratemilliseconds
collectionr   r=   outlieraverage_timestartendaverage_tick_times                 r   	test_tickClockTypeTest.test_tickf   s   	  
G 	
sAJJ|d*+affh' 
 JZ9G&!!'* : S_-J? 	|I G
		()Aaff%678 * JZ9G%'8 899!!'* : iik
 	s{AX>!#j/2S_D$$&7 	 	
r   c                 ,   [        5       nSnSnSnU R                  UR                  U5      X$-  U-
  5        [        R                  R                  S5        U R                  UR                  U5      X$-  U-
  5        [        R                  R                  S5        U R                  UR                  U5      X$-  U-
  5        SnU R                  UR                  U5      X%-  U-
  5        SnU R                  UR                  U5      X&-  U-
  5        Sn[        X'-  5      nU R                  UR                  U5      X-
  5        Sn	[        X)-  5      n
U R                  UR                  U	5      X-
  5        S	nU R                  UR                  U5      S	5        S
nU R                  UR                  U5      S	5        Sn[        X--  5      nU R                  UR                  U5      X-
  5        SnU R                  UR                  U5      X/-  U-
  5        g)zTest tick_busy_loopr+   rE   (   r      i  #   i  r   g     `@@TN)r   assertGreaterEqualtick_busy_looppygamer!   waitintr   )r
   r   second_lengthshortfall_tolerance
sample_fpshigh_fpslow_fpslow_non_factor_fps#frame_length_without_decimal_placeshigh_non_factor_fps%frame_length_without_decimal_places_2zero_fpsnegative_fpsfractional_fps%frame_length_without_decimal_places_3bool_fpss                   r   test_tick_busy_loop!ClockTypeTest.test_tick_busy_loop   s<    G 
Z('+>>	
 	Z('+>>	
 	Z('+>>	

 X&)AEX(X	
 W%(?CV'V	
  .1./
+ 	/0/E	

 "03/1
- 	011G	

 ))(3Q7 )),7;03M4R0S-^,1G	

 X&)AEX(X	
r    )__name__
__module____qualname____firstlineno____tags__r   r   r   r6   unittestskipIfplatformmachineosenvirongetrA   rX   rr   __static_attributes__rt   r   r   r   r   
   s    zH:%H84 __X%%'724DE__


tT"$M8 F8< __X%%'724DE__


tT"$M@
 F@
DK
r   r   c                      \ rS rSrS/r\R                  " \R                  " 5       S:H  S5      \R                  " \	R                  R                  SS5      S5      S 5       5       rS	 r\R                  " \R                  " 5       S:H  S5      \R                  " \	R                  R                  SS5      S5      S
 5       5       rS rS rS rSrg)TimeModuleTest   r   r8   r9   r:   Nr;   c                     SnSnSnU R                  [        R                  R                  XU5        U R	                  [        R                  R                  5        g)zTests time.delay() function.r-   rD      N)_wait_delay_checkra   r!   r1   _type_error_checksr
   millisr0   r   s       r   
test_delayTimeModuleTest.test_delay   sG     
v{{00&eL 1 12r   c                     SnSnSnU R                  [        [        R                  R	                  5       5      [
        :H  5        [        U5       H  n[        R                  R	                  5       n[        R                  " 5       n[        R                  R                  U5        [        [        R                  " 5       U-
  S-  5      n[        R                  R	                  5       U-
  nU R                  XUS9  M     g)zTests time.get_ticks()rD   r-      r+   r   N)
r	   r   ra   r!   	get_ticksrc   r   r1   rL   r#   )	r
   r0   r   r   r=   
curr_ticks	curr_time	time_diff
ticks_diffs	            r   test_get_ticksTimeModuleTest.test_get_ticks  s    	 
V[[2245<=z"A..0J		IKKf%tyy{Y6$>?I..0:=J"":"F #r   c                 
    [         R                  " 5         [         R                  R                  5       n[         R                  R	                  U5      nSnSnSnSn[         R                  R                  5         [         R                  R                  X5        [         R                  R                  5       nXtU-  -   U-   nXe:  a[  [         R                  R                  5        H  n	X:X  d  M
  US-  nM     [         R                  R                  5       U:  a  OXe:  a  M[  [         R                  R                  US5        [         R                  R                  5       n
U R                  Xe5        U R                  XE-  X-
  US9  [         R                  R                  S5        U R                  U[         R                  R                  5       5        [         R                  R                  X5        [         R                  R                  [        US-  5      5        U R                  [         R                  R                  5       R                  U5      S	5        [         R                  R                  XS
-  5        [         R                  R                  US-  5        U R                  U[         R                  R                  5       5        [         R                  R                  XS	-  5        [         R                  R                  US-  5        U R                  [         R                  R                  5       R                  U5      S5        [         R                  R                  X5        [         R                  R                  [        US-  5      5        U R                  [         R                  R                  5       R                  U5      S5        [         R                  R                  US
S5        [         R                  R                  S5        U R                  [         R                  R                  5       R                  U5      S5        [         R                  R	                  U5      [         R                  R	                  USSSS/S9[         R                  R	                  [         R                   [         R"                  SS9/nS	nSnU H  n[         R                  R                  XUS9  [         R                  R                  SU-  U-  5        U R                  [         R                  R                  5       R                  U5      U5        M     [         R$                  " 5         g)zTests time.set_timer()r-   r      r   rE   r   r\   g      @   r   r,         g      @Tr[   9gwz5   |   )"    )foobazlola)keyunicode)loopsN)ra   initeventcustom_typeEventclearr!   	set_timerr   r   r   r#   r1   assertNotInrc   countKEYDOWNK_aquit)r
   TIMER_EVENT_TYPEtimer_eventr   timer_delaytest_numbereventsr?   max_test_timer   t2events_to_testrepeatr   es                  r   test_set_timerTimeModuleTest.test_set_timer   s   	 	!<<335ll(()9:.< [[""$;66>"))+'aKF ,
 {{$$&6 " 	.2[[""$-{8"'O 	#fll&6&6&89 	.<#kC/01))+11+>B.b0@A+/*fll&6&6&89.a@+/*))+11+>B.<#kC/01))+11+>B 	.D9"))+11+>B LL/0LL g2C?   LLv~~6::sK
 AKK!!!6!:KKa&j612V\\--/55a8&A   	r   c                     SnSnSnU R                  [        R                  R                  XU5        U R	                  [        R                  R                  5        g)zTests time.wait() function.r   r   r-   N)r   ra   r!   rb   r   r   s       r   	test_waitTimeModuleTest.test_waitp  sE    
v{{//UK 0 01r   c                     [         R                   " 5       n[        U5       H  nU" U5      nU R                  XrUS9  M     [         R                   " 5       n[        X-
  S-  5      n	U R                  X-  X$S9  g)aL  "
call func_to_check(millis) "iterations" times and check each time if
function "waited" for given millisecond (+- delta). At the end, take
average time for each call (whole_duration/iterations), which should
be equal to millis (+- delta - acceptable margin of error).
*Created to avoid code duplication during delay and wait tests
r   r+   N)r!   r   r#   rL   )
r
   func_to_checkr   r0   r   
start_timer=   	wait_time	stop_timedurations
             r   r    TimeModuleTest._wait_delay_checkz  sp     YY[
z"A%f-I""9E"B # IIK	)0D89x4fJr   c                      U R                  [        US5        U R                  [        [        R                  R                  S5        U R                  [        [        R                  R                  S5        g)z?Checks 3 TypeError (float, tuple, string) for the func_to_checkr*   )r   rE   10N)assertRaises	TypeErrorra   r!   r1   )r
   r   s     r   r   !TimeModuleTest._type_error_checks  sO    =)]C8)V[[%6%6?)V[[%6%6=r   rt   )ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   rt   r   r   r   r      s    zH__X%%'724DE__


tT"$M3 F3G* __X%%'724DE__


tT"$MJ FJX2K(>r   r   __main__)r~   r|   rz   ra   r!   r   TestCaser   r   ru   mainrt   r   r   <module>r      se    	    m
H%% m
`Z>X&& Z>~ zMMO r   