
    ljr)                       d dl m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
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 d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ ddlmZm Z  ddl!m"Z"m#Z#m$Z$m%Z% dZ& ee'          (                                j)        d         Z*e* edd          z  Z+dZ,	 d:deedd;d%Z-d<d0Z.d=d7Z/d>d9Z0dS )?    )annotationsN)Callable)Path)Any)FixtureRequest)Scene)
tempconfig)ManimConfig)ThreeDCamera)CairoRenderer)OpenGLRenderer)ThreeDScene)StrPath   )_ControlDataWriter_FramesTester)DummySceneFileWriter_make_scene_file_writer_class_make_test_renderer_class_make_test_scene_classscene   control_datagraphical_units_datai.  T)
last_framerenderer_class
base_scenefuncCallable | Noner   boolr   $type[CairoRenderer | OpenGLRenderer]r   type[Scene]custom_configr   returnr   c               T    dfd}t          |           r ||           S |S )aS  Compares the frames generated by the test with control frames previously registered.

    If there is no control frames for this test, the test will fail. To generate
    control frames for a given test, pass ``--set_test`` flag to pytest
    while running the test.

    Note that this decorator can be use with or without parentheses.

    Parameters
    ----------
    last_frame
        whether the test should test the last frame, by default True.
    renderer_class
        The base renderer to use (OpenGLRenderer/CairoRenderer), by default CairoRenderer
    base_scene
        The base class for the scene (ThreeDScene, etc.), by default Scene

    .. warning::
        By default, last_frame is True, which means that only the last frame is tested.
        If the scene has a moving animation, then the test must set last_frame to False.
    tested_scene_constructr   r$   c           	     l    t           t          j                   j        vrt	          dt            d          t          j        t          j         d                     }d j        vrt	          d           j        	                    d          t          t                    sJ  j        t          d          d          t          j                   d	
 fd            }t          |j                                                  }d	|j        vr(|t          j        d	t          j        j                  gz  }d|j        vr(|t          j        dt          j        j                  gz  }|                    |          }||_        g |_        t/           dg           }||_        |S )Nz;Invalid graphical test function test function : must have 'z'as one of the parameters.)r   __module_test__zyThere is no module test name indicated for the graphical unit test. You have to declare __module_test__ in the test file.test_argsr   requestr   tmp_pathr   kwargsr$   Nonec                   t           u r0t          j                    t          k     rt	          j        d           t          j        g|R i |}d                    d |	                                D                       z   }t                    }||d<   ||d<   r
d|d<   d|d	<   | j                            d
          }	 j        d         }n# t          $ r d }Y nw xY wt          t!          |||          
||| j                            d          |d         |d         f          }	t#          i |          5   |	             d d d            d S # 1 swxY w Y   d S )Nz9Cairo version is too old. Skipping cairo graphical tests._c              3  t   K   | ]3}d t          |d                    dt          |d                    dV  4dS )r0   r   [r   ]N)str).0tups     `/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/utils/testing/frames_comparison.py	<genexpr>zNframes_comparison.<locals>.decorator_maker.<locals>.wrapper.<locals>.<genexpr>k   s[       8 8580CAKK00#c!f++0008 8 8 8 8 8    text_dirtex_dirr   
frame_rateTdry_runz
--set_test__file__z--show_diffpixel_heightpixel_width)	file_pathr   	constructr   is_set_test_data_testr   	show_diff
size_frame)r   cairocairo_versionMIN_CAIRO_VERSIONpytestskip	functoolspartialjoinitems_config_testconfig	getoption__globals__	Exception_make_test_comparing_frames_control_data_pathr	   )r+   r,   r*   r-   rB   test_name_with_paramconfig_testssetting_testtest_file_path	real_testr   r#   r   module_namer   	test_namer&   s             r7   wrapperz;frames_comparison.<locals>.decorator_maker.<locals>.wrapperX   s    -//')),===WXXX!)*@R4RRR6RRI $-sxx 8 8<BLLNN8 8 8 0 0 $  (
33L'/L$&.L# /-.\**.Y'">33LAAL&!7!CJ!O & & &!%&3,"( 	  &#-&2%!.22=AA(8,}:UV  I" =|=}=>>  	                 s$   C C! C!EE #E )
parameters
pytestmark)
r*   r   r+   r   r,   r   r-   r   r$   r.   )SCENE_PARAMETER_NAMEinspectgetfullargspecr*   rS   	signaturerK   rL   rR   get
isinstancer4   __name__lenwrapslistr^   values	ParameterKEYWORD_ONLYreplace__signature__r_   getattr)r&   old_sigr]   r^   new_sig	new_marksr[   r\   r   r#   r   r   s   `     @@r7   decorator_makerz*frames_comparison.<locals>.decorator_makerB   s    )*@AAFG G ~Nb~~~  
 #4DAAA
 
 $:$FFF L   -8<<=NOO+s+++++*3CLLNNC		/	0	05	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 
1	05	n ',335566
 G...7,Y8I8VWWXXJW///!*g.?.LMM J //Z/88 '  2L"EE	&r9   )r&   r   r$   r   )callable)r   r   r   r   r#   rs   s    ```` r7   frames_comparisonru   $   sc    <` ` ` ` ` ` ` ` `H ~~ %t$$$r9   rA   r   rB   Callable[[Scene], None]typerC   rD   rE   tupleCallable[[], None]c                   	
 |rt          | |          
nt          | |          
st          
          nt          	t	          |          d	
fd}|S )a  Create the real pytest test that will fail if the frames mismatch.

    Parameters
    ----------
    file_path
        The path of the control frames.
    base_scene
        The base scene class.
    construct
        The construct method (= the test function)
    renderer_class
        The renderer base class.
    show_diff
        whether to visually show_diff (see --show_diff)

    Returns
    -------
    Callable[[], None]
        The pytest test.
    )rE   )rD   r$   r.   c            	     n                                    5  t          t          ur           n t                              }  | d          }|                                 r-                    d|j                                                   d d d            d S # 1 swxY w Y   d S )N)file_writer_class)r|   camera_class)r   construct_testtest_rendererT)skip_animations)testingr   r   r   rendercheck_framerenderer	get_frame)sceneTestedscene_testedr   rB   r|   frames_testerr   testRenderers     r7   rZ   z._make_test_comparing_frames.<locals>.real_test   s8   ""$$ 	Q 	Q0%( "44 !L3DEEEE%*;%1    K  ';t<<<L!!! Q))"l.C.M.M.O.OPPP)	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Qs   BB**B.1B.)r$   r.   )r   r   r   r   r   )rA   r   rB   r   rC   r   rD   rE   rZ   r|   r   r   s    ``  `   @@@r7   rT   rT      s    <  F'9*(
 (
 (
 &i9EEE 	"%m444! 
 -^<<LQ Q Q Q Q Q Q Q Q Q Q. r9   rY   
str | Noner[   r4   r\   rX   c                   | t           } t          |                                           j        dz  |z  }|r|                    d           |s&|                                st          d|           ||z                      d          }|s/|                                st          d| d|j         d          |S )	Nr   T)exist_okz0The control frames directory can't be found  in z.npzzThe control frame for the test z cannot be found in z3. Make sure you generated the control frames first.)	r>   r   absoluteparentmkdirexistsrS   with_suffixis_file)rY   r[   r\   rX   paths        r7   rU   rU      s      "((**1NB[PD "

D
!!! S SQ4QQRRR9))&11D 
 
@i @ @T[ @ @ @
 
 	
 Kr9   r
   c                    t                                          t          t          t                    j        | rdndz                      S )Nz$config_graphical_tests_monoframe.cfgz&config_graphical_tests_multiframes.cfg)r
   digest_filer4   r   r>   r   )r   s    r7   rO   rO   	  sO    ==$$NN! >66=		
 	
	 	 	r9   )N)r   r   r   r    r   r!   r   r"   r#   r   r$   r   )rA   r   r   r"   rB   rv   r   rw   rC   r    r   r    rD   r    rE   rx   r$   ry   )
rY   r   r[   r4   r\   r4   rX   r    r$   r   )r   r    r$   r
   )1
__future__r   rK   ra   collections.abcr   pathlibr   typingr   rF   rI   _pytest.fixturesr   manimr   manim._configr	   manim._config.utilsr
   manim.camera.three_d_camerar   manim.renderer.cairo_rendererr   manim.renderer.opengl_rendererr   manim.scene.three_d_scener   manim.typingr   _frames_testersr   r   _test_class_makersr   r   r   r   r`   r>   r   parents_tests_root_dir_pathPATH_CONTROL_DATArH   ru   rT   rU   rO    r9   r7   <module>r      s8   " " " " " "      $ $ $ $ $ $               + + + + + +       $ $ $ $ $ $ + + + + + + 4 4 4 4 4 4 7 7 7 7 7 7 9 9 9 9 9 9 1 1 1 1 1 1             > > > > > > > >             tH~~..008; (44@V+W+WW   !D ;H#D D D D D DNC C C CL   0
 
 
 
 
 
r9   