
    :Qgi                        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 d dlm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d Z y)    )annotations)MockFixture)assert_round_trips_through_JSONexample_doc_path)chunk_by_title)TableText)partition_epub)#UNSTRUCTURED_INCLUDE_DEBUG_METADATAc                 "   t        t        d            } t        |       dkD  sJ t        | d   t              sJ | d   j
                  j                  d      sJ t        r+| D ch c]  }|j                  j                   c}dhk(  sJ y y c c}w )Nsimple.epubr   za shared cultureepub)
r
   r   len
isinstancer	   text
startswithr   metadatadetection_origin)elementselements     b/var/www/html/answerous/venv/lib/python3.12/site-packages/test_unstructured/partition/test_epub.py!test_partition_epub_from_filenamer      s    .}=>Hx=1hqk4(((A;&&'9:::*AIJg  11JvhVVV +Js   $Bc                 R    t        t        d            } | d   t        d      k(  sJ y )Nwinter-sports.epub
   zContents. List of Illustrations (In certain versions of this etext [in certain
browsers] clicking on the image will bring up a larger
version.) (etext transcriber's note))r
   r   r   r   s    r   ;test_partition_epub_from_filename_returns_table_in_elementsr      s6    ./CDEHB<5	^       c                     t        t        d      d      5 } t        |       }d d d        t              dkD  sJ |d   j                  j                  d      sJ y # 1 sw Y   :xY w)Nr   rbfiler   z,The Project Gutenberg eBook of Winter Sports)openr   r
   r   r   r   fr   s     r   test_partition_epub_from_filer&      sg    	34d	; *q!q)* x=1A;&&'UVVV	* *s   AA%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   filename.0es     r   	<genexpr>zTtest_partition_epub_from_filename_gets_filename_from_filename_arg.<locals>.<genexpr>-   s     Fqzz""m3F   #%r
   r   r   allr   s    r   Atest_partition_epub_from_filename_gets_filename_from_filename_argr2   )   s8    .}=>Hx=1FXFFFFr   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Nr)   r+   s     r   r.   zCtest_partition_epub_from_file_gets_filename_None.<locals>.<genexpr>5   s     =qqzz""d*=   "$)r#   r   r
   r   r1   r$   s     r   0test_partition_epub_from_file_gets_filename_Noner7   0   s[    	}-t	4 *!q)* x=1=H====	* *s   AAc                 x    t        t        d      d      } t        |       dkD  sJ t        d | D              sJ y )Nr   orig-name.epub)metadata_filenamer   c              3  N   K   | ]  }|j                   j                  d k(    ywr9   Nr)   )r,   r   s     r   r.   zNtest_partition_epub_from_filename_prefers_metadata_filename.<locals>.<genexpr><   s"     Uw((,<<Ur/   r0   r   s    r   ;test_partition_epub_from_filename_prefers_metadata_filenamer=   8   s;    .}=QabHx=1UHUUUUr   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    r9   )r"   r:   c              3  N   K   | ]  }|j                   j                  d k(    ywr<   r)   r+   s     r   r.   zJtest_partition_epub_from_file_prefers_metadata_filename.<locals>.<genexpr>C   s      I1qzz""&66Ir/   r#   r   r
   r1   r$   s     r   7test_partition_epub_from_file_prefers_metadata_filenamerA   ?   sP    	}-t	4 N!q<LMN IIIIIN Ns   AA
c                     dt        t        d            } t        fd| D              s-J d dt        | d   j                  j
                                y )Nzapplication/epubr   c              3  P   K   | ]  }|j                   j                  k(    y wr5   )r   filetype)r,   r-   EPUB_MIME_TYPEs     r   r.   zStest_partition_epub_gets_the_EPUB_MIME_type_in_metadata_filetype.<locals>.<genexpr>L   s      Gqzz""n4G   #&zExpected all elements to have 'z' as their filetype, but got: r   )r
   r   r1   reprr   rD   )r   rE   s    @r   @test_partition_epub_gets_the_EPUB_MIME_type_in_metadata_filetyperH   I   s`    'N.}=>HGhGG 
).)9 :!%%../0	2Gr   c                    d| j                  d       t        t        d            }t        fd|D              sJ y )N2024-06-14T16:01:292unstructured.partition.epub.get_last_modified_datereturn_valuer   c              3  P   K   | ]  }|j                   j                  k(    y wr5   r   last_modified)r,   r-   filesystem_last_modifieds     r   r.   zXtest_partition_epub_from_file_path_gets_last_modified_from_filesystem.<locals>.<genexpr>]   s!     Vqzz''+CCVrF   patchr
   r   r1   )mockerr   rQ   s     @r   Etest_partition_epub_from_file_path_gets_last_modified_from_filesystemrU   U   sG    4
LL<Kc   ./CDEH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r5   rO   r+   s     r   r.   zHtest_partition_epub_from_file_gets_last_modified_None.<locals>.<genexpr>d   s     BAqzz''4/Br6   r@   r$   s     r   5test_partition_epub_from_file_gets_last_modified_NonerX   `   sI    	}-t	4 *!q)* BBBBB* *s   A  A	c                    d}d| j                  d|       t        t        d            }t        fd|D              sJ y )NrJ   2020-03-08T06:10:23rK   rL   r   )metadata_last_modifiedc              3  P   K   | ]  }|j                   j                  k(    y wr5   rO   r,   r-   r[   s     r   r.   zTtest_partition_epub_from_file_path_prefers_metadata_last_modified.<locals>.<genexpr>r   s!     Taqzz''+AATrF   rR   )rT   rQ   r   r[   s      @r   Atest_partition_epub_from_file_path_prefers_metadata_last_modifiedr^   g   sT    42
LL<Kc   -.G]H T8TTTTr   c                     dt        t        d      d      5 } t        |       }d d d        t        fdD              sJ y # 1 sw Y    xY w)NrZ   r   r    )r"   r[   c              3  N   K   | ]  }|j                   j                  u   y wr5   rO   r]   s     r   r.   zOtest_partition_epub_from_file_prefers_metadata_last_modified.<locals>.<genexpr>z   s!     Taqzz''+AATs   "%r@   )r%   r   r[   s     @r   <test_partition_epub_from_file_prefers_metadata_last_modifiedra   u   sW    2	}-t	4 Y!qAWXY T8TTTTY Ys   AAc                 6    d} t        |       }t        |       y )Nzexample-docs/winter-sports.epubr*   )r
   r   r*   r   s     r   test_partition_epub_with_jsonre      s    0Hx0H#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   ,test_add_chunking_strategy_on_partition_epubrn      sI     !56Ii(H#ILNH%FX%%%V###r   c                     t        d      } t        |       }t        | dddd      }t        |ddd      }||k7  sJ ||k(  sJ y )Nr   rc   rg      r   )rh   max_charactersnew_after_n_charscombine_text_under_n_chars)rq   rr   rs   ri   rj   s       r   8test_add_chunking_strategy_on_partition_epub_non_defaultrt      sf     !56Iy1H#$#$N #$	F X%%%V###r   c                 p    t        d      } t        |       }|d   j                  j                  dgk(  sJ y )Nr   rc   r   eng)r   r
   r   	languagesrd   s     r   2test_partition_epub_element_metadata_has_languagesrx      s7     45Hx0HA;))eW444r   c                     d} t        | d      }|D cg c]  }|j                  j                   }}|dgddgdgdgdggk(  sJ y c c}w )Nz,example-docs/language-docs/eng_spa_mult.epubT)r*   detect_language_per_elementrv   spa)r
   r   rw   )r*   r   r   langss       r   8test_partition_epub_respects_detect_language_per_elementr}      s]    =HxTRH7?@GW''@E@eWuenugwHHHH As   AN)rT   r   )!
__future__r   pytest_mockr   test_unstructured.unit_utilsr   r   unstructured.chunking.titler   unstructured.documents.elementsr   r	   unstructured.partition.epubr
   &unstructured.partition.utils.constantsr   r   r   r&   r2   r7   r=   rA   rH   rU   rX   r^   ra   re   rn   rt   rx   r}    r   r   <module>r      sy    " # Z 6 7 6 VWWG>VJWCUU.$$(5Ir   