a
    ¡˜ëj  ã                   @  sD  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
d�edd�edd�edd�edd�edd�gZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&œd'd(„Zd)d*„ Z d%d&œd+d,„Z!d-d.„ Z"d/d0„ Z#d1d2„ Z$d3d4„ Z%d5d6„ Z&dS )7z3Test-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                  C  sR   t tdƒƒ} | tksJ ‚| D ]}|jjdksJ ‚qtrNdd„ | D ƒdhksNJ ‚d S )Núfake-power-point.pptc                 S  s   h | ]}|j j’qS © )ÚmetadataZdetection_origin©Ú.0Úelementr   r   úc/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/test_unstructured/partition/test_ppt.pyÚ	<setcomp>   ó    z3test_partition_ppt_from_filename.<locals>.<setcomp>Zpptx)r   r   ÚEXPECTED_PPT_OUTPUTr   Úfilenamer   )Úelementsr   r   r   r   Ú test_partition_ppt_from_filename   s    r   c                   C  s:   t  t¡� ttdƒƒ W d   ƒ n1 s,0    Y  d S )Nzdoesnt-exist.ppt)ÚpytestÚraisesÚ
ValueErrorr   r   r   r   r   r   Ú+test_partition_ppt_raises_with_missing_file!   s    r   c                  C  sb   t tdƒdƒ�} t| d�}W d   ƒ n1 s.0    Y  |tksDJ ‚|D ]}|jjd u sHJ ‚qHd S )Nr   Úrb©Úfile©Úopenr   r   r   r   r   ©Úfr   r   r   r   r   Útest_partition_ppt_from_file&   s
    (r'   c                  C  sd   t tdƒdƒ�} t| dd�}W d   ƒ n1 s00    Y  |tksFJ ‚|D ]}|jjdksJJ ‚qJd S )Nr   r    Útest©r"   Úmetadata_filenamer#   r%   r   r   r   Ú3test_partition_ppt_from_file_with_metadata_filename.   s
    *r+   c               	   C  sl   t dƒ} t| dƒ�F}t t¡� t| |d� W d   ƒ n1 s@0    Y  W d   ƒ n1 s^0    Y  d S )Nr   r    )r   r"   )r   r$   r   r   r   r   )r   r&   r   r   r   Ú-test_partition_ppt_raises_with_both_specified6   s    r,   c                   C  s4   t  t¡� tƒ  W d   ƒ n1 s&0    Y  d S ©N)r   r   r   r   r   r   r   r   ÚDtest_partition_ppt_raises_when_neither_file_path_or_file_is_provided<   s    r.   c                  C  s6   t tdƒƒ} t| ƒdksJ ‚tdd„ | D ƒƒs2J ‚d S )Nr   r   c                 s  s   | ]}|j jd kV  qdS )r   N©r   r   ©r   Úer   r   r   Ú	<genexpr>H   r   zStest_partition_ppt_from_filename_gets_filename_from_filename_arg.<locals>.<genexpr>©r   r   ÚlenÚall©r   r   r   r   Ú@test_partition_ppt_from_filename_gets_filename_from_filename_argD   s    r7   c                  C  sb   t tdƒdƒ�} t| d�}W d   ƒ n1 s.0    Y  t|ƒdksHJ ‚tdd„ |D ƒƒs^J ‚d S )Nr   r    r!   r   c                 s  s   | ]}|j jd u V  qd S r-   r/   r0   r   r   r   r2   P   r   zBtest_partition_ppt_from_file_gets_filename_None.<locals>.<genexpr>)r$   r   r   r4   r5   ©r&   r   r   r   r   Ú/test_partition_ppt_from_file_gets_filename_NoneK   s    (r9   c                  C  s:   t tdƒdd�} t| ƒdks J ‚tdd„ | D ƒƒs6J ‚d S )Nr   r(   )r*   r   c                 s  s   | ]}|j jd kV  qdS ©r(   Nr/   r   r   r   r   r2   W   r   zMtest_partition_ppt_from_filename_prefers_metadata_filename.<locals>.<genexpr>r3   r6   r   r   r   Ú:test_partition_ppt_from_filename_prefers_metadata_filenameS   s    r;   c                  C  sT   t tdƒdƒ�} t| dd�}W d   ƒ n1 s00    Y  tdd„ |D ƒƒsPJ ‚d S )Nr   r    r(   r)   c                 s  s   | ]}|j jd kV  qdS r:   r/   r0   r   r   r   r2   ^   r   zItest_partition_ppt_from_file_prefers_metadata_filename.<locals>.<genexpr>©r$   r   r   r5   r8   r   r   r   Ú6test_partition_ppt_from_file_prefers_metadata_filenameZ   s    *r=   r   )Úmockerc                   s<   d‰ | j dˆ d� ttdƒƒ}t‡ fdd„|D ƒƒs8J ‚d S )Nú2024-05-01T15:37:28ú1unstructured.partition.ppt.get_last_modified_date©Zreturn_valuer   c                 3  s   | ]}|j jˆ kV  qd S r-   ©r   Úlast_modifiedr0   ©Úfilesystem_last_modifiedr   r   r2   l   r   zWtest_partition_ppt_from_file_path_gets_last_modified_from_filesystem.<locals>.<genexpr>©Úpatchr   r   r5   )r>   r   r   rD   r   ÚDtest_partition_ppt_from_file_path_gets_last_modified_from_filesystemd   s    ÿrH   c                  C  sR   t tdƒdƒ�} t| d�}W d   ƒ n1 s.0    Y  tdd„ |D ƒƒsNJ ‚d S )Nr   r    r!   c                 s  s   | ]}|j jd u V  qd S r-   rB   r0   r   r   r   r2   s   r   zGtest_partition_ppt_from_file_gets_last_modified_None.<locals>.<genexpr>r<   r8   r   r   r   Ú4test_partition_ppt_from_file_gets_last_modified_Noneo   s    (rI   c                   sD   d}d‰ | j d|d� ttdƒˆ d�}t‡ fdd„|D ƒƒs@J ‚d S )	Nr?   ú2020-07-05T09:24:28r@   rA   r   ©Úmetadata_last_modifiedc                 3  s   | ]}|j jˆ kV  qd S r-   rB   r0   rK   r   r   r2   �   r   zStest_partition_ppt_from_file_path_prefers_metadata_last_modified.<locals>.<genexpr>rF   )r>   rE   r   r   rK   r   Ú@test_partition_ppt_from_file_path_prefers_metadata_last_modifiedv   s    ÿÿrM   c                  C  sV   d} t tdƒdƒ�}t|| d�}W d   ƒ n1 s40    Y  |d jj| ksRJ ‚d S )NrJ   r   r    )r"   rL   r   )r$   r   r   r   rC   )rL   r&   r   r   r   r   Ú;test_partition_ppt_from_file_prefers_metadata_last_modified„   s    *rN   c                  C  s   t tdƒƒ} t| ƒ d S )Nr   )r   r   r   r6   r   r   r   Útest_partition_ppt_with_json�   s    rO   c                  C  s@   t dƒ} t| ƒ}t| dd�}t|ƒ}||ks0J ‚||ks<J ‚d S )Nr   Zby_title)Zchunking_strategy)r   r   r   )Ú	file_pathr   Zchunk_elementsÚchunksr   r   r   Ú4test_add_chunking_strategy_by_title_on_partition_ppt•   s    rR   c                  C  sX   t tdƒddd�} | d jjdgks(J ‚tdd„ | D ƒƒs>J ‚tdd„ | D ƒƒsTJ ‚d	S )
zSIntegration test of params: languages, include_page_break, and include_slide_notes.úlanguage-docs/eng_spa_mult.pptT)Zinclude_page_breaksZinclude_slide_notesr   Úengc                 s  s   | ]}t |tƒV  qd S r-   )Ú
isinstancer	   r   r   r   r   r2   ¦   r   z,test_partition_ppt_params.<locals>.<genexpr>c                 s  s   | ]}|j d kV  qdS )zThis is a slide note.Nr   r   r   r   r   r2   ¨   r   N)r   r   r   Ú	languagesÚanyr6   r   r   r   Útest_partition_ppt_paramsž   s    ýrX   c                  C  sH   t tdƒdd�} dd„ | D ƒ}dd„ | D ƒ}d|v s8J ‚d	|v sDJ ‚d S )
NrS   T)Zdetect_language_per_elementc                 S  s   g | ]}|j j‘qS r   ©r   rV   r   r   r   r   Ú
<listcomp>¯   r   zKtest_partition_ppt_respects_detect_language_per_element.<locals>.<listcomp>c                 S  s    h | ]}|j jr|j jd  ’qS )r   rY   r   r   r   r   r   ²   r   zJtest_partition_ppt_respects_detect_language_per_element.<locals>.<setcomp>rT   Zspa)r   r   )r   Zlangsr   r   r   Ú7test_partition_ppt_respects_detect_language_per_element«   s    ÿr[   )'Ú__doc__Ú
__future__r   r   Zpytest_mockr   Ztest_unstructured.unit_utilsr   r   Zunstructured.chunking.titler   Zunstructured.documents.elementsr   r   r	   r
   Zunstructured.partition.pptr   Z&unstructured.partition.utils.constantsr   r   r   r   r'   r+   r,   r.   r7   r9   r;   r=   rH   rI   rM   rN   rO   rR   rX   r[   r   r   r   r   Ú<module>   sB   ú
	
	