o
    tBh2                  
   @   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
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e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-  d.ddd/ge	jjded0d&gdgdd1d2 Z+e	jd+e	jd,e	jj ej)ej*d-  d.ddd/ge	jjded0d&gdgdd3d4 Z,e	jj e j-d5kd6dd7d8 Z.e	jd9d:d;gd<d= Z/e	jd>g d?d@dA Z0dBdC Z1dDdE Z2dS )F    N)Path)pyplot)	animationc                    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   v/var/www/html/riverr-enterprise-integrations-main/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   r/   r0   r1   r   r   r   setup7   s
   
zNullMovieWriter.setupc                 K   s   || _ |  jd7  _d S )Nr   )savefig_kwargsr2   )r3   r5   r   r   r   
grab_frame>   s   zNullMovieWriter.grab_framec                 C      d S r	   r   r3   r   r   r   finishB      zNullMovieWriter.finishN)__name__
__module____qualname____doc__r4   r6   r9   r   r   r   r   r.   +   s
    r.   c                 C   s   d}d}t dd}t }| j||||d |jtdksJ |j|ks&J |j|ks-J |jdks4J |j	|ks;J |j
| jksCJ d S )Nunused.null2   r   )foo)r0   writerr5   r   r   )r&   r.   saver   r!   figurer/   r0   r1   r5   r2   
save_count)r-   filenamer0   r5   rB   r   r   r   test_null_movie_writerF   s   

rG   )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_deleteX   s   
"rT   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   r7   r	   r   r8   r   r   r   _rung   r:   z<test_movie_writer_dpi_default.<locals>.DummyMovieWriter._runN)r;   r<   r=   rU   r   r   r   r   DummyMovieWriterf   s    rV   r?   r   unusedr   )r   MovieWriterr!   rD   r4   r0   )rV   r   rF   fpscodecbitrate
extra_argsrB   r   r   r   test_movie_writer_dpi_defaulte   s   r]   nullc                   @   s&   e Zd Z		dddZedd ZdS )RegisteredNullMovieWriterNc                 C   r7   r	   r   )r3   rY   rZ   r[   r\   metadatar   r   r   __init__      z"RegisteredNullMovieWriter.__init__c                 C   s   dS )NTr   )clsr   r   r   isAvailable   rb   z%RegisteredNullMovieWriter.isAvailable)NNNNN)r;   r<   r=   ra   classmethodrd   r   r   r   r   r_   x   s    	
r_   )	)ffmpeg	movie.mp4)ffmpeg_filerg   )avconvrg   )avconv_filerg   )imagemagick	movie.gif)imagemagick_filerl   )pillowrl   )htmlz
movie.html)r^   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_availablerP   markskipr   r   r'   )rB   outputrv   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_formatrf   )g33333%@gQk"@g      Y@h264   i  )rY   rB   r[   r0   rZ   r   )r!   rcParamsr   r)   _figset_size_inchesas_cwdrC   )tmpdirrB   rz   rx   r-   r0   rZ   r   r   r   test_save_animation_smoketest   s"   


r   rB   rf   Requires FFMpeg)reasonrp   rk   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 )NrI   rk   r   r   )animation.writerzanimation.htmlr   )rL   rM   r   rN   rO   r   FFMpegWriterrd   rP   rw   r)   r!   
rc_context_repr_html_rQ   UserWarning)rB   ro   wantr-   r   r   r   test_animation_repr_html   s&   



"r   r   )r   c                 C   s   | j dt d d S )Nr?   rB   )rC   r.   rS   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_pathrf   win32truewhere)	lenr   rt   _registeredmplr~   ru   sysrL   )binr   r   r   test_movie_writer_registry   s   

r   method_nameto_html5_videor   zanimation writer not installed	to_jshtmlr   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   |   K |ddtjd   tt| d}|d tt|d t	t
j |d W d   n1 s:w   Y  W d   dS W d   dS 1 sRw   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.:rf   z#!/bin/sh
[[ $@ -eq 0 ]]
i  z	test.mpegN)r   setenvosenvironr   r   
write_textchmodrP   raises
subprocessCalledProcessErrorrC   )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}tj||||| d	}t }|jd
|d tdksFJ t	j
  D ]}| d u | ksXJ qMd S )Nc                   @   s   e Zd ZdS )z2test_funcanimation_cache_frame_data.<locals>.FrameN)r;   r<   r=   r   r   r   r   Frame0  s    r   c                      r   r	   r
   r   r   r   r   r   4  r   z1test_funcanimation_cache_frame_data.<locals>.initc                    s     | d | d   fS )Nr   r   r
   framer   r   r   r   8  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_generator>  s   z=test_funcanimation_cache_frame_data.<locals>.frames_generator)r    r   r   r?   r   r   )r!   r"   r#   r&   r   r)   r.   rC   r   r   rN   rO   )	r   r   r+   r   r   r   r-   rB   fr   )r   r   r   r   #test_funcanimation_cache_frame_data+  s$   

r   return_value)Nstringr   )r   artistc                    sf   t  \}}|g \  fdd}tt tj||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   k  s   z test_draw_frame.<locals>.animateT)blit)r!   r"   r#   rP   r   RuntimeErrorr   r)   )r   r   r+   r   r   r   r   test_draw_frameY  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   ztest.gifrn   r   	exhaustedrJ   )r!   r"   r   r)   iterr   r   rC   rP   rQ   r   _startr   r   r+   r   r-   r   r   r   test_exhausted_animationx  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   rJ   )r!   r"   r   r)   rP   rQ   r   r   r   r   r   r   test_no_frame_warning  s   
"r   )3r   pathlibr   rL   r   r   r   numpyr   rP   
matplotlibr   r   r!   r   fixturer-   AbstractMovieWriterr.   rG   rv   parametrizer&   rT   r]   rt   registerr_   rs   r{   r   r   skipifr   rd   ImageMagickWriterr   r   r   r   r   ru   r~   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s    









-
