
    4Hj                     l    d dl Zd dlmc mZ d dlZd dlmZ d dl	m
Z
mZmZ defdZd Zd Zd Zd	 ZdS )
    N)Path)build_preview_framesrender_preview_videowrite_frame_imagesreturnc                  p    t          d          } t          j        |                     d                    S )NzTdata/render_manifests/testbatch_002_top3/ai-004-stop-asking-ai-to-think-for-you.jsonzutf-8)encoding)r   jsonloads	read_text)paths    G/home/agent/jarvis_runtime/AutoShortsBot/tests/test_preview_renderer.py	_manifestr      s.    fggD:dnngn66777    c                     t                      } t          | dd          }t          d | d         D                       }t          |          }||k    }|st	          j        d|fd||f          dt          j                    v st	          j        t                    rt	          j	        t                    ndd	t          j                    v st	          j        |          rt	          j	        |          nd	t	          j	        |          d
t          j                    v st	          j        |          rt	          j	        |          nd
dz  }dd|iz  }t          t	          j        |                    d x}}|d         d         }d}||k    }|slt	          j        d|fd||f          t	          j	        |          t	          j	        |          dz  }	dd|	iz  }
t          t	          j        |
                    d x}x}}|d         d         }d}||k    }|slt	          j        d|fd||f          t	          j	        |          t	          j	        |          dz  }	dd|	iz  }
t          t	          j        |
                    d x}x}}|d         d         }d}||k    }|slt	          j        d|fd||f          t	          j	        |          t	          j	        |          dz  }	dd|	iz  }
t          t	          j        |
                    d x}x}}|d         d         }|j        }d}||k    }|st	          j        d|fd||f          t	          j	        |          t	          j	        |          t	          j	        |          dz  }
dd|
iz  }t          t	          j        |                    d x}x}x}}|d         d         }| d         d         d         }||k    }|slt	          j        d|fd||f          t	          j	        |          t	          j	        |          dz  }	dd|	iz  }
t          t	          j        |
                    d x}x}}d S ) N    widthheightc              3   2   K   | ]}|d          dk    dV  dS )trackvisual   N ).0items     r   	<genexpr>zOtest_build_preview_frames_creates_one_frame_per_visual_scene.<locals>.<genexpr>   s0      WWTT']h=V=Vq=V=V=V=VWWr   timeline==)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py5)slenframesvisual_count)py0py1py3py5zassert %(py7)spy7r   scene_idscene_01z%(py1)s == %(py4)sr&   py4assert %(py6)spy6start_msduration_ms>)z%(py1)s > %(py4)simage)r   r   )z,%(py3)s
{%(py3)s = %(py1)s.size
} == %(py6)sr&   r'   r0   assert %(py8)spy8text)r   r   sumr"   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationsize)manifestr#   r$   @py_assert2@py_assert4@py_format6@py_format8@py_assert0@py_assert3@py_format5@py_format7@py_assert5@py_format9s                r   <test_build_preview_frames_creates_one_frame_per_visual_scenerO      s   {{H!(#cBBBFWWXj%9WWWWWLv;;&;,&&&&&&&&&&;,&&&&&&&&&&&&3&&&&&3&&&&&&&&&&&&&v&&&&&v&&&&&&;&&&&&&&&&&&,&&&&&,&&&&&&&&&&&&&&&&&&&&&&&&&&&!9Z .J. J.......... J..... ....J...........................!9Z %A% A%%%%%%%%%% A%%%%% %%%%A%%%%%%%%%%%%%%%%%%%%%%%%%%%!9]#'a'#a''''''''''#a'''''#''''a'''''''''''''''''''''''''''!9W0"0j0"j0000000000"j000000000"0000j00000000000000000000000000000!9V? 4Q 7 ?? ??????????? ?????????? ??????????????????????????????r   c            
         t                      } t          | dd          }d |D             }d |D             }t          |          }d}||k    }|st          j        d|fd||f          d	t          j                    v st          j        t                    rt          j        t                    nd	d
t          j                    v st          j        |          rt          j        |          nd
t          j        |          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}x}}t          |          }t          |          }	||	z
  }
d}|
|k    }|st          j        d|fd|
|f          dt          j                    v st          j        t                    rt          j        t                    ndd
t          j                    v st          j        |          rt          j        |          nd
t          j        |          d	t          j                    v st          j        t                    rt          j        t                    nd	d
t          j                    v st          j        |          rt          j        |          nd
t          j        |	          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}x}	x}
x}}t          |          }d}||k    }|st          j        d|fd||f          d	t          j                    v st          j        t                    rt          j        t                    nd	dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}x}}d |D             }t          |          }|sddt          j                    v st          j        t                    rt          j        t                    ndt          j        |          t          j        |          dz  }t          t          j
        |                    d x}}d |D             }t          |          }|sddt          j                    v st          j        t                    rt          j        t                    ndt          j        |          t          j        |          dz  }t          t          j
        |                    d x}}d S )Nr   r   r   c                 *    g | ]}|d          d         S )
typographymain_font_sizer   r   frames     r   
<listcomp>zNtest_preview_frames_keep_main_text_readable_and_consistent.<locals>.<listcomp>#   s#    LLLE%%&67LLLr   c                 *    g | ]}|d          d         S )rR   retention_font_sizer   rT   s     r   rV   zNtest_preview_frames_keep_main_text_readable_and_consistent.<locals>.<listcomp>$   s#    VVVeu\*+@AVVVr   "   )>=)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} >= %(py6)smin
main_sizesr%   r&   r'   r0   r7   r8      )<=)z[(%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} - %(py7)s
{%(py7)s = %(py4)s(%(py5)s)
}) <= %(py11)smax)r%   r&   r'   r.   r(   r)   py11zassert %(py13)spy13   retention_sizesc              3   :   K   | ]}|d          d         dk    V  dS )rR   main_line_count   Nr   rT   s     r   r   zMtest_preview_frames_keep_main_text_readable_and_consistent.<locals>.<genexpr>(   s2      OOuu\"#45:OOOOOOr   ,assert %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}allr%   py2r.   c              3   :   K   | ]}|d          d         dk    V  dS )rR   retention_line_count   Nr   rT   s     r   r   zMtest_preview_frames_keep_main_text_readable_and_consistent.<locals>.<genexpr>)   s2      TTEu\"#9:a?TTTTTTr   )r   r   r[   r;   r<   r=   r>   r?   r@   rA   rB   r`   ri   )rD   r#   r\   rd   rE   rM   rF   rL   rN   @py_assert6@py_assert8@py_assert10@py_assert9@py_format12@py_format14@py_assert1rJ   rK   s                     r   :test_preview_frames_keep_main_text_readable_and_consistentrv      s   {{H!(#cBBBFLLVLLLJVVvVVVOz?? b ?b          ?b            3     3             z     z      ?    b                           z??1S__1?_,11,1111111111,11111111111131111131111111111111z11111z111111?11111111111S11111S111111111111111111111111_11111111111111111111111111111111111%2%2%%%%%%%%%%2%%%%%%%%%%%%3%%%%%3%%%%%%%%%%%%%%%%%%%%%%%%%%%%2%%%%%%%%%%%%%%%%%%%%%%%%%%%OOOOOO3OOOOOOOOOOOOOOOO3OOOOO3OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOTTVTTTT3TTTTTTTTTTTTTTTT3TTTTT3TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTr   c           	         t                      }t          |dd          }t          ||           }t          |          }d}||k    }|st	          j        d|fd||f          dt          j                    v st	          j        t                    rt	          j	        t                    nddt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          d	z  }d
d|iz  }t          t	          j        |                    d x}x}}d |D             }	t          |	          }
|
sddt          j                    v st	          j        t                    rt	          j	        t                    ndt	          j	        |	          t	          j	        |
          dz  }t          t	          j        |                    d x}	}
|d         }|j        } |            }|j        }d} ||          }|sdt	          j	        |          t	          j	        |          t	          j	        |          t	          j	        |          t	          j	        |          t	          j	        |          dz  }t          t	          j        |                    d x}x}x}x}x}}d S )N    r      r    )z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sr"   pathsr]   r7   r8   c              3   ,   K   | ]}|j         d k    V  dS )z.pngN)suffix)r   r   s     r   r   zKtest_write_frame_images_outputs_png_contact_sheet_inputs.<locals>.<genexpr>3   s)      77t{f$777777r   rh   ri   rj   r   s   PNGzassert %(py11)s
{%(py11)s = %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py3)s
{%(py3)s = %(py1)s.read_bytes
}()
}.startswith
}(%(py9)s)
})r&   r'   r(   r)   py9ra   )r   r   r   r"   r;   r<   r=   r>   r?   r@   rA   rB   ri   
read_bytes
startswith)tmp_pathrD   r#   r{   rE   rM   rF   rL   rN   ru   rJ   rK   rI   ro   rp   rq   rs   s                    r   8test_write_frame_images_outputs_png_contact_sheet_inputsr   ,   s   {{H!(#cBBBFvx00Eu:::?:33uu:77777737777777777777777377777377777777777777777777777777777778787  7 +7J7++J77777777877777777 7777+7777J7777777777777777777777777777777777r   c                 P   t                      }t          || dz  ddd          }|d         }|j        }d}||k    }|st          j        d|fd	||f          t          j        |          t          j        |          t          j        |          d
z  }dd|iz  }t          t          j        |                    d x}x}x}}|d         }|j        } |            }|s`dt          j        |          t          j        |          t          j        |          dz  }	t          t          j        |	                    d x}x}}|d         }|j	        } |            }|j
        }
d}|
|k    }|st          j        d|fd|
|f          t          j        |          t          j        |          t          j        |          t          j        |
          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}x}x}x}
x}}|d         }d}||k    }|slt          j        d|fd||f          t          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}x}}d S )Nzpreview.mp4rx   ry      )r   r   fpsoutput_pathz.mp4r    )z.%(py3)s
{%(py3)s = %(py1)s.suffix
} == %(py6)sr6   r7   r8   zAassert %(py5)s
{%(py5)s = %(py3)s
{%(py3)s = %(py1)s.exists
}()
})r&   r'   r(   i  r3   )z`%(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py3)s
{%(py3)s = %(py1)s.stat
}()
}.st_size
} > %(py10)s)r&   r'   r(   r)   py10zassert %(py12)spy12frame_countrz   r,   r-   r/   r0   )r   r   r}   r;   r<   r@   rA   rB   existsstatst_size)r   rD   resultrI   rE   rM   rF   rL   rN   rG   ro   rr   rp   @py_format11@py_format13rJ   rK   s                    r   0test_render_preview_video_writes_mp4_with_ffmpegr   7   s;   {{H!(H},DCX[acdddF- 1 '161'61111111111'611111 1111'1111611111111111111111111111111111- ) ')'')))))))) ))))'))))))))))))))))))))))))))- 6 %6%%''6'/6$6/$6666666666/$66666 6666%6666'6666/6666$666666666666666666666666666666666- %A% A%%%%%%%%%% A%%%%% %%%%A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%r   )builtinsr=   _pytest.assertion.rewrite	assertionrewriter;   r
   pathlibr   autoshorts.preview_rendererr   r   r   dictr   rO   rv   r   r   r   r   r   <module>r      s                                84 8 8 8 8
@ @ @U U U8 8 8& & & & &r   