o
    OZŽhÈ#  ã                   @   s¬   d dl Z d dlZe j d¡dkrdZd dlZd dlmZ d dlZd dlm	Z	 G dd„ dej
ƒZG d	d
„ d
ej
ƒZG dd„ dej
ƒZddd„Zdd„ ZedkrTe ¡  dS dS )é    NZSDL_VIDEODRIVERÚdummy)ÚignoreÚsubprocess_ignore)Útrunk_relative_path)Úscrapc                   @   s–   e Zd Zedd„ ƒZe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e dejvd¡dd„ ƒZdd„ ZdS ) ÚScrapModuleTestc                 C   ó"   t j ¡  t j d¡ t ¡  d S ©N)é   r
   ©ÚpygameÚdisplayÚinitÚset_moder   ©Úcls© r   úF/var/www/auris/lib/python3.10/site-packages/pygame/tests/scrap_test.pyÚ
setUpClass   ó   
zScrapModuleTest.setUpClassc                 C   s   t j ¡  d S ©N)r   r   Úquitr   r   r   r   ÚtearDownClass   s   zScrapModuleTest.tearDownClassc                 C   s"   t  ¡  t  ¡  |  t  ¡ ¡ dS )zAEnsures scrap module still initialized after multiple init calls.N)r   r   Ú
assertTrueÚget_init©Úselfr   r   r   Ú	test_init   s   zScrapModuleTest.test_initc                 C   s4   t j}d}t ||¡ t ¡  |  t |¡|¡ dS )z?Ensures reinitializing the scrap module doesn't clear its data.s   test_init__reinitN)r   Ú
SCRAP_TEXTr   Úputr   ÚassertEqualÚget)r   Z	data_typeZexpected_datar   r   r   Útest_init__reinit    s
   z!ScrapModuleTest.test_init__reinitc                 C   s   |   t ¡ ¡ dS )z%Ensures get_init gets the init state.N)r   r   r   r   r   r   r   Útest_get_init*   s   zScrapModuleTest.test_get_initc                 C   ó   |   ¡  dS )z#Ensures contains works as expected.N©Zfailr   r   r   r   Útodo_test_contains.   ó   z"ScrapModuleTest.todo_test_containsc                 C   r$   )zEnsures get works as expected.Nr%   r   r   r   r   Útodo_test_get2   r'   zScrapModuleTest.todo_test_getc                 C   sD   d}t  ¡ rt  tjd¡ t  ¡ r|  d¡ t  |¡}|  |¡ dS )z•Ensures get works when there is no data of the requested type
        in the clipboard and the clipboard is owned by the pygame application.
        Útest_get__owned_empty_types   text to clipboardz4requires the pygame application to own the clipboardN)r   Úlostr   r   r   ÚskipTestr!   ÚassertIsNone©r   Ú	DATA_TYPEÚdatar   r   r   r)   6   s   

z*ScrapModuleTest.test_get__owned_empty_typec                 C   r$   )z$Ensures get_types works as expected.Nr%   r   r   r   r   Útodo_test_get_typesI   r'   z#ScrapModuleTest.todo_test_get_typesc                 C   r$   )zEnsures lost works as expected.Nr%   r   r   r   r   Útodo_test_lostM   r'   zScrapModuleTest.todo_test_lostc                 C   s,   t  tj¡ t  tj¡ |  tt jd¡ dS )z#Ensures set_mode works as expected.iK  N)r   r   r   ÚSCRAP_SELECTIONZSCRAP_CLIPBOARDÚassertRaisesÚ
ValueErrorr   r   r   r   Útest_set_modeQ   s   zScrapModuleTest.test_set_modec                 C   sH   t  tjd¡ |  t  tj¡d¡ t  tjd¡ |  t  tj¡d¡ dS )z.Ensures put can place text into the clipboard.s   Hello worlds   Another StringN)r   r   r   r   r    r!   r   r   r   r   Útest_put__textX   s   zScrapModuleTest.test_put__textzpygame.imagezrequires pygame.image modulec                 C   sD   t j tdƒ¡}t j |d¡}t t j|¡ |  t 	t j¡|¡ dS )z5Ensures put can place a BMP image into the clipboard.zexamples/data/asprite.bmpZRGBAN)
r   ÚimageÚloadr   Ztostringr   r   Z	SCRAP_BMPr    r!   )r   ZsfZexpected_stringr   r   r   Útest_put__bmp_imageb   s   z#ScrapModuleTest.test_put__bmp_imagec                 C   s*   d}t  |d¡ t  |¡}|  |d¡ dS )ziEnsures put can place data into the clipboard
        when using a user defined type identifier.
        zarbitrary buffers   bufN)r   r   r!   r    )r   r.   Úrr   r   r   Útest_putk   s   
zScrapModuleTest.test_putN)Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r   r   r"   r#   r&   r(   r)   r0   r1   r5   r6   ÚunittestZskipIfÚsysÚmodulesr9   r;   r   r   r   r   r      s$    




r   c                   @   sP   e Zd ZdZedd„ ƒZedd„ ƒZdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ ZdS )Ú ScrapModuleClipboardNotOwnedTestzæTest the scrap module's functionality when the pygame application is
    not the current owner of the clipboard.

    A separate class is used to prevent tests that acquire the clipboard from
    interfering with these tests.
    c                 C   r   r	   r   r   r   r   r   r      r   z+ScrapModuleClipboardNotOwnedTest.setUpClassc                 C   s   t  ¡  t j ¡  d S r   )r   r   r   r   r   r   r   r   …   s   z.ScrapModuleClipboardNotOwnedTest.tearDownClassc                 C   s   t  ¡ s|  d¡ d S d S )Nz8requires the pygame application to not own the clipboard)r   r*   r+   r   r   r   r   Ú_skip_if_clipboard_owned‹   s   ÿz9ScrapModuleClipboardNotOwnedTest._skip_if_clipboard_ownedc                 C   ó$   |   ¡  d}t |¡}|  |¡ dS )z¡Ensures get works when there is no data of the requested type
        in the clipboard and the clipboard is not owned by the pygame
        application.
        Útest_get__not_ownedN)rD   r   r!   r,   r-   r   r   r   rF   ‘   s   
z4ScrapModuleClipboardNotOwnedTest.test_get__not_ownedc                 C   s    |   ¡  t ¡ }|  |t¡ dS )zcEnsures get_types works when the clipboard is not owned
        by the pygame application.
        N)rD   r   Z	get_typesZassertIsInstanceÚlist)r   Ú
data_typesr   r   r   Útest_get_types__not_owned    s   z:ScrapModuleClipboardNotOwnedTest.test_get_types__not_ownedc                 C   rE   )zbEnsures contains works when the clipboard is not owned
        by the pygame application.
        Útest_contains__not_ownedN)rD   r   ÚcontainsZassertFalse)r   r.   rK   r   r   r   rJ   ª   s   
z9ScrapModuleClipboardNotOwnedTest.test_contains__not_ownedc                 C   s   |   ¡  t ¡ }|  |¡ dS )z^Ensures lost works when the clipboard is not owned
        by the pygame application.
        N)rD   r   r*   r   )r   r*   r   r   r   Útest_lost__not_owned¸   s   z5ScrapModuleClipboardNotOwnedTest.test_lost__not_ownedN)r<   r=   r>   Ú__doc__r?   r   r   rD   rF   rI   rJ   rL   r   r   r   r   rC   w   s    


rC   c                   @   s\   e Zd ZddgZzej ¡  W n	 ey   Y nw ej ¡ dkr#dgZej 	¡  dd„ Z
dS )ÚX11InteractiveTestr   r   Zx11Úinteractivec                 C   s  ddl m}m}m} ddlm}m} ddlm}m}m	} d}	| 
¡  | dd¡}
| 
¡  | d¡ | d	¡}| t  d
¡¡ d}d |¡}t|||
dƒ | ¡  | ¡  t 
¡  t |¡ t || d¡¡ 	 | ¡ }|j|krqn|j|kr||j|k}	nqgt j ¡  |  |	¡ dS )zÝPATCH: pygame.scrap on X11, fix copying into PRIMARY selection

        Copying into theX11 PRIMARY selection (mouse copy/paste) would not
        work due to a confusion between content type and clipboard type.

        r   )r   ÚeventÚfreetype)r2   r   )ÚKEYDOWNÚK_yÚQUITFNé   zInteractive X11 Paste Test)iX  éÈ   ÚwhitezScrap put() succeeded.z–Some text has been placed into the X11 clipboard. Please click the center mouse button in an open text window to retrieve it.

Did you get "{}"? (y/n)é   zUTF-8)r   r   rP   rQ   Zpygame.localsr2   r   rR   rS   rT   r   ZFontZset_captionr   ÚfillÚColorÚformatÚ	word_wrapÚflipZpumpr   r   ÚencodeÚwaitÚtypeÚkeyr   r   )r   r   rP   rQ   r2   r   rR   rS   rT   ÚsuccessÚfontÚscreenÚtextÚmsgÚer   r   r   Útest_issue_208Î   s<   

û



ú
z!X11InteractiveTest.test_issue_208N)r<   r=   r>   Ú__tags__r   r   r   Ú	ExceptionZ
get_driverr   rh   r   r   r   r   rN   Ã   s    ÿ
rN   ©r   r   r   c                 C   s  d|_ |  ¡ \}}|d|  }|d|  }td| ¡  ƒ}	|||	 }
}| d¡}t|ƒD ]R}|dkr;|||	 }
}q-| |¡}|
|j |j |krQ|||	 }
}|
|j |j |kr_tdƒ‚||j	 |j
 |krmtdƒ‚| | |
|fd |¡ |
|j|j 7 }
q-|
|fS )NTé   g      ô?ú Ú
zword too wide for the surfaceztext to long for the surface)ÚoriginÚget_sizeÚintZget_sized_heightZget_rectÚiwordsÚwidthÚxr4   ÚheightÚyZ	render_to)Zsurfre   rc   ÚmarginÚcolorZ
surf_widthZsurf_heightrs   ru   Zline_spacingrt   rv   ÚspaceÚwordZboundsr   r   r   r\   ù   s(   

r\   c                 c   sÐ    d}|}t | ƒ}||k rf| | dkr|d7 }|d }nD| | dkr.|d7 }dV  |d }n2||kr<| |d … V  |}n$| | dkrL| ||… V  |}n| | dkr\| ||… V  |}n|d7 }||k sd S d S )Nr   rm   r
   rn   )Úlen)re   ÚheadÚtailÚendr   r   r   rr     s.   €

îrr   Ú__main__)r   rk   )ÚosrA   Úenvironr!   ri   r@   Zpygame.tests.test_utilsr   r   r   ZTestCaser   rC   rN   r\   rr   r<   Úmainr   r   r   r   Ú<module>   s     jL
6ÿ