
    rbiG                     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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j                    d             Z G d d	ej                  Zd
 Zej                            d ee          gdg          d             Zd Zej                             d           G d de                      Z!g dZ"d Z#ej                            d e#                      ej                            d ee          gdg          d                         Z$ej                            d e#                      d             Z%ej                            d ej&        dej        '                    ej(        )                                 d                     ej&        dej        '                    ej*        )                                 d                    g          ej                            dg d           ej                            d ee          gdg          d!                                     Z+ej                            dd" e, e-d#                    d$gdg          d%             Z.d& Z/ej                            d' ej&        d(ej        '                    ej        0                    ej1        d)                    d*                    d+g          ej                            d ed,-          gdg          d.                         Z2ej                            d' ej&        d(ej        '                    ej        0                    ej1        d)                    d*                    d+g          ej                            d ed,-          gdg          d/                         Z3ej        '                     ej4        d0          du d1          d2             Z5ej                            d3d4d5g          d6             Z6ej                            d7g d8          d9             Z7d: Z8d; Z9 ed<g=          d>             Z:ej                            d ee          gdg          d?             Z;ej                            d ee          gdg          d@             Z<ej                            d ee          gdg          dA             Z=dB Z>dC Z?dS )D    N)Path)pyplot)	animation)PillowWriter)check_figures_equalc                 r   t          j                    \  }}|                    g g           \  |                    dd           |                    dd           fd}f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                  6                          g g             fS Nset_datalines   o/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/matplotlib/tests/test_animation.pyinitzanim.<locals>.init       b"u    c                     t          j        ddd          }t          j        || z             }                    ||           fS )Nr   r	   d   )nplinspacesinr   )ixyr   s      r   animatezanim.<locals>.animate!   sB    K2s##F1q5MM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   animr3      s     lnnGCGGBOOEDKK2KKA         ''7B//00FJJw	 788Evx5ASw$AA&AAAr   c                   $    e Zd ZdZd Zd Z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                 L    || _         || _        || _        || _        d| _        d S )Nr   )r#   outfiledpiargs_count)selfr#   r7   r8   r9   s        r   setupzNullMovieWriter.setup;   s)    	r   c                 V    ddl m}  ||           || _        | xj        dz  c_        d S )Nr   )_validate_grabframe_kwargsr   )matplotlib.animationr>   savefig_kwargsr:   )r;   r@   r>   s      r   
grab_framezNullMovieWriter.grab_frameB   sA    CCCCCC"">222,qr   c                     d S r   r&   r;   s    r   finishzNullMovieWriter.finishH   s    r   N)__name__
__module____qualname____doc__r<   rA   rD   r&   r   r   r5   r5   /   sK        	 	        r   r5   c                    dt           j        d<   d}d}t          d          }t                      }|                     ||||           |j        t          j        d          k    sJ |j        |k    sJ |j        |k    sJ |j	        d	k    sJ |
                                D ]\  }}|j        |         |k    sJ |j        | j        k    sJ d S )
Nautozsavefig.facecolorunused.null2   r   )foo)r8   writerr@   r   r&   )r'   rcParamsr,   r5   saver#   figurer7   r8   r9   itemsr@   r:   _save_count)r3   filenamer8   r@   rN   kvs          r   test_null_movie_writerrW   L   s   (.CL$%H
Ca[[[NFIIhC+  - - - :A&&&&>X%%%%:;" $$&& - -1$Q'1,,,,,=D,,,,,,,r   r3   )r    )indirectc                 8   t          j                    dk    rt          j                                         t          j        di | } t          j        t          d          5  ~ t          j                                         d d d            d S # 1 swxY w Y   d S )NPyPyzAnimation was deletedmatchr&   )
platformpython_implementationr   testingbreak_cyclesr   r/   pytestwarnsWarningr3   s    r   test_animation_deletere   b   s    %''611 	
!!!"**T**D	g%<	=	=	= " "

!!!" " " " " " " " " " " " " " " " " "s   " BBBc                       G d dt           j                  } t          j                    }d}d}d}d}dg} | ||||          }|                    ||           |j        |j        k    sJ d S )Nc                       e Zd Zd ZdS )7test_movie_writer_dpi_default.<locals>.DummyMovieWriterc                     d S r   r&   rC   s    r   _runz<test_movie_writer_dpi_default.<locals>.DummyMovieWriter._runq   s    Dr   N)rE   rF   rG   rj   r&   r   r   DummyMovieWriterrh   p   s#        	 	 	 	 	r   rk   rK   r"   unusedr   )r   MovieWriterr'   rQ   r<   r8   )rk   r#   rT   fpscodecbitrate
extra_argsrN   s           r   test_movie_writer_dpi_defaultrr   o   s        90   
 *,,CH
CEGJc5':>>F
LLh:      r   nullc                   0    e Zd Z	 	 ddZed             ZdS )RegisteredNullMovieWriterNc                     d S r   r&   )r;   rn   ro   rp   rq   metadatas         r   __init__z"RegisteredNullMovieWriter.__init__   s    r   c                     dS )NTr&   )clss    r   isAvailablez%RegisteredNullMovieWriter.isAvailable   s    tr   )NNNNN)rE   rF   rG   rx   classmethodr{   r&   r   r   ru   ru      sK         6:+/      [  r   ru   ))ffmpeg	movie.mp4)ffmpeg_filer~   )imagemagick	movie.gif)imagemagick_filer   )pillowr   )htmlz
movie.html)rs   z
movie.nullc               #     K   t           D ]\  } }t          j                            |           sgt          j                            d|  d          }t	          j        | d ||g          V  t	          j        | d t          |          |g          V  t          j        |          }t          |dd g          D ]}| ||fV  | |t          |          fV  d S )Nzwriter 'z' not available on this systemmarkssupported_formats)
WRITER_OUTPUTr   writersis_availablera   markskipr   r   r-   )rN   outputr   writer_classframe_formats        r   gen_writersr      s     ' 5 5 --f55 	;##A6AAAC CD,vtVD6BBBBBB,vtT&\\$HHHHHH (0#L2EvNN 	5 	5L,....,V44444	55 5r   zwriter, frame_format, outputc           	      *   ||t           j        d<   t          j        d	i |}d }d }|dk    r|j                            d           d}d}|                                 5  |                    |d|d||           d d d            n# 1 swxY w Y   ~d S )
Nanimation.frame_formatr}   g33333%@gQk"@      Y@h264   i  )rn   rN   rp   r8   ro   r&   )r'   rO   r   r/   _figset_size_inchesas_cwdrP   )tmpdirrN   r   r   r3   r8   ro   s          r   test_save_animation_smoketestr      s     1=-."**T**D
CE	!!-000 
  		&b# 	 	 	 	               	s   BBBc                 `   t           j        |         }||t          j        d<   t          j                    \  }}d }d }|dk    r|                    d           d}d} |            }	|                                 5  |	                    |||          5  |	                                 dD ]S}
t          j
        t          d|
          5   |	j        d	i |
t                      i d d d            n# 1 swxY w Y   T	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )
Nr   r}   r   r   r   >   r8   formatbbox_inchesz.grab_frame got an unexpected keyword argument r[   r&   )r   r   r'   rO   r(   r   r   savingrA   ra   raises	TypeErrorobject)r   rN   r   r   WriterClassr#   r1   r8   ro   test_writerrU   s              r   test_grabframer      s   #F+K1=-.lnnGC
CEM***+--K 
 	< 	<VS11 	< 	<""$$$5 < <]!TqTT   < < +K*;;a];;;	< < < < < < < < < < < < < < <<	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<sZ   ;D#7D
C2	&D2C66D9C6:D?D#D	D#D	D##D'*D'rN   r}   Requires FFMpeg)reasonr   r   zRequires ImageMagickz
html, want))noneN)html5z<video width)jshtmlz<script c                 R   t          j                    dk    rt          j                                         | dk    r8|dk    r2t
          j                                        st          j	        d           t          j
        di |}t          j        | |d          5  |                                }d d d            n# 1 swxY w Y   |W|J t          j        t                    5  ~t          j                                         d d d            d S # 1 swxY w Y   d S ||v sJ d S )NrZ   r   r   r   )animation.writerzanimation.htmlr&   )r]   r^   r   r_   r`   r   FFMpegWriterr{   ra   r   r/   r'   
rc_context_repr_html_rb   UserWarning)rN   r   wantr3   s       r   test_animation_repr_htmlr      s   " %''611 	
!!!-DGOO*6688 %4 	%&&& "**T**D	V+/1 1 
2 
2 " "!!" " " " " " " " " " " " " " " ||||\+&& 	& 	&J##%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& t||||||s$   B==CC' DDDr	   r"   )
save_countr!   c                 L    |                      dt                                 d S )NrK   rN   )rP   r5   rd   s    r   test_no_length_framesr     s&     	IImO$5$5I66666r   c                  6   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_pathr}   win32truewhere)	lenr   r   _registeredmplrO   r   sysr]   )bins    r   test_movie_writer_registryr     s    y ,--1111,ECL() --h77777LG++&&C,/CL()))(3333333r   method_nameto_html5_videor   zanimation writer not installed	to_jshtmlr   )r!   c                    |                     d           |                                5  t          j        ddi          5   t	          ||                        d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          |j                  dk    sJ |j        \  }|j        dk    r|j        dk    sJ d S )NWARNINGzanimation.embed_limitgư>r   zmatplotlib.animation)		set_levelr   r   r   r-   r   recordsname	levelname)r   caplogr   r3   records        r   test_embed_limitr   $  sL    Y	 ) )^4d;<< 	) 	)&GD+&&(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)) ) ) ) ) ) ) ) ) ) ) ) ) ) ) v~!####nGFK111 I------s5   A=A&A=&A*	*A=-A*	.A==BBc                    |                                 5   t          ||                        t          t          t	          |                                                              g k    sJ 	 d d d            d S # 1 swxY w Y   d S r   )r   r-   listr   striterdir)r   r   r3   s      r   test_cleanup_temporariesr   6  s     
 7 7"k""$$$DV%%--//00B666667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s   AA==BBz/bin/shzrequires a POSIX OSc                    |                                  5  |                    ddt          j        d         z              t	          t          |           d          }|                    d           t          j        |d           t          j	        t          j                  5  |                    d           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w 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.:r}   s   #!/bin/sh
[[ $@ -eq 0 ]]
i  z	test.mpegN)r   setenvosenvironr   r   write_byteschmodra   r   
subprocessCalledProcessErrorrP   )r   monkeypatchr3   exe_paths       r   test_failing_ffmpegr   C  sN    
 # #64"*V*<#<===FX..;<<<
5!!!]:899 	# 	#IIk"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	## # # # # # # # # # # # # # # # # #s6   BC$C:CC
	
CC
	CC"%C"cache_frame_dataFTc                   
 t          j                    \  }}|                    g g           \   G d dt                    
fd}fd}g 
fd}d}t	          j        ||||| |          }t                      }|                    d|	           t                    d
k    sJ t          j
                                         D ]}	 |	            d u | k    sJ d S )Nc                       e Zd ZdS )2test_funcanimation_cache_frame_data.<locals>.FrameN)rE   rF   rG   r&   r   r   Framer   Z  s        r   r   c                  6                          g g             fS r   r   r   s   r   r   z1test_funcanimation_cache_frame_data.<locals>.init^  r   r   c                 N                         | d         | d                    fS )Nr   r   r   )framer   s    r   r   z4test_funcanimation_cache_frame_data.<locals>.animateb  s&    eCj%*---ur   c               3   
  K   t          d          D ]o} t          j        ddd          }t          j                            d          } ||          }                    t          j        |                     |V  pd S )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_generatorh  s      q 
	 
	AAr3''A	s##AEAOOOE ##GK$6$6777KKKK
	 
	r   r   )r%   r!   r   r   rK   r   r"   )r'   r(   r)   r,   r   r/   r5   rP   r   r   r_   r`   )r   r#   r1   r   r   r   
MAX_FRAMESr3   rN   fr   r   r   s             @@@r   #test_funcanimation_cache_frame_datar   U  sa   lnnGCGGBOOED                      J"34*:4D.8: : :D
 FIImFI+++  A%%%%J 1 1 t 0000001 1r   return_value)Nstringr   )r   artistc                     t          j                    \  }}|                    g           \   fd}t          j        t
                    5  t          j        ||dd           d d d            d S # 1 swxY w Y   d S )Nc                 L                         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>.animate  s5    q!fq!f%%%8##Kr   TF)blitr   )r'   r(   r)   ra   r   RuntimeErrorr   r/   )r   r#   r1   r   r   s   `   @r   test_draw_framer     s     lnnGCGGBKKED            
|	$	$ 
 
te	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   A55A9<A9c           	         t          j                    \  }}d }t          j        ||t	          t          d                    dd          }|                                 5  |                    dd           d d d            n# 1 swxY w Y   t          j	        t          d	          5  |                                 d d d            d S # 1 swxY w Y   d S )
Nc                     g S r   r&   r   s    r   updatez(test_exhausted_animation.<locals>.update      	r   r	   Fr!   repeatr   test.gifr   r   	exhaustedr[   )r'   r(   r   r/   iterr   r   rP   ra   rb   r   _startr   r#   r1   r   r3   s        r   test_exhausted_animationr	    sT   lnnGC   "VDrOOE  D
 
 / /		*X	.../ / / / / / / / / / / / / / / 
k	5	5	5                   s$   !BB	B	+CCCc                     t          j                    \  }}d }t          j        ||g dd          }t	          j        t          d          5  |                                 d d d            d S # 1 swxY w Y   d S )Nc                     g S r   r&   r   s    r   r   z%test_no_frame_warning.<locals>.update  r  r   Fr  r  r[   )r'   r(   r   r/   ra   rb   r   r  r  s        r   test_no_frame_warningr    s    lnnGC   "VBu  D
 
k	5	5	5                   s   A00A47A4png)
extensionsc                    |                                 }|                    ddt          j        z             |                    dd           t          j        ddt          j        z  d          |                    g g           \  fd}fd}t          j        |||dd	d
          }| 	                                5  |
                    d           d d d            n# 1 swxY w Y   |                                 }|                    ddt          j        z             |                    dd           |                    t          j        dz                        d S )Nr      r
   r   r   c                  6                          g g             fS r   r   r   s   r   r   z"test_animation_frame.<locals>.init  r   r   c                 f                         t          j        | dz  z                        fS )Nr   )r   r   r   )r   r   r   s    r   r   z%test_animation_frame.<locals>.animate  s0    aAG,,---ur   r"   TF)r%   r!   r   r  r  g{Gz?)add_subplotr*   r   pir+   r   r)   r   r/   r   rP   r   )	r   fig_testfig_refr1   r   r   r3   r   r   s	          @@r   test_animation_framer    s   
 
				BKK1ru9KKA
Aq25y#&&AGGBOOED          "'T!%! ! !D 
  		*               
				BKK1ru9KKA GGArva'k""#####s   C&&C*-C*c           	         d}t          t          d                    }d|dt          |          d}t          j        t
          t          j        |                    5  t          j	        di i | ||d} d d d            n# 1 swxY w Y   | j
        t          |          k    sJ |                                  d S )	Nr"   r  %You passed in an explicit save_count=z0 which is being ignored in favor of len(frames)=.r[   r!   r   r&   )r   r   r   ra   rb   r   reescaper   r/   rS   
_init_drawr3   r   r!   match_targets       r   ,test_save_count_override_warnings_has_lengthr!    s!    J%((^^F	Z 	 	v;;	 	 	  
k<)@)@	A	A	A 
 
& 
 
BBzBBB
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 s6{{****OOs   "BBBc           	      *   d}d}d|ddz   d|dz   }t          j        t          t          j        |                    5  t          j        d
i i | ||d	} d d d            n# 1 swxY w Y   | j        |k    sJ |                                  d S )Nr"      r   z#which is being ignored in favor of frames=r  r[   r  r&   )	ra   rb   r   r  r  r   r/   rS   r  r  s       r   (test_save_count_override_warnings_scalerr&    s
   JF3Z333-	.6	  
k<)@)@	A	A	A 
 
& 
 
BBzBBB
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 

 v%%%%OOs   A''A+.A+c           	      L   d}t          t          d                    }d|d|d}t          j        t          t          j        |                    5  t          j        d	i i | ||d} d d d            n# 1 swxY w Y   | j	        du sJ | 
                                 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`.r[   )r   r!   Fr&   )r  r   ra   rb   r   r  r  r   r/   _cache_frame_datar  )r3   r   r!   r   s       r   test_disable_cache_warningr)    s   %((^^F	?6 	? 	?&	? 	? 	?  
k<)@)@	A	A	A 
 
& 
 
NN+;vNNN
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 !U****OOs   A::A>A>c                     t           j        dk    rd}nd}t          j        t          |          5  |                     dt          j                               d d d            d S # 1 swxY w Y   d S )Nr   z,\[WinError 3] .*'\\\\foo\\\\bar\\\\aardvark'z\[Errno 2] .*'/foor[   z+/foo/bar/aardvark/thiscannotreallyexist.mp4r   )r   r]   ra   r   FileNotFoundErrorrP   r   FFMpegFileWriter)r3   	match_strs     r   test_movie_writer_invalid_pathr.  #  s    
|wC		)		(		:	:	: 7 7		?"355 	 	7 	7 	77 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s   )A''A+.A+c                     t          j                    \  } }t          j        ddddd          }|                    |           |                    dd           |                    dd           t          d          }|                    | d	d
           |                    d           |j	        d         }|
                                d         d         dk     sJ t          j        |            dS )zGTest animation exhaustion with transparency using PillowWriter directly)r   r   r   redg      ?)coloralphar   r   )rn   z
unused.gifr   )r8   T)transparentr
         N)r'   r(   	Rectangle	add_patchr*   r+   r   r<   rA   _frames
getextremaclose)r#   r1   rectrN   r   s        r    test_animation_with_transparencyr<  -  s    lnnGC=AU#>>>DLLKK1KK1b!!!F
LLlL,,,
$'''N2Ea #c))))IcNNNNNr   )@r   pathlibr   r]   r  shutilr   r   r   numpyr   ra   
matplotlibr   r   r'   r   r?   r   matplotlib.testing.decoratorsr   fixturer3   AbstractMovieWriterr5   rW   r   parametrizer,   re   rr   r   registerru   r   r   r   r   r   skipifr   r{   ImageMagickWriterr   r  r   r   r   r   rO   r   r   whichr   r   r   r	  r  r  r!  r&  r)  r.  r<  r&   r   r   <module>rI     s   				        				      



           $ $ $ $ $ $             - - - - - - = = = = = = B B B4    i3   :- - -, $$T"2"2"2!3vhGG	" 	" HG	"! ! !& F##       $#"  5 5 5$ 7GG$$T"2"2"2!3vhGG  HG HG* 7GG< < HG<> FL**&22444$ + & &' ' ' FLV[//+77999) 0 + +, , ,	$ 	 	  ( ( (  
 $$T"2"2"2!3vhGG  HG 	 	 2 
$$uuQxx..112X   
7 7 
74 4 4 V\"&+*<*<**3<8J+KLLL/ += +1 +1 2 2 2   $$a...!1VHEE/ / FE / V\"&+*<*<**3<8J+KLLL/ += +1 +1 2 2 2   $$a...!1VHEE7 7 FE 7 LFL++t3<QRR# # SR#" +eT];;,1 ,1 <;,1^  * * *  
 
 
*  $   ((($ $ )($B $$T"2"2"2!3vhGG  HG$ $$T"2"2"2!3vhGG  HG$ $$T"2"2"2!3vhGG  HG&7 7 7    r   