
    fa$                     X   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	 ddlZddlmZ ddlmZ d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z% G d de      Z&d Z' e'        G d de&             Z(edd       Z)d Z*d Z+y# e$ r Y pw xY w) z Tests for IPython.lib.display.

    )NamedTemporaryFilemkdtemp)splitjoindirnameN)TestCasemock)BytesIO)display)skipif_not_numpyc                  ~    t        j                  d      } t        j                  t        j                  d            } y)z(FileLink: Test class can be instantiatedexample.txtN)r   FileLinkpathlibPurePathfls    Y/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/lib/tests/test_display.pytest_instantiation_FileLinkr   ,   s-    			-	(B			'**=9	:B    c                  p    t        j                  d      } | j                         j                  d      sJ y)zEFileLink: Calling _repr_html_ on non-existent files returns a warningr   zPath (<tt>example.txt</tt>)N)r   r   _repr_html_
startswithr   s    r   *test_warning_on_non_existent_path_FileLinkr   2   s.    			-	(B>>&&'DEEEr   c                      t               } t        j                  | j                        }|j	                         }d| j                  d| j                  d}||k(  sJ y)zMFileLink: Calling _repr_html_ functions as expected on existing filepath
    z	<a href='' target='_blank'></a><br>N)r   r   r   namer   tfr   actualexpecteds       r   test_existing_path_FileLinkr#   8   sL     
	B			"''	"B^^F<>GGRWWMHXr   c                      t               } t        j                  | j                        }t	        |      }| j                  }||k(  sJ y)zHFileLink: Calling repr() functions as expected on existing filepath
    N)r   r   r   r   reprr   s       r    test_existing_path_FileLink_reprr&   B   s@     
	B			"''	"B"XFwwHXr   c                  j    t               } t        j                  t        t        j
                  |        y)z1FileLink: Raises error when passed directory
    N)r   pytestraises
ValueErrorr   r   )tds    r   #test_error_on_directory_to_FileLinkr,   L   s!     
B
MM*g..3r   c                  .    t        j                  d      } y)z.FileLinks: Test class can be instantiated
    exampleN)r   	FileLinksflss    r   test_instantiation_FileLinksr2   V   s     

I
&Cr   c                  p    t        j                  d      } | j                         j                  d      sJ y)zFFileLinks: Calling _repr_html_ on non-existent files returns a warningr.   zPath (<tt>example</tt>)N)r   r/   r   r   r0   s    r   +test_warning_on_non_existent_path_FileLinksr4   [   s.    


I
&C??''(ABBBr   c                     t               } t        |       }t        |       }t        j                  |       }|j	                         }|j                  d      }|j                          d| z  d|j                  j                  dd      dt        |j                        d   d	d|j                  j                  dd      dt        |j                        d   d	g}|j                          ||k(  sJ y
)zIFileLinks: Calling _repr_html_ functions as expected on existing dir
    dir
z%s/<br>z&nbsp;&nbsp;<a href='\/r      r   N)	r   r   r   r/   r   r   sortr   replacer+   tf1tf2r   r!   r"   s         r   test_existing_path_FileLinksrA   a   s     
B

$C

$C			2	B^^F\\$F
KKM B((""4,U388_Q-?A ((""4,U388_Q-?ABH
 MMOXr   c                     t               } t        |       }t        |       }d }t        j                  | |      }|j	                         }|j                  d      }|j                          ddg}|j                          ||k(  sJ y)zMFileLinks: Calling _repr_html_ functions as expected w/ an alt formatter
    r6   c                 
    ddgS Nhelloworld r   fnamesincluded_suffixess      r   fake_formatterzBtest_existing_path_FileLinks_alt_formatter.<locals>.fake_formatter}         r   )notebook_display_formatterr8   rE   rF   N)r   r   r   r/   r   r   r<   r+   r?   r@   rK   r   r!   r"   s          r   *test_existing_path_FileLinks_alt_formatterrO   w   sz     
B

$C

$C!			2	HB^^F\\$F
KKM HMMOXr   c                  l   t               } t        |       }t        |       }t        j                  |       }t	        |      }|j                  d      }|j                          d| z  dt        |j                        d   z  dt        |j                        d   z  g}|j                          ||k(  sJ y)zFFileLinks: Calling repr() functions as expected on existing directory r6   r8   z%s/z  %sr;   N)r   r   r   r/   r%   r   r<   r   r>   s         r   !test_existing_path_FileLinks_reprrQ      s    	B

$C

$C			2	B"XF\\$F
KKM
FU388_Q%77sxxQRAS8STHMMOXr   c                  
   t               } t        |       }t        |       }d }t        j                  | |      }t	        |      }|j                  d      }|j                          ddg}|j                          ||k(  sJ y)zEFileLinks: Calling repr() functions as expected w/ alt formatter
    r6   c                 
    ddgS rD   rG   rH   s      r   rK   zGtest_existing_path_FileLinks_repr_alt_formatter.<locals>.fake_formatter   rL   r   )terminal_display_formatterr8   rE   rF   N)r   r   r   r/   r%   r   r<   rN   s          r   /test_existing_path_FileLinks_repr_alt_formatterrU      sw     
B

$C

$C!			2	HB"XF\\$F
KKM HMMOXr   c                      t               } t        |       }t        j                  t        t
        j                  |j                         y)z-FileLinks: Raises error when passed file
    r6   N)r   r   r(   r)   r*   r   r/   r   )r+   r?   s     r   test_error_on_file_to_FileLinksrW      s/     
B

$C
MM*g//:r   c                  |   t               } t        |       }t        |       }t        |      }t        j                  |       }t	        |      }|j                  d      }t        |      dk(  sJ |       t        j                  | d      }t	        |      }|j                  d      }t        |      dk(  sJ |       y)z5FileLinks: Does not recurse when recursive=False
    r6   r8      F)	recursive   N)r   r   r   r/   strr   len)r+   r    subtdsubtfr   r!   s         r   test_recursive_FileLinksr`      s     
B		#BOE5)E			2	BWF\\$Fv;!#V#			2	/BWF\\$Fv;!#V#r   c                  b    t        t        t              d      } t        j                  |        y )Nztest.wavfilename)pjoinr   __file__r   Audio)paths    r   test_audio_from_filerh      s    "J/DMM4 r   c                   b    e Zd Zed        Zed        Zed        Zed        Zed        Zd Z	y)TestAudioDataWithNumpyc                     t               }t        j                  |d      }t        t	        |j
                              t        |      k(  sJ y ND  rate)get_test_toner   rf   r]   read_wavdataself	test_toneaudios      r   test_audio_from_numpy_arrayz2TestAudioDataWithNumpy.test_audio_from_numpy_array   s9    !O	ie48EJJ'(C	N:::r   c                     t               }t        j                  t        |      d      }t	        t        |j                              t	        |      k(  sJ y rl   )rp   r   rf   listr]   rq   rr   rs   s      r   test_audio_from_listz+TestAudioDataWithNumpy.test_audio_from_list   s=    !O	d9oE:8EJJ'(C	N:::r   c                 ^    | j                  t        t        j                  t	                      y N)assertRaisesr*   r   rf   rp   rt   s    r   /test_audio_from_numpy_array_without_rate_raiseszFTestAudioDataWithNumpy.test_audio_from_numpy_array_without_rate_raises   s    *gmm]_Er   c                 0   t        j                  t         j                        j                  }dD ]d  }t	        j
                  t        |      d      }t        j                  t        j                  t        |j                                    }||k(  rdJ  y )N)r;         ?r[   rm   rn   )
numpyiinfoint16maxr   rf   rp   absrq   rr   )rt   expected_max_valuescalerv   actual_max_values        r   test_audio_data_normalizationz4TestAudioDataWithNumpy.test_audio_data_normalization   so    "[[599  	:EMM-"6UCE$yy8EJJ3G)HI#'9999	:r   c                    t        j                  t         j                        j                  }dD ]  }t	        |      }t        j                  t        j
                  |            }t        ||z        }t        j                  |dd      }t        j                  t        j
                  t        |j                                    }||k(  rJ  y )N)r;   r   g?rm   Fro   	normalize)r   r   r   r   rp   r   intr   rf   rq   rr   )rt   	max_int16r   ru   test_tone_max_absr   rv   r   s           r   %test_audio_data_without_normalizationz<TestAudioDataWithNumpy.test_audio_data_without_normalization   s    KK,00	" 	:E%e,I %		%))I*> ?!$Y1B%B!CMM)%5IE$yy8EJJ3G)HI#'9999	:r   c                 `    | j                  t        d        | j                  t        d        y )Nc                  4    t        j                  dgdd      S )Ngjt?rm   Fr   r   rf   rG   r   r   <lambda>zfTestAudioDataWithNumpy.test_audio_data_without_normalization_raises_for_invalid_data.<locals>.<lambda>   s    GMM5'G r   c                  4    t        j                  dgdd      S )Ngjtrm   Fr   r   rG   r   r   r   zfTestAudioDataWithNumpy.test_audio_data_without_normalization_raises_for_invalid_data.<locals>.<lambda>   s    GMM6(%H r   )r}   r*   r~   s    r   =test_audio_data_without_normalization_raises_for_invalid_datazTTestAudioDataWithNumpy.test_audio_data_without_normalization_raises_for_invalid_data   s.    G	I 	H	Jr   N)
__name__
__module____qualname__r   rw   rz   r   r   r   r   rG   r   r   rj   rj      sl    ; ;
 ; ;
 F F : : : :Jr   rj   c                      	 dd l } t        j                  dt        j                  t                    S # t
        $ r d cY S w xY w)Nr   znumpy.array)side_effectc                     | S r|   rG   )xs    r   r   z.simulate_numpy_not_installed.<locals>.<lambda>   s     r   )r   r	   patch	MagicMockImportErrorModuleNotFoundError)r   s    r   simulate_numpy_not_installedr      s9    zz-K)PQQ s   14 AAc                       e Zd Zed        Zy)TestAudioDataWithoutNumpyc                 f    t        t                     gdz  | j                  t        fd       y )Nr[   c                  2    t        j                   d      S rl   r   )stereo_signals   r   r   zMTestAudioDataWithoutNumpy.test_audio_raises_for_nested_list.<locals>.<lambda>  s    W]]=u-U r   )ry   rp   r}   	TypeError)rt   r   s    @r   !test_audio_raises_for_nested_listz;TestAudioDataWithoutNumpy.test_audio_raises_for_nested_list   s(    mo./!3)%UVr   N)r   r   r   r   r   rG   r   r   r   r      s     W Wr   r   c                     t        j                  dt         j                  z  dz  t        j                  ddd      z        | z  S )Nr[   i  r   r;   rm   )r   sinpilinspace)r   s    r   rp   rp     s5    99Q\C'%..Au*EEFNNr   c                    t        j                  t        |             5 }|j                  |j	                               }|j	                         |j                         z  }t        j                  d|z  |      cd d d        S # 1 sw Y   y xY w)Nz<%sh)waveopenr
   
readframes
getnframesgetnchannelsstructunpack)rr   	wave_file	wave_datanum_sampless       r   rq   rq     sq    	74=	! >Y(()=)=)?@	**,y/E/E/GG}}Vk19=> > >s   ABBc                  z    t        j                  t              } | j                         j	                  d      sJ y )Nrb   z<style>)r   Codere   r   r   )cs    r   test_code_from_filer     s*    h'A==?%%i000r   )r;   ),__doc__tempfiler   r   os.pathr   r   rd   r   r   unittestr   r	   r   r   ior
   r(   r   r   IPython.libr   IPython.testing.decoratorsr   r   r   r#   r&   r,   r2   r4   rA   rO   rQ   rU   rW   r`   rh   rj   r   r   rp   rq   r   rG   r   r   <module>r      s    1 1 1  #    	
   7;F4'
C,$$;$ !+JX +JZ W 6 W  W O O>1e  		s   B! !B)(B)