a
    ¡˜ëj·  ã                   @  s´   d Z ddlmZ ddlmZmZmZ ddlZddlm	Z	m
Z
 ddlmZmZ ddlmZmZmZ G dd	„ d	ƒZG d
d„ dƒZG dd„ dƒZddddddœdd„Zdddœdd„ZdS )z@Unit-test suite for the `unstructured.chunking.dispatch` module.é    )Úannotations)ÚAnyÚIterableÚOptionalN)Úadd_chunking_strategyÚregister_chunking_strategy)Ú_ChunkerSpecÚchunk)ÚCompositeElementÚElementÚTextc                   @  s    e Zd ZdZdd„ Zdd„ ZdS )ÚDescribe_add_chunking_strategyzNUnit-test suite for `unstructured.chunking.add_chunking_strategy()` decorator.c                 C  s(   t tƒ}|dd�}|tdƒgks$J ‚d S )NÚbasic)Úchunking_strategyzLorem ipsum.

Sit amet.)r   Úpartition_thisr
   )ÚselfÚdecorated_partitionerÚchunks© r   úg/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/test_unstructured/chunking/test_dispatch.pyÚ?it_dispatches_the_partitioned_elements_to_the_indicated_chunker   s    
z^Describe_add_chunking_strategy.it_dispatches_the_partitioned_elements_to_the_indicated_chunkerc                 C  s*   t tƒ}|ƒ }|tdƒtdƒgks&J ‚d S )NúLorem ipsum.ú	Sit amet.)r   r   r   )r   r   Úelementsr   r   r   Ú<but_it_skips_dispatch_when_no_chunking_strategy_is_specified   s    z[Describe_add_chunking_strategy.but_it_skips_dispatch_when_no_chunking_strategy_is_specifiedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   r   c                   @  s    e Zd ZdZdd„ Zdd„ ZdS )ÚDescribe_chunkzFUnit-test suite for `unstructured.chunking.dispatch.chunk()` function.c                 C  sH   t dtƒ dddœ}ttdƒtdƒgdfi |¤Ž}|tdƒgksDJ ‚d S )NZby_something_elseiî  Úbar)Úmax_charactersZfooZLoremZIpsumz=chunked 2 elements with `(max_characters=750, whizbang=None)`)r   Úchunk_by_something_elser	   r   r
   )r   Úkwargsr   r   r   r   ÚAit_dispatches_to_the_chunker_registered_for_the_chunking_strategy%   s    
üÿzPDescribe_chunk.it_dispatches_to_the_chunker_registered_for_the_chunking_strategyc                 C  s>   t jtdd�� tg dd� W d   ƒ n1 s00    Y  d S )Nz'unrecognized chunking strategy 'foobar')ÚmatchZfoobar)r   r   )ÚpytestZraisesÚ
ValueErrorr	   )r   r   r   r   Ú@it_raises_when_the_requested_chunking_strategy_is_not_registered4   s
    þzODescribe_chunk.it_raises_when_the_requested_chunking_strategy_is_not_registeredN)r   r   r   r   r$   r(   r   r   r   r   r   "   s   r   c                   @  s    e Zd ZdZdd„ Zdd„ ZdS )ÚDescribe_ChunkerSpeczJUnit-test suite for `unstructured.chunking.dispatch._ChunkerSpec` objects.c                 C  s   t tƒ}|jtu sJ ‚d S )N)r   r"   Zchunker©r   Úspecr   r   r   Ú+it_provides_access_to_the_chunking_function?   s    z@Describe_ChunkerSpec.it_provides_access_to_the_chunking_functionc                 C  s   t tƒ}|jdksJ ‚d S )N)r!   Úwhizbang)r   r"   Zkw_arg_namesr*   r   r   r   Ú<it_knows_which_keyword_args_the_chunking_function_can_acceptC   s    zQDescribe_ChunkerSpec.it_knows_which_keyword_args_the_chunking_function_can_acceptN)r   r   r   r   r,   r.   r   r   r   r   r)   <   s   r)   zIterable[Element]zOptional[int]zOptional[float]zlist[Element])r   r!   r-   Úreturnc                 C  s*   t | ƒ}tdt|ƒ› d|› d|› d�ƒgS )z3A "fake" minimal chunker suitable for use in tests.zchunked z  elements with `(max_characters=z, whizbang=z)`)Úlistr
   Úlen)r   r!   r-   Zelsr   r   r   r"   K   s    ÿÿÿÿr"   r   )r#   r/   c                  K  s   t dƒt dƒgS )zA fake partitioner.r   r   )r   )r#   r   r   r   r   Z   s    r   )NN)r   Ú
__future__r   Útypingr   r   r   r&   Zunstructured.chunkingr   r   Zunstructured.chunking.dispatchr   r	   Zunstructured.documents.elementsr
   r   r   r   r   r)   r"   r   r   r   r   r   Ú<module>   s     ý