
    :Qg                    H   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZmZmZmZ ddlmZ dd	lmZ  ed
       ed       ed       ed       ed       ed      gZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd#dZd Z d#dZ!d Z"d Z#d  Z$d! Z%d" Z&y)$z3Test-suite for `unstructured.partition.ppt` module.    )annotationsN)MockFixture)assert_round_trips_through_JSONexample_doc_path)chunk_by_title)ListItemNarrativeText	PageBreakTitle)partition_ppt)#UNSTRUCTURED_INCLUDE_DEBUG_METADATAzAdding a Bullet SlidetextzFind the bullet slide layoutz$Use _TextFrame.text for first bulletz5Use _TextFrame.add_paragraph() for subsequent bulletszHere is a lot of text!z Here is some text in a text box!c                     t        t        d            } | t        k(  sJ | D ]  }|j                  j                  dk(  rJ  t
        r+| D ch c]  }|j                  j                   c}dhk(  sJ y y c c}w )Nfake-power-point.pptpptx)r   r   EXPECTED_PPT_OUTPUTmetadatafilenamer   detection_origin)elementselements     a/var/www/html/answerous/venv/lib/python3.12/site-packages/test_unstructured/partition/test_ppt.py test_partition_ppt_from_filenamer      s    -.DEFH**** C((,BBBBC*AIJg  11JvhVVV +Js   A4c                     t        j                  t              5  t        t	        d             d d d        y # 1 sw Y   y xY w)Nzdoesnt-exist.ppt)pytestraises
ValueErrorr   r        r   +test_partition_ppt_raises_with_missing_filer!   !   s2    	z	" <&'9:;< < <s	   8Ac                     t        t        d      d      5 } t        |       }d d d        t        k(  sJ |D ]  }|j                  j
                  J  y # 1 sw Y   4xY w)Nr   rbfileopenr   r   r   r   r   fr   r   s      r   test_partition_ppt_from_filer*   &   sj    	56	= ) a()**** 1((0001) )s   AAc                     t        t        d      d      5 } t        | d      }d d d        t        k(  sJ |D ]  }|j                  j
                  dk(  rJ  y # 1 sw Y   7xY w)Nr   r#   testr%   metadata_filenamer&   r(   s      r   3test_partition_ppt_from_file_with_metadata_filenamer/   .   sr    	56	= C a6BC**** 3((F2223C Cs   AA#c                     t        d      } t        | d      5 }t        j                  t              5  t        | |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r#   )r   r%   )r   r'   r   r   r   r   )r   r)   s     r   -test_partition_ppt_raises_with_both_specifiedr1   6   sX     67H	h	 1FMM*$= 1xa01 1 1 1 1 1s"   AA AA	AA&c                 t    t        j                  t              5  t                d d d        y # 1 sw Y   y xY wN)r   r   r   r   r   r    r   Dtest_partition_ppt_raises_when_neither_file_path_or_file_is_providedr4   <   s(    	z	"   s   .7c                 t    t        t        d            } t        |       dkD  sJ t        d | D              sJ y )Nr   r   c              3  N   K   | ]  }|j                   j                  d k(    yw)r   Nr   r   .0es     r   	<genexpr>zStest_partition_ppt_from_filename_gets_filename_from_filename_arg.<locals>.<genexpr>H   s      Oqzz""&<<O   #%r   r   lenallr   s    r   @test_partition_ppt_from_filename_gets_filename_from_filename_argrA   D   s9    -.DEFHx=1OhOOOOr    c                     t        t        d      d      5 } t        |       }d d d        t              dkD  sJ t	        d |D              sJ y # 1 sw Y   .xY w)Nr   r#   r$   r   c              3  L   K   | ]  }|j                   j                  d u   y wr3   r7   r8   s     r   r;   zBtest_partition_ppt_from_file_gets_filename_None.<locals>.<genexpr>P   s     =qqzz""d*=   "$)r'   r   r   r>   r?   r)   r   s     r   /test_partition_ppt_from_file_gets_filename_NonerF   K   s\    	56	= ) a() x=1=H====	) )s   AAc                 x    t        t        d      d      } t        |       dkD  sJ t        d | D              sJ y )Nr   r,   )r.   r   c              3  N   K   | ]  }|j                   j                  d k(    ywr,   Nr7   r9   r   s     r   r;   zMtest_partition_ppt_from_filename_prefers_metadata_filename.<locals>.<genexpr>W   s!     Kww((F2Kr<   r=   r@   s    r   :test_partition_ppt_from_filename_prefers_metadata_filenamerK   S   s<    -.DEY_`Hx=1K(KKKKr    c                     t        t        d      d      5 } t        | d      }d d d        t        d D              sJ y # 1 sw Y   xY w)Nr   r#   r,   r-   c              3  N   K   | ]  }|j                   j                  d k(    ywrI   r7   r8   s     r   r;   zItest_partition_ppt_from_file_prefers_metadata_filename.<locals>.<genexpr>^   s     ?qzz""f,?r<   r'   r   r   r?   rE   s     r   6test_partition_ppt_from_file_prefers_metadata_filenamerO   Z   sP    	56	= C a6BC ?h????C Cs   AA
c                    d| j                  d       t        t        d            }t        fd|D              sJ y )N2024-05-01T15:37:281unstructured.partition.ppt.get_last_modified_datereturn_valuer   c              3  P   K   | ]  }|j                   j                  k(    y wr3   r   last_modified)r9   r:   filesystem_last_modifieds     r   r;   zWtest_partition_ppt_from_file_path_gets_last_modified_from_filesystem.<locals>.<genexpr>l   s!     Vqzz''+CCV   #&patchr   r   r?   )mockerr   rX   s     @r   Dtest_partition_ppt_from_file_path_gets_last_modified_from_filesystemr]   d   sG    4
LL;Jb   -.DEFHVXVVVVr    c                     t        t        d      d      5 } t        |       }d d d        t        d D              sJ y # 1 sw Y   xY w)Nr   r#   r$   c              3  L   K   | ]  }|j                   j                  d u   y wr3   rV   r8   s     r   r;   zGtest_partition_ppt_from_file_gets_last_modified_None.<locals>.<genexpr>s   s     BAqzz''4/BrD   rN   rE   s     r   4test_partition_ppt_from_file_gets_last_modified_Noner`   o   sJ    	56	= ) a() BBBBB) )s   A  A	c                    d}d| j                  d|       t        t        d            }t        fd|D              sJ y )NrQ   2020-07-05T09:24:28rR   rS   r   )metadata_last_modifiedc              3  P   K   | ]  }|j                   j                  k(    y wr3   rV   )r9   r:   rc   s     r   r;   zStest_partition_ppt_from_file_path_prefers_metadata_last_modified.<locals>.<genexpr>   s!     Taqzz''+AATrY   rZ   )r\   rX   r   rc   s      @r   @test_partition_ppt_from_file_path_prefers_metadata_last_modifiedre   v   sT    42
LL;Jb   /0I_H T8TTTTr    c                     d} t        t        d      d      5 }t        ||       }d d d        d   j                  j                  | k(  sJ y # 1 sw Y   (xY w)Nrb   r   r#   )r%   rc   r   )r'   r   r   r   rW   )rc   r)   r   s      r   ;test_partition_ppt_from_file_prefers_metadata_last_modifiedrg      sb    2	56	= X a@VWX A;--1GGGGX Xs   AAc                 B    t        t        d            } t        |        y )Nr   )r   r   r   r@   s    r   test_partition_ppt_with_jsonri      s    -.DEFH#H-r    c                 |    t        d      } t        |       }t        | d      }t        |      }||k7  sJ ||k(  sJ y )Nr   by_title)chunking_strategy)r   r   r   )	file_pathr   chunk_elementschunkss       r   4test_add_chunking_strategy_by_title_on_partition_pptrp      sI     !78IY'H"9
KNH%FX%%%V###r    c                     t        t        d      dd      } | d   j                  j                  dgk(  sJ t	        d | D              sJ t	        d | D              sJ y)	zSIntegration test of params: languages, include_page_break, and include_slide_notes.language-docs/eng_spa_mult.pptT)include_page_breaksinclude_slide_notesr   engc              3  <   K   | ]  }t        |t                y wr3   )
isinstancer
   rJ   s     r   r;   z,test_partition_ppt_params.<locals>.<genexpr>   s     F'z'9-Fs   c              3  :   K   | ]  }|j                   d k(    yw)zThis is a slide note.Nr   rJ   s     r   r;   z,test_partition_ppt_params.<locals>.<genexpr>   s     O7w||66Os   N)r   r   r   	languagesanyr@   s    r   test_partition_ppt_paramsr{      se    9:  H
 A;))eW444FXFFFFOhOOOOr    c                    t        t        d      d      } | D cg c]  }|j                  j                   }}| D ch c]2  }|j                  j                  s|j                  j                  d   4 }}d|v sJ d|v sJ y c c}w c c}w )Nrr   T)detect_language_per_elementr   ru   spa)r   r   r   ry   )r   r   langss      r   7test_partition_ppt_respects_detect_language_per_elementr      s    9:X\H 8@@GW''@E@ ;CawgFVFVF`F`W''*aEaE>>E>> A bs   BB	B	)r\   r   )'__doc__
__future__r   r   pytest_mockr   test_unstructured.unit_utilsr   r   unstructured.chunking.titler   unstructured.documents.elementsr   r	   r
   r   unstructured.partition.pptr   &unstructured.partition.utils.constantsr   r   r   r!   r*   r/   r1   r4   rA   rF   rK   rO   r]   r`   re   rg   ri   rp   r{   r   r   r    r   <module>r      s    9 "  # Z 6 U U 4 V 
&'0189IJ/09: W<
131P>L@WCUH.
$
P	r    