Format: application/x-python-code
⬇ Download File (9.5 KB)
   1  o
   2  
   3  ��ha$�@s\dZddlmZmZddlmZmZmZddl	Z	ddl
   4  mZmZddl
   5  Z
   6  ddlZddlmZddlZzddlZWn	eyAYnwddlmZddlmZd	d
   7  �Zdd�Zd
   8  d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z dd�Z!dd�Z"dd �Z#d!d"�Z$d#d$�Z%Gd%d&�d&e�Z&d'd(�Z'e'�Gd)d*�d*e&��Z(ed2d,d-��Z)d.d/�Z*d0d1�Z+dS)3z Tests for IPython.lib.display.
   9  
  10  �)�NamedTemporaryFile�mkdtemp)�split�join�dirnameN)�TestCase�mock)�BytesIO)�display)�skipif_not_numpycCst�d�}t�t�d��}dS)z(FileLink: Test class can be instantiated�example.txtN)r
  11  �FileLink�pathlib�PurePath��fl�r�Tc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/lib/tests/test_display.py�test_instantiation_FileLink,s
  12  rcC� t�d�}|���d�sJ�dS)zEFileLink: Calling _repr_html_ on non-existent files returns a warningrzPath (<tt>example.txt</tt>)N)r
  13  r
  14  �_repr_html_�
  15  startswithrrrr�*test_warning_on_non_existent_path_FileLink2�
  16  rcCs:t�}t�|j�}|��}d|j|jf}||ksJ�dS)zMFileLink: Calling _repr_html_ functions as expected on existing filepath
  17      z'<a href='%s' target='_blank'>%s</a><br>N)rr
  18  r
  19  �namer��tfr�actual�expectedrrr�test_existing_path_FileLink8s
  20  rcCs0t�}t�|j�}t|�}|j}||ksJ�dS)zHFileLink: Calling repr() functions as expected on existing filepath
  21      N)rr
  22  r
  23  r�reprrrrr� test_existing_path_FileLink_reprBs
  24  r!cCst�}t�ttj|�dS)z1FileLink: Raises error when passed directory
  25      N)r�pytest�raises�
  26  ValueErrorr
  27  r
  28  )�tdrrr�#test_error_on_directory_to_FileLinkLsr&cCst�d�}dS)z.FileLinks: Test class can be instantiated
  29      �exampleN)r
  30  �	FileLinks�Zflsrrr�test_instantiation_FileLinksVsr*cCr)zFFileLinks: Calling _repr_html_ on non-existent files returns a warningr'zPath (<tt>example</tt>)N)r
  31  r(rrr)rrr�+test_warning_on_non_existent_path_FileLinks[rr+cCs�t�}t|d�}t|d�}t�|�}|��}|�d�}|��d|d|j�dd�t|j�dfd|j�dd�t|j�dfg}|��||ksLJ�dS)	zIFileLinks: Calling _repr_html_ functions as expected on existing dir
  32      ��dir�
  33  z%s/<br>z3&nbsp;&nbsp;<a href='%s' target='_blank'>%s</a><br>�\�/�N)	rrr
  34  r(rr�sortr�replace�r%�tf1�tf2rrrrrr�test_existing_path_FileLinksas"
  35  
  36  
  37  
  38  ���r7cCsjt�}t|d�}t|d�}dd�}tj||d�}|��}|�d�}|��ddg}|��||ks3J�dS)	zMFileLinks: Calling _repr_html_ functions as expected w/ an alt formatter
  39      r,cS�ddgS�N�hello�worldr�r�fnamesZincluded_suffixesrrr�fake_formatter}�zBtest_existing_path_FileLinks_alt_formatter.<locals>.fake_formatter)Znotebook_display_formatterr.r:r;N)rrr
  40  r(rrr2�r%r5r6r>rrrrrr�*test_existing_path_FileLinks_alt_formatterw�
  41  
  42  
  43  rAcCs�t�}t|d�}t|d�}t�|�}t|�}|�d�}|��d|dt|j�ddt|j�dg}|��||ks>J�dS)zFFileLinks: Calling repr() functions as expected on existing directory r,r.z%s/z  %sr1N)rrr
  44  r(r rr2rr4rrr�!test_existing_path_FileLinks_repr�s
  45  
  46  
  47  
  48  *rCcCsjt�}t|d�}t|d�}dd�}tj||d�}t|�}|�d�}|��ddg}|��||ks3J�dS)	zEFileLinks: Calling repr() functions as expected w/ alt formatter
  49      r,cSr8r9rr<rrrr>�r?zGtest_existing_path_FileLinks_repr_alt_formatter.<locals>.fake_formatter)Zterminal_display_formatterr.r:r;N)rrr
  50  r(r rr2r@rrr�/test_existing_path_FileLinks_repr_alt_formatter�rBrDcCs&t�}t|d�}t�ttj|j�dS)z-FileLinks: Raises error when passed file
  51      r,N)rrr"r#r$r
  52  r(r)r%r5rrr�test_error_on_file_to_FileLinks�s
  53  rEcCs�t�}t|d�}t|d�}t|d�}t�|�}t|�}|�d�}t|�dks*J|��tj|dd�}t|�}|�d�}t|�dksDJ|��dS)z5FileLinks: Does not recurse when recursive=False
  54      r,r.�F)�	recursive�N)rrr
  55  r(�strr�len)r%rZsubtdZsubtfrrrrr�test_recursive_FileLinks�s
  56  
  57  
  58  
  59  
  60  
  61  rKcCsttt�d�}tj|d�dS)Nztest.wav��filename)�pjoinr�__file__r
  62  �Audio)�pathrrr�test_audio_from_file�srRc@sPeZdZedd��Zedd��Zedd��Zedd��Zed	d
  63  ��Zdd�Z	d
  64  S)�TestAudioDataWithNumpycCs2t�}tj|dd�}tt|j��t|�ksJ�dS�N�D���rate)�
  65  get_test_toner
  66  rPrJ�read_wav�data��self�	test_tone�audiorrr�test_audio_from_numpy_array�sz2TestAudioDataWithNumpy.test_audio_from_numpy_arraycCs6t�}tjt|�dd�}tt|j��t|�ksJ�dSrT)rXr
  67  rP�listrJrYrZr[rrr�test_audio_from_list�sz+TestAudioDataWithNumpy.test_audio_from_listcCs|�ttjt��dS�N)�assertRaisesr$r
  68  rPrX�r\rrr�/test_audio_from_numpy_array_without_rate_raises�szFTestAudioDataWithNumpy.test_audio_from_numpy_array_without_rate_raisescCsPt�tj�j}dD]}tjt|�dd�}t�t�t|j	���}||ks%J�q	dS)N)r1��?rHrUrV)
  69  �numpy�iinfo�int16�maxr
  70  rPrX�absrYrZ)r\�expected_max_value�scaler^�actual_max_valuerrr�test_audio_data_normalization�s�z4TestAudioDataWithNumpy.test_audio_data_normalizationcCsrt�tj�j}dD]-}t|�}t�t�|��}t||�}tj|ddd�}t�t�t	|j
  71  ���}||ks6J�q	dS)N)r1rfg�������?rUF�rW�	normalize)rgrhrirjrXrk�intr
  72  rPrYrZ)r\Z	max_int16rmr]Ztest_tone_max_absrlr^rnrrr�%test_audio_data_without_normalization�s�z<TestAudioDataWithNumpy.test_audio_data_without_normalizationcCs$|�tdd��|�tdd��dS)NcS�tjdgddd�S)Ngj�t��?rUFrp�r
  73  rPrrrr�<lambda>��zfTestAudioDataWithNumpy.test_audio_data_without_normalization_raises_for_invalid_data.<locals>.<lambda>cSrt)Ngj�t��rUFrprurrrrrv�rw)rcr$rdrrr�=test_audio_data_without_normalization_raises_for_invalid_data�s��zTTestAudioDataWithNumpy.test_audio_data_without_normalization_raises_for_invalid_dataN)
  74  �__name__�
  75  __module__�__qualname__rr_rarerorsrxrrrrrS�s
  76  
  77  
  78  
  79  
  80  
  81  rScCs:zddl}t�dtjtd��WStydd�YSw)Nrznumpy.array)Zside_effectcSs|Srbr)�xrrrrv�sz.simulate_numpy_not_installed.<locals>.<lambda>)rgr�patchZ	MagicMock�ImportError�ModuleNotFoundError)rgrrr�simulate_numpy_not_installed�s�r�c@seZdZedd��ZdS)�TestAudioDataWithoutNumpycs(tt��gd�|�t�fdd��dS)NrHcstj�dd�SrTrur�Z
  82  stereo_signalrrrvszMTestAudioDataWithoutNumpy.test_audio_raises_for_nested_list.<locals>.<lambda>)r`rXrc�	TypeErrorrdrr�r�!test_audio_raises_for_nested_list�sz;TestAudioDataWithoutNumpy.test_audio_raises_for_nested_listN)ryrzr{rr�rrrrr��sr�r1cCs&t�dtjdt�ddd��|S)NrHi�rr1rU)rg�sin�piZlinspace)rmrrrrXs&rXcCs`t�t|���}|�|���}|��|��}t�d||�Wd�S1s)wYdS)Nz<%sh)�wave�openr	Z
  83  readframesZ
  84  getnframesZgetnchannels�struct�unpack)rZZ	wave_fileZ	wave_dataZnum_samplesrrrrYs
  85  $�rYcCs"tjtd�}|���d�sJ�dS)NrLz<style>)r
  86  ZCoderOrr)�crrr�test_code_from_filesr�)r1),�__doc__�tempfilerrZos.pathrrrNrrZunittestrrr�r��ior	r"rgr~ZIPython.libr
  87  ZIPython.testing.decoratorsrrrrr!r&r*r+r7rArCrDrErKrRrSr�r�rXrYr�rrrr�<module>sL�
  88  
  89  
  90  
  91  -