o
    OZŽh9ƒ  ã                   @   s¬  d dl Z d dlZd dlZd dlZd dlZejejejejej	ej
ejejejejejejejejejfZe  e¡Ze ejdejiejdejieji ejddiej	ddii¡ g dejf‘dejf‘dejf‘dejf‘d	ejf‘d
ejf‘dej	f‘dej
f‘dejf‘dejf‘dejf‘dejf‘dejf‘dejf‘dejf‘dejf‘dejf‘dejf‘dejf‘d‘dejf‘dejf‘dej f‘dej!f‘dej"f‘dej#f‘dej$f‘d ej%f‘d!ej&f‘d"ej'f‘d#ej(f‘d$ej)f‘d%ej*f‘d&ej+f‘d'ej,f‘d(ej-f‘d)ej.f‘d*ej/f‘d+ej0f‘R Z1G d,d-„ d-ej2ƒZ3d.Z4G d/d0„ d0ej2ƒZ5G d1d2„ d2ej2ƒZ6G d3d4„ d4ej2ƒZ7G d5d6„ d6ej2ƒZ8e9d7krTe :¡  dS dS )8é    NÚkeyZbuttoné   ZNoEventZActiveEventZKeyDownZKeyUpZMouseMotionZMouseButtonDownZMouseButtonUpZJoyAxisMotionZJoyBallMotionZJoyHatMotionZJoyButtonDownZJoyButtonUpZVideoResizeZVideoExposeZQuitZ
SysWMEventZMidiInZMidiOutÚ	UserEvent)ÚUnknownéÿÿ  ZFingerMotionZ
FingerDownZFingerUpZMultiGestureZ
MouseWheelZ	TextInputZTextEditingZControllerAxisMotionZControllerButtonDownZControllerButtonUpZControllerDeviceAddedZControllerDeviceRemovedZControllerDeviceMappedZDropFileZAudioDeviceAddedZAudioDeviceRemovedZDropTextZ	DropBeginZDropCompletec                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚEventTypeTestc                 C   sØ   t jjt jddd}|  |jd¡ |  |jd¡ |  |jt j¡ |  |j	|j
¡ d|_|  |jd¡ d|_|  |jd¡ |  tt|dd¡ |  tt|dd	¡ t|ƒ}d
}|D ]}|  ||¡ qV| jtt jjddd d	S )z&Ensure an Event object can be created.r   Ú1)Ú	some_attrÚ
other_attré   é   Útyper   ÚdictN)r   r   Ú__dict__r	   r
   Únew_attré
   éd   ©r   )ÚpygameÚeventÚEventÚ	USEREVENTÚassertEqualr	   r
   r   ZassertIsr   r   r   ÚassertRaisesÚAttributeErrorÚsetattrÚdirZassertInÚ
ValueError)ÚselfÚeÚdÚattrsÚattr© r#   úF/var/www/auris/lib/python3.10/site-packages/pygame/tests/event_test.pyÚ
test_EventU   s    zEventTypeTest.test_Eventc                 C   s>   zt tjjtd ddƒ W d S  ty   |  d¡ Y d S w )Nr   õ   Ã­©Úaz5Event object raised exception for non-ascii character)Ústrr   r   r   ÚEVENT_TYPESÚUnicodeEncodeErrorZfail©r   r#   r#   r$   Útest_as_strw   s
   ÿzEventTypeTest.test_as_strc                 C   sD   |   tj tj¡¡ tjtjtjtjfD ]}|  	tj |¡¡ qd S ©N)
ÚassertFalser   r   r   ÚNOEVENTÚMOUSEBUTTONDOWNÚACTIVEEVENTZWINDOWLEAVEZUSEREVENT_DROPFILEÚ
assertTrue)r   Ú
event_typer#   r#   r$   Útest_event_bool   s   üúzEventTypeTest.test_event_boolc                 C   sð   t jjtd dd}t jjtd dd}t jjtd dd}t jjtd dd}|  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ dS )z-Ensure that events can be compared correctly.r   r   r'   é   N)r   r   r   r*   r   ÚassertNotEqual)r   r(   ÚbÚcr    r#   r#   r$   Útest_event_equality‹   s"   z!EventTypeTest.test_event_equalityN)Ú__name__Ú
__module__Ú__qualname__r%   r-   r5   r:   r#   r#   r#   r$   r   T   s
    "

r   zÈ
This test is dependent on timing. The event queue is cleared in preparation for
tests. There is a small window where outside events from the OS may have effected
results. Try running the test again.
c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚEventModuleArgsTestc                 C   ó   t j ¡  t j ¡  d S r.   ©r   ÚdisplayÚinitr   Úclearr,   r#   r#   r$   ÚsetUp°   ó   
zEventModuleArgsTest.setUpc                 C   s   t j ¡  d S r.   )r   rA   Úquitr,   r#   r#   r$   ÚtearDown´   s   zEventModuleArgsTest.tearDownc                 C   s°   t j ¡  t j d ¡ t j d d¡ t jjdd t jjdd t jjd d t jjt jt jgd t jjt jdd |  tt jjd¡ |  tt jjd¡ |  tt jjd¡ d S )	NTF©Úpump©Ú	eventtype©rK   rI   i   y      ð?       @Zfoo)	r   r   ÚgetÚKEYUPÚKEYDOWNr   r   r   Ú	TypeErrorr,   r#   r#   r$   Útest_get·   s   
zEventModuleArgsTest.test_getc                 C   s¢   t j ¡  t j d ¡ t j d d¡ t jjdd t jjdd t jjd d t jjt jt jgd t jjt jdd |  tt jjd¡ |  tt jj	g d¢¡ d S )NTFrH   rJ   rL   iÿÿ)r(   r8   r9   )
r   r   rC   rN   rO   r   r   r   rP   rM   r,   r#   r#   r$   Ú
test_clearÇ   s   
zEventModuleArgsTest.test_clearc                 C   sÂ   t j ¡  t j d ¡ t j d d¡ t jjdd t jjdd t jjd d t jjt jt jgd t jjt jdd G dd„ dƒ}|  tt jjd¡ |  tt jjd	g¡ |  tt jj|ƒ ¡ d S )
NTFrH   rJ   rL   c                   @   s   e Zd ZdS )z*EventModuleArgsTest.test_peek.<locals>.FooN)r;   r<   r=   r#   r#   r#   r$   ÚFooá   s    rS   éÿÿÿÿiöÿÿÿ)	r   r   ÚpeekrN   rO   r   r   r   rP   )r   rS   r#   r#   r$   Ú	test_peekÖ   s   
zEventModuleArgsTest.test_peekN)r;   r<   r=   rD   rG   rQ   rR   rV   r#   r#   r#   r$   r>   ¯   s    r>   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚEventCustomTypeTestzrThose tests are special in that they need the _custom_event counter to
    be reset before and/or after being run.c                 C   s   t  ¡  t  ¡  t j ¡  d S r.   )r   rF   rB   rA   r,   r#   r#   r$   rD   î   s   zEventCustomTypeTest.setUpc                 C   s   t  ¡  d S r.   )r   rF   r,   r#   r#   r$   rG   ó   s   zEventCustomTypeTest.tearDownc                 C   s†   |   tj ¡ tjd ¡ tj ¡ }tj ¡ }|   ||d ¡ tj |¡}tj |¡ tj |¡}|   t|ƒd¡ |   |d j	|¡ d S )Nr   r   )
r   r   r   Úcustom_typer   r   ÚpostrM   Úlenr   )r   ZatypeZatype2ÚevÚqueuer#   r#   r$   Útest_custom_typeö   s   

z$EventCustomTypeTest.test_custom_typec                 C   s|   d}t j ¡ d }t|t jƒD ]}t j ¡ }q|  |t jd ¡ |  t j¡ t j ¡  W d  ƒ dS 1 s7w   Y  dS )z”Ensure custom_type() raises error when no more custom types.

        The last allowed custom type number should be (pygame.NUMEVENTS - 1).
        rT   r   N)r   r   rX   ÚrangeÚ	NUMEVENTSr   r   Úerror)r   ÚlastÚstartÚ_r#   r#   r$   Útest_custom_type__end_boundary  s   "ÿz2EventCustomTypeTest.test_custom_type__end_boundaryc                 C   sP   t j ¡ }|  |t j ¡ d ¡ t  ¡  t  ¡  t j ¡  |  |t j ¡ ¡ dS )z2Ensure custom events get 'deregistered' by quit().r   N)r   r   rX   r   rF   rB   rA   )r   Úbeforer#   r#   r$   Útest_custom_type__reset  s   

z+EventCustomTypeTest.test_custom_type__resetN)	r;   r<   r=   Ú__doc__rD   rG   r]   rd   rf   r#   r#   r#   r$   rW   ê   s    rW   c                   @   sŒ  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d„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$e% &dE¡dFdG„ ƒZ'dHdI„ Z(dJdK„ Z)e% &dE¡dLdM„ ƒZ*e% +e,j- .dN¡dOkdP¡e% +e/ 0¡ dQk dR¡dSdT„ ƒƒZ1dUdV„ Z2dWS )XÚEventModuleTestc                 O   s   | j |i |¤Ž d S r.   )ÚassertCountEqual)r   ÚargsÚkwargsr#   r#   r$   Ú_assertCountEqual  s   z!EventModuleTest._assertCountEqualc                 C   sš   |dd… }|D ]4}|D ]}|j D ]}|j | |j | kr nq| |¡  nqtdt|ƒ d t|ƒ d t|ƒ ƒ‚qt|ƒdkrKtdt|ƒ ƒ‚dS )zFind events like expected events, raise on unexpected or missing,
        ignore additional event properties if expected properties are present.Nz	Expected z among remaining events z out of r   zUnexpected Events: )r   ÚremoveÚAssertionErrorr)   rZ   )r   ÚexpectedÚgotZ
items_leftZexpected_elementÚitemr   r#   r#   r$   Ú_assertExpectedEvents!  s6   
ÿ
üÿþýüûÿþ
ÿz%EventModuleTest._assertExpectedEventsc                 C   r?   r.   r@   r,   r#   r#   r$   rD   =  rE   zEventModuleTest.setUpc                 C   r?   r.   ©r   r   rC   rA   rF   r,   r#   r#   r$   rG   A  rE   zEventModuleTest.tearDownc                 C   s   d}|   tj|¡ dS )zCEnsures NUMEVENTS does not exceed the maximum SDL number of events.r   N)ZassertLessEqualr   r_   )r   ZMAX_SDL_EVENTSr#   r#   r$   Útest_event_numeventsE  s   z$EventModuleTest.test_event_numeventsc                 C   s$   t jjt jdd}|  |jd¡ d S )NÚattr1©ru   )r   r   r   r   r   ru   )r   Úe1r#   r#   r$   Útest_event_attributeL  s   z$EventModuleTest.test_event_attributec                    sà   t d ‰ t d }tj ˆ ¡ |  tj ˆ ¡¡ |  tj |¡¡ tj tjjˆ fi t	ˆ  ¤Ž¡}|  |¡ tj tjj|fi t	| ¤Ž¡}|  |¡ tj 
¡ }‡ fdd„|D ƒ}‡ fdd„|D ƒ}|  |g ¡ |  ||v ¡ dS )z,Ensure events can be blocked from the queue.r   r   c                    s   g | ]	}|j ˆ kr|‘qS r#   r   ©Ú.0r   ©r   r#   r$   Ú
<listcomp>e  s    z4EventModuleTest.test_set_blocked.<locals>.<listcomp>c                    s   g | ]
}|j ˆ kr|j ‘qS r#   r   ry   r{   r#   r$   r|   f  s    N)r*   r   r   Úset_blockedr3   Úget_blockedr/   rY   r   ÚEVENT_TEST_PARAMSrM   r   )r   Zunblocked_eventZpostedÚretZshould_be_blockedZshould_be_allowed_typesr#   r{   r$   Útest_set_blockedP  s$   ÿ
ÿ

z EventModuleTest.test_set_blockedc                 C   sL   t jt jt jt jt jt jt jg}t j 	|¡ |D ]}|  
t j |¡¡ qdS )z0Ensure a sequence of event types can be blocked.N)r   rO   rN   ÚMOUSEMOTIONr1   ÚMOUSEBUTTONUPZWINDOWFOCUSLOSTr   r   r}   r3   r~   ©r   Úevent_typesÚetyper#   r#   r$   Ú test_set_blocked__event_sequencek  s   ù
ÿz0EventModuleTest.test_set_blocked__event_sequencec                 C   s,   t j d¡ tD ]}|  t j |¡¡ qdS )z+Ensure all events can be unblocked at once.N)r   r   r}   r*   r3   r~   ©r   r   r#   r#   r$   Útest_set_blocked_all|  s   ÿz$EventModuleTest.test_set_blocked_allc              	   C   s   t jjt jdd}t j |¡ t j ¡ }|  |j|jt¡ t	ddƒD ]#}t j t jjt
| fi tt
|  ¤Ž¡ |  t j ¡ jt
| t¡ q"dS )z)Ensure events can be posted to the queue.ru   rv   r   é   N)r   r   r   r   rY   Úpollr   ru   Úrace_condition_notificationr^   r*   r   r   )r   rw   Úposted_eventÚir#   r#   r$   Útest_post__and_pollƒ  s   
ÿÿûz#EventModuleTest.test_post__and_pollc                 C   sº   t j ¡ }t jjt jt jdt jjt jt j|dt jjt jt jddt jjt jt j	ddt jjt jt j
dddt jjt jt j|ddg}|D ]}t j |¡ t j ¡ }|  ||t¡ qFdS )	z1Ensure keydown events can be posted to the queue.©r   )r   ÚmodÚg)r   ÚunicodeN)r   r‘   Zwindowr   )r   r‘   r“   )r   r   Zget_modsr   r   rO   ZK_pZK_yZK_gÚK_aZK_mZK_erY   r‹   r   rŒ   )r   ZactivemodkeysÚeventsr   r   r#   r#   r$   Útest_post_and_get_keydown•  s   
ÿú
ýz)EventModuleTest.test_post_and_get_keydownc                 C   sj   t j t jjt jddittdƒƒd¡ t j ¡ }|  |j	t j¡ |  |j
d¡ |  |jttdƒƒ¡ d S )Nr(   A   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar   )Útest)r   r   rY   r   r   Úlistr^   r‹   r   r   r(   r—   rˆ   r#   r#   r$   Útest_post_large_user_event©  s   ÿÿ
z*EventModuleTest.test_post_large_user_eventc                 C   s„   t j t j¡ |  t j t j t j¡¡¡ |  t j ¡ ¡ t j t j¡ |  	t j t j t j¡¡¡ |  
t j ¡ t j t j¡¡ dS )zr
        Test blocked events are not posted. Also test whether post()
        returns a boolean correctly
        N)r   r   r}   r   r/   rY   r   r‹   Úset_allowedr3   r   r,   r#   r#   r$   Útest_post_blockedµ  s    z!EventModuleTest.test_post_blockedc                 C   s^   d}t |ƒD ]}tj tj tj¡¡ qtj ¡ }|  t|ƒ|¡ |  	t
dd„ |D ƒƒ¡ dS )z3Ensure get() retrieves all the events on the queue.r   c                 s   s    | ]	}|j tjkV  qd S r.   )r   r   r   ry   r#   r#   r$   Ú	<genexpr>Ê  s   € z+EventModuleTest.test_get.<locals>.<genexpr>N)r^   r   r   rY   r   r   rM   r   rZ   r3   Úall)r   Z	event_cntrc   r\   r#   r#   r$   rQ   Á  s   
zEventModuleTest.test_getc                 C   s¤   t j t j¡}t j |¡ t j t j¡}|  t|ƒd¡ |  |d jt j¡ d}t	|ƒD ]}t j |¡ q,t j t jg¡}|  t|ƒ|¡ |D ]}|  ||¡ qGd S )Nr   r   r   )
r   r   r   r   rY   rM   r   rZ   r   r^   )r   r[   r\   Z
TESTEVENTSrc   Úqr   r#   r#   r$   Útest_get_typeÌ  s   ÿzEventModuleTest.test_get_typec                 C   s    |   tjtjjtjdtj¡ d S )NF)r   r   r`   r   rM   rO   rN   r,   r#   r#   r$   Útest_get_exclude_throwÛ  s   ÿz&EventModuleTest.test_get_exclude_throwc                 C   sä   t j t j t j¡¡ t j t j t j¡¡ t jjt jd}|  t|ƒd¡ |  |d j	t j¡ t j t j t j
¡¡ t j t j t j¡¡ t jjt jt j
fd}|  t|ƒd¡ |  |d j	t j¡ t j ¡ }|  t|ƒd¡ d S )N)Úexcluder   r   r6   )r   r   rY   r   r   rO   rM   r   rZ   r   rN   )r   r\   r#   r#   r$   Útest_get_excludeà  s   
z EventModuleTest.test_get_excludec                 C   sb   g }t j ¡  t j ¡ }|  ||¡ tD ]}t j |¡}|  ||¡ qt j t¡}|  ||¡ dS )z/Ensure get() works correctly on an empty queue.N)r   r   rC   rM   ÚassertListEqualr*   )r   Úexpected_eventsÚretrieved_eventsr4   r#   r#   r$   Útest_get__empty_queueñ  s   

z%EventModuleTest.test_get__empty_queuec                 C   s@  t jt jt jg}t j}g }t j ¡  t j |¡}| j||d g }t j ¡  t j 	t jj
|fi t| ¤Ž¡ t j |¡}| j||d t jj
|d fi t|d  ¤Žg}t j ¡  t j 	|d ¡ t j |¡}| j||d t j ¡  g }|D ]}| t jj
|fi t| ¤Ž¡ t j 	|d ¡ qwt j |¡}| j||d dS )z2Ensure get() can handle a sequence of event types.)ro   rp   r   rT   N)r   rO   rN   r‚   rƒ   r   rC   rM   rr   rY   r   r   Úappend)r   r…   Úother_event_typer¤   r¥   r†   r#   r#   r$   Útest_get__event_sequence  s8   

ÿÿ

ÿz(EventModuleTest.test_get__event_sequencec                 C   s    t j ¡  |  t j ¡ g ¡ dS )z0Ensure get() clears the event queue after a callN)r   r   rM   r   r,   r#   r#   r$   Útest_get_clears_queue9  s   
z%EventModuleTest.test_get_clears_queuec                 C   sn   t D ]}tj tjj|fi t| ¤Ž¡ qtj ¡ }|  |jtj	¡ tj 
¡  tj ¡ }|  |jtj	t¡ dS )z3Ensure clear() removes all the events on the queue.N)r*   r   r   rY   r   r   r‹   r7   r   r0   rC   r   rŒ   )r   r   Z
poll_eventr#   r#   r$   rR   >  s   "


zEventModuleTest.test_clearc                 C   s2   g }t j ¡  t j ¡  t j ¡ }|  ||¡ dS )z1Ensure clear() works correctly on an empty queue.N)r   r   rC   rM   r£   )r   r¤   r¥   r#   r#   r$   Útest_clear__empty_queueK  s
   


z'EventModuleTest.test_clear__empty_queuec                 C   s¤   t dd… }t dd… }g }|D ]}tj tjj|fi t| ¤Ž¡ q|D ]}| tjj|fi t| ¤Ž¡ tj |d ¡ q%tj |¡ tj ¡ }|  	||¡ dS )z?Ensure a sequence of event types can be cleared from the queue.Né   r   rT   )
r*   r   r   rY   r   r   r§   rC   rM   rl   )r   Zcleared_event_typesZexpected_event_typesr¤   r†   Zremaining_eventsr#   r#   r$   Útest_clear__event_sequenceW  s   "ÿ
z*EventModuleTest.test_clear__event_sequencec                 C   s0   t D ]\}}|  tj |¡|d|d›¡ qdS )z3Ensure event_name() returns the correct event name.Ú0xÚXN©ÚNAMES_AND_EVENTSr   r   r   Ú
event_name©r   Zexpected_namer   r#   r#   r$   Útest_event_nameo  s
   ÿÿzEventModuleTest.test_event_namec                 C   s:   d}t tjtjƒD ]}|  tj |¡|d|d›¡ q	dS )zuEnsures event_name() returns the correct name for user events.

        Tests the full range of user events.
        r   r®   r¯   N)r^   r   r   r_   r   r   r²   r³   r#   r#   r$   Ú test_event_name__userevent_rangev  s   ÿÿz0EventModuleTest.test_event_name__userevent_rangec                 C   s<   d}t jd t jfD ]}|  t j |¡|d|d›¡ q
dS )zoEnsures event_name() does not return 'UserEvent' for events
        just outside the user event range.
        r   r   r®   r¯   N)r   r   r_   r7   r   r²   )r   Zunexpected_namer   r#   r#   r$   Ú#test_event_name__userevent_boundary‚  s   ÿÿz3EventModuleTest.test_event_name__userevent_boundaryc                 C   s2   t D ]\}}|  tjj|d|d|d›¡ qdS )zDEnsure event_name() returns the correct event name when kwargs used.r   r®   r¯   Nr°   r³   r#   r#   r$   Útest_event_name__kwargs  s
   ÿÿz'EventModuleTest.test_event_name__kwargsc                 C   sl   t jt jt jg}|D ]}t j t jj|fi t| ¤Ž¡ q
|D ]}|  t j 	|¡¡ q|  t j 	|¡¡ dS )z&Ensure queued events can be peeked at.N)
r   rO   rN   r‚   r   rY   r   r   r3   rU   )r   r…   r4   r#   r#   r$   rV   ”  s   ÿzEventModuleTest.test_peekc                 C   s  t jt jt jg}t j}t j ¡  t j |¡}|  |¡ t j ¡  t j 	t jj
|fi t| ¤Ž¡ t j |¡}|  |¡ t j ¡  t j 	t jj
|d fi t|d  ¤Ž¡ t j |¡}|  |¡ t j ¡  |D ]}t j 	t jj
|fi t| ¤Ž¡ qft j |¡}|  |¡ dS )z3Ensure peek() can handle a sequence of event types.r   N)r   rO   rN   r‚   rƒ   r   rC   rU   r/   rY   r   r   r3   )r   r…   r¨   Úpeekedr†   r#   r#   r$   Útest_peek__event_sequence¤  s,   


ÿ

ÿ

"z)EventModuleTest.test_peek__event_sequencec                 C   sX   t j ¡  t j ¡ }|  |¡ tD ]}t j |¡}|  |¡ qt j t¡}|  |¡ dS )z0Ensure peek() works correctly on an empty queue.N)r   r   rC   rU   r/   r*   )r   r¸   r4   r#   r#   r$   Útest_peek__empty_queueÌ  s   


z&EventModuleTest.test_peek__empty_queuec                 C   sH   t d }tj |¡ |  tj |¡¡ tj |¡ |  tj |¡¡ dS )z5Ensure a blocked event type can be unblocked/allowed.r   N)r*   r   r   r}   r3   r~   rš   r/   )r   r   r#   r#   r$   Útest_set_allowedß  s
   z EventModuleTest.test_set_allowedc                 C   sP   t jt jt jt jt jg}t j |¡ t j |¡ |D ]}|  	t j 
|¡¡ qdS )zBEnsure a sequence of blocked event types can be unblocked/allowed.N)r   rO   rN   r‚   r1   rƒ   r   r}   rš   r/   r~   r„   r#   r#   r$   Ú test_set_allowed__event_sequenceê  s   ûÿz0EventModuleTest.test_set_allowed__event_sequencec                 C   sT   t j d¡ tD ]}|  t j |¡¡ qt j d¡ tD ]}|  t j |¡¡ qdS )z3Ensure all events can be unblocked/allowed at once.N)r   r   r}   r*   r3   r~   rš   r/   rˆ   r#   r#   r$   Útest_set_allowed_allú  s   ÿz$EventModuleTest.test_set_allowed_allc                 C   s   t j ¡  dS )z!Ensure pump() functions properly.N)r   r   rI   r,   r#   r#   r$   Ú	test_pump  s   zEventModuleTest.test_pumpz(flaky test, and broken on 2.0.18 windowsc                 C   óH   t j d¡}t j d¡ |  t j ¡ ¡ t j d¡ |  t j ¡ ¡ dS )z¦Ensure event grabbing can be enabled and disabled.

        WARNING: Moving the mouse off the display during this test can cause it
                 to fail.
        ©r   r   TFN)r   rA   Úset_moder   Úset_grabr3   Úget_grabr/   ©r   Úsurfr#   r#   r$   Ú test_set_grab__and_get_symmetric  s
   z0EventModuleTest.test_set_grab__and_get_symmetricc                 C   s\   t j d¡ tD ]}t j |¡}|  |¡ qt j d¡ tD ]}t j |¡}|  |¡ qdS )z1Ensure an event's blocked state can be retrieved.N)r   r   rš   r*   r~   r/   r}   r3   )r   r†   Úblockedr#   r#   r$   Útest_get_blocked  s   ýz EventModuleTest.test_get_blockedc                 C   s‚   t jt jt jt jt jt jt jg}t j 	|¡}|  
|¡ t j |d ¡ t j 	|¡}|  |¡ t j |¡ t j 	|¡}|  |¡ dS )z:Ensure get_blocked() can handle a sequence of event types.r6   N)r   rO   rN   r‚   r1   rƒ   ZWINDOWMINIMIZEDr   r   r~   r/   r}   r3   )r   r…   rÇ   r#   r#   r$   Ú test_get_blocked__event_sequence1  s    ù

z0EventModuleTest.test_get_blocked__event_sequencec                 C   sD   t j d¡}tdƒD ]}t j |d ¡ |  t j ¡ |d ¡ q
dS )z#Ensure get_grab() works as expectedrÀ   r¬   r6   N)r   rA   rÁ   r^   r   rÂ   r   rÃ   )r   rÅ   rŽ   r#   r#   r$   Útest_get_grabU  s
   þzEventModuleTest.test_get_grabZSDL_VIDEODRIVERÚdummyz4requires the SDL_VIDEODRIVER to be a non dummy value)r6   r   é   zNeeds at least SDL 2.0.16c                 C   r¿   )zCEnsure set_keyboard_grab() and get_keyboard_grab() work as expectedrÀ   TFN)r   rA   rÁ   r   Zset_keyboard_grabr3   Zget_keyboard_grabr/   rÄ   r#   r#   r$   Ú,test_set_keyboard_grab_and_get_keyboard_grab^  s
   z<EventModuleTest.test_set_keyboard_grab_and_get_keyboard_grabc                 C   sÚ   t j ¡  t j ¡ }|  |jt j¡ t j t j¡}t jjt j	t j
d}t jjt jt j
d}t j |¡ t j |¡ t j |¡ |  t j ¡ j|j¡ |  t j ¡ j|j¡ |  t j ¡ j|j¡ |  t j ¡ jt j¡ dS )zEnsure poll() works as expectedr   N)r   r   rC   r‹   r   r   r0   r   r   rO   r”   rN   rY   )r   r[   rw   Úe2Ze3r#   r#   r$   Ú	test_polln  s   

zEventModuleTest.test_pollN)3r;   r<   r=   rl   rr   rD   rG   rt   rx   r   r‡   r‰   r   r–   r™   r›   rQ   rŸ   r    r¢   r¦   r©   rª   rR   r«   r­   r´   rµ   r¶   r·   rV   r¹   rº   r»   r¼   r½   r¾   ÚunittestÚskiprÆ   rÈ   rÉ   rÊ   ZskipIfÚosÚenvironrM   r   Zget_sdl_versionrÍ   rÏ   r#   r#   r#   r$   rh     s`    3(	
$
þrh   c                   @   s*   e Zd ZdgZdd„ Zdd„ Zdd„ ZdS )	ÚEventModuleTestsWithTimingZtimingc                 C   r?   r.   r@   r,   r#   r#   r$   rD   †  rE   z EventModuleTestsWithTiming.setUpc                 C   r?   r.   rs   r,   r#   r#   r$   rG   Š  rE   z#EventModuleTestsWithTiming.tearDownc                 C   s®  t jjtd fi ttd  ¤Ž}t j |¡ t j ¡ }|  |j|j¡ t j d¡}|  |jt j	¡ t jjtd fi ttd  ¤Ž}t j |¡ t j d¡}|  |j|j¡ t j
 t jdd¡ dt jdfdt jdfdt j	dfdt jd	fd
t j	d
ffD ]"\}}}t
 ¡ }|  t j |¡j|¡ | jt
 ¡ | |d dd qyt j
 t jdd¡ t
 ¡ }|  t j ¡ jt j¡ | jt
 ¡ | ddd t j
 t jdd¡ |  t j d¡jt j	¡ dS )z.Ensure wait() waits for an event on the queue.r   r   é2   é   é<   éA   é   é-   é   éF   iè  g{®Gáz„?)Údeltar   gš™™™™™¹?é(   N)r   r   r   r*   r   rY   Úwaitr   r   r0   ÚtimeZ	set_timerr   Úperf_counterZassertAlmostEqual)r   r   Z
wait_eventZ	wait_timeÚexpected_typeZexpected_timeÚ
start_timer#   r#   r$   Útest_event_waitŽ  s8    
 




ûÿz*EventModuleTestsWithTiming.test_event_waitN)r;   r<   r=   Z__tags__rD   rG   rä   r#   r#   r#   r$   rÔ   ƒ  s
    rÔ   Ú__main__);Úcollectionsrà   rÐ   rÒ   r   rO   rN   r‚   r1   rƒ   ZJOYAXISMOTIONZJOYBALLMOTIONZJOYHATMOTIONZJOYBUTTONDOWNZJOYBUTTONUPZVIDEORESIZEZVIDEOEXPOSEZQUITZ
SYSWMEVENTr   r*   Údefaultdictr   r   ÚupdateZK_SPACEr0   r2   ZMIDIINZMIDIOUTZFINGERMOTIONZ
FINGERDOWNZFINGERUPZMULTIGESTUREZ
MOUSEWHEELZ	TEXTINPUTZTEXTEDITINGZCONTROLLERAXISMOTIONZCONTROLLERBUTTONDOWNZCONTROLLERBUTTONUPZCONTROLLERDEVICEADDEDZCONTROLLERDEVICEREMOVEDZCONTROLLERDEVICEREMAPPEDZDROPFILEZAUDIODEVICEADDEDZAUDIODEVICEREMOVEDZDROPTEXTZ	DROPBEGINZDROPCOMPLETEr±   ZTestCaser   rŒ   r>   rW   rh   rÔ   r;   Úmainr#   r#   r#   r$   Ú<module>   sô    ï


ûÿÿþýüûúùø	÷
öõôóòñðïîíìëêéèçæåäãâá à!ß"Þ#Ý$Ü%Û&Ú'Ù+T;1    l
=ÿ