o
    tVÆgÈ#  ã                   @   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 )é    NÚ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   úK/home/ubuntu/.local/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   Ú	data_typeÚ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©Ú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_SELECTIONÚ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.bmpÚRGBAN)
r   ÚimageÚloadr   Útostringr   r    Ú	SCRAP_BMPr!   r"   )r   ÚsfÚ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   r2   Úrr   r   r   Útest_putk   s   
zScrapModuleTest.test_putN)Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r   r   r%   r&   r*   r,   r-   r4   r5   r:   r;   ÚunittestÚskipIfÚsysÚmodulesrC   rE   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)rO   r   r"   r0   r1   r   r   r   rQ   ‘   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)rO   r   Ú	get_typesÚassertIsInstanceÚlist)r   Ú
data_typesr   r   r   Útest_get_types__not_owned    s   z:ScrapModuleClipboardNotOwnedTest.test_get_types__not_ownedc                 C   rP   )zbEnsures contains works when the clipboard is not owned
        by the pygame application.
        Útest_contains__not_ownedN)rO   r   ÚcontainsÚassertFalse)r   r2   rX   r   r   r   rW   ª   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)rO   r   r.   r   )r   r.   r   r   r   Útest_lost__not_owned¸   s   z5ScrapModuleClipboardNotOwnedTest.test_lost__not_ownedN)rF   rG   rH   Ú__doc__rI   r   r   rO   rQ   rV   rW   rZ   r   r   r   r   rN   w   s    


rN   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   Ú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)r6   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   r_   r`   Úpygame.localsr6   r   ra   rb   rc   r   ÚFontÚset_captionr   ÚfillÚColorÚformatÚ	word_wrapÚflipÚpumpr   r    ÚencodeÚwaitÚtypeÚkeyr   r   )r   r   r_   r`   r6   r   ra   rb   rc   ÚsuccessÚfontÚscreenÚtextÚmsgÚer   r   r   Útest_issue_208Î   s<   

û



ú
z!X11InteractiveTest.test_issue_208N)rF   rG   rH   Ú__tags__r   r   r   Ú	ExceptionÚ
get_driverr   r{   r   r   r   r   r\   Ã   s    ÿ
r\   ©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ÚintÚget_sized_heightÚget_rectÚiwordsÚwidthÚxr9   ÚheightÚyÚ	render_to)Úsurfrx   rv   ÚmarginÚcolorÚ
surf_widthÚsurf_heightr‰   r‹   Úline_spacingrŠ   rŒ   ÚspaceÚwordÚboundsr   r   r   rn   ù   s(   

rn   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   r   r   r‚   )Úlen)rx   ÚheadÚtailÚendr   r   r   rˆ     s.   €

îrˆ   Ú__main__)r   r   )ÚosrL   Úenvironr"   r|   rJ   Úpygame.tests.test_utilsr   r   r   ÚTestCaser   rN   r\   rn   rˆ   rF   Úmainr   r   r   r   Ú<module>   s     jL
6ÿ