
    G8cH6                     F   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 d dlmZ  e	j"                         d        Z G d dej&                        Zd	 Ze	j,                  j/                  d
 ee      gd
g      d        Zd Zej6                  j9                  d       G d de             Zg dZd Ze	j,                  j/                  d e             e	j,                  j/                  d
 ee      gd
g      d               Z e	j,                  j/                  d e	jB                  de	j,                  jE                  ejF                  jI                          d             e	jB                  de	j,                  jE                  ejJ                  jI                          d            g      e	j,                  j/                  dg d      e	j,                  j/                  d
 ee      gd
g      d                      Z&e	j,                  j/                  d
 e e' e(d             !      gd
g      d"        Z)d# Z*e	j,                  j/                  d$ e	jB                  d%e	j,                  jE                  ej6                  jW                  ejX                  d&          d'            d(g      e	j,                  j/                  d
 ed)!      gd
g      d*               Z-e	j,                  j/                  d$ e	jB                  d%e	j,                  jE                  ej6                  jW                  ejX                  d&          d'            d(g      e	j,                  j/                  d
 ed)!      gd
g      d+               Z.e	j,                  jE                  e j^                  d,k7  d-      d.        Z0e	j,                  j/                  d/d0d1g      d2        Z1e	j,                  j/                  d3g d4      d5        Z2d6 Z3d7 Z4 ed8g9      d:        Z5y);    N)Path)pyplot)	animation)check_figures_equalc                 L   t        j                         \  }}|j                  g g       \  |j                  dd       |j	                  dd       fd}fd}t        t        | di             }|j                  dt        j                        }d	|vrd
|d	<    |d|||d|S )z)Create a simple animation (with options).r   
      c                  .     j                  g g         fS Nset_datalines   A/usr/lib/python3/dist-packages/matplotlib/tests/test_animation.pyinitzanim.<locals>.init       b"u    c                     t        j                  ddd      }t        j                  || z         }j                  ||       fS )Nr   r   d   )nplinspacesinr   )ixyr   s      r   animatezanim.<locals>.animate   s;    KK2s#FF1q5Maur   paramklassframes   )figfunc	init_func )
pltsubplotsplotset_xlimset_ylimdictgetattrpopr   FuncAnimation)requestr"   axr   r   kwargsr   r   s          @r   animr2      s     llnGCGGBOEDKK2KKA ''7B/0FJJw	 7 78EvxASw$A&AAr   c                   "    e Zd ZdZd Zd Zd Zy)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                 J    || _         || _        || _        || _        d| _        y )Nr   )r"   outfiledpiargs_count)selfr"   r6   r7   r8   s        r   setupzNullMovieWriter.setup8   s%    	r   c                 <    || _         | xj                  dz  c_        y )Nr
   )savefig_kwargsr9   )r:   r=   s     r   
grab_framezNullMovieWriter.grab_frame?   s    ,qr   c                      y r   r%   r:   s    r   finishzNullMovieWriter.finishC   s    r   N)__name__
__module____qualname____doc__r;   r>   rA   r%   r   r   r4   r4   ,   s    	r   r4   c                 h   d}d}t        d      }t               }| j                  ||||       |j                  t	        j
                  d      k(  sJ |j                  |k(  sJ |j                  |k(  sJ |j                  dk(  sJ |j                  |k(  sJ |j                  | j                  k(  sJ y )Nunused.null2   r   )foo)r7   writerr=   r
   r%   )r+   r4   saver"   r&   figurer6   r7   r8   r=   r9   
save_count)r2   filenamer7   r=   rJ   s        r   test_null_movie_writerrO   G   s    H
Ca[NFIIhC+  - ::A&&&>>X%%%::;;"  N222==DOO+++r   r2   )r   )indirectc                 6   t        j                         dk(  rt        j                  j	                          t        j                  di | } t        j                  t        d      5  ~ t        j                  j	                          d d d        y # 1 sw Y   y xY w)NPyPyzAnimation was deletedmatchr%   )
platformpython_implementationr   testingbreak_cyclesr   r.   pytestwarnsWarningr2   s    r   test_animation_deleter]   Y   so    %%'61 	

!""*T*D	g%<	= "


!" " "s   & BBc                       G d dt         j                        } t        j                         }d}d}d}d}dg} | ||||      }|j	                  ||       |j
                  |j
                  k(  sJ y )Nc                       e Zd Zd Zy)7test_movie_writer_dpi_default.<locals>.DummyMovieWriterc                      y r   r%   r@   s    r   _runz<test_movie_writer_dpi_default.<locals>.DummyMovieWriter._runh   s    r   N)rB   rC   rD   rb   r%   r   r   DummyMovieWriterr`   g   s    	r   rc   rG   r!   unusedr
   )r   MovieWriterr&   rL   r;   r7   )rc   r"   rN   fpscodecbitrate
extra_argsrJ   s           r   test_movie_writer_dpi_defaultrj   f   sp    900 
 **,CH
CEGJc5':>F
LLh::   r   nullc                   (    e Zd Z	 	 ddZed        Zy)RegisteredNullMovieWriterNc                      y r   r%   )r:   rf   rg   rh   ri   metadatas         r   __init__z"RegisteredNullMovieWriter.__init__   s    r   c                      y)NTr%   )clss    r   isAvailablez%RegisteredNullMovieWriter.isAvailable   s    r   )NNNNN)rB   rC   rD   rp   classmethodrs   r%   r   r   rm   rm   y   s#     6:+/  r   rm   ))ffmpeg	movie.mp4)ffmpeg_filerv   )imagemagick	movie.gif)imagemagick_filery   )pillowry   )htmlz
movie.html)rk   z
movie.nullc               #     K   t         D ]  \  } }t        j                  j                  |       set        j
                  j                  d|  d      }t	        j                  | d ||g       t	        j                  | d t        |      |g       t        j                  |    }t        |dd g      D ]  }| ||f | |t        |      f   y w)Nzwriter 'z' not available on this systemmarkssupported_formats)
WRITER_OUTPUTr   writersis_availablerY   markskipr   r   r,   )rJ   outputr   writer_classframe_formats        r   gen_writersr      s     ' 5  --f5;;##6("@ACD,,vtVD6BB,,vtT&\$HH ((0#L2EvN 	5L,..,V44	55s   CCzwriter, frame_format, outputc           	      $   ||t         j                  d<   t        j                  d	i |}d }d }|dk(  r|j                  j                  d       d}d}| j                         5  |j                  |d|d||       d d d        ~y # 1 sw Y   ~y xY w)
Nzanimation.frame_formatru   )g33333%@gQk"@g      Y@h264   i  )rf   rJ   rh   r7   rg   r%   )r&   rcParamsr   r.   _figset_size_inchesas_cwdrK   )tmpdirrJ   r   r   r2   r7   rg   s          r   test_save_animation_smoketestr      s     1=-.""*T*D
CE		!!-0 
 		&b# 	 	 		 	s   #BBrJ   ru   Requires FFMpeg)reasonr~   rx   zRequires ImageMagickz
html, want))noneN)html5z<video width)jshtmlz<script c                 @   t        j                         dk(  rt        j                  j	                          | dk(  r8|dk(  r3t
        j                  j                         st        j                  d       t        j                  di |}t        j                  | |d      5  |j                         }d d d        |F|J t        j                  t              5  ~t        j                  j	                          d d d        y ||v sJ y # 1 sw Y   XxY w# 1 sw Y   y xY w)NrR   rx   r   r   )animation.writerzanimation.htmlr%   )rU   rV   r   rW   rX   r   FFMpegWriterrs   rY   r   r.   r&   
rc_context_repr_html_rZ   UserWarning)rJ   r|   wantr2   s       r   test_animation_repr_htmlr      s    " %%'61 	

!-DGO**668%& ""*T*D	V+/1 
2 "!" |||\\+& 	&JJ##%	& 	& t||" "
	& 	&s    D DDDr!   )r    c                 :    | j                  dt                      y )NrG   rJ   )rK   r4   r\   s    r   test_no_length_framesr      s     	IImO$5I6r   c                  R   t        t        j                  j                        dkD  sJ dt        j
                  d<   t        j                  j                  d      rJ t        j                  dk7  rdnd} | t        j
                  d<   t        j                  j                  d      sJ y )Nr   not_available_ever_xxxxzanimation.ffmpeg_pathru   win32truewhere)	lenr   r   _registeredmplr   r   sysrU   )bins    r   test_movie_writer_registryr      s    y  ,,-111,ECLL()  --h777LLG+&C,/CLL()))(333r   method_nameto_html5_videor   zanimation writer not installed	to_jshtmlr
   c                 z   |j                  d       |j                         5  t        j                  ddi      5   t	        ||               d d d        d d d        t        |j                        dk(  sJ |j                  \  }|j                  dk(  r|j                  dk(  sJ y # 1 sw Y   ZxY w# 1 sw Y   ^xY w)NWARNINGzanimation.embed_limitgư>r
   zmatplotlib.animation)		set_levelr   r   r   r,   r   recordsname	levelname)r   caplogr   r2   records        r   test_embed_limitr      s     Y	 )^^4d;< 	)&GD+&(	)) v~~!###nnGFKK11  I-/ .-	) 	)) )s"   B1B%B1%B.	*B11B:c                     |j                         5   t        ||               t        t        t	        |            j                               g k(  sJ 	 d d d        y # 1 sw Y   y xY wr   )r   r,   listr   striterdir)r   r   r2   s      r   test_cleanup_temporariesr   
  sV     
 7"k"$DV%--/0B6667 7 7s   AAA&posixzrequires a POSIX OSc                    | j                         5  |j                  ddt        j                  d   z          t	        t        |       d      }|j                  d       t        j                  |d       t        j                  t        j                        5  |j                  d       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)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.:ru   s   #!/bin/sh
[[ $@ -eq 0 ]]
i  z	test.mpegN)r   setenvosenvironr   r   write_byteschmodrY   raises
subprocessCalledProcessErrorrK   )r   monkeypatchr2   exe_paths       r   test_failing_ffmpegr     s     
 #64"**V*<#<=FX.;<
5!]]:889 	#IIk"	## #
	# 	## #s$   BCB:)C:C	?CCcache_frame_dataFTc                   	
 t        j                         \  }}|j                  g g       \   G d dt              	fd}fd}g 
	
fd}t	        j
                  |||||       }t               }|j                  d|       t        
      d	k(  sJ t        j                  j                          
D ]  } |       d u | k7  rJ  y )
Nc                       e Zd Zy)2test_funcanimation_cache_frame_data.<locals>.FrameN)rB   rC   rD   r%   r   r   Framer   .  s    r   r   c                  .     j                  g g         fS r   r   r   s   r   r   z1test_funcanimation_cache_frame_data.<locals>.init2  r   r   c                 :    j                  | d   | d          fS )Nr   r   r   )framer   s    r   r   z4test_funcanimation_cache_frame_data.<locals>.animate6  s     eCj%*-ur   c               3      K   t        d      D ]j  } t        j                  ddd      }t        j                  j	                  d      } ||      }j                  t        j                  |             | l y w)Nr!   r   r   r   )r   r   )ranger   r   randomrandappendweakrefref)_r   r   r   r   frames_generateds       r   frames_generatorz=test_funcanimation_cache_frame_data.<locals>.frames_generator<  sg     q 
	AAr3'A		s#AAOE ##GKK$67K
	s   A:A=)r$   r    r   rG   r   r!   )r&   r'   r(   r+   r   r.   r4   rK   r   r   rW   rX   )r   r"   r0   r   r   r   r2   rJ   fr   r   r   s            @@@r   #test_funcanimation_cache_frame_datar   )  s    llnGCGGBOED   ""34*:4DFD FIImFI+ A%%%JJ 1 t 00001r   return_value)Nstringr
   )r   artistc                      t        j                         \  }}|j                  g       \   fd}t        j                  t
              5  t        j                  ||d       d d d        y # 1 sw Y   y xY w)Nc                 B    j                  ddgd| g       dk(  rS S )Nr   r
   r   r   )r   r   r   s    r   r   z test_draw_frame.<locals>.animatei  s,    q!fq!f%8#Kr   T)blit)r&   r'   r(   rY   r   RuntimeErrorr   r.   )r   r"   r0   r   r   s   `   @r   test_draw_framer   W  s]     llnGCGGBKED  
|	$ 9W489 9 9s   A..A7c           	         t        j                         \  }}d }t        j                  ||t	        t        d            dd      }| j                         5  |j                  dd       d d d        t        j                  t        d	      5  |j                          d d d        y # 1 sw Y   >xY w# 1 sw Y   y xY w)
Nc                     g S r   r%   r   s    r   updatez(test_exhausted_animation.<locals>.updatey      	r   r   Fr    repeatr   test.gifr{   r   	exhaustedrS   )r&   r'   r   r.   iterr   r   rK   rY   rZ   r   _startr   r"   r0   r   r2   s        r   test_exhausted_animationr   v  s    llnGC ""VDrOED
 
 /		*X	./ 
k	5  / / s   B(B4(B14B=c                     t        j                         \  }}d }t        j                  ||g dd      }t	        j
                  t        d      5  |j                          d d d        y # 1 sw Y   y xY w)Nc                     g S r   r%   r   s    r   r   z%test_no_frame_warning.<locals>.update  r   r   Fr   r   rS   )r&   r'   r   r.   rY   rZ   r   r   r   s        r   test_no_frame_warningr     sb    llnGC ""VBuD
 
k	5   s   A**A3png)
extensionsc                    |j                         }|j                  ddt        j                  z         |j	                  dd       t        j
                  ddt        j                  z  d      |j                  g g       \  fd}fd}t        j                  |||dd	d
      }| j                         5  |j                  d       d d d        |j                         }|j                  ddt        j                  z         |j	                  dd       |j                  t        j                  dz                y # 1 sw Y   wxY w)Nr      r	   r
   r   c                  .     j                  g g         fS r   r   r   s   r   r   z"test_animation_frame.<locals>.init  r   r   c                 `    j                  t        j                  | dz  z                fS )Nr   )r   r   r   )r   r   r   s    r   r   z%test_animation_frame.<locals>.animate  s)    aAG,-ur   r!   TF)r$   r    r   r   r   g{Gz?)add_subplotr)   r   pir*   r   r(   r   r.   r   rK   r   )	r   fig_testfig_refr0   r   r   r2   r   r   s	          @@r   test_animation_framer    s	   
 
			BKK1ruu9KKA
Aq255y#&AGGBOED ""'T!%!D 
 		* 
			BKK1ruu9KKA GGArvva'k"# s   :EE)6r   pathlibr   rU   r   r   r   numpyr   rY   
matplotlibr   r   r&   r   matplotlib.testing.decoratorsr   fixturer2   AbstractMovieWriterr4   rO   r   parametrizer+   r]   rj   r   registerrm   r   r   r   r   skipifr   rs   ImageMagickWriterr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r%   r   r   <module>r     sU   	    
     $   = B B4i33 6,$ $T"2!3vhG	" H	"!& F#  $"5$ 7G$T"2!3vhG H H* FLL**&&2244$ + &' FLLV[[//++7799) 0 +,	$ 	  ( 
 $T"2!3vhG H	 2 $d58n"=!>#)(  ,7,74 V\\"&++*<*<**3<<8J+KLL/ += +1 2  $a.!1VHE/ F/ V\\"&++*<*<**3<<8J+KLL/ += +1 2  $a.!1VHE7 F7 BGGw&/DE# F#" +eT];*1 <*1Z  * 99&$ ($ )$r   