o
    jG                  
   @   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Zd dlm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# 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d0ej&d1ejj'ej0ej1d2  d3d!d"d4gejjded5d6gdgdd7d8 Z2ejd0ej&d1ejj'ej0ej1d2  d3d!d"d4gejjded5d6gdgdd9d: Z3ejj'e4d;du d<d!d=d> Z5ejd?d@dAgdBdC Z6ejdDg dEdFdG Z7dHdI Z8dJdK Z9edLgdMdNdO Z:ejjdeedgdgddPdQ Z;ejjdeedgdgddRdS Z<ejjdeedgdgddTdU Z=dVdW Z>dXdY Z?dS )Z    N)Path)pyplot)	animation)PillowWriter)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   `/var/www/html/Deteccion_Ine/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    r1   r2   r3   r   r   r   setup;   s
   
zNullMovieWriter.setupc                 K   s,   ddl m} || || _|  jd7  _d S )Nr   )_validate_grabframe_kwargsr	   )matplotlib.animationr7   savefig_kwargsr4   )r5   r9   r7   r   r   r   
grab_frameB   s   zNullMovieWriter.grab_framec                 C      d S r   r   r5   r   r   r   finishH      zNullMovieWriter.finishN)__name__
__module____qualname____doc__r6   r:   r=   r   r   r   r   r0   /   s
    r0   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   )Zfoo)r2   writerr9   r	   r   )r#   rcParamsr(   r0   saver    figurer1   r2   r3   itemsr9   r4   _save_count)r/   filenamer2   r9   rF   kvr   r   r   test_null_movie_writerL   s   


rO   )r   )Z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_deleteb   s   
"r[   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   r;   r   r   r<   r   r   r   _runq   r>   z<test_movie_writer_dpi_default.<locals>.DummyMovieWriter._runN)r?   r@   rA   r\   r   r   r   r   DummyMovieWriterp   s    r]   rD   r   Zunusedr	   )r   ZMovieWriterr#   rI   r6   r2   )r]   r    rL   fpscodecbitrate
extra_argsrF   r   r   r   test_movie_writer_dpi_defaulto   s   rb   nullc                   @   s&   e Zd Z		dddZedd ZdS )RegisteredNullMovieWriterNc                 C   r;   r   r   )r5   r^   r_   r`   ra   metadatar   r   r   __init__      z"RegisteredNullMovieWriter.__init__c                 C   s   dS )NTr   )clsr   r   r   isAvailable   rg   z%RegisteredNullMovieWriter.isAvailable)NNNNN)r?   r@   rA   rf   classmethodri   r   r   r   r   rd      s    	
rd   ))ffmpeg	movie.mp4)Zffmpeg_filerl   )imagemagick	movie.gif)Zimagemagick_filern   )pillowrn   )htmlz
movie.html)rc   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ZmarksZsupported_formats)
WRITER_OUTPUTr   writersis_availablerW   markskipr   r   r)   )rF   outputru   Zwriter_classframe_formatr   r   r   gen_writers   s   

ry   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 )
Nanimation.frame_formatrk   g33333%@gQk"@      Y@h264   i  )r^   rF   r`   r2   r_   r   )r#   rG   r   r+   Z_figset_size_inchesas_cwdrH   )tmpdirrF   rx   rw   r/   r2   r_   r   r   r   test_save_animation_smoketest   s"   


r   c                 C   s  t j| }|d ur|tjd< t \}}d }d }|dkr%|d d}d}| }	|  V |	|||6 |	  dD ]'}
t	j
td|
d |	jd	i |
t i W d    n1 s]w   Y  q;W d    n1 smw   Y  W d    d S W d    d S 1 sw   Y  d S )
Nrz   rk   r{   r|   r}   >   r2   formatZbbox_inchesz.grab_frame got an unexpected keyword argument rQ   r   )r   rs   r#   rG   r$   r   r   Zsavingr:   rW   raises	TypeErrorobject)r   rF   rx   rw   ZWriterClassr    r-   r2   r_   Ztest_writerrM   r   r   r   test_grabframe   s6   



"r   rF   rk   Requires FFMpeg)reasonrq   rm   zRequires ImageMagickz
html, want))noneN)html5z<video width)Z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 )NrP   rm   r   r   )animation.writerzanimation.htmlr   )rS   rT   r   rU   rV   r   FFMpegWriterri   rW   rv   r+   r#   
rc_contextZ_repr_html_rX   UserWarning)rF   rp   Zwantr/   r   r   r   test_animation_repr_html   s&   



"r   r   r   )
save_countr   c                 C   s   | j dt d d S )NrD   rF   )rH   r0   rZ   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   Znot_available_ever_xxxxzanimation.ffmpeg_pathrk   win32truewhere)	lenr   rs   Z_registeredmplrG   rt   sysrS   )binr   r   r   test_movie_writer_registry  s   

r   method_nameZto_html5_videor   zanimation writer not installedZ	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)	Z	set_levelr   r   r   r)   r   recordsname	levelname)r   Z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_temporaries6  s   
"r   z/bin/shz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.:rk   s   #!/bin/sh
[[ $@ -eq 0 ]]
i  z	test.mpegN)r   Zsetenvosenvironr   r   write_byteschmodrW   r   
subprocessCalledProcessErrorrH   )r   Zmonkeypatchr/   Zexe_pathr   r   r   test_failing_ffmpegC  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@   rA   r   r   r   r   FrameZ  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   b  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   randomZrandappendweakrefref)_r   r   r   )r   frames_generatedr   r   frames_generatorh  s   z=test_funcanimation_cache_frame_data.<locals>.frames_generatorr   )r"   r   r   r   rD   r   r   )r#   r$   r%   r(   r   r+   r0   rH   r   r   rU   rV   )
r   r    r-   r   r   r   Z
MAX_FRAMESr/   rF   fr   )r   r   r   r   #test_funcanimation_cache_frame_dataU  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   z test_draw_frame.<locals>.animateTF)blitr   )r#   r$   r%   rW   r   RuntimeErrorr   r+   )r   r    r-   r   r   r   r   test_draw_frame  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.gifro   r   	exhaustedrQ   )r#   r$   r   r+   iterr   r   rH   rW   rX   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   rQ   )r#   r$   r   r+   rW   rX   r   r   r   r   r   r   test_no_frame_warning  s   
"r   Z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?)Zadd_subplotr&   r   pir'   r   r%   r   r+   r   rH   r   )r   Zfig_testZ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)=.rQ   r   r   r   )r   r   r   rW   rX   r   reescaper   r+   rK   
_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   rQ   r   r   )	rW   rX   r   r   r   r   r+   rK   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`.rQ   )r   r   Fr   )r   r   rW   rX   r   r   r   r   r+   Z_cache_frame_datar   )r/   r   r   r   r   r   r   test_disable_cache_warning  s   r   c                 C   sZ   t jdkrd}nd}tjt|d | jdt d W d    d S 1 s&w   Y  d S )Nr   z,\[WinError 3] .*'\\\\foo\\\\bar\\\\aardvark'z\[Errno 2] .*'/foorQ   z+/foo/bar/aardvark/thiscannotreallyexist.mp4r   )r   rS   rW   r   FileNotFoundErrorrH   r   ZFFMpegFileWriter)r/   Z	match_strr   r   r   test_movie_writer_invalid_path#  s   
"r   c                  C   s   t  \} }t jdddddd}|| |dd |dd tdd}|j| d	d
d |jdd |j	d }|
 d d dk sEJ t |  dS )zGTest animation exhaustion with transparency using PillowWriter directly)r   r   r	   redg      ?)coloralphar   r~   )r^   z
unused.gifr   )r2   T)transparentr         N)r#   r$   Z	RectangleZ	add_patchr&   r'   r   r6   r:   Z_framesZ
getextremaclose)r    r-   rectrF   r   r   r   r    test_animation_with_transparency-  s   


r   )@r   pathlibr   rS   r   shutilr   r   r   numpyr   rW   Z
matplotlibr   r   r#   r   r8   r   Zmatplotlib.testing.decoratorsr   Zfixturer/   ZAbstractMovieWriterr0   rO   ru   Zparametrizer(   r[   rb   rs   registerrd   rr   ry   r   r   r   Zskipifr   ri   ZImageMagickWriterr   r   r   r   r   rt   rG   r   r   whichr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s    










/


!



