
    3i                         S r SSKrSSKJr  SSKJr  SSKJrJ	r	  S\SS4S jr
S\SS4S	 jrS\SS4S
 jrS\SS4S jrS\SS4S jrg)z
Integration test for Chroma's Task API

Tests the task creation, execution, and removal functionality
for automatically processing collections.
    N)Client)System)ChromaErrorNotFoundErrorbasic_http_clientreturnc                    [         R                  " U 5      nUR                  5         UR                  SSS0S9nUR	                  / SQ/ SQSS0SS	0SS	0/S
9  UR                  5       S:X  d   eUR                  SSSSS9u  p4USL d   eUc   e[        U5      S:  d   eUR	                  SS/SS/S9  UR                  5       S:X  d   eUR                  SSS9nUSL d   eg)zBTest creating and removing a task with the record_counter operatormy_documentdescriptionz$Sample documents for task processing)namemetadatadoc1doc2doc3)z+The quick brown fox jumps over the lazy dogz7Machine learning is a subset of artificial intelligencez(Python is a popular programming languagesourceproverbtech)ids	documents	metadatas   count_my_docsrecord_countermy_documents_countsN	task_nameoperator_nameoutput_collection_nameparamsTr   doc4doc5zChroma is a vector databasezTasks automate data processingr   r      r   delete_output)	ClientCreatorfrom_systemresetget_or_create_collectionaddcountcreate_tasklenremove_task)r   client
collectionsuccesstask_ids        a/home/james-whalen/.local/lib/python3.13/site-packages/chromadb/test/distributed/test_task_api.pytest_task_create_and_remover5      sJ   &&'89F
LLN 00!GH 1 J NN$

 i(8V*<x>PQ   """ "--!&4	 . G d??w<! NNV),
   """ $$! % G d??    c                    [         R                  " U 5      nUR                  5         UR                  SS9nUR	                  S/S/S9  [
        R                  " [        SS9   UR                  SS	S
SS9  SSS5        g! , (       d  f       g= f)zBTest that creating a task with an invalid operator raises an errortest_invalid_operatorr   id1ztest documentr#   zoperator not foundmatchinvalid_tasknonexistent_operatoroutput_collectionNr   )	r'   r(   r)   r*   r+   pytestraisesr   r-   r   r0   r1   s      r4   test_task_with_invalid_operatorrC   J   s    &&'89F
LLN006M0NJNNw?*;N< 
{*>	?$0#6	 	 	
 
@	?	?s   !A==
Bc                    [         R                  " U 5      nUR                  5         UR                  SS9nUR	                  SS/SS/S9  UR                  SS	S
SS9u  p4USL d   eUc   eUR                  SS9nUR	                  SS/SS/S9  UR                  SS	SSS9u  pgUSL d   eUc   eXG:w  d   eUR                  SSS9SL d   eUR                  SSS9SL d   eg)z+Test creating tasks on multiple collectionscollection_1r9   r:   id2r   r   r#   task_1r   output_1Nr   Tcollection_2id3id4r   r!   task_2output_2r%   )r'   r(   r)   create_collectionr+   r-   r/   )r   r0   collection1success1task_id1collection2success2task_id2s           r4   test_task_multiple_collectionsrU   \   sD   &&'89F
LLN ***?KOO662BOC$00&)	 1 H t ***?KOO662BOC$00&)	 1 H t  ""XT"JdRRR""XT"JdRRRr6   c                    [         R                  " U 5      nUR                  5         UR                  SS9nUR	                  / SQ/ SQS9  UR                  SSSS	S
9u  p4USL d   eUc   eUR                  SSSS	S
9u  pVUSL d   eUc   eXF:w  d   eUR                  SSSS	S
9u  pxUSL d   eUc   eX:w  d   eX:w  d   e[        R                  " [        SS9   UR                  SSSS	S
9  S	S	S	5        UR                  SSS9SL d   eUR                  SSS9SL d   eUR                  SSS9SL d   eg	! , (       d  f       NN= f)z3Test creating multiple tasks on the same collectionmulti_task_collectionr9   )r:   rF   rJ   r   r#   rG   r   rH   Nr   TrL   rM   task_3output_3zalready existsr;   output_duplicater%   )
r'   r(   r)   rN   r+   r-   r@   rA   r   r/   )	r   r0   r1   rP   rQ   rS   rT   success3task_id3s	            r4   test_task_multiple_tasksr]      s   &&'89F
LLN ))/F)GJNN,8PNQ $//&)	 0 H t $//&)	 0 H t  $//&)	 0 H t 
{*:	;*#5	 	 	
 
< !!HD!ITQQQ!!HD!ITQQQ!!HD!ITQQQ 
<	;s   D33
Ec                    [         R                  " U 5      nUR                  5         UR                  SS9nUR	                  S/S/S9  [
        R                  " [        SS9   UR                  SS	S
9  SSS5        g! , (       d  f       g= f)z<Test removing a task that doesn't exist raises NotFoundErrortest_collectionr9   r:   testr#   zdoes not existr;   nonexistent_taskFr%   N)	r'   r(   r)   rN   r+   r@   rA   r   r/   rB   s      r4   test_task_remove_nonexistentrb      sz    &&'89F
LLN))/@)AJNNw6(N3 
},<	=( 	 	
 
>	=	=s   !A;;
B	)__doc__r@   chromadb.api.clientr   r'   chromadb.configr   chromadb.errorsr   r   r5   rC   rU   r]   rb    r6   r4   <module>rh      s     7 " 696 9d 9x
v 
$ 
$&Sf &S &SR;R ;R4 ;R|
F 
t 
r6   