o
    li@                  
   @   s  d dl Z d dlmZ d dlZd dlZd dlZd dlZd dlZd dlZ	d dl
Z
d dlZd dlmZ d dlmZ d dlmZ e
 dd ZG dd	 d	ejZd
d Ze
jjdeedgdgddd Zdd ZejdG dd deZg dZdd Z e
jde  e
jjdeedgdgddd Z!e
jde
j"de
jj#ej$%  ddde
j"d e
jj#ej&%  d!ddge
jd"g d#e
jjdeedgdgdd$d% Z'e
jjdd&e(e)d'd(gdgdd)d* Z*d+d, Z+e
jd-e
j"d.e
jj#ej,ej-d/  d0ddd1ge
jjded2d3gdgdd4d5 Z.e
jd-e
j"d.e
jj#ej,ej-d/  d0ddd1ge
jjded2d3gdgdd6d7 Z/e
jj#e j0d8kd9dd:d; Z1e
jd<d=d>gd?d@ Z2e
jdAg dBdCdD Z3dEdF Z4dGdH Z5edIgdJdKdL Z6e
jjdeedgdgddMdN Z7e
jjdeedgdgddOdP Z8e
jjdeedgdgddQdR Z9dSdT Z:dS )U    N)Path)pyplot)	animation)check_figures_equalc                    s   t  \}}|g g \ |dd |dd  fdd} fdd}tt| d	i }|d
tj	}d|vr<d|d< |d|||d|S )z)Create a simple animation (with options).r   
      c                           g g   fS Nset_data liner   ]/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/matplotlib/tests/test_animation.pyinit      zanim.<locals>.initc                    s.   t ddd}t ||  } ||  fS )Nr   r   d   )nplinspacesinr   )ixyr   r   r   animate   s   zanim.<locals>.animateparamklassframes   )figfunc	init_funcNr   )
pltsubplotsplotset_xlimset_ylimdictgetattrpopr   FuncAnimation)requestr   axr   r   kwargsr   r   r   r   anim   s   r.   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	NullMovieWritera  
    A minimal MovieWriter.  It doesn't actually write anything.
    It just saves the arguments that were given to the setup() and
    grab_frame() methods as attributes, and counts how many times
    grab_frame() is called.

    This class doesn't have an __init__ method with the appropriate
    signature, and it doesn't define an isAvailable() method, so
    it cannot be added to the 'writers' registry.
    c                 G   s"   || _ || _|| _|| _d| _d S )Nr   )r   outfiledpiargs_count)selfr   r0   r1   r2   r   r   r   setup9   s
   
zNullMovieWriter.setupc                 K   s   || _ |  jd7  _d S )Nr   )savefig_kwargsr3   )r4   r6   r   r   r   
grab_frame@   s   zNullMovieWriter.grab_framec                 C      d S r
   r   r4   r   r   r   finishD      zNullMovieWriter.finishN)__name__
__module____qualname____doc__r5   r7   r:   r   r   r   r   r/   -   s
    r/   c                 C   s   dt jd< d}d}tdd}t }| j||||d |jt dks$J |j|ks+J |j|ks2J |j	d	ks9J |
 D ]\}}|j| |ksJJ q=|j| jksSJ d S )
Nautozsavefig.facecolorunused.null2   r   )foo)r1   writerr6   r   r   )r"   rcParamsr'   r/   saver   figurer0   r1   r2   itemsr6   r3   _save_count)r.   filenamer1   r6   rD   kvr   r   r   test_null_movie_writerH   s   


rM   )r   )indirectc                 C   sf   t  dkrtj  tjdi | } tjt	dd ~ tj  W d    d S 1 s,w   Y  d S )NPyPyzAnimation was deletedmatchr   )
platformpython_implementationr   testingbreak_cyclesr   r*   pytestwarnsWarningr.   r   r   r   test_animation_delete^   s   
"rZ   c                  C   s^   G dd dt j} t }d}d}d}d}dg}| ||||}||| |j|jks-J d S )Nc                   @   s   e Zd Zdd ZdS )z7test_movie_writer_dpi_default.<locals>.DummyMovieWriterc                 S   r8   r
   r   r9   r   r   r   _runm   r;   z<test_movie_writer_dpi_default.<locals>.DummyMovieWriter._runN)r<   r=   r>   r[   r   r   r   r   DummyMovieWriterl   s    r\   rA   r   unusedr   )r   MovieWriterr"   rG   r5   r1   )r\   r   rJ   fpscodecbitrate
extra_argsrD   r   r   r   test_movie_writer_dpi_defaultk   s   rc   nullc                   @   s&   e Zd Z		dddZedd ZdS )RegisteredNullMovieWriterNc                 C   r8   r
   r   )r4   r_   r`   ra   rb   metadatar   r   r   __init__      z"RegisteredNullMovieWriter.__init__c                 C   s   dS )NTr   )clsr   r   r   isAvailable   rh   z%RegisteredNullMovieWriter.isAvailable)NNNNN)r<   r=   r>   rg   classmethodrj   r   r   r   r   re   ~   s    	
re   ))ffmpeg	movie.mp4)ffmpeg_filerm   )imagemagick	movie.gif)imagemagick_filerp   )pillowrp   )htmlz
movie.html)rd   z
movie.nullc                  c   s    t D ]J\} }tj| s0tjd|  d}tj| d ||gdV  tj| d t||gdV  qtj|  }t	|dd gD ]}| ||fV  | |t|fV  q<qd S )Nzwriter 'z' not available on this systemmarkssupported_formats)
WRITER_OUTPUTr   writersis_availablerV   markskipr   r   r(   )rD   outputrz   writer_classframe_formatr   r   r   gen_writers   s   

r   zwriter, frame_format, outputc              	   C   s   |d ur	|t jd< tjd	i |}d }d }|dkr#|jd d}d}|   |j|d|d||d W d    ~d S 1 s?w   Y  ~d S )
Nzanimation.frame_formatrl   )g33333%@gQk"@g      Y@h264   i  )r_   rD   ra   r1   r`   r   )r"   rE   r   r*   _figset_size_inchesas_cwdrF   )tmpdirrD   r~   r|   r.   r1   r`   r   r   r   test_save_animation_smoketest   s"   


r   rD   rl   Requires FFMpeg)reasonrt   ro   zRequires ImageMagickz
html, want))noneN)html5z<video width)jshtmlz<script c                 C   s   t  dkrtj  | dkr|dkrtj st	d tj
di |}t| |d | }W d    n1 s<w   Y  |d u ri|d u sKJ tt ~tj  W d    d S 1 sbw   Y  d S ||v soJ d S )NrO   ro   r   r   )animation.writerzanimation.htmlr   )rR   rS   r   rT   rU   r   FFMpegWriterrj   rV   r{   r*   r"   
rc_context_repr_html_rW   UserWarning)rD   rs   wantr.   r   r   r   test_animation_repr_html   s&   



"r   r   r   )
save_countr   c                 C   s   | j dt d d S )NrA   rD   )rF   r/   rY   r   r   r   test_no_length_frames   s   r   c                  C   s^   t tjjdks
J dtjd< tjdrJ tjdkrdnd} | tjd< tjds-J d S )Nr   not_available_ever_xxxxzanimation.ffmpeg_pathrl   win32truewhere)	lenr   rx   _registeredmplrE   ry   sysrR   )binr   r   r   test_movie_writer_registry   s   

r   method_nameto_html5_videor   zanimation writer not installed	to_jshtmlr   )r   c              	   C   s   | d | % tddi t||   W d    n1 s"w   Y  W d    n1 s1w   Y  t|jdks?J |j\}|jdkrM|jdksOJ d S )NWARNINGzanimation.embed_limitgư>r   zmatplotlib.animation)		set_levelr   r   r   r(   r   recordsname	levelname)r   caplogr   r.   recordr   r   r   test_embed_limit   s   


r   c                 C   sV   |   t||   ttt| g ksJ W d    d S 1 s$w   Y  d S r
   )r   r(   listr   striterdir)r   r   r.   r   r   r   test_cleanup_temporaries  s   
"r   posixzrequires a POSIX OSc              	   C   s   |   I |ddtjd   tt| d}|d t|d t	t
j |d W d   n1 s8w   Y  W d   dS W d   dS 1 sPw   Y  dS )a!  
    Test that we correctly raise a CalledProcessError when ffmpeg fails.

    To do so, mock ffmpeg using a simple executable shell script that
    succeeds when called with no arguments (so that it gets registered by
    `isAvailable`), but fails otherwise, and add it to the $PATH.
    PATHz.:rl   s   #!/bin/sh
[[ $@ -eq 0 ]]
i  z	test.mpegN)r   setenvosenvironr   r   write_byteschmodrV   raises
subprocessCalledProcessErrorrF   )r   monkeypatchr.   exe_pathr   r   r   test_failing_ffmpeg  s   
	
"r   cache_frame_dataFTc           
         s   t  \}}|g g \G dd dt fdd}fdd}g  fdd}d	}tj||||| |d
}t }|jd|d tdksIJ t	j
  D ]}	|	 d u | ks[J qPd S )Nc                   @   s   e Zd ZdS )z2test_funcanimation_cache_frame_data.<locals>.FrameN)r<   r=   r>   r   r   r   r   Frame6  s    r   c                      r	   r
   r   r   r   r   r   r   :  r   z1test_funcanimation_cache_frame_data.<locals>.initc                    s     | d | d   fS )Nr   r   r   framer   r   r   r   >  s   z4test_funcanimation_cache_frame_data.<locals>.animatec                  3   sP    t dD ] } tddd}tjd} ||d}t| |V  qd S )Nr   r   r   r   )r   r   )ranger   r   randomrandappendweakrefref)_r   r   r   )r   frames_generatedr   r   frames_generatorD  s   z=test_funcanimation_cache_frame_data.<locals>.frames_generatorr   )r!   r   r   r   rA   r   r   )r"   r#   r$   r'   r   r*   r/   rF   r   r   rT   rU   )
r   r   r,   r   r   r   
MAX_FRAMESr.   rD   fr   )r   r   r   r   #test_funcanimation_cache_frame_data1  s(   

r   return_value)Nstringr   )r   artistc                    sh   t  \}}|g \  fdd}tt tj||ddd W d    d S 1 s-w   Y  d S )Nc                    s$     ddgd| g dkr S S )Nr   r   r   r   r   r   r   r   r   r   s  s   z test_draw_frame.<locals>.animateTF)blitr   )r"   r#   r$   rV   r   RuntimeErrorr   r*   )r   r   r,   r   r   r   r   test_draw_framea  s   	"r   c                 C   s   t  \}}dd }tj||ttdddd}|   |jddd W d    n1 s.w   Y  tj	t
d	d
 |  W d    d S 1 sJw   Y  d S )Nc                 S      g S r
   r   r   r   r   r   update  r;   z(test_exhausted_animation.<locals>.updater   Fr   repeatr   test.gifrr   r   	exhaustedrP   )r"   r#   r   r*   iterr   r   rF   rV   rW   r   _startr   r   r,   r   r.   r   r   r   test_exhausted_animation  s   

"r   c                 C   sd   t  \}}dd }tj||g ddd}tjtdd |  W d    d S 1 s+w   Y  d S )Nc                 S   r   r
   r   r   r   r   r   r     r;   z%test_no_frame_warning.<locals>.updateFr   r   rP   )r"   r#   r   r*   rV   rW   r   r   r   r   r   r   test_no_frame_warning  s   
"r   png)
extensionsc                    s   |  }|ddtj  |dd tddtj d|g g \  fdd} fdd	}tj|||d
ddd}| 	  |
d W d    n1 sPw   Y  |  }|ddtj  |dd |td  d S )Nr      r   r   r   c                      r	   r
   r   r   r   r   r   r     r   z"test_animation_frame.<locals>.initc                    s      t| d    fS )Nr   )r   r   r   r   r   r   r   r   r     s   z%test_animation_frame.<locals>.animater   TF)r!   r   r   r   r   g{Gz?)add_subplotr%   r   pir&   r   r$   r   r*   r   rF   r   )r   fig_testfig_refr,   r   r   r.   r   r   r   test_animation_frame  s$   
r   c                 C   s   d}t td}d|dt|d}tjtt|d tj	di i | ||d} W d    n1 s7w   Y  | j
t|ksEJ |   d S )	Nr   r   %You passed in an explicit save_count=z0 which is being ignored in favor of len(frames)=.rP   r   r   r   )r   r   r   rV   rW   r   reescaper   r*   rI   
_init_drawr.   r   r   match_targetr   r   r   ,test_save_count_override_warnings_has_length  s   r   c                 C   s   d}d}d|dd d|d }t jtt|d tjd
i i | ||d	} W d    n1 s6w   Y  | j|ksBJ |   d S )Nr      r    z#which is being ignored in favor of frames=r   rP   r   r   )	rV   rW   r   r   r   r   r*   rI   r   r   r   r   r   (test_save_count_override_warnings_scaler  s   

r   c                 C   s   d}t td}d|d|d}tjtt|d tjd	i i | ||d} W d    n1 s5w   Y  | j	du sAJ | 
  d S )
NTr   r   ze which we can infer the length of, did not pass an explicit *save_count* and passed cache_frame_data=z.  To avoid a possibly unbounded cache, frame data caching has been disabled. To suppress this warning either pass `cache_frame_data=False` or `save_count=MAX_FRAMES`.rP   )r   r   Fr   )r   r   rV   rW   r   r   r   r   r*   _cache_frame_datar   )r.   r   r   r   r   r   r   test_disable_cache_warning  s   r   c                 C   sf   t jdkrtd}ntd}tjt|d | jdt	 d W d    d S 1 s,w   Y  d S )Nr   z7[WinError 3] The system cannot find the path specified:z*[Errno 2] No such file or directory: '/foorP   z+/foo/bar/aardvark/thiscannotreallyexist.mp4r   )
r   rR   r   r   rV   r   FileNotFoundErrorrF   r   FFMpegFileWriter)r.   	match_strr   r   r   test_movie_writer_invalid_path  s   

"r   );r   pathlibr   rR   r   r   r   r   numpyr   rV   
matplotlibr   r   r"   r   matplotlib.testing.decoratorsr   fixturer.   AbstractMovieWriterr/   rM   rz   parametrizer'   rZ   rc   rx   registerre   rw   r   r   r   skipifr   rj   ImageMagickWriterr   r   r   r   r   ry   rE   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s    









/


!


