B
    Mô`¢   ã            
   @   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	mZ d dl	mZ G dd„ dejƒZdd„ Zd	d
„ Zdd„ Zej d¡G dd„ deƒƒZdddddddddg	Zedd„ eD ƒ7 Zej de¡dd„ ƒZ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¡d)d*„ ƒZ ej d"ejd#ejjej e
jd$ ¡ d%d&�d'�d(g¡d+d,„ ƒZ!ejje j"d-kd.d&�d/d0„ ƒZ#ej d1d2d3g¡d4d5„ ƒZ$dS )6é    N)ÚPath)Úpyplot)Ú	animationc               @   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   )ÚfigÚoutfileÚdpiÚargsÚ_count)Úselfr   r   r   r	   © r   úC/tmp/pip-unpacked-wheel-0c1wfn4v/matplotlib/tests/test_animation.pyÚsetup   s
    zNullMovieWriter.setupc             K   s   || _ |  jd7  _d S )Né   )Úsavefig_kwargsr
   )r   r   r   r   r   Ú
grab_frame"   s    zNullMovieWriter.grab_framec             C   s   d S )Nr   )r   r   r   r   Úfinish&   s    zNullMovieWriter.finishN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s   
r   c                 s<   t  ¡ \}}| g ¡\‰ dd„ }‡ fdd„}tj||f| ŽS )Nc               S   s   d S )Nr   r   r   r   r   Úinit.   s    zmake_animation.<locals>.initc                s   ˆ   ddgd| g¡ ˆ fS )Nr   r   )Úset_data)Úi)Úliner   r   Úanimate1   s    zmake_animation.<locals>.animate)ÚpltÚsubplotsÚplotr   ÚFuncAnimation)Úkwargsr   Úaxr   r   r   )r   r   Úmake_animation*   s
    r"   c              C   s–   d} t | d�}d}d}tdd�}tƒ }|j||||d� |jt d¡ksLt‚|j|ksZt‚|j	|ksht‚|j
d	ksvt‚|j|ks„t‚|j| ks’t‚d S )
Né   )Úframeszunused.nullé2   r   )Zfoo)r   Úwriterr   r   r   )r"   Údictr   Úsaver   r   ÚfigureÚAssertionErrorr   r   r	   r   r
   )Z
num_framesÚanimÚfilenamer   r   r&   r   r   r   Útest_null_movie_writer8   s    


r-   c              C   s^   G dd„ dt jƒ} t ¡ }d}d}d}d}dg}| ||||ƒ}| ||¡ |j|jksZt‚d S )Nc               @   s   e Zd Zdd„ ZdS )z7test_movie_writer_dpi_default.<locals>.DummyMovieWriterc             S   s   d S )Nr   )r   r   r   r   Ú_runP   s    z<test_movie_writer_dpi_default.<locals>.DummyMovieWriter._runN)r   r   r   r.   r   r   r   r   ÚDummyMovieWriterO   s   r/   zunused.nullr#   Zunusedr   )r   ZMovieWriterr   r)   r   r   r*   )r/   r   r,   ÚfpsÚcodecÚbitrateÚ
extra_argsr&   r   r   r   Útest_movie_writer_dpi_defaultN   s    r4   Únullc               @   s"   e Zd Zddd„Zedd„ ƒZdS )ÚRegisteredNullMovieWriterNc             C   s   d S )Nr   )r   r0   r1   r2   r3   Úmetadatar   r   r   Ú__init__j   s    z"RegisteredNullMovieWriter.__init__c             C   s   dS )NTr   )Úclsr   r   r   ÚisAvailablen   s    z%RegisteredNullMovieWriter.isAvailable)NNNNN)r   r   r   r8   Úclassmethodr:   r   r   r   r   r6   a   s   	 
r6   )Úffmpegz	movie.mp4)Zffmpeg_filez	movie.mp4)Zavconvz	movie.mp4)Zavconv_filez	movie.mp4)Zimagemagickz	movie.gif)Zimagemagick_filez	movie.gif)Zpillowz	movie.gif)Úhtmlz
movie.html)r5   z
movie.nullc             C   s   g | ]\}}|t |ƒf‘qS r   )r   )Ú.0r&   Úoutputr   r   r   ú
<listcomp>   s    r@   zwriter, outputc       
   	      sÆ   t j |¡st d| ¡ t ¡ \}}| g g ¡\‰ | dd¡ | 	dd¡ d }d }|dkrn| 
d¡ d}d	}‡ fd
d„}‡ fdd„}|  ¡ �. t j|||dd�}	|	j|d|d||d� W d Q R X d S )Nz(writer '%s' not available on this systemr   é
   éÿÿÿÿr   r<   )g33333³%@gìQ¸…k"@g      Y@Zh264c                  s   ˆ   g g ¡ ˆ fS )N)r   r   )r   r   r   r   —   s    z+test_save_animation_smoketest.<locals>.initc                s.   t  ddd¡}t  ||  ¡}ˆ  ||¡ ˆ fS )Nr   rA   éd   )ÚnpÚlinspaceÚsinr   )r   ÚxÚy)r   r   r   r   ›   s    z.test_save_animation_smoketest.<locals>.animater#   )Ú	init_funcr$   é   iô  )r0   r&   r2   r   r1   )r   ÚwritersÚis_availableÚpytestÚskipr   r   r   Zset_xlimZset_ylimZset_size_inchesÚas_cwdr   r(   )
Útmpdirr&   r?   r   r!   r   r1   r   r   r+   r   )r   r   Útest_save_animation_smoketest…   s$    

rQ   c               C   s"   t ttdƒƒd�jdtƒ d� d S )Nr#   )r$   zunused.null)r&   )r"   ÚiterÚranger(   r   r   r   r   r   Útest_no_length_frames©   s    rT   c              C   s^   t tjjƒdkst‚dtjd< tj d¡r.t‚tj	dkr<dnd} | tjd< tj d¡sZt‚d S )Nr   Znot_available_ever_xxxxzanimation.ffmpeg_pathr<   Úwin32ÚtrueÚwhere)
Úlenr   rK   Z_registeredr*   ÚmplÚrcParamsrL   ÚsysÚplatform)Úbinr   r   r   Útest_movie_writer_registry®   s    

r^   Úmethod_nameZto_html5_videozanimation.writerzanimation writer not installed)Úreason)ZmarksZ	to_jshtmlc          
   C   s€   |  d¡ | ¡ �2 t ddi¡� ttdd�| ƒƒ  W d Q R X W d Q R X t|jƒdks\t‚|j\}|j	dkrx|j
dks|t‚d S )NÚWARNINGzanimation.embed_limitg�íµ ÷Æ°>r   )r$   zmatplotlib.animation)Z	set_levelrO   rY   Z
rc_contextÚgetattrr"   rX   Úrecordsr*   ÚnameÚ	levelname)r_   ZcaplogrP   Úrecordr   r   r   Útest_embed_limit¸   s    

&
rg   c          	   C   sF   |  ¡ �4 ttdd�| ƒƒ  ttt|ƒƒ ¡ ƒg ks8t‚W d Q R X d S )Nr   )r$   )rO   rb   r"   Úlistr   ÚstrÚiterdirr*   )r_   rP   r   r   r   Útest_cleanup_temporariesÉ   s    
rk   Úposixzrequires a POSIX OSc          
   C   sz   |   ¡ �h | ddtjd  ¡ tt| ƒdƒ}| d¡ t t|ƒd¡ t 	t
j¡� tƒ  d¡ W dQ R X W dQ R X 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<   z#!/bin/sh
[[ $@ -eq 0 ]]
ií  z	test.mpegN)rO   ZsetenvÚosÚenvironr   ri   Ú
write_textÚchmodrM   ZraisesÚ
subprocessÚCalledProcessErrorr"   r(   )rP   ZmonkeypatchZexe_pathr   r   r   Útest_failing_ffmpegÕ   s    	

rt   Ú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sŒt	‚xˆD ]}|ƒ d k| ks’t	‚q’W d S )Nc               @   s   e Zd ZdS )z2test_funcanimation_cache_frame_data.<locals>.FrameN)r   r   r   r   r   r   r   ÚFrameí   s   rv   c                  s   ˆ   g g ¡ ˆ fS )N)r   r   )r   r   r   r   ñ   s    z1test_funcanimation_cache_frame_data.<locals>.initc                s   ˆ   | d | d ¡ ˆ fS )NrG   rH   )r   )Úframe)r   r   r   r   õ   s    z4test_funcanimation_cache_frame_data.<locals>.animatec              3   sR   xLt dƒD ]@} t ddd¡}tj d¡}ˆ ||d�}ˆ t |¡¡ |V  q
W d S )Nr#   r   rA   rC   )rG   rH   )rS   rD   rE   ÚrandomZrandÚappendÚweakrefÚref)Ú_rG   rH   rw   )rv   Úframes_generatedr   r   Úframes_generatorû   s    z=test_funcanimation_cache_frame_data.<locals>.frames_generator)rI   r$   ru   zunused.null)r&   r#   )
r   r   r   r'   r   r   r   r(   rX   r*   )	ru   r   r!   r   r   r~   r+   r&   Úfr   )rv   r}   r   r   Ú#test_funcanimation_cache_frame_dataè   s    

r€   )%rn   Úpathlibr   rr   r[   rz   ZnumpyrD   rM   Z
matplotlibrY   r   r   r   ZAbstractMovieWriterr   r"   r-   r4   rK   Úregisterr6   ZWRITER_OUTPUTÚmarkZparametrizerQ   rT   r^   ÚparamZskipifrL   rZ   rg   rk   rd   rt   r€   r   r   r   r   Ú<module>   sV   $


