a
    ¡˜ëjF[  ã                   @  sÈ  d dl mZ d dlZd dlZd dlZd dlm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mZ d d
lm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  d dl!m"Z" e #e$¡j% &¡ Z'G dd„ dƒZ(dd„ Z)dd„ Z*dd„ Z+dd„ Z,G dd„ dej-ƒZ.G dd„ dej/ƒZ0ej1 2dedƒdfd g¡d!d"„ ƒZ3ej1 4d#¡d$d%„ ƒZ5ed&ƒfd'd(„Z6ed)ƒfd*d+„Z7ed,ƒfd-d.„Z8ed)ƒfd/d0„Z9edƒfd1d2„Z:edƒfd3d4„Z;ej1j4d5d6�edƒfd7d8„ƒZ<ej1 2d9e j=e j>g¡d:d;„ ƒZ?d<d=„ Z@d>d?„ ZAd@dA„ ZBdBdC„ ZCdDdEœdFdG„ZDdDdEœdHdI„ZEdDdEœdJdK„ZFdDdEœdLdM„ZGdNdO„ ZHdDdEœdPdQ„ZIdRdS„ ZJdTdU„ ZKdVdW„ ZLedXƒfdYdZ„ZMej1 2d[g d\¢¡d]d^„ ƒZNd_d`„ ZOdadb„ ZPed&ƒfdcdd„ZQed)ƒfdedf„ZRdgdh„ ZSdidj„ ZTej1 2dkdldmg¡dndo„ ƒZUdpdq„ ZVej1 2drdsdtg¡dudv„ ƒZWdwdx„ ZXe Y¡ dydz„ ƒZZd{d|„ Z[ej1 2d}d[d~g¡ej1 2dd€d�g¡ed‚ƒfdƒd„„ƒƒZ\ed…ƒfd†d‡„Z]ej1 2d9e j=e j>g¡dˆd‰œdŠd‹„ƒZ^dŒd�„ Z_dS )Žé    )ÚannotationsN)Úmock)ÚImage)ÚMockFixture)Úlayout)ÚTesseractError)Úassert_element_extraction)Úassert_round_trips_through_JSONÚexample_doc_path)Úchunk_by_title)ÚElementType)ÚimageÚpdf)Úocr)Ú#UNSTRUCTURED_INCLUDE_DEBUG_METADATAÚPartitionStrategy)Úonlyc                   @  s   e Zd Zdd„ Zdd„ ZdS )ÚMockResponsec                 C  s   || _ || _d S ©N©Ústatus_codeÚresponse)Úselfr   r   © r   úo/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/test_unstructured/partition/pdf_image/test_image.pyÚ__init__   s    zMockResponse.__init__c                 C  s   | j S r   )r   ©r   r   r   r   Újson"   s    zMockResponse.jsonN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s   r   c                 K  s   t di d�S )NéÈ   r   ©r   ©ÚurlÚkwargsr   r   r   Úmock_healthy_get&   s    r&   c                 K  s   t di d�S ©Niô  r   r"   r#   r   r   r   Úmock_unhealthy_get*   s    r(   c                 K  s   t di d�S r'   r"   r#   r   r   r   Úmock_unsuccessful_post.   s    r)   c                 K  s4   dddddœgdœddddœgdœgi}t d	|d
�S )NÚpagesr   ÚTitleú#Charlie Brown and the Great Pumpkin)ÚtypeÚtext)ÚnumberÚelementsé   zA Charlie Brown Christmasr!   r   r"   )r$   r%   r   r   r   r   Úmock_successful_post2   s    ÿþ
þùÿr2   c                   @  s   e Zd Zdddœdd„ZdS )ÚMockPageLayoutÚintr   ©r/   r   c                 C  s<   || _ || _tjjddddddd�g| _tj | j¡| _d S )Nr+   r   é   r,   )r-   Úx1Úy1Zx2Úy2r.   )	r/   r   r   ÚLayoutElementÚfrom_coordsr0   ÚLayoutElementsÚ	from_listÚelements_array)r   r/   r   r   r   r   r   E   s    úÿ
zMockPageLayout.__init__N)r   r   r    r   r   r   r   r   r3   D   s   r3   c                   @  s   e Zd Zedd„ ƒZdS )ÚMockDocumentLayoutc                 C  s   t dt dd¡d�gS )Nr   Ú1)r1   r1   r5   )r3   r   Únewr   r   r   r   r*   V   s    ÿzMockDocumentLayout.pagesN)r   r   r    Úpropertyr*   r   r   r   r   r?   U   s   r?   )ÚfilenameÚfilezimg/example.jpg)Ns   0000c                 C  sn   |   tddd„ ¡ |   tddd„ ¡ |   tddd„ ¡ |   tddd„ ¡ tj||d	d
�}|d jdksjJ ‚d S )NZprocess_data_with_modelc                  _  s   t ƒ S r   ©r?   ©Úargsr%   r   r   r   Ú<lambda>h   ó    z,test_partition_image_local.<locals>.<lambda>Zprocess_file_with_modelc                  _  s   t ƒ S r   rE   rF   r   r   r   rH   m   rI   Úprocess_data_with_ocrc                  _  s   t ƒ S r   rE   rF   r   r   r   rH   r   rI   c                  _  s   t ƒ S r   rE   rF   r   r   r   rH   w   rI   T)Úis_imager   r,   )Úsetattrr   r   r   Ú_partition_pdf_or_image_localr.   )ZmonkeypatchrC   rD   Zpartition_image_responser   r   r   Útest_partition_image_local]   s4    ýýýýýrN   z4Needs to be fixed upstream in unstructured-inferencec                   C  s>   t  t¡�  tjdd dd� W d   ƒ n1 s00    Y  d S )NÚ T)rC   rD   rK   )ÚpytestÚraisesÚFileNotFoundErrorr   rM   r   r   r   r   Ú2test_partition_image_local_raises_with_no_filename‚   s    rS   ú img/layout-parser-paper-fast.jpgc                 C  sf   t j| tjd�}dd„ |D ƒ}d}d}|d j|ks8J ‚|| jjd usLJ ‚t|| jjtƒsbJ ‚d S )N©rC   Ústrategyc                 S  s0   g | ](}|j tjkrt|j d ¡ƒdkr|‘qS )ú é
   )Úcategoryr   ÚTITLEÚlenr.   Úsplit©Ú.0Úelr   r   r   Ú
<listcomp>Œ   s   z;test_partition_image_with_auto_strategy.<locals>.<listcomp>úOLayoutParser: A Unified Toolkit for Deep Learning Based Document Image Analysisé   r   )	r   Úpartition_imager   ÚAUTOr.   ÚmetadataÚdetection_class_probÚ
isinstanceÚfloat)rC   r0   ÚtitlesÚtitleÚidxr   r   r   Ú'test_partition_image_with_auto_strategyˆ   s    ÿrl   ú&img/layout-parser-paper-with-table.jpgc                 C  sT   t j| tjdd�}dd„ |D ƒ}t|ƒdks0J ‚d|d v s@J ‚d|d v sPJ ‚d S )	NT©rC   rV   Úinfer_table_structurec                 S  s   g | ]}|j jr|j j‘qS r   ©re   Ztext_as_htmlr]   r   r   r   r`   ž   rI   z>test_partition_image_with_table_extraction.<locals>.<listcomp>r1   ú<table><thead><tr>r   ú</thead><tbody><tr>)r   rc   r   ÚHI_RESr[   )rC   r0   Útabler   r   r   Ú*test_partition_image_with_table_extraction–   s    ýru   ú%img/layout-parser-paper-combined.tiffc                 C  s(   t j| tjd�}|d jjdks$J ‚d S )NrU   éÿÿÿÿr6   )r   rc   r   rd   re   Úpage_number©rC   r0   r   r   r   Ú(test_partition_image_with_multipage_tiff¤   s    rz   c                 C  sx   t j | jd¡}t |¡}| |¡ tj|t	j
dd�}dd„ |D ƒ}t|ƒdksTJ ‚d|d v sdJ ‚d	|d v stJ ‚d S )
Nzexample.bmpTrn   c                 S  s   g | ]}|j jr|j j‘qS r   rp   r]   r   r   r   r`   ¸   rI   z1test_partition_image_with_bmp.<locals>.<listcomp>r1   rq   r   rr   )ÚosÚpathÚjoinÚdirnamer   ÚopenÚsaver   rc   r   rs   r[   )ÚtmpdirrC   Zbmp_filenameÚimgr0   rt   r   r   r   Útest_partition_image_with_bmp«   s    

ýrƒ   c                 C  s`   t j tdt  ¡ ¡�"}tj| tjdd� W d   ƒ n1 s<0    Y  |j	j
 d¡dks\J ‚d S )NZprocess_file_with_ocrúeng+swe©rC   rV   Úocr_languagesr†   )r   ÚpatchÚobjectr   Ú	MagicMockr   rc   r   rs   Ú	call_argsr%   Úget)rC   Úmock_partitionr   r   r   Ú)test_partition_image_with_language_passed¾   s    ýý$r�   c              	   C  sŠ   t j tdt  ¡ ¡�L}t| dƒ�"}tj|tj	dd� W d   ƒ n1 sH0    Y  W d   ƒ n1 sf0    Y  |j
j d¡dks†J ‚d S )NrJ   Úrbr„   )rD   rV   r†   r†   )r   r‡   rˆ   r   r‰   r   r   rc   r   rs   rŠ   r%   r‹   )rC   rŒ   Úfr   r   r   Ú3test_partition_image_from_file_with_language_passedÍ   s    ý
üNr�   z*Current catching too many tesseract errors)Úreasonc                 C  s@   t  t¡�" tj| tjdd� W d   ƒ n1 s20    Y  d S )NÚfakeroor…   )rP   rQ   r   r   rc   r   rs   ©rC   r   r   r   Ú1test_partition_image_raises_with_invalid_languageÛ   s    ýr”   rV   c                 C  s8   t dƒ}tj|ddg| d�}|d jjddgks4J ‚d S )Núimg/english-and-korean.pngÚengZkor)rC   Ú	languagesrV   r   )r
   r   rc   re   r—   )rV   rC   r0   r   r   r   Ú7test_partition_image_strategies_keep_languages_metadataç   s    ýr˜   c                  C  sR   t dƒ} tj| dtjd�}|d jdks,J ‚|d j dd¡ d	¡ d
¡sNJ ‚d S )Nr•   úeng+kor)rC   r†   rV   r   úRULES AND INSTRUCTIONSrb   rW   rO   ú,õ   ì•ˆë…•í•˜ì„¸ìš”)	r
   r   rc   r   ÚOCR_ONLYr.   ÚreplaceÚlstripÚ
startswithry   r   r   r   Ú,test_partition_image_with_ocr_detects_koreanù   s    ýr¡   c                  C  s|   t dƒ} t| dƒ�"}tj|dtjd�}W d   ƒ n1 s:0    Y  |d jdksVJ ‚|d j dd	¡ d
¡ 	d¡sxJ ‚d S )Nr•   rŽ   r™   )rD   r†   rV   r   rš   rb   rW   rO   r›   rœ   )
r
   r   r   rc   r   r�   r.   rž   rŸ   r    )rC   r�   r0   r   r   r   Ú6test_partition_image_with_ocr_detects_korean_from_file  s    ý$r¢   c                  C  sD   t dƒ} t t¡� tj| dd� W d   ƒ n1 s60    Y  d S )Nr•   r’   rU   )r
   rP   rQ   Ú
ValueErrorr   rc   r“   r   r   r   Ú-test_partition_image_raises_with_bad_strategy  s    r¤   c                  C  s¸   t dƒ} t| dƒ�}tj|d�}W d   ƒ n1 s40    Y  d}d}|| j|ksXJ ‚|| jjd uslJ ‚|| jjd us€J ‚t|| jjt	ƒs–J ‚t
r´dd„ |D ƒdd	hks´J ‚d S )
NrT   rŽ   ©rD   ra   r6   c                 S  s   h | ]}|j j’qS r   )re   Zdetection_origin©r^   Úelementr   r   r   Ú	<setcomp>(  rI   z?test_partition_image_default_strategy_hi_res.<locals>.<setcomp>ZyoloxZocr_tesseract)r
   r   r   rc   r.   re   Úcoordinatesrf   rg   rh   r   )rC   r�   r0   rj   rk   r   r   r   Ú,test_partition_image_default_strategy_hi_res  s    *þrª   r   )Úmockerc                   s>   d‰ | j dˆ d� t tdƒ¡}t‡ fdd„|D ƒƒs:J ‚d S )Nú2029-07-05T09:24:28ú1unstructured.partition.pdf.get_last_modified_date©Zreturn_valuer•   c                 3  s   | ]}|j jˆ kV  qd S r   ©re   Zlast_modified©r^   Úe©Úfilesystem_last_modifiedr   r   Ú	<genexpr>:  rI   zYtest_partition_image_from_file_path_gets_last_modified_from_filesystem.<locals>.<genexpr>©r‡   r   rc   r
   Úall©r«   r0   r   r²   r   ÚFtest_partition_image_from_file_path_gets_last_modified_from_filesystem1  s    þr¸   c                   sD   d‰ | j dˆ d� tjtdƒtjd�}t‡ fdd„|D ƒƒs@J ‚d S )Nr¬   r­   r®   r•   ©rV   c                 3  s   | ]}|j jˆ kV  qd S r   r¯   r°   r²   r   r   r´   J  rI   zntest_partition_image_from_file_path_with_hi_res_strategy_gets_last_modified_from_filesystem.<locals>.<genexpr>©r‡   r   rc   r
   r   rs   r¶   r·   r   r²   r   Ú[test_partition_image_from_file_path_with_hi_res_strategy_gets_last_modified_from_filesystem=  s    þ
ÿr»   c                   sF   d}d‰ | j d|d� tjtdƒˆ d�}t‡ fdd„|D ƒƒsBJ ‚d S )	Nr¬   ú2009-07-05T09:24:28r­   r®   r•   ©Úmetadata_last_modifiedc                 3  s   | ]}|j jˆ kV  qd S r   r¯   r°   r½   r   r   r´   Z  rI   zUtest_partition_image_from_file_path_prefers_metadata_last_modified.<locals>.<genexpr>rµ   ©r«   r³   r0   r   r½   r   ÚBtest_partition_image_from_file_path_prefers_metadata_last_modifiedM  s    þþrÀ   c                   sJ   d}d‰ | j d|d� tjtdƒtjˆ d�}t‡ fdd„|D ƒƒsFJ ‚d S )	Nr¬   r¼   r­   r®   r•   )rV   r¾   c                 3  s   | ]}|j jˆ kV  qd S r   r¯   r°   r½   r   r   r´   m  rI   zjtest_partition_image_from_file_path_with_hi_res_strategy_prefers_metadata_last_modified.<locals>.<genexpr>rº   r¿   r   r½   r   ÚWtest_partition_image_from_file_path_with_hi_res_strategy_prefers_metadata_last_modified]  s    þýrÁ   c                  C  sT   t tdƒdƒ�} tj| d�}W d   ƒ n1 s00    Y  tdd„ |D ƒƒsPJ ‚d S )Nr•   rŽ   r¥   c                 s  s   | ]}|j jd u V  qd S r   r¯   r°   r   r   r   r´   t  rI   zItest_partition_image_from_file_gets_last_modified_None.<locals>.<genexpr>©r   r
   r   rc   r¶   ©r�   r0   r   r   r   Ú6test_partition_image_from_file_gets_last_modified_Nonep  s    *rÄ   c                 C  sX   t tdƒdƒ� }tj|tjd�}W d   ƒ n1 s40    Y  tdd„ |D ƒƒsTJ ‚d S )Nr•   rŽ   )rD   rV   c                 s  s   | ]}|j jd u V  qd S r   r¯   r°   r   r   r   r´   }  rI   z^test_partition_image_from_file_with_hi_res_strategy_gets_last_modified_None.<locals>.<genexpr>©r   r
   r   rc   r   rs   r¶   )r«   r�   r0   r   r   r   ÚKtest_partition_image_from_file_with_hi_res_strategy_gets_last_modified_Nonew  s    .rÆ   c                    s^   d‰ t tdƒdƒ�} tj| ˆ d�}W d   ƒ n1 s60    Y  t‡ fdd„|D ƒƒsZJ ‚d S )Nr¼   r•   rŽ   )rD   r¾   c                 3  s   | ]}|j jˆ kV  qd S r   r¯   r°   r½   r   r   r´   †  rI   zPtest_partition_image_from_file_prefers_metadata_last_modified.<locals>.<genexpr>rÂ   rÃ   r   r½   r   Ú=test_partition_image_from_file_prefers_metadata_last_modified€  s    ,rÇ   c                    sb   d‰ t tdƒdƒ�"} tj| ˆ tjd�}W d   ƒ n1 s:0    Y  t‡ fdd„|D ƒƒs^J ‚d S )Nr¼   r•   rŽ   )rD   r¾   rV   c                 3  s   | ]}|j jˆ kV  qd S r   r¯   r°   r½   r   r   r´   “  rI   zetest_partition_image_from_file_with_hi_res_strategy_prefers_metadata_last_modified.<locals>.<genexpr>rÅ   rÃ   r   r½   r   ÚRtest_partition_image_from_file_with_hi_res_strategy_prefers_metadata_last_modified‰  s    ý$rÈ   c                  C  s    t jtdƒtjd�} t| ƒ d S )NrT   r¹   )r   rc   r
   r   rd   r	   )r0   r   r   r   Útest_partition_msg_with_json™  s
    þrÉ   r•   c                 C  s<   t j| tjd�}dd„ |d jjjD ƒ}|g d¢ks8J ‚d S )NrU   c                 S  s    g | ]\}}t |ƒt |ƒf‘qS r   )r4   )r^   ÚxÚyr   r   r   r`   ¥  rI   zOtest_partition_image_with_ocr_has_coordinates_from_filename.<locals>.<listcomp>r   ))é   é   )rÌ   é%   )é}  rÎ   )rÏ   rÍ   )r   rc   r   r�   re   r©   Úpoints)rC   r0   Zint_coordinatesr   r   r   Ú;test_partition_image_with_ocr_has_coordinates_from_filename¡  s    rÑ   rC   )rm   r•   rT   c                 C  sh   dd l }tjt| ƒtjd�}|D ]B}|jr |jjj	}|D ](}|d |j
usNJ ‚|d |j
us8J ‚q8q d S )Nr   rU   r1   )Úmathr   rc   r
   r   r�   r.   re   r©   rÐ   Únan)rC   rÒ   r0   r§   ZboxZpointr   r   r   ÚCtest_partition_image_with_ocr_coordinates_are_not_nan_from_filename©  s    
ÿ
rÔ   c                  C  st   t dƒ} t d¡�N}tj| tjdgd� |jd \}}d|v sBJ ‚|d dksRJ ‚W d   ƒ n1 sf0    Y  d S )Nzimg/jpn-vert.jpegz:unstructured.partition.pdf_image.ocr.process_file_with_ocrZjpn_vert©rC   rV   r—   r   r†   )r
   r   r‡   r   rc   r   rs   Zcall_args_list)rC   Zmock_process_file_with_ocrÚ_r%   r   r   r   Ú4test_partition_image_formats_languages_for_tesseractÃ  s    ÿ
ÿr×   c                 C  s,   t dƒ}tj|tjdd� d| jv s(J ‚d S )NrT   r–   r…   z*The ocr_languages kwarg will be deprecated)r
   r   rc   r   rs   r.   )ZcaplogrC   r   r   r   Ú-test_partition_image_warns_with_ocr_languagesÐ  s    rØ   c                 C  s>   t j| d�}t j| dd�}t|ƒ}||ks.J ‚||ks:J ‚d S )Nr“   Úby_title)Úchunking_strategy)r   rc   r   ©rC   r0   Zchunk_elementsÚchunksr   r   r   Ú-test_add_chunking_strategy_on_partition_imageÖ  s
    rÝ   c                 C  sJ   t j| tjdd�}t j| tjddd�}t|ƒ}||ks:J ‚||ksFJ ‚d S )NTrn   rÙ   )rV   ro   rÚ   )r   rc   r   rs   r   rÛ   r   r   r   Ú4test_add_chunking_strategy_on_partition_image_hi_resà  s    ýürÞ   c                  C  sn   t j td¡�L} tjtdƒdd� t| jƒ d| jj	v s<J ‚| jj	d sLJ ‚W d   ƒ n1 s`0    Y  d S )NrM   rT   Útest)Ú
model_namerà   ©
r   r‡   rˆ   r   r   rc   r
   ÚprintrŠ   r%   ©Zmockpartitionr   r   r   Ú$test_partition_image_uses_model_nameó  s    þÿ
rä   c                  C  s‚   t j td¡�`} tjtdƒdd� t| jƒ d| jj	vs<J ‚d| jj	v sLJ ‚| jj	d dks`J ‚W d   ƒ n1 st0    Y  d S )NrM   rT   rß   )Úhi_res_model_namerà   rå   rá   rã   r   r   r   Ú+test_partition_image_uses_hi_res_model_name   s    þÿ
ræ   )Úocr_modeÚidx_title_element)Úentire_pager6   )Úindividual_blocksr1   c                 C  s2   t dƒ}tj|| tjd�}|| jtjks.J ‚d S )NrT   ©rC   rç   rV   )r
   r   rc   r   rs   rY   r   rZ   )rç   rè   rC   r0   r   r   r   Ú$test_partition_image_hi_res_ocr_mode  s
    ÿrì   c                  C  sH   t dƒ} t t¡�" tj| dtjd�}W d   ƒ n1 s:0    Y  d S )NrT   Zinvalid_ocr_moderë   )r
   rP   rQ   r£   r   rc   r   rs   )rC   rÖ   r   r   r   Ú,test_partition_image_hi_res_invalid_ocr_mode  s
    ÿrí   rç   ré   rê   c                 C  s~   t dƒ}tj|| tjdd�}dd„ |D ƒ}t|ƒdks:J ‚d|d v sJJ ‚d	|d v sZJ ‚d
|d v sjJ ‚d|d v szJ ‚d S )Nrm   T)rC   rç   rV   ro   c                 S  s   g | ]}|j jr|j j‘qS r   rp   r]   r   r   r   r`   5  rI   zNtest_partition_image_hi_res_ocr_mode_with_table_extraction.<locals>.<listcomp>r1   rq   r   rr   z%Layouts of history Japanese documentsz:Layouts of scanned modern magazines and scientific reports)r
   r   rc   r   rs   r[   )rç   rC   r0   rt   r   r   r   Ú:test_partition_image_hi_res_ocr_mode_with_table_extraction&  s    ürî   c                  C  sH   t dƒ} t t¡�" tj| tjdd� W d   ƒ n1 s:0    Y  d S )NrT   r–   rÕ   )r
   rP   rQ   Ú	TypeErrorr   rc   r   rs   r“   r   r   r   Ú<test_partition_image_raises_type_error_for_invalid_languages=  s    rð   c                  C  sR   t jdtjdd�d�} t jjdddddd	�g| _t j | j¡| _	t j
| gd
�}|S )Nr1   ÚJPEG)Úformatr5   r   iX  i   Zhello)r.   )r*   )r   Ú
PageLayoutr   r‰   r:   r;   r0   r<   r=   r>   ÚDocumentLayout)ÚpageÚdocr   r   r   Úinference_resultsC  s    
þr÷   c                 C  s€   d}t jd| d��*}tjtd|› �ƒtjd�}W d   ƒ n1 sB0    Y  | ¡  t|ƒ}|j	j
dkslJ ‚|j	j|ks|J ‚d S )Nzlayout-parser-paper-fast.jpgz?unstructured_inference.inference.layout.process_file_with_modelr®   zimg/rU   rñ   )r   r‡   r   rc   r
   r   rs   Zassert_called_oncer   re   ZfiletyperC   )r÷   rC   Zmock_inference_funcr0   r§   r   r   r   Ú!test_partition_image_has_filenameO  s    þþ$rø   Ú	file_moderŽ   Úextract_image_block_to_payloadFTzimg/embedded-images-tables.jpgc              	   C  sš   ddg}t  ¡ �v}| dkr.tj||||d�}n<t|dƒ�"}tj||||d�}W d   ƒ n1 s`0    Y  t||||ƒ W d   ƒ n1 sŒ0    Y  d S )Nr   ZTablerC   )rC   Úextract_image_block_typesrú   Úextract_image_block_output_dirrŽ   )rD   rû   rú   rü   )ÚtempfileÚTemporaryDirectoryr   rc   r   r   )rù   rú   rC   rû   r�   r0   r�   r   r   r   Ú'test_partition_image_element_extractione  s&    
üü$ÿrÿ   zimg/DA-1p.heicc                 C  s.   t j| tjd�}dd„ |D ƒ}d|v s*J ‚d S )NrU   c                 S  s   g | ]}|j tjkr|j‘qS r   )rY   r   rZ   r.   r]   r   r   r   r`   ˆ  rI   z;test_partition_image_works_on_heic_file.<locals>.<listcomp>Z	CREATURES)r   rc   r   rd   )rC   r0   ri   r   r   r   Ú'test_partition_image_works_on_heic_file„  s    r   Ústrr¹   c                 C  sT   t jtdƒ| dd�}t jtdƒ| dd�}dd„ |D ƒ}dd„ |D ƒ}||ksPJ ‚d S )Nrm   r6   )rV   Ústarting_page_numberc                 S  s   g | ]
}|j ‘qS r   ©Úidr¦   r   r   r   r`   ›  rI   z2test_deterministic_element_ids.<locals>.<listcomp>c                 S  s   g | ]
}|j ‘qS r   r  r¦   r   r   r   r`   œ  rI   ©r   rc   r
   )rV   Z
elements_1Z
elements_2Zids_1Zids_2r   r   r   Útest_deterministic_element_idsŒ  s    ýýr  c                  C  s4   t jtdƒdd�} dd„ | D ƒ}|ddhks0J ‚d S )Nrv   r6   )r  c                 S  s   h | ]}|j j’qS r   )re   rx   r¦   r   r   r   r¨   ¦  rI   zFtest_multi_page_tiff_starts_on_starting_page_number.<locals>.<setcomp>rb   r  )r0   r*   r   r   r   Ú3test_multi_page_tiff_starts_on_starting_page_number¡  s    þr  )`Ú
__future__r   r{   Úpathlibrý   Zunittestr   rP   ZPILr   Zpytest_mockr   Z unstructured_inference.inferencer   Zunstructured_pytesseractr   Z.test_unstructured.partition.pdf_image.test_pdfr   Ztest_unstructured.unit_utilsr	   r
   Zunstructured.chunking.titler   Zunstructured.documents.elementsr   Zunstructured.partitionr   r   Z unstructured.partition.pdf_imager   Z&unstructured.partition.utils.constantsr   r   Zunstructured.utilsr   ÚPathÚ__file__ÚparentÚresolveZ	DIRECTORYr   r&   r(   r)   r2   ró   r3   rô   r?   ÚmarkZparametrizerN   ÚskiprS   rl   ru   rz   rƒ   r�   r�   r”   rs   r�   r˜   r¡   r¢   r¤   rª   r¸   r»   rÀ   rÁ   rÄ   rÆ   rÇ   rÈ   rÉ   rÑ   rÔ   r×   rØ   rÝ   rÞ   rä   ræ   rì   rí   rî   rð   Zfixturer÷   rø   rÿ   r   r  r  r   r   r   r   Ú<module>   sä   	
þþ


ÿ
ÿ
ÿ
	þ
ÿ
ÿþþ
			ÿ
þ
ÿ
ÿ
þþ
	þþ

ýÿ

þ