a
    ¡˜ëjB¿  ã                   @  sx  d 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m	Z	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mZmZmZmZmZmZ dd	lmZ dd
lmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2 dddœdd„Z3dddœdd„Z4dddœdd„Z5dddœdd„Z6dd„ Z7dd„ Z8ej9 :dddg¡d d!œd"d#„ƒZ;d$d%„ Z<d&d'„ Z=d(d)„ Z>d*d+„ Z?d,d-„ Z@d.d/„ ZAd0d1„ ZBd2d3„ ZCd4d5œd6d7„ZDd8d9„ ZEd4d5œd:d;„ZFd<d=„ ZGd>d?d@œdAdB„ZHd>d?d@œdCdD„ZId>dEdEdFœdGdH„ZJdEdEdIœdJdK„ZKddLœdMdN„ZLd>dOœdPdQ„ZMd>dOœdRdS„ZNd>dOœdTdU„ZOdVdW„ ZPdXdY„ ZQdZd[„ ZRd\d]„ ZSd^d_„ ZTd`da„ ZUdbdc„ ZVddde„ ZWdfdg„ ZXdhdi„ ZYdjdk„ ZZe [¡ ddlœdmdn„ƒZ\e [¡ dEdlœdodp„ƒZ]e [¡ dEdlœdqdr„ƒZ^e [¡ dsdt„ ƒZ_e [¡ dudv„ ƒZ`e [¡ dwdxddyœdzd{„ƒZae [¡ d>dlœd|d}„ƒZbG d~d„ dƒZcG d€d�„ d�ƒZdd‚dƒ„ ZedS )„z4Test suite for `unstructured.partition.docx` module.é    )ÚannotationsN)ÚAnyÚIterator)ÚDocument)Ú	Paragraph)ÚMockFixture)ÚFixtureRequestÚMockÚassert_round_trips_through_JSONÚexample_doc_pathÚfunction_mockÚinstance_mockÚproperty_mock)Úchunk_by_title)ÚAddressÚCompositeElementÚElementÚFooterÚHeaderÚImageÚListItemÚNarrativeTextÚ	PageBreakÚTableÚ
TableChunkÚTextÚTitle)ÚDocxPartitionerOptionsÚ_DocxPartitionerÚpartition_docxÚregister_picture_partitioner)Ú#UNSTRUCTURED_INCLUDE_DEBUG_METADATAÚPartitionStrategyÚstrzlist[Element])Úmock_document_file_pathÚexpected_elementsc                 C  sb   t | ƒ}||ksJ ‚|d jjd u s(J ‚|D ]}|jjdks,J ‚q,tr^dd„ |D ƒdhks^J ‚d S )Nr   úmock_document.docxc                 S  s   h | ]}|j j’qS © )ÚmetadataZdetection_origin©Ú.0Úelementr'   r'   úd/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/test_unstructured/partition/test_docx.pyÚ	<setcomp>E   ó    z4test_partition_docx_from_filename.<locals>.<setcomp>Údocx)r   r(   Úpage_numberÚfilenamer!   )r$   r%   Úelementsr+   r'   r'   r,   Ú!test_partition_docx_from_filename;   s    r3   z
list[Text]c              	   C  sš   t  ¡ �\}t| dƒ�}| | ¡ ¡ W d  ƒ n1 s80    Y  | d¡ t|d�}W d  ƒ n1 sj0    Y  ||ks€J ‚tdd„ |D ƒƒs–J ‚dS )zû`partition_docx()` accepts a SpooledTemporaryFile as its `file` argument.

    `python-docx` will NOT accept a `SpooledTemporaryFile` in Python versions before 3.11 so we need
    to ensure the source file is appropriately converted in this case.
    ÚrbNr   ©Úfilec                 s  s   | ]}|j jd u V  qd S ©N©r(   r1   ©r*   Úer'   r'   r,   Ú	<genexpr>X   r.   z8test_partition_docx_with_spooled_file.<locals>.<genexpr>)ÚtempfileÚSpooledTemporaryFileÚopenÚwriteÚreadÚseekr   Úall)r$   r%   Úspooled_temp_fileZ	test_filer2   r'   r'   r,   Ú%test_partition_docx_with_spooled_fileH   s    
,
(rD   c                 C  s^   t | dƒ�}t|d�}W d   ƒ n1 s*0    Y  ||ks@J ‚|D ]}|jjd u sDJ ‚qDd S )Nr4   r5   )r>   r   r(   r1   )r$   r%   Úfr2   r+   r'   r'   r,   Útest_partition_docx_from_file[   s
    (rF   c                 C  s&   t  d¡}t| |d�}||ks"J ‚d S )Ns   abcde)r1   r6   )ÚioÚBytesIOr   )r$   r%   rE   r2   r'   r'   r,   Ú:test_partition_docx_uses_file_path_when_both_are_specifiedc   s    
rI   c                   C  s8   t jtdd�� tƒ  W d   ƒ n1 s*0    Y  d S )Nz5either `filename` or `file` argument must be provided©Úmatch)ÚpytestÚraisesÚ
ValueErrorr   r'   r'   r'   r,   Ú'test_partition_docx_raises_with_neitherk   s    rO   c                  C  sF   t tdƒƒ} dd„ | D ƒg d¢ks&J ‚dd„ | D ƒtttgksBJ ‚dS )zHDocx with no sections partitions recognizing both paragraphs and tables.úteams_chat.docxc                 S  s   g | ]
}|j ‘qS r'   ©Útextr9   r'   r'   r,   Ú
<listcomp>v   r.   z5test_parition_docx_from_team_chat.<locals>.<listcomp>)z)0:0:0.0 --> 0:0:1.510
Some Body
OK. Yeah.z'0:0:3.270 --> 0:0:4.250
James Bond
Umm.zsaved-by Dennis Forsythec                 S  s   g | ]}t |ƒ‘qS r'   )Útyper9   r'   r'   r,   rS   {   r.   N)r   r   r   r   ©r2   r'   r'   r,   Ú!test_parition_docx_from_team_chats   s    rV   Úinfer_table_structureTFÚbool©rW   c                 C  s@   t tdƒ| d�}t|d jdƒo.|d jjd u}|| ks<J ‚d S )Núfake_table.docxrY   r   Útext_as_html)r   r   Úhasattrr(   r[   )rW   r2   Z$table_element_has_text_as_html_fieldr'   r'   r,   Ú)test_partition_docx_infer_table_structure~   s    ÿþr]   c                  C  s\   t tdƒƒ} t| d tƒsJ ‚| d jdks0J ‚| d jjdksDJ ‚| d jjdksXJ ‚d S )NrZ   r   z4Header Col 1 Header Col 2 Lorem ipsum A Link examplezv<table><tr><td>Header Col 1</td><td>Header Col 2</td></tr><tr><td>Lorem ipsum</td><td>A Link example</td></tr></table>)r   r   Ú
isinstancer   rR   r(   r[   r1   rU   r'   r'   r,   Ú#test_partition_docx_processes_tableŠ   s    
ÿr_   c                  C  sR   t tdƒƒ} | d tdƒks J ‚| d tdƒks4J ‚| D ]}|jjdks8J ‚q8d S )Núhandbook-1p.docxr   zUS Trustee HandbookéÿÿÿÿZ	Copyright)r   r   r   r   r(   r1   )r2   r+   r'   r'   r,   Ú+test_partition_docx_grabs_header_and_footer˜   s
    rb   c                  C  s@   t tdƒdd�} ddd„ | D ƒvs&J ‚tdd„ | D ƒƒs<J ‚d	S )
aÓ  Hard page-breaks by themselves are not enough to locate page-breaks in a document.

    In particular, they are redundant when rendered page-breaks are present, which they usually are
    in a native Word document, so lead to double-counting those page-breaks. When rendered page
    breaks are *not* present, only a small fraction will be represented by hard page-breaks so hard
    breaks are a false-positive and will generally produce incorrect page numbers.
    z(handbook-1p-no-rendered-page-breaks.docxT©Úinclude_page_breaksr   c                 S  s   g | ]}t |ƒj‘qS r'   ©rT   Ú__name__r9   r'   r'   r,   rS   °   r.   zqtest_partition_docx_includes_neither_page_breaks_nor_numbers_when_rendered_breaks_not_present.<locals>.<listcomp>c                 s  s   | ]}|j jd u V  qd S r7   )r(   r0   r9   r'   r'   r,   r;   ±   r.   zptest_partition_docx_includes_neither_page_breaks_nor_numbers_when_rendered_breaks_not_present.<locals>.<genexpr>N©r   r   rB   rU   r'   r'   r,   Ú]test_partition_docx_includes_neither_page_breaks_nor_numbers_when_rendered_breaks_not_present¤   s
    ÿrh   c                  C  sR   t tdƒdd�} ddd„ | D ƒvs&J ‚| d jjdks:J ‚| d jjd	ksNJ ‚d
S )zšPage-number metadata is not supressed when `include_page_breaks` arga is False.

    Only inclusion of PageBreak elements is affected by that option.
    r`   Frc   r   c                 S  s   g | ]}t |ƒj‘qS r'   re   r9   r'   r'   r,   rS   »   r.   zetest_partition_docx_includes_page_numbers_when_page_break_elements_are_suppressed.<locals>.<listcomp>é   éþÿÿÿé   N©r   r   r(   r0   rU   r'   r'   r,   ÚQtest_partition_docx_includes_page_numbers_when_page_break_elements_are_suppressed´   s    rm   c                  C  sT   t tdƒddd�} ddd„ | D ƒv s(J ‚| d jjdks<J ‚| d	 jjd
ksPJ ‚d S )Nr`   Té   )rd   Ústarting_page_numberr   c                 S  s   g | ]}t |ƒj‘qS r'   re   r9   r'   r'   r,   rS   Å   r.   zWtest_partition_docx_includes_page_break_elements_when_so_instructed.<locals>.<listcomp>ri   rj   é   rl   rU   r'   r'   r,   ÚCtest_partition_docx_includes_page_break_elements_when_so_instructedÀ   s    
ÿrq   c                  C  s>   t tdƒƒ} | d tdƒks J ‚tdd„ | D ƒƒdks:J ‚d S )Nz example-list-items-multiple.docxra   zCThis is simply dummy text of the printing and typesetting industry.c                 s  s   | ]}t |tƒrd V  qdS )ri   N)r^   r   r9   r'   r'   r,   r;   Ó   r.   z4test_partition_docx_detects_lists.<locals>.<genexpr>é
   )r   r   r   ÚsumrU   r'   r'   r,   Ú!test_partition_docx_detects_listsÍ   s
    ÿ
rt   c                  C  s*   t tdƒdd�} tdd„ | D ƒƒs&J ‚d S )Núsimple.docxÚtest)Úmetadata_filenamec                 s  s   | ]}|j jd kV  qdS ©rv   Nr8   r)   r'   r'   r,   r;   Û   r.   z\test_partition_docx_from_filename_prefers_metadata_filename_when_provided.<locals>.<genexpr>rg   rU   r'   r'   r,   ÚItest_partition_docx_from_filename_prefers_metadata_filename_when_providedÙ   s    ry   c                  C  sT   t tdƒdƒ�} t| dd�}W d   ƒ n1 s00    Y  tdd„ |D ƒƒsPJ ‚d S )Nru   r4   rv   )r6   rw   c                 s  s   | ]}|j jd kV  qdS rx   r8   r)   r'   r'   r,   r;   á   r.   zXtest_partition_docx_from_file_prefers_metadata_filename_when_provided.<locals>.<genexpr>)r>   r   r   rB   ©rE   r2   r'   r'   r,   ÚEtest_partition_docx_from_file_prefers_metadata_filename_when_providedÞ   s    *r{   r   )Úmockerc                 C  s6   d}| j d|d� ttdƒƒ}|d jj|ks2J ‚d S )Nz2029-07-05T09:24:28ú2unstructured.partition.docx.get_last_modified_date©Úreturn_valueú	fake.docxr   ©Úpatchr   r   r(   Úlast_modified)r|   Úfilesystem_last_modifiedr2   r'   r'   r,   ÚEtest_partition_docx_from_file_path_gets_last_modified_from_filesystemç   s    ÿr…   c                  C  sP   t tdƒdƒ�} t| d�}W d   ƒ n1 s.0    Y  |d jjd u sLJ ‚d S )Nru   r4   r5   r   ©r>   r   r   r(   rƒ   rz   r'   r'   r,   Ú5test_partition_docx_from_file_gets_last_modified_Noneò   s    (r‡   c                 C  s>   d}d}| j d|d� ttdƒ|d�}|d jj|ks:J ‚d S )Nz2023-11-01T14:13:07ú2020-07-05T09:24:28r}   r~   r€   )Úmetadata_last_modifiedr   r�   )r|   r„   r‰   r2   r'   r'   r,   ÚAtest_partition_docx_from_file_path_prefers_metadata_last_modifiedù   s    ÿÿrŠ   c                  C  sV   d} t tdƒdƒ�}t|| d�}W d   ƒ n1 s40    Y  |d jj| ksRJ ‚d S )Nrˆ   ru   r4   )r6   r‰   r   r†   )r‰   rE   r2   r'   r'   r,   Ú<test_partition_docx_from_file_prefers_metadata_last_modified  s    *r‹   údict[str, Any]zlist[dict[str, str]])Ú	opts_argsÚexpected_emphasized_textsc                 C  sÂ   t dƒ| d< tf i | ¤Ž}t|ƒ}|jjd }t| |¡ƒ}|jdksJJ ‚||ksVJ ‚|jjd }t| |¡ƒ}|jdks~J ‚|g ksŠJ ‚|jjd }t| |¡ƒ}|jdks²J ‚|g ks¾J ‚d S )	Núfake-doc-emphasized-text.docxÚ	file_pathri   ú$I am a bold italic bold-italic text.rk   Ú rn   úI am a normal text.)r   r   r   Ú	_documentÚ
paragraphsÚlistZ_iter_paragraph_emphasisrR   )r�   rŽ   ÚoptsÚpartitionerÚ	paragraphÚemphasized_textsr'   r'   r,   Ú(test_get_emphasized_texts_from_paragraph  s    r›   c                 C  sL   t dƒ| d< tf i | ¤Ž}t|ƒ}|jjd }t| |¡ƒ}||ksHJ ‚d S ©Nr�   r�   r   )r   r   r   r”   Útablesr–   Z_iter_table_emphasis)r�   rŽ   r—   r˜   Útablerš   r'   r'   r,   Útest_iter_table_emphasis)  s    rŸ   z	list[str])r�   Ú!expected_emphasized_text_contentsÚexpected_emphasized_text_tagsc                 C  sX   t dƒ| d< tf i | ¤Ž}t|ƒ}|jjd }| |¡\}}||ksHJ ‚||ksTJ ‚d S rœ   )r   r   r   r”   r�   Z_table_emphasis)r�   r    r¡   r—   r˜   rž   Úemphasized_text_contentsÚemphasized_text_tagsr'   r'   r,   Útest_table_emphasis6  s    r¤   )r    r¡   c                 C  sÂ   t tdƒƒ}t|d tƒsJ ‚|d jj| ks2J ‚|d jj|ksFJ ‚|d tdƒksZJ ‚|d jj| ksnJ ‚|d jj|ks‚J ‚|d tdƒks–J ‚|d jjd u sªJ ‚|d jjd u s¾J ‚d S )Nr�   r   ri   r‘   rk   r“   )r   r   r^   r   r(   r¢   r£   r   )r    r¡   r2   r'   r'   r,   Ú*test_partition_docx_grabs_emphasized_textsF  s    r¥   )r$   c                 C  s   t | ƒ}t|ƒ d S r7   )r   r
   )r$   r2   r'   r'   r,   Útest_partition_docx_with_jsonY  s    r¦   ©r�   c           
      C  s    t dƒ| d< tf i | ¤Ž}t|ƒ}g d¢}|jj}t|ƒD ]`\}\}}|| }| |¡}	||jv sxJ d|g› d|› �ƒ‚|	|ks:J d|› d|› d|	› �ƒ‚q:d S )	Nzcategory-level.docxr�   ))r   zCall me Ishmael.)r   zA Heading 1)r   z#Whenever I find myself growing grim)r   zA top level list item)ri   z
Next level)ri   ZSame)r   zSecond top-level list item)r   z$whenever I find myself involuntarily)r   r’   )ri   zA Heading 2)r   z)This is my substitute for pistol and ball)r   zAnother Heading 1)r   zThere now is your insular cityz
paragraph[z].text does not contain zexpected paragraph[z] to have depth==z, got )r   r   r   r”   r•   Ú	enumerateZ_parse_category_depth_by_stylerR   )
r�   r—   r˜   Ú
test_casesr•   ÚidxÚdepthrR   r™   Zactual_depthr'   r'   r,   Ú"test_parse_category_depth_by_style^  s    
 ÿþr¬   c                 C  sZ   t f i | ¤Ž}t|ƒ}g d¢}t|ƒD ].\}\}}| |¡|ks&J d|| › d�ƒ‚q&d S )N))r   ú	Heading 1)ri   z	Heading 2)rk   z	Heading 3)ri   ZSubtitle)r   ÚList)ri   zList 2)rk   zList 3)r   úList Bullet)ri   zList Bullet 2)rk   zList Bullet 3)r   zList Number)ri   zList Number 2)rk   zList Number 3z
test case z failed)r   r   r¨   Z#_parse_category_depth_by_style_name)r�   r—   r˜   r©   rª   r«   rR   r'   r'   r,   Ú'test_parse_category_depth_by_style_name  s    ÿþr°   c                 C  s*   t f i | ¤Ž}t|ƒ}| ¡ dks&J ‚d S )Nr   )r   r   Z#_parse_category_depth_by_style_ilvl)r�   r—   r˜   r'   r'   r,   Ú'test_parse_category_depth_by_style_ilvl˜  s    r±   c                  C  s@   t tdƒdd�} t tdƒƒ}t|ƒ}| |ks0J ‚| |ks<J ‚d S )Nr`   Úby_title)Úchunking_strategy)r   r   r   )Úchunk_elementsr2   Úchunksr'   r'   r,   Ú9test_add_chunking_strategy_on_partition_docx_default_argsž  s    ÿr¶   c                  C  sx   t dƒ} t| dddd�}t| ƒ}t|ddd�}||ks:J ‚||ksFJ ‚|D ](}t|ttfƒs`J ‚t|jƒdksJJ ‚qJd S )Nr�   r²   é	   é   )r³   Úmax_charactersÚcombine_text_under_n_chars)r¹   rº   )r   r   r   r^   r   r   ÚlenrR   )Z	docx_pathr´   r2   rµ   Úchunkr'   r'   r,   Ú,test_add_chunking_strategy_on_partition_docx©  s    ÿr½   c                  C  s,   t dƒ} t| d�}|d jjdgks(J ‚d S )Nr`   ©r1   r   Úeng©r   r   r(   Ú	languages©r1   r2   r'   r'   r,   Ú2test_partition_docx_element_metadata_has_languages¼  s    
rÃ   c                  C  sH   t dƒ} t| dd�}dd„ |D ƒ}|dgddgdgdgdggksDJ ‚d S )Nzlanguage-docs/eng_spa_mult.docxT)r1   Zdetect_language_per_elementc                 S  s   g | ]}|j j‘qS r'   )r(   rÁ   r)   r'   r'   r,   rS   Å  r.   zLtest_partition_docx_respects_detect_language_per_element.<locals>.<listcomp>r¿   Zspa)r   r   )r1   r2   Zlangsr'   r'   r,   Ú8test_partition_docx_respects_detect_language_per_elementÂ  s    rÄ   c                  C  s0   t dƒ} t| dgd�}|d jjdgks,J ‚d S )Nr`   Zdeu©r1   rÁ   r   rÀ   rÂ   r'   r'   r,   Ú*test_partition_docx_respects_languages_argÉ  s    rÆ   c                  C  sB   t  t¡�$ tdƒ} t| dd� W d   ƒ n1 s40    Y  d S )Nr`   r¿   rÅ   )rL   rM   Ú	TypeErrorr   r   r¾   r'   r'   r,   Ú:test_partition_docx_raises_TypeError_for_invalid_languagesÏ  s    rÈ   c                  C  sR  t tdƒƒ} | d }|jdks"J ‚|j}|jd u s6J ‚|jd u sDJ ‚|jd u sRJ ‚| d }|jdkshJ ‚|j}|jd u s|J ‚|jd u sŠJ ‚|jd u s˜J ‚| d }|jdks®J ‚|j}|jdd	d
dœgksÌJ ‚|jd	gksÜJ ‚|jd
gksìJ ‚| d }|jdk�sJ ‚|j}|jddddœgk�s$J ‚|jdgk�s6J ‚|jdgk�sHJ ‚| d }|jdk�s`J ‚|j}|jddddœgk�s€J ‚|jdgk�s’J ‚|jdgk�s¤J ‚| d }|jdk�s¼J ‚|j}|jddddœgk�sÜJ ‚|jdgk�sîJ ‚|jdgk�s J ‚| d }|jdk�sJ ‚|j}|jd u �s.J ‚|jd u �s>J ‚|jd u �sNJ ‚d S )Nzhlink-meta.docxr   ZOneri   zTwo with link to bookmark.rk   zThree with link to foo.com.é   zlink to foo.comzhttps://foo.com)Ústart_indexrR   Úurlrn   z,Four with link to foo.com searching for bar.rr   z!link to foo.com searching for barzhttps://foo.com?q=barrp   z/Five with link to foo.com introduction section.z$link to foo.com introduction sectionzhttp://foo.com/#introé   zEight with link to file.zlink to filezcourt-exif.jpgé   zNine.)r   r   rR   r(   ÚlinksZ
link_textsZ	link_urls)r2   r+   r(   r'   r'   r,   Ú/test_partition_docx_includes_hyperlink_metadataØ  s~    ýÿ
ýÿýÿýÿrÏ   c                  C  sT   t dƒ} dd„ t| ƒD ƒ}dd„ t| ƒD ƒ}||ks8J ‚t|ƒtt|ƒƒksPJ ‚d S )Nzduplicate-paragraphs.docxc                 S  s   g | ]
}|j ‘qS r'   ©Úidr)   r'   r'   r,   rS   /  r.   zTtest_partition_docx_assigns_deterministic_and_unique_element_ids.<locals>.<listcomp>c                 S  s   g | ]
}|j ‘qS r'   rÐ   r)   r'   r'   r,   rS   0  r.   )r   r   r»   Úset)Zdocument_pathÚidsZids_2r'   r'   r,   Ú@test_partition_docx_assigns_deterministic_and_unique_element_ids,  s
    rÔ   c                  C  s*   t tdƒƒ} dd„ | D ƒg d¢ks&J ‚d S )Nzdocx-shapes.docxc                 S  s   g | ]
}|j ‘qS r'   rQ   r)   r'   r'   r,   rS   >  r.   z8test_it_considers_text_inside_shapes.<locals>.<listcomp>)z,Paragraph with single <inline-image> within.z:Paragraph with <inline-image1> and <inline-image2> within.z'Paragraph with floating shape attached.)r   r   )Zpartitioned_docr'   r'   r,   Ú$test_it_considers_text_inside_shapes;  s    rÕ   c                   C  s"   t dd„ ttdƒƒD ƒƒrJ ‚d S )Nc                 s  s   | ]}t |tƒV  qd S r7   ©r^   r   r9   r'   r'   r,   r;   J  s   zMtest_partition_docx_generates_no_Image_elements_by_default.<locals>.<genexpr>úcontains-pictures.docx)Úanyr   r   r'   r'   r'   r,   Ú:test_partition_docx_generates_no_Image_elements_by_defaultI  s    
ÿrÙ   c                  C  st   G dd„ dƒ} t | ƒ ttdƒƒ}d t_t|ƒdks8J ‚dd„ |D ƒ}t|ƒdksVJ ‚dd„ |D ƒg d	¢kspJ ‚d S )
Nc                   @  s"   e Zd Zeddddœdd„ƒZdS )z`test_partition_docx_uses_registered_picture_partitioner.<locals>.FakeParagraphPicturePartitionerr   r   zIterator[Image])r™   r—   Úreturnc                 s  s:   t  |j› |j› � ¡ ¡ ¡ }td|› d|j› �ƒV  d S )NzImage with hash z, strategy: )ÚhashlibÚsha1rR   ÚstrategyÚencodeÚ	hexdigestr   )Úclsr™   r—   Z	call_hashr'   r'   r,   Úiter_elementsQ  s    zntest_partition_docx_uses_registered_picture_partitioner.<locals>.FakeParagraphPicturePartitioner.iter_elementsN)rf   Ú
__module__Ú__qualname__Úclassmethodrá   r'   r'   r'   r,   ÚFakeParagraphPicturePartitionerP  s   rå   r×   rÉ   c                 S  s   g | ]}t |tƒr|‘qS r'   rÖ   r9   r'   r'   r,   rS   a  r.   zKtest_partition_docx_uses_registered_picture_partitioner.<locals>.<listcomp>é   c                 S  s   g | ]
}|j ‘qS r'   rQ   r9   r'   r'   r,   rS   c  r.   )úJImage with hash 429de54e71f1f0fb395b6f6191961a3ea1b64dc0, strategy: hi_reszJImage with hash 5e0cd2c62809377d8ce7422d8ca6b0cf5f4453bc, strategy: hi_resrç   zJImage with hash ccbd34be6096544babc391890cb0849c24cc046c, strategy: hi_reszJImage with hash a41b819c7b4a9750ec0f9198c59c2057d39c653c, strategy: hi_reszJImage with hash ba0dc2a1205af8f6d9e06c8d415df096b0a9c428, strategy: hi_res)r    r   r   r   Z_PicturePartitionerClsr»   )rå   r2   Zimage_elementsr'   r'   r,   Ú7test_partition_docx_uses_registered_picture_partitionerO  s    rè   )rÚ   c                	   C  s4   t dƒtdƒtdƒtdƒtdƒtdƒtdƒtdƒgS )	Nú&These are a few of my favorite things:ZParrotsÚHockeyÚAnalysisú4This is my first thought. This is my second thought.úThis is my third thought.Ú2023úDOYLESTOWN, PA 18901)r   r   r   r   r   r'   r'   r'   r,   r%   p  s    ør%   c                   C  s   g d¢S )N)ÚboldÚitalicúbold-italicrò   r'   r'   r'   r'   r,   r    ~  s    r    c                   C  s   g d¢S )N)ÚbÚiró   rô   r'   r'   r'   r'   r,   r¡   ƒ  s    r¡   c                   C  s$   dddœdddœdddœdddœgS )Nrð   ró   )rR   Útagrñ   rô   rò   r'   r'   r'   r'   r,   rŽ   ˆ  s
    ürŽ   c                  C  sž   t  ¡ } | jddd� | jddd� | jddd� | jddd� | jd	dd� | jd
dd� | jd	dd� | jddd� | jddd� |  d¡ |  d¡ | S )Nré   r­   )Ústyleu   â€¢ ParrotsZNormalu   â€¢ rê   r¯   r’   rë   rì   rí   z	Body Textrî   rï   )r/   r   Zadd_paragraph)Údocumentr'   r'   r,   Úmock_document’  s    

rø   r   zpathlib.Path)rø   Útmp_pathrÚ   c                 C  s   t |d ƒ}|  |¡ |S )Nr&   )r#   Úsave)rø   rù   r1   r'   r'   r,   r$   ­  s    
r$   c                   C  s   ddddddœS )z¼All default arguments for `DocxPartitionerOptions`.

    Individual argument values can be changed to suit each test. Makes construction of opts more
    compact for testing purposes.
    NT)r6   r�   rd   rW   rÝ   r'   r'   r'   r'   r,   r�   ´  s    ûr�   c                   @  sð  e Zd ZdZddœdd„Zddœdd„Zddd	œd
d„Zej 	dddg¡dddœdd„ƒZ
ej 	dddg¡dddœdd„ƒZddœdd„Zddœdd„Zdddœdd„Zddœdd„Zej 	dd d!g¡d"dd#œd$d%„ƒZej 	d&d'd(g¡ddd)dd*d+œd,d-„ƒZddœd.d/„Zddœd0d1„Zej 	d2d3ejd4fejd5fg¡dd6d6d7œd8d9„ƒZej 	d:d;d<g¡dd6dd=œd>d?„ƒZddœd@dA„ZddœdBdC„ZddœdDdE„ZddœdFdG„ZddœdHdI„ZddœdJdK„ZddœdLdM„Ze  ¡ dddNœdOdP„ƒZ!d!S )QÚDescribeDocxPartitionerOptionszQUnit-test suite for `unstructured.partition.docx.DocxPartitionerOptions` objects.rŒ   r§   c                 C  s.   t dƒ|d< tjf i |¤Ž}t|tƒs*J ‚d S )Nru   r�   )r   r   Úloadr^   ©Úselfr�   r—   r'   r'   r,   Ú$it_provides_a_validating_constructorÑ  s    zCDescribeDocxPartitionerOptions.it_provides_a_validating_constructorc                 C  sB   t jtdd��  tjf i |¤Ž W d   ƒ n1 s40    Y  d S )Nzno DOCX document specified, rJ   ©rL   rM   rN   r   rü   ©rþ   r�   r'   r'   r,   Ú(and_it_raises_when_options_are_not_validØ  s    zGDescribeDocxPartitionerOptions.and_it_raises_when_options_are_not_validr   )Úrequestr�   c                 C  s^   t |tƒ}t|d|d�}t|tddd�}tf i |¤Ž}|j}| ¡  | d¡ ||u sZJ ‚d S )Nz)unstructured.partition.docx.docx.Documentr~   Ú
_docx_filez
abcde.docx)r   r   r   r   r   r÷   Úassert_called_once_with)rþ   r  r�   Z	document_Zdocx_Document_Z_docx_file_prop_r—   r÷   r'   r'   r,   Úit_loads_the_docx_documentÞ  s    
ÿÿ
z9DescribeDocxPartitionerOptions.it_loads_the_docx_documentÚ	arg_valueTFrX   )r  r�   c                 C  s(   ||d< t f i |¤Ž}|j|u s$J ‚d S )Nrd   )r   rd   ©rþ   r  r�   r—   r'   r'   r,   ÚPit_knows_whether_to_emit_PageBreak_elements_as_part_of_the_output_element_streamô  s    zoDescribeDocxPartitionerOptions.it_knows_whether_to_emit_PageBreak_elements_as_part_of_the_output_element_streamc                 C  s(   ||d< t f i |¤Ž}|j|u s$J ‚d S )NrW   )r   rW   r  r'   r'   r,   Ú:it_knows_whether_to_include_text_as_html_in_Table_metadataÿ  s    zYDescribeDocxPartitionerOptions.it_knows_whether_to_include_text_as_html_in_Table_metadatac                 C  sn   t f i |¤Ž}| ¡ }tt|d ƒtƒs*J ‚|jdks8J ‚t t¡� t|ƒ W d   ƒ n1 s`0    Y  d S )Nrk   )	r   Úincrement_page_numberr^   Únextr   r0   rL   rM   ÚStopIteration©rþ   r�   r—   Zpage_break_iterr'   r'   r,   ÚDit_generates_a_PageBreak_element_when_the_page_number_is_incremented
  s    zcDescribeDocxPartitionerOptions.it_generates_a_PageBreak_element_when_the_page_number_is_incrementedc                 C  sb   d|d< t f i |¤Ž}| ¡ }t t¡� t|ƒ W d   ƒ n1 sF0    Y  |jdks^J ‚d S )NFrd   rk   )r   r  rL   rM   r  r  r0   r  r'   r'   r,   ÚSbut_it_does_not_generate_a_PageBreak_element_when_include_page_breaks_option_is_off  s    &zrDescribeDocxPartitionerOptions.but_it_does_not_generate_a_PageBreak_element_when_include_page_breaks_option_is_offr	   )r�   Úget_last_modified_date_c                 C  s<   d|d< d|_ tf i |¤Ž}|j}| d¡ |dks8J ‚d S )Nza/b/document.docxr�   z2024-04-02T20:32:35)r   r   rƒ   r  )rþ   r�   r  r—   rƒ   r'   r'   r,   ÚDit_gets_last_modified_from_the_filesystem_when_file_path_is_provided$  s    
zcDescribeDocxPartitionerOptions.it_gets_last_modified_from_the_filesystem_when_file_path_is_providedc                 C  s2   t  d¡}||d< tf i |¤Ž}|jd u s.J ‚d S ©Ns   abcdefgr6   )rG   rH   r   rƒ   )rþ   r�   r6   r—   r'   r'   r,   ÚRbut_it_falls_back_to_None_for_the_last_modified_date_when_no_file_path_is_provided0  s    
zqDescribeDocxPartitionerOptions.but_it_falls_back_to_None_for_the_last_modified_date_when_no_file_path_is_providedr�   z
u/v/w.docxNz
str | None)r�   r�   c                 C  s(   ||d< t f i |¤Ž}|j|ks$J ‚d S ©Nr�   )r   Zmetadata_file_path)rþ   r�   r�   r—   r'   r'   r,   Ú,it_uses_the_file_path_argument_when_provided;  s    zKDescribeDocxPartitionerOptions.it_uses_the_file_path_argument_when_provided)Ú
page_countÚdocument_contains_pagebreaksÚexpected_value)rÌ   TrÌ   )ri   FNÚintz
int | None)r  r�   r  r  r  c           	      C  sB   t |td|d�}tf i |¤Ž}||_|j}| ¡  ||u s>J ‚d S )NÚ_document_contains_pagebreaksr~   )r   r   Z_page_counterÚmetadata_page_numberr  )	rþ   r  r�   r  r  r  Z#_document_contains_pagebreaks_prop_r—   r  r'   r'   r,   ÚBit_reports_None_when_no_rendered_page_breaks_are_found_in_documentF  s    üzaDescribeDocxPartitionerOptions.it_reports_None_when_no_rendered_page_breaks_are_found_in_documentc                 C  sT   t f i |¤Ž}|jdksJ ‚t| ¡ ƒ |jdks6J ‚t| ¡ ƒ |jdksPJ ‚dS )z)In DOCX, page-number is the slide number.ri   rk   rn   N©r   r0   r–   r  rý   r'   r'   r,   Ú!it_keeps_track_of_the_page_numberb  s    z@DescribeDocxPartitionerOptions.it_keeps_track_of_the_page_numberc                 C  sB   t f i |¤ddi¤Ž}|jdks$J ‚t| ¡ ƒ |jdks>J ‚d S )Nro   rn   rp   r  rý   r'   r'   r,   ÚEit_assigns_the_correct_page_number_when_starting_page_number_is_givenl  s    zdDescribeDocxPartitionerOptions.it_assigns_the_correct_page_number_when_starting_page_number_is_given)r  r  )NÚhi_resÚfastr!  r#   )r�   r  r  c                 C  s(   ||d< t f i |¤Ž}|j|ks$J ‚d S )NrÝ   )r   rÝ   )rþ   r�   r  r  r—   r'   r'   r,   Ú+it_knows_which_partitioning_strategy_to_usew  s    zJDescribeDocxPartitionerOptions.it_knows_which_partitioning_strategy_to_use)Ú	file_namer  )úpage-breaks.docxT)rP   F)r�   r$  r  c                 C  s,   t |ƒ|d< tf i |¤Ž}|j|u s(J ‚d S r  )r   r   r  )rþ   r�   r$  r  r—   r'   r'   r,   Ú2it_knows_whether_the_document_contains_page_breaks…  s    zQDescribeDocxPartitionerOptions.it_knows_whether_the_document_contains_page_breaksc                 C  s(   d|d< t f i |¤Ž}|jdks$J ‚d S )Nú
l/m/n.docxr�   )r   r  rý   r'   r'   r,   ÚDit_uses_the_path_to_open_the_presentation_when_file_path_is_provided’  s    zcDescribeDocxPartitionerOptions.it_uses_the_path_to_open_the_presentation_when_file_path_is_providedc                 C  s~   t  ¡ �b}| d¡ ||d< tf i |¤Ž}|j}||us<J ‚t|tjƒsLJ ‚| ¡ dks\J ‚W d   ƒ n1 sp0    Y  d S r  )	r<   r=   r?   r   r  r^   rG   rH   Úgetvalue)rþ   r�   rC   r—   Ú	docx_filer'   r'   r,   ÚFand_it_uses_a_BytesIO_file_to_replaces_a_SpooledTemporaryFile_providedš  s    

zeDescribeDocxPartitionerOptions.and_it_uses_a_BytesIO_file_to_replaces_a_SpooledTemporaryFile_providedc                 C  sV   t  d¡}||d< tf i |¤Ž}|j}||u s2J ‚t|t jƒsBJ ‚| ¡ dksRJ ‚d S r  )rG   rH   r   r  r^   r)  )rþ   r�   r6   r—   r*  r'   r'   r,   ÚFand_it_uses_the_provided_file_directly_when_not_a_SpooledTemporaryFile¨  s    
zeDescribeDocxPartitionerOptions.and_it_uses_the_provided_file_directly_when_not_a_SpooledTemporaryFilec                 C  sJ   d|d< t jtdd��  tjf i |¤Ž W d   ƒ n1 s<0    Y  d S )Nr'  r�   z'no such file or directory: 'l/m/n.docx'rJ   )rL   rM   ÚFileNotFoundErrorr   rü   r  r'   r'   r,   Ú*it_raises_when_no_file_exists_at_file_path·  s    zIDescribeDocxPartitionerOptions.it_raises_when_no_file_exists_at_file_pathc                 C  sN   t dƒ|d< tjtdd��  tjf i |¤Ž W d   ƒ n1 s@0    Y  d S )Nú
simple.docr�   ú*not a ZIP archive \(so not a DOCX file\): rJ   )r   rL   rM   rN   r   rü   r  r'   r'   r,   Ú=and_it_raises_when_the_file_at_file_path_is_not_a_ZIP_archive¼  s    z\DescribeDocxPartitionerOptions.and_it_raises_when_the_file_at_file_path_is_not_a_ZIP_archivec              	   C  sx   t tdƒdƒ�V}||d< tjtdd��  tjf i |¤Ž W d   ƒ n1 sL0    Y  W d   ƒ n1 sj0    Y  d S )Nr/  r4   r6   r0  rJ   )r>   r   rL   rM   rN   r   rü   )rþ   r�   rE   r'   r'   r,   Ú<and_it_raises_when_the_file_like_object_is_not_a_ZIP_archiveÃ  s    z[DescribeDocxPartitionerOptions.and_it_raises_when_the_file_like_object_is_not_a_ZIP_archivec                 C  sB   t jtdd��  tjf i |¤Ž W d   ƒ n1 s40    Y  d S )Nz1no DOCX document specified, either `filename` or rJ   r   r  r'   r'   r,   Ú:and_it_raises_when_neither_a_file_path_or_file_is_providedË  s    zYDescribeDocxPartitionerOptions.and_it_raises_when_neither_a_file_path_or_file_is_provided)r  rÚ   c                 C  s
   t |dƒS )Nr}   )r   )rþ   r  r'   r'   r,   r  Ñ  s    z6DescribeDocxPartitionerOptions.get_last_modified_date_)"rf   râ   rã   Ú__doc__rÿ   r  r  rL   ÚmarkÚparametrizer	  r
  r  r  r  r  r  r  r  r   r"   ZFASTZHI_RESr#  r&  r(  r+  r,  r.  r1  r2  r3  Úfixturer  r'   r'   r'   r,   rû   Ì  sN   


þ
þ
ÿ
rû   c                   @  sˆ   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„Zdd„ Z	ddœdd„Z
ddœdd„Zddœdd„ZdS )ÚDescribe_DocxPartitionerzCUnit-test suite for `unstructured.partition.docx._DocxPartitioner`.rŒ   r§   c                 C  s<   t f i |¤Ž}t tdƒ¡jd }t|ƒ |¡dks8J ‚d S )Núdocx-tables.docxr   zv<table><tr><td>Header Col 1</td><td>Header Col 2</td></tr><tr><td>Lorem ipsum</td><td>A link example</td></tr></table>)r   r/   r   r   r�   r   Ú_convert_table_to_html©rþ   r�   r—   rž   r'   r'   r,   Úit_can_convert_a_table_to_htmlÛ  s
    ÿz7Describe_DocxPartitioner.it_can_convert_a_table_to_htmlc                 C  sJ   t f i |¤Ž}t tdƒ¡jd }t ddt|ƒ |¡¡}|dksFJ ‚dS )á°  
        Fixture table is:

            +---+-------------+---+
            | a |     >b<     | c |
            +---+-------------+---+
            |   | +-----+---+ |   |
            |   | |  e  | f | |   |
            | d | +-----+---+ | i |
            |   | | g&t | h | |   |
            |   | +-----+---+ |   |
            +---+-------------+---+
            | j |      k      | l |
            +---+-------------+---+
        r9  ri   z +<ú<z˜<table><tr><td>a</td><td>&gt;b&lt;</td><td>c</td></tr><tr><td>d</td><td>e f g&amp;t h</td><td>i</td></tr><tr><td>j</td><td>k</td><td>l</td></tr></table>N)	r   r/   r   r   r�   ÚreÚsubr   r:  )rþ   r�   r—   rž   Úhtmlr'   r'   r,   Ú)and_it_can_convert_a_nested_table_to_htmlæ  s    ÿzBDescribe_DocxPartitioner.and_it_can_convert_a_nested_table_to_htmlc                 C  sB   t f i |¤Ž}t tdƒ¡jd }d t|ƒ |¡¡dks>J ‚d S )Nr9  r   ú z4Header Col 1 Header Col 2 Lorem ipsum A link example©r   r/   r   r   r�   Újoinr   Z_iter_table_textsr;  r'   r'   r,   Ú$it_can_convert_a_table_to_plain_text  s
    ÿz=Describe_DocxPartitioner.it_can_convert_a_table_to_plain_textc                 C  sB   t f i |¤Ž}t tdƒ¡jd }d t|ƒ |¡¡dks>J ‚dS )r=  r9  ri   rC  za >b< c d e f g&t h i j k lNrD  r;  r'   r'   r,   Ú/and_it_can_convert_a_nested_table_to_plain_text  s
    ÿzHDescribe_DocxPartitioner.and_it_can_convert_a_nested_table_to_plain_textc                 C  sB   t f i |¤Ž}t tdƒ¡jd }d t|ƒ |¡¡dks>J ‚dS )zÚ
        Fixture table is:

            +---+-------+
            | a | b     |
            |   +---+---+
            |   | c | d |
            +---+---+   |
            | e     |   |
            +-------+---+
        r9  rk   rC  z	a b c d eNrD  r;  r'   r'   r,   Ú/but_the_text_of_a_merged_cell_appears_only_once#  s    zHDescribe_DocxPartitioner.but_the_text_of_a_merged_cell_appears_only_oncec                 C  s  t ttdƒƒƒ}t|ƒ}|j d¡s(J ‚t|ƒ}t|ƒjdksBJ ‚|jdksPJ ‚|jj	dks`J ‚t|ƒ}t|ƒjdkszJ ‚|jdks”J d|j›�ƒ‚|jj	dks²J d	|jj	›�ƒ‚t|ƒ}t|ƒjdksÌJ ‚|jdksæJ d|j›�ƒ‚|jj	d
k�sJ d	|jj	›�ƒ‚t|ƒ}t|ƒjdk�s"J ‚|jdk�s>J d|j›�ƒ‚|jj	dk�s^J d	|jj	›�ƒ‚t|ƒ}t|ƒjdk�szJ ‚|jdk�s–J d|j›�ƒ‚|jj	dk�s¶J d	|jj	›�ƒ‚t|ƒ}t|ƒjdk�sÒJ ‚|jdk�sîJ d|j›�ƒ‚|jj	dk�sJ d	|jj	›�ƒ‚dS )ak  DOCX permits table rows to start late and end early.

        It is relatively rare in the wild, but DOCX tables are unique (as far as I know) in that
        they allow rows to start late, like in column 3, and end early, like the last cell is in
        column 5 of a 7 column table.

        A practical example might look like this:

                       +------+------+
                       | East | West |
            +----------+------+------+
            | Started  |  25  |  32  |
            +----------+------+------+
            | Finished |  17  |  21  |
            +----------+------+------+
        z tables-with-incomplete-rows.docxzExample of DOCX table r   za b c dzI<table><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></table>za b czactual e.text=zD<table><tr><td>a</td><td/></tr><tr><td>b</td><td>c</td></tr></table>zactual e.metadata.text_as_html=zX<table><tr><td>a</td><td>a</td><td/></tr><tr><td>b</td><td>c</td><td>d</td></tr></table>zX<table><tr><td>a</td><td>b</td><td/></tr><tr><td>a</td><td>c</td><td>d</td></tr></table>za b c d e fz¿<table><tr><td>a</td><td>a</td><td>b</td><td>c</td></tr><tr><td/><td>d</td><td>d</td><td/></tr><tr><td>e</td><td>d</td><td>d</td><td>f</td></tr><tr><td/><td>d</td><td>d</td><td/></tr></table>z"Data More Dato WTF? Strange FormataD  <table><tr><td>Data</td><td>Data</td><td/></tr><tr><td>Data</td><td>Data</td><td/></tr><tr><td>Data</td><td>Data</td><td/></tr><tr><td/><td>More</td><td/></tr><tr><td>Dato</td><td/></tr><tr><td>WTF?</td><td>WTF?</td><td/></tr><tr><td>Strange</td><td>Strange</td><td/></tr><tr><td/><td>Format</td><td>Format</td></tr></table>N)
Úiterr   r   r  rR   Ú
startswithrT   rf   r(   r[   )rþ   r2   r:   r'   r'   r,   Ú,it_can_partition_tables_with_incomplete_rows3  sb    ÿ	ÿþ	ÿûÿûÿù
ÿõzEDescribe_DocxPartitioner.it_can_partition_tables_with_incomplete_rowsc                 C  sÊ   dddœdd„}t dƒ|d< tf i |¤Ž}tdƒtd	ƒtd
ƒtd	ƒtdƒtdƒtdƒtd	ƒtd	ƒtdƒtdƒtd	ƒtdƒg}t |¡}t|ƒD ]6\}}||| ksŽJ d||| ƒ› d||ƒ› d�ƒ‚qŽdS )a¬  Page-break behavior has some subtleties.

        * A hard page-break does not generate a PageBreak element (because that would double-count
          it). Word inserts a rendered page-break for the hard break at the effective location.
        * A (rendered) page-break mid-paragraph produces two elements, like `Text, PageBreak, Text`,
          so each Text (subclass) element gets the right page-number.
        * A rendered page-break mid-hyperlink produces two text elements, but the hyperlink itself
          is not split; the entire hyperlink goes on the page where the hyperlink starts, even
          though some of its text appears on the following page. The rest of the paragraph, after
          the hyperlink, appears on the following page.
        * Odd and even-page section starts can lead to two page-breaks, like an odd-page section
          start could go from page 3 to page 5 because 5 is the next odd page.
        r   r#   )r:   rÚ   c                 S  s   | j j› d| › d�S )z?A more detailed `repr()` to aid debugging when assertion fails.z('z'))Ú	__class__rf   )r:   r'   r'   r,   Ústr_repr¶  s    z[Describe_DocxPartitioner.it_places_page_breaks_precisely_where_they_occur.<locals>.str_reprr%  r�   zsFirst page, tab here:	followed by line-break here:
here:
and here:
no-break hyphen here:-and hard page-break here>>r’   z•<<Text on second page. The font is big so it breaks onto third page--------------------here-->> <<but break falls inside link so text stays together.zContinuous section break here>>z<<followed by text on same pagezOdd-page section break here>>z9<<producing two page-breaks to get from page-3 to page-5.zQThen text gets big again so a "natural" rendered page break happens again here>> z<<and then more text proceeds.z

Expected: z

Got:      Ú
N)r   r   r   r   r   r   Ziter_document_elementsr¨   )rþ   r�   rM  r—   Úexpectedr2   rª   r:   r'   r'   r,   Ú0it_places_page_breaks_precisely_where_they_occur§  s<    ÿÿÿà#
þÿzIDescribe_DocxPartitioner.it_places_page_breaks_precisely_where_they_occurc                 C  sR   t dƒ|d< tf i |¤Ž}t|ƒ}|jjd }| |¡}t|ƒ}|jdksNJ ‚d S )Núdocx-hdrftr.docxr�   r   z:First header para
Table cell1 Table cell2
Last header para)r   r   r   r”   ÚsectionsZ_iter_section_headersr  rR   )rþ   r�   r—   r˜   ÚsectionZheader_iterr+   r'   r'   r,   Ú*it_includes_table_cell_text_in_Header_textê  s    
zCDescribe_DocxPartitioner.it_includes_table_cell_text_in_Header_textc                 C  sR   t dƒ|d< tf i |¤Ž}t|ƒ}|jjd }| |¡}t|ƒ}|jdksNJ ‚dS )z?This case also verifies nested-table and merged-cell behaviors.rQ  r�   r   zpara1
cell1 a b c d e f
para2N)r   r   r   r”   rR  Z_iter_section_footersr  rR   )rþ   r�   r—   r˜   rS  Zfooter_iterr+   r'   r'   r,   Ú*it_includes_table_cell_text_in_Footer_textõ  s    
zCDescribe_DocxPartitioner.it_includes_table_cell_text_in_Footer_textN)rf   râ   rã   r4  r<  rB  rF  rG  rH  rK  rP  rT  rU  r'   r'   r'   r,   r8  Ö  s   tCr8  c                  C  sN   t tdƒƒ} t| tƒsJ ‚tdd„ | D ƒƒs0J ‚tdd„ | D ƒƒsJJ dƒ‚dS )zSTest that partition_docx does not crash on a DOCX with malformed/merged table rows.zgrid_offset_error.docxc                 s  s   | ]}t |d ƒV  qdS )rR   N)r\   ©r*   Úelr'   r'   r,   r;     r.   z@test_partition_docx_skips_malformed_row_cells.<locals>.<genexpr>c                 s  s   | ]}|j  ¡ V  qd S r7   )rR   ÚstriprV  r'   r'   r,   r;     r.   z&Expected some non-empty extracted textN)r   r   r^   r–   rB   rØ   rU   r'   r'   r,   Ú-test_partition_docx_skips_malformed_row_cells  s    rY  )fr4  Ú
__future__r   rÛ   rG   Úpathlibr?  r<   Útypingr   r   r/   rL   Zdocx.documentr   Zdocx.text.paragraphr   Zpytest_mockr   Ztest_unstructured.unit_utilsr   r	   r
   r   r   r   r   Zunstructured.chunking.titler   Zunstructured.documents.elementsr   r   r   r   r   r   r   r   r   r   r   r   r   Zunstructured.partition.docxr   r   r   r    Z&unstructured.partition.utils.constantsr!   r"   r3   rD   rF   rI   rO   rV   r5  r6  r]   r_   rb   rh   rm   rq   rt   ry   r{   r…   r‡   rŠ   r‹   r›   rŸ   r¤   r¥   r¦   r¬   r°   r±   r¶   r½   rÃ   rÄ   rÆ   rÈ   rÏ   rÔ   rÕ   rÙ   rè   r7  r%   r    r¡   rŽ   rø   r$   r�   rû   r8  rY  r'   r'   r'   r,   Ú<module>   sš   $	<	!	T!
	
    .