rL iG ddlZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl mZddl mZddlmZddlmZe j*dZGdd ej.Zd Ze j4j7d ee gd g dZdZej>jAdGddeZ!gdZ"dZ#e j4j7de#e j4j7d ee gd g dZ$e j4j7de#dZ%e j4j7de jLde j4jOejPjS de jLde j4jOejTjS dge j4j7dgd e j4j7d ee gd g d!Z+e j4j7d d"e,e-d#d$gd g d%Z.d&Z/e j4j7d'e jLd(e j4jOej>jae jbd) d*d+ge j4j7d ed,-gd g d.Z2e j4j7d'e jLd(e j4jOej>jae jbd) d*d+ge j4j7d ed,-gd g d/Z3e j4jOejhd0dud1d2Z5e j4j7d3d4d5gd6Z6e j4j7d7gd8d9Z7d:Z8d;Z9edZ:e j4j7d ee gd g d?Z;e j4j7d ee gd g d@ZdCZ?y)DN)Path)pyplot) animation) PillowWriter)check_figures_equalcLtj\}}|jgg\|jdd|j ddfd}fd}t t |di}|jdtj}d |vrd |d <|d |||d |S) z)Create a simple animation (with options).r c.jggfSNset_datalinese/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/tests/test_animation.pyinitzanim..init b"u ctjddd}tj||z}j||fS)Nrr d)nplinspacesinr)ixyrs ranimatezanim..animate!s; KK2s # FF1q5M au rparamklassframes)figfunc init_func) pltsubplotsplotset_xlimset_ylimdictgetattrpopr FuncAnimation)requestr#axrrkwargsr rs @ranimr3sllnGC GGBOEDKK2KKA''7B/ 0F JJw 7 7 8Evx  ASw$ A& AArc"eZdZdZdZdZdZy)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. cJ||_||_||_||_d|_y)Nr)r#outfiledpiargs_count)selfr#r7r8r9s rsetupzNullMovieWriter.setup;s%   rc Xddlm}||||_|xjdz c_y)Nr)_validate_grabframe_kwargsr )matplotlib.animationr>savefig_kwargsr:)r;r@r>s r grab_framezNullMovieWriter.grab_frameBs#C">2, q rcyr r&r;s rfinishzNullMovieWriter.finishHs rN)__name__ __module__ __qualname____doc__r<rArDr&rrr5r5/s   rr5cdtjd<d}d}td}t}|j |||||j tj dk(sJ|j|k(sJ|j|k(sJ|jd k(sJ|jD]\}}|j||k(rJ|j|jk(sJy) Nautozsavefig.facecolor unused.null2r)foo)r8writerr@r r&)r'rcParamsr,r5saver#figurer7r8r9itemsr@r: _save_count)r3filenamer8r@rNkvs rtest_null_movie_writerrWLs(.CLL$%H Ca[N  FIIhC+- ::A && & >>X %% % ::   ;;"  $$&-1$$Q'1,,,- ==D,, ,, ,rr3)r )indirectc6tjdk(rtjj t j di|}tjtd5~tjj dddy#1swYyxYw)NPyPyzAnimation was deletedmatchr&) platformpython_implementationrtesting break_cyclesrr/pytestwarnsWarningr3s rtest_animation_deleterebso%%'61 !  " " *T *D g%< ="  !"""s & BBcGddtj}tj}d}d}d}d}dg}|||||}|j |||j |j k(sJy)NceZdZdZy)7test_movie_writer_dpi_default..DummyMovieWritercyr r&rCs r_runz.DummyMovieWriter._runqs rN)rErFrGrjr&rrDummyMovieWriterrhps rrkrKr"unusedr )r MovieWriterr'rQr<r8)rkr#rTfpscodecbitrate extra_argsrNs rtest_movie_writer_dpi_defaultrrosp900 **,CH C EGJ c5': >F LLh ::  rnullc(eZdZ ddZedZy)RegisteredNullMovieWriterNcyr r&)r;rnrorprqmetadatas r__init__z"RegisteredNullMovieWriter.__init__s rcy)NTr&)clss r isAvailablez%RegisteredNullMovieWriter.isAvailablesr)NNNNN)rErFrGrx classmethodr{r&rrrurus#6:+/ rru))ffmpeg movie.mp4) ffmpeg_filer~) imagemagick movie.gif)imagemagick_filer)pillowr)htmlz movie.html)rsz movie.nullc#KtD]\}}tjj|setj j d|d}t j|d||gt j|dt||gtj|}t|ddgD]}|||f||t|fyw)Nzwriter 'z' not available on this systemmarkssupported_formats) WRITER_OUTPUTrwriters is_availableramarkskiprrr-)rNoutputr writer_class frame_formats r gen_writersrs' 5  --f5;;##6("@ACD,,vtVD6B B,,vtT&\$H H  ((0 #L2EvN 5L,. .,V 4 4 5 5sCCzwriter, frame_format, outputc $||tjd<tjd i|}d}d}|dk(r|jj dd}d}|j 5|j|d|d||ddd~y#1swY~yxYw) Nanimation.frame_formatr}g33333%@gQk"@Y@h264i)rnrNrpr8ror&)r'rOrr/_figset_size_inchesas_cwdrP)tmpdirrNrrr3r8ros rtest_save_animation_smoketestrs1= -.  " " *T *D C E  !!-0  &b#    s #BBc 4tj|}||tjd<tj\}}d}d}|dk(r|j dd}d}|} |j 5| j|||5| jdD]E} tjtd| 5| jd i| tidddG ddddddy#1swYcxYw#1swYxYw#1swYyxYw) Nrr}rrr>r8format bbox_inchesz.grab_frame got an unexpected keyword argument r[r&) rrr'rOr(rrsavingrAraraises TypeErrorobject) rrNrr WriterClassr#r1r8ro test_writerrUs rtest_grabframers##F+K1= -.llnGC C E  M*-K  <   VS 1 <  " " $5 <]]! NqeT<+K**;a]; << < < < < <<  < < < r zmatplotlib.animation) set_levelrrrr-rrecordsname levelname)rcaplogrr3records rtest_embed_limitr$s Y ) ^^4d; < ) &GD+ & ( )) v~~ ! ## #nnGF KK1 1  I-/ .-  ) )))s"B1B% B1%B. *B11B:c|j5t||ttt |j gk(sJ dddy#1swYyxYwr )rr-listrstriterdir)rrr3s rtest_cleanup_temporariesr6sV 7"k"$DV%--/0B666777s AAA&z/bin/shzrequires a POSIX OSc|j5|jddtjdzt t |d}|j dtj|dtjtj5|jdddddddy#1swYxYw#1swYyxYw)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 ]] iz test.mpegN) rsetenvosenvironrr write_byteschmodrar subprocessCalledProcessErrorrP)r monkeypatchr3exe_paths rtest_failing_ffmpegrCs #64"**V*<#<=F X.;< 5! ]]:88 9 # IIk " # ##  # # ##s$BCB:)C:C ?CCcache_frame_dataFTc tj\}}|jgg\ Gddt fd} fd}g fd}d}t j ||||||}t }|jd| t d k(sJtjj D]} | du|k7rJy) Nc eZdZy)2test_funcanimation_cache_frame_data..FrameN)rErFrGr&rrFramerZs rrc.jggfSr rrsrrz1test_funcanimation_cache_frame_data..init^rrc:j|d|dfS)Nrrr)framers rrz4test_funcanimation_cache_frame_data..animatebs  eCj%*-u rc3KtdD]j}tjddd}tjj d}||}j t j||lyw)Nr"rr r)rr)rangerrrandomrandappendweakrefref)_rrrrframes_generateds rframes_generatorz=test_funcanimation_cache_frame_data..frames_generatorhsgq A Ar3'A s#AAOE  # #GKK$6 7K sA:A=r)r%r!rrrKrr") r'r(r)r,rr/r5rPrrr_r`) rr#r1rrr MAX_FRAMESr3rNfrrrs @@@r#test_funcanimation_cache_frame_datarUsllnGC GGBOED   J  " "34*:4D.8 :D  FIImFI+  A %% %JJ 1t 00001r return_value)Nstringr )rartistctj\}}|jg\fd}tjt 5t j||dddddy#1swYyxYw)NcBjddgd|gdk(rSS)Nrr rr)rrrs rrz test_draw_frame..animates, q!fq!f% 8 #K rTF)blitr)r'r(r)rar RuntimeErrorrr/)rr#r1rrs` @rtest_draw_framersbllnGC GGBKED  | $  te    s A//A8c tj\}}d}tj||t t ddd}|j 5|jdddddtjtd 5|jdddy#1swY>xYw#1swYyxYw) NcgSr r&rs rupdatez(test_exhausted_animation..update rr Fr!repeatrtest.gifrr exhaustedr[) r'r(rr/iterrrrPrarbr_startrr#r1rr3s rtest_exhausted_animationr sllnGC  " " VDrOE D / *X ./ k 5 //sB(B4(B14B=ctj\}}d}tj||gdd}t j t d5|jdddy#1swYyxYw)NcgSr r&rs rrz%test_no_frame_warning..updaterrFrrr[)r'r(rr/rarbrrrs rtest_no_frame_warningr sbllnGC  " " VBu D k 5 s A**A3png) extensionsc|j}|jddtjz|j ddtj ddtjzd|j gg\fd}fd}tj|||dd d }|j5|jd ddd|j}|jddtjz|j dd|j tjd zy#1swYwxYw)Nrr r rc.jggfSr rrsrrz"test_animation_frame..initrrc`jtj|dz zfS)Nr)rrr)rrrs rrz%test_animation_frame..animates) aAG ,-u rr"TF)r%r!rrrg{Gz?) add_subplotr*rpir+rr)rr/rrPr) rfig_testfig_refr1rrr3rrs @@rtest_animation_framers     BKK1ruu9KKA Aq255y#&A GGBOED  " "'T! % !D  *    BKK1ruu9KKAGGArvva'k"#s :EE c fd}ttd}d|dt|d}tjt t j|5tjdii|||d}ddd|jt|k(sJ|jy#1swY4xYw) Nr"r%You passed in an explicit save_count=z0 which is being ignored in favor of len(frames)=.r[r!rr&) rrrrarbrreescaperr/rS _init_drawr3rr! match_targets r,test_save_count_override_warnings_has_lengthr!sJ %(^F 0ZM2 v;.  k<)@ A && BBzB     s6{ ** *OO   s B''B0c ,d}d}d|ddzd|dz}tjttj|5t j d ii|||d }ddd|j|k(sJ|jy#1swY+xYw) Nr"r z#which is being ignored in favor of frames=rr[rr&) rarbrrrrr/rSrrs r(test_save_count_override_warnings_scalerr&sJ F 0ZM3- . 6)1   k<)@ A && BBzB    v %% %OO   s B  Bc @d}ttd}d|d|d}tjtt j |5tjd ii|||d}ddd|jdusJ|jy#1swY*xYw) 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[)rr!Fr&) rrrarbrrrrr/_cache_frame_datar)r3rr!r s rtest_disable_cache_warningr)s %(^F 6+(&()? ? k<)@ A && NN+;vN    ! !U ** *OO   s BBctjdk(rd}nd}tjt|5|j dt jdddy#1swYyxYw)Nrz,\[WinError 3] .*'\\\\foo\\\\bar\\\\aardvark'z\[Errno 2] .*'/foor[z+/foo/bar/aardvark/thiscannotreallyexist.mp4r)rr]rarFileNotFoundErrorrPrFFMpegFileWriter)r3 match_strs rtest_movie_writer_invalid_pathr.#s\ ||wC ) ( :7 ?"335  7777s &A##A,ctj\}}tjddddd}|j||j dd|j ddt d}|j|d d |jd |jd}|jdddksJtj|y)zGTest animation exhaustion with transparency using PillowWriter directly)rrr redg?)coloralpharr)rnz unused.gifr)r8T) transparentr N) r'r( Rectangle add_patchr*r+rr<rA_frames getextremaclose)r#r1rectrNrs r test_animation_with_transparencyr<-sllnGC ==AU# >DLLKK1KK1 b !F LLlL, $' NN2 E    a  #c )) )IIcNr)@rpathlibrr]rshutilrrrnumpyrra matplotlibrrr'rr?rmatplotlib.testing.decoratorsrfixturer3AbstractMovieWriterr5rWr parametrizer,rerrrregisterrurrrrrskipifrr{ImageMagickWriterrrrrrrrOrrwhichrrrr r rr!r&r)r.r<r&rrrIs:    $ -=BB4 i33 :-,$T"2!3vhG "H "!& F#$"  5$7G$T"2!3vhG HH *7G<H<>FLL **&&224 4$+&'FLLV[[//++779 9)0+, $ ( $T"2!3vhGH   2 $uQx.12X 7  74V\\"&++*<*<    * *3<<8J+K LL/+=+12 $a.!1VHE/F /V\\"&++*<*<    * *3<<8J+K LL/+=+12 $a.!1VHE7F 7 LFLL+t3