o
    û›ha$  ã                   @   s\  d Z ddlmZmZ ddlmZmZmZ ddl	Z	ddl
mZmZ ddlZddlZddlmZ ddlZzddlZW n	 eyA   Y nw ddlmZ ddlm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%G d%d&„ d&eƒZ&d'd(„ Z'e'ƒ G d)d*„ d*e&ƒƒZ(ed2d,d-„ƒZ)d.d/„ Z*d0d1„ Z+dS )3z Tests for IPython.lib.display.

é    )ÚNamedTemporaryFileÚmkdtemp)ÚsplitÚjoinÚdirnameN)ÚTestCaseÚmock)ÚBytesIO)Údisplay)Úskipif_not_numpyc                  C   s   t  d¡} t  t d¡¡} dS )z(FileLink: Test class can be instantiatedúexample.txtN)r
   ÚFileLinkÚpathlibÚPurePath©Úfl© r   úTc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/lib/tests/test_display.pyÚtest_instantiation_FileLink,   s   
r   c                  C   ó    t  d¡} |  ¡  d¡sJ ‚dS )zEFileLink: Calling _repr_html_ on non-existent files returns a warningr   zPath (<tt>example.txt</tt>)N)r
   r   Ú_repr_html_Ú
startswithr   r   r   r   Ú*test_warning_on_non_existent_path_FileLink2   ó   
r   c                  C   s:   t ƒ } t | j¡}| ¡ }d| j| jf }||ksJ ‚dS )zMFileLink: Calling _repr_html_ functions as expected on existing filepath
    z'<a href='%s' target='_blank'>%s</a><br>N)r   r
   r   Únamer   ©Útfr   ÚactualÚexpectedr   r   r   Útest_existing_path_FileLink8   s
   r   c                  C   s0   t ƒ } t | j¡}t|ƒ}| j}||ksJ ‚dS )zHFileLink: Calling repr() functions as expected on existing filepath
    N)r   r
   r   r   Úreprr   r   r   r   Ú test_existing_path_FileLink_reprB   s
   r!   c                  C   s   t ƒ } t ttj| ¡ dS )z1FileLink: Raises error when passed directory
    N)r   ÚpytestÚraisesÚ
ValueErrorr
   r   )Útdr   r   r   Ú#test_error_on_directory_to_FileLinkL   s   r&   c                  C   s   t  d¡} dS )z.FileLinks: Test class can be instantiated
    ÚexampleN)r
   Ú	FileLinks©Zflsr   r   r   Útest_instantiation_FileLinksV   s   r*   c                  C   r   )zFFileLinks: Calling _repr_html_ on non-existent files returns a warningr'   zPath (<tt>example</tt>)N)r
   r(   r   r   r)   r   r   r   Ú+test_warning_on_non_existent_path_FileLinks[   r   r+   c                  C   sœ   t ƒ } t| d�}t| d�}t | ¡}| ¡ }| d¡}| ¡  d|  d|j dd¡t|jƒd f d|j dd¡t|jƒd f g}| ¡  ||ksLJ ‚dS )	zIFileLinks: Calling _repr_html_ functions as expected on existing dir
    ©ÚdirÚ
z%s/<br>z3&nbsp;&nbsp;<a href='%s' target='_blank'>%s</a><br>ú\ú/é   N)	r   r   r
   r(   r   r   Úsortr   Úreplace©r%   Útf1Útf2r   r   r   r   r   r   Útest_existing_path_FileLinksa   s"   



ÿÿýr7   c                  C   sj   t ƒ } t| d�}t| d�}dd„ }tj| |d�}| ¡ }| d¡}| ¡  ddg}| ¡  ||ks3J ‚dS )	zMFileLinks: Calling _repr_html_ functions as expected w/ an alt formatter
    r,   c                 S   ó   ddgS ©NÚhelloÚworldr   ©r   ÚfnamesZincluded_suffixesr   r   r   Úfake_formatter}   ó   zBtest_existing_path_FileLinks_alt_formatter.<locals>.fake_formatter)Znotebook_display_formatterr.   r:   r;   N)r   r   r
   r(   r   r   r2   ©r%   r5   r6   r>   r   r   r   r   r   r   Ú*test_existing_path_FileLinks_alt_formatterw   ó   


rA   c                  C   s€   t ƒ } t| d�}t| d�}t | ¡}t|ƒ}| d¡}| ¡  d|  dt|jƒd  dt|jƒd  g}| ¡  ||ks>J ‚dS )zFFileLinks: Calling repr() functions as expected on existing directory r,   r.   z%s/z  %sr1   N)r   r   r
   r(   r    r   r2   r   r4   r   r   r   Ú!test_existing_path_FileLinks_repr‰   s   



*rC   c                  C   sj   t ƒ } t| d�}t| d�}dd„ }tj| |d�}t|ƒ}| d¡}| ¡  ddg}| ¡  ||ks3J ‚dS )	zEFileLinks: Calling repr() functions as expected w/ alt formatter
    r,   c                 S   r8   r9   r   r<   r   r   r   r>   ž   r?   zGtest_existing_path_FileLinks_repr_alt_formatter.<locals>.fake_formatter)Zterminal_display_formatterr.   r:   r;   N)r   r   r
   r(   r    r   r2   r@   r   r   r   Ú/test_existing_path_FileLinks_repr_alt_formatter˜   rB   rD   c                  C   s&   t ƒ } t| d�}t ttj|j¡ dS )z-FileLinks: Raises error when passed file
    r,   N)r   r   r"   r#   r$   r
   r(   r   )r%   r5   r   r   r   Útest_error_on_file_to_FileLinksª   s   
rE   c                  C   sŒ   t ƒ } t| d�}t | d�}t|d�}t | ¡}t|ƒ}| d¡}t|ƒdks*J |ƒ‚tj| dd�}t|ƒ}| d¡}t|ƒdksDJ |ƒ‚dS )z5FileLinks: Does not recurse when recursive=False
    r,   r.   é   F)Ú	recursiveé   N)r   r   r
   r(   Ústrr   Úlen)r%   r   ZsubtdZsubtfr   r   r   r   r   Útest_recursive_FileLinks²   s   





rK   c                  C   s   t ttƒdƒ} tj| d� d S )Nztest.wav©Úfilename)Úpjoinr   Ú__file__r
   ÚAudio)Úpathr   r   r   Útest_audio_from_fileÂ   s   rR   c                   @   sP   e Zd Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZed	d
„ ƒZdd„ Z	dS )ÚTestAudioDataWithNumpyc                 C   s2   t ƒ }tj|dd�}tt|jƒƒt|ƒksJ ‚d S ©NéD¬  ©Úrate)Úget_test_toner
   rP   rJ   Úread_wavÚdata©ÚselfÚ	test_toneÚaudior   r   r   Útest_audio_from_numpy_arrayÈ   s   z2TestAudioDataWithNumpy.test_audio_from_numpy_arrayc                 C   s6   t ƒ }tjt|ƒdd�}tt|jƒƒt|ƒksJ ‚d S rT   )rX   r
   rP   ÚlistrJ   rY   rZ   r[   r   r   r   Útest_audio_from_listÎ   s   z+TestAudioDataWithNumpy.test_audio_from_listc                 C   s   |   ttjtƒ ¡ d S ©N)ÚassertRaisesr$   r
   rP   rX   ©r\   r   r   r   Ú/test_audio_from_numpy_array_without_rate_raisesÔ   s   zFTestAudioDataWithNumpy.test_audio_from_numpy_array_without_rate_raisesc                 C   sP   t  t j¡j}dD ]}tjt|ƒdd�}t  t  t|j	ƒ¡¡}||ks%J ‚q	d S )N)r1   ç      à?rH   rU   rV   )
ÚnumpyÚiinfoÚint16Úmaxr
   rP   rX   ÚabsrY   rZ   )r\   Úexpected_max_valueÚscaler^   Úactual_max_valuer   r   r   Útest_audio_data_normalizationØ   s   ýz4TestAudioDataWithNumpy.test_audio_data_normalizationc                 C   sr   t  t j¡j}dD ]-}t|ƒ}t  t  |¡¡}t|| ƒ}tj|ddd�}t  t  t	|j
ƒ¡¡}||ks6J ‚q	d S )N)r1   rf   gš™™™™™É?rU   F©rW   Ú	normalize)rg   rh   ri   rj   rX   rk   Úintr
   rP   rY   rZ   )r\   Z	max_int16rm   r]   Ztest_tone_max_absrl   r^   rn   r   r   r   Ú%test_audio_data_without_normalizationà   s   úz<TestAudioDataWithNumpy.test_audio_data_without_normalizationc                 C   s$   |   tdd„ ¡ |   tdd„ ¡ d S )Nc                   S   ó   t jdgddd�S )Ngj¼t“ð?rU   Frp   ©r
   rP   r   r   r   r   Ú<lambda>î   ó    zfTestAudioDataWithNumpy.test_audio_data_without_normalization_raises_for_invalid_data.<locals>.<lambda>c                   S   rt   )Ngj¼t“ð¿rU   Frp   ru   r   r   r   r   rv   ñ   rw   )rc   r$   rd   r   r   r   Ú=test_audio_data_without_normalization_raises_for_invalid_dataë   s   þþzTTestAudioDataWithNumpy.test_audio_data_without_normalization_raises_for_invalid_dataN)
Ú__name__Ú
__module__Ú__qualname__r   r_   ra   re   ro   rs   rx   r   r   r   r   rS   Æ   s    





rS   c                  C   s:   zdd l } t dtjtd�¡W S  ty   dd„  Y S w )Nr   znumpy.array)Zside_effectc                 S   s   | S rb   r   )Úxr   r   r   rv   ø   s    z.simulate_numpy_not_installed.<locals>.<lambda>)rg   r   ÚpatchZ	MagicMockÚImportErrorÚModuleNotFoundError)rg   r   r   r   Úsimulate_numpy_not_installedó   s   ÿr€   c                   @   s   e Zd Zedd„ ƒZdS )ÚTestAudioDataWithoutNumpyc                    s(   t tƒ ƒgd ‰ |  t‡ fdd„¡ d S )NrH   c                      s   t jˆ dd�S rT   ru   r   ©Zstereo_signalr   r   rv     s    zMTestAudioDataWithoutNumpy.test_audio_raises_for_nested_list.<locals>.<lambda>)r`   rX   rc   Ú	TypeErrorrd   r   r‚   r   Ú!test_audio_raises_for_nested_listþ   s   z;TestAudioDataWithoutNumpy.test_audio_raises_for_nested_listN)ry   rz   r{   r   r„   r   r   r   r   r�   ú   s    r�   r1   c                 C   s&   t  dt j d t  ddd¡ ¡|  S )NrH   i¸  r   r1   rU   )rg   ÚsinÚpiZlinspace)rm   r   r   r   rX     s   &rX   c                 C   s`   t  t| ƒ¡�}| | ¡ ¡}| ¡ | ¡  }t d| |¡W  d   ƒ S 1 s)w   Y  d S )Nz<%sh)ÚwaveÚopenr	   Z
readframesZ
getnframesZgetnchannelsÚstructÚunpack)rZ   Z	wave_fileZ	wave_dataZnum_samplesr   r   r   rY     s
   $ýrY   c                  C   s"   t jtd�} |  ¡  d¡sJ ‚d S )NrL   z<style>)r
   ZCoderO   r   r   )Úcr   r   r   Útest_code_from_file  s   rŒ   )r1   ),Ú__doc__Útempfiler   r   Zos.pathr   r   rN   r   r   Zunittestr   r   r‰   r‡   Úior	   r"   rg   r~   ZIPython.libr
   ZIPython.testing.decoratorsr   r   r   r   r!   r&   r*   r+   r7   rA   rC   rD   rE   rK   rR   rS   r€   r�   rX   rY   rŒ   r   r   r   r   Ú<module>   sL    ÿ



-	