Skip to content

Commit e2226f5

Browse files
committed
test: add test
1 parent 2109a28 commit e2226f5

File tree

2 files changed

+143
-141
lines changed

2 files changed

+143
-141
lines changed

test/testcase/test_async/test_async_retrieval.py

+47-45
Original file line numberDiff line numberDiff line change
@@ -231,51 +231,53 @@ async def test_a_update_record_by_text(self, text_splitter):
231231
assume_record_result(update_record_data, res_dict)
232232
records = list_records(collection_id=self.collection_id, order="desc", limit=20, after=None, before=None)
233233

234-
# @pytest.mark.run(order=34)
235-
# @pytest.mark.asyncio
236-
# @pytest.mark.parametrize("text_splitter", text_splitter_list)
237-
# async def test_a_update_record_by_web(self, text_splitter):
238-
# # Update a record.
239-
#
240-
# update_record_data = {
241-
# "type": "web",
242-
# "title": "Machine learning",
243-
# "collection_id": self.collection_id,
244-
# "record_id": self.record_id,
245-
# "url": "https://docs.tasking.ai/docs/guide/getting_started/overview/",
246-
# "text_splitter": text_splitter,
247-
# "metadata": {"test": "test"},
248-
# }
249-
# res = await a_update_record(**update_record_data)
250-
# logger.info(f"a_update_record:{res}")
251-
# res_dict = vars(res)
252-
# assume_record_result(update_record_data, res_dict)
253-
#
254-
# @pytest.mark.run(order=34)
255-
# @pytest.mark.asyncio
256-
# @pytest.mark.parametrize("upload_file_data", upload_file_data_list[2:3])
257-
# async def test_a_update_record_by_file(self, upload_file_data):
258-
# # upload file
259-
# upload_file_res = await a_upload_file(**upload_file_data)
260-
# upload_file_dict = vars(upload_file_res)
261-
# file_id = upload_file_dict["file_id"]
262-
# pytest.assume(file_id is not None)
263-
#
264-
# # Update a record.
265-
#
266-
# update_record_data = {
267-
# "type": "file",
268-
# "title": "Machine learning",
269-
# "collection_id": self.collection_id,
270-
# "record_id": self.record_id,
271-
# "file_id": file_id,
272-
# "text_splitter": TokenTextSplitter(chunk_size=200, chunk_overlap=100),
273-
# "metadata": {"test": "test"},
274-
# }
275-
# res = await a_update_record(**update_record_data)
276-
# logger.info(f"a_update_record:{res}")
277-
# res_dict = vars(res)
278-
# assume_record_result(update_record_data, res_dict)
234+
@pytest.mark.run(order=34)
235+
@pytest.mark.asyncio
236+
@pytest.mark.parametrize("text_splitter", text_splitter_list)
237+
async def test_a_update_record_by_web(self, text_splitter):
238+
# Update a record.
239+
240+
update_record_data = {
241+
"type": "web",
242+
"title": "Machine learning",
243+
"collection_id": self.collection_id,
244+
"record_id": self.record_id,
245+
"url": "https://docs.tasking.ai/docs/guide/getting_started/overview/",
246+
"text_splitter": text_splitter,
247+
"metadata": {"test": "test"},
248+
}
249+
res = await a_update_record(**update_record_data)
250+
logger.info(f"a_update_record:{res}")
251+
res_dict = vars(res)
252+
assume_record_result(update_record_data, res_dict)
253+
records = list_records(collection_id=self.collection_id, order="desc", limit=20, after=None, before=None)
254+
255+
@pytest.mark.run(order=34)
256+
@pytest.mark.asyncio
257+
@pytest.mark.parametrize("upload_file_data", upload_file_data_list[2:3])
258+
async def test_a_update_record_by_file(self, upload_file_data):
259+
# upload file
260+
upload_file_res = await a_upload_file(**upload_file_data)
261+
upload_file_dict = vars(upload_file_res)
262+
file_id = upload_file_dict["file_id"]
263+
pytest.assume(file_id is not None)
264+
265+
# Update a record.
266+
267+
update_record_data = {
268+
"type": "file",
269+
"title": "Machine learning",
270+
"collection_id": self.collection_id,
271+
"record_id": self.record_id,
272+
"file_id": file_id,
273+
"text_splitter": TokenTextSplitter(chunk_size=200, chunk_overlap=100),
274+
"metadata": {"test": "test"},
275+
}
276+
res = await a_update_record(**update_record_data)
277+
logger.info(f"a_update_record:{res}")
278+
res_dict = vars(res)
279+
assume_record_result(update_record_data, res_dict)
280+
records = list_records(collection_id=self.collection_id, order="desc", limit=20, after=None, before=None)
279281

280282
@pytest.mark.run(order=79)
281283
@pytest.mark.asyncio

test/testcase/test_sync/test_sync_retrieval.py

+96-96
Original file line numberDiff line numberDiff line change
@@ -314,99 +314,99 @@ def test_delete_record(self, collection_id):
314314
pytest.assume(new_nums == 0)
315315

316316

317-
# @pytest.mark.test_sync
318-
# class TestChunk:
319-
#
320-
# @pytest.mark.run(order=41)
321-
# def test_query_chunks(self, collection_id):
322-
# # Query chunks.
323-
#
324-
# query_text = "Machine learning"
325-
# top_k = 1
326-
# res = query_chunks(
327-
# collection_id=collection_id, query_text=query_text, top_k=top_k, max_tokens=20000, score_threshold=0.04
328-
# )
329-
# pytest.assume(len(res) == top_k)
330-
# for chunk in res:
331-
# chunk_dict = vars(chunk)
332-
# assume_query_chunk_result(query_text, chunk_dict)
333-
# pytest.assume(chunk_dict["score"] >= 0.04)
334-
#
335-
# @pytest.mark.run(order=42)
336-
# def test_create_chunk(self, collection_id):
337-
# # Create a chunk.
338-
# create_chunk_data = {
339-
# "collection_id": collection_id,
340-
# "content": "Machine learning is a subfield of artificial intelligence (AI) that involves the development of algorithms that allow computers to learn from and make decisions or predictions based on data.",
341-
# }
342-
# res = create_chunk(**create_chunk_data)
343-
# res_dict = vars(res)
344-
# assume_chunk_result(create_chunk_data, res_dict)
345-
#
346-
# @pytest.mark.run(order=43)
347-
# def test_list_chunks(self, collection_id):
348-
# # List chunks.
349-
#
350-
# nums_limit = 1
351-
# res = list_chunks(limit=nums_limit, collection_id=collection_id)
352-
# pytest.assume(len(res) == nums_limit)
353-
#
354-
# after_id = res[-1].chunk_id
355-
# after_res = list_chunks(limit=nums_limit, after=after_id, collection_id=collection_id)
356-
# pytest.assume(len(after_res) == nums_limit)
357-
#
358-
# twice_nums_list = list_chunks(limit=nums_limit * 2, collection_id=collection_id)
359-
# pytest.assume(len(twice_nums_list) == nums_limit * 2)
360-
# pytest.assume(after_res[-1] == twice_nums_list[-1])
361-
# pytest.assume(after_res[0] == twice_nums_list[nums_limit])
362-
#
363-
# before_id = after_res[0].chunk_id
364-
# before_res = list_chunks(limit=nums_limit, before=before_id, collection_id=collection_id)
365-
# pytest.assume(len(before_res) == nums_limit)
366-
# pytest.assume(before_res[-1] == twice_nums_list[nums_limit - 1])
367-
# pytest.assume(before_res[0] == twice_nums_list[0])
368-
#
369-
# @pytest.mark.run(order=44)
370-
# def test_get_chunk(self, collection_id):
371-
# # list chunks
372-
#
373-
# chunks = list_chunks(collection_id=collection_id)
374-
# for chunk in chunks:
375-
# chunk_id = chunk.chunk_id
376-
# res = get_chunk(collection_id=collection_id, chunk_id=chunk_id)
377-
# logger.info(f"get chunk response: {res}")
378-
# res_dict = vars(res)
379-
# pytest.assume(res_dict["collection_id"] == collection_id)
380-
# pytest.assume(res_dict["chunk_id"] == chunk_id)
381-
#
382-
# @pytest.mark.run(order=45)
383-
# def test_update_chunk(self, collection_id, chunk_id):
384-
# # Update a chunk.
385-
#
386-
# update_chunk_data = {
387-
# "collection_id": collection_id,
388-
# "chunk_id": chunk_id,
389-
# "content": "Machine learning is a subfield of artificial intelligence (AI) that involves the development of algorithms that allow computers to learn from and make decisions or predictions based on data.",
390-
# "metadata": {"test": "test"},
391-
# }
392-
# res = update_chunk(**update_chunk_data)
393-
# res_dict = vars(res)
394-
# assume_chunk_result(update_chunk_data, res_dict)
395-
#
396-
# @pytest.mark.run(order=46)
397-
# def test_delete_chunk(self, collection_id):
398-
# # List chunks.
399-
#
400-
# chunks = list_chunks(collection_id=collection_id, limit=5)
401-
# for index, chunk in enumerate(chunks):
402-
# chunk_id = chunk.chunk_id
403-
#
404-
# # Delete a chunk.
405-
#
406-
# delete_chunk(collection_id=collection_id, chunk_id=chunk_id)
407-
#
408-
# # List chunks.
409-
#
410-
# new_chunks = list_chunks(collection_id=collection_id)
411-
# chunk_ids = [chunk.chunk_id for chunk in new_chunks]
412-
# pytest.assume(chunk_id not in chunk_ids)
317+
@pytest.mark.test_sync
318+
class TestChunk:
319+
320+
@pytest.mark.run(order=41)
321+
def test_query_chunks(self, collection_id):
322+
# Query chunks.
323+
324+
query_text = "Machine learning"
325+
top_k = 1
326+
res = query_chunks(
327+
collection_id=collection_id, query_text=query_text, top_k=top_k, max_tokens=20000, score_threshold=0.04
328+
)
329+
pytest.assume(len(res) == top_k)
330+
for chunk in res:
331+
chunk_dict = vars(chunk)
332+
assume_query_chunk_result(query_text, chunk_dict)
333+
pytest.assume(chunk_dict["score"] >= 0.04)
334+
335+
@pytest.mark.run(order=42)
336+
def test_create_chunk(self, collection_id):
337+
# Create a chunk.
338+
create_chunk_data = {
339+
"collection_id": collection_id,
340+
"content": "Machine learning is a subfield of artificial intelligence (AI) that involves the development of algorithms that allow computers to learn from and make decisions or predictions based on data.",
341+
}
342+
res = create_chunk(**create_chunk_data)
343+
res_dict = vars(res)
344+
assume_chunk_result(create_chunk_data, res_dict)
345+
346+
@pytest.mark.run(order=43)
347+
def test_list_chunks(self, collection_id):
348+
# List chunks.
349+
350+
nums_limit = 1
351+
res = list_chunks(limit=nums_limit, collection_id=collection_id)
352+
pytest.assume(len(res) == nums_limit)
353+
354+
after_id = res[-1].chunk_id
355+
after_res = list_chunks(limit=nums_limit, after=after_id, collection_id=collection_id)
356+
pytest.assume(len(after_res) == nums_limit)
357+
358+
twice_nums_list = list_chunks(limit=nums_limit * 2, collection_id=collection_id)
359+
pytest.assume(len(twice_nums_list) == nums_limit * 2)
360+
pytest.assume(after_res[-1] == twice_nums_list[-1])
361+
pytest.assume(after_res[0] == twice_nums_list[nums_limit])
362+
363+
before_id = after_res[0].chunk_id
364+
before_res = list_chunks(limit=nums_limit, before=before_id, collection_id=collection_id)
365+
pytest.assume(len(before_res) == nums_limit)
366+
pytest.assume(before_res[-1] == twice_nums_list[nums_limit - 1])
367+
pytest.assume(before_res[0] == twice_nums_list[0])
368+
369+
@pytest.mark.run(order=44)
370+
def test_get_chunk(self, collection_id):
371+
# list chunks
372+
373+
chunks = list_chunks(collection_id=collection_id)
374+
for chunk in chunks:
375+
chunk_id = chunk.chunk_id
376+
res = get_chunk(collection_id=collection_id, chunk_id=chunk_id)
377+
logger.info(f"get chunk response: {res}")
378+
res_dict = vars(res)
379+
pytest.assume(res_dict["collection_id"] == collection_id)
380+
pytest.assume(res_dict["chunk_id"] == chunk_id)
381+
382+
@pytest.mark.run(order=45)
383+
def test_update_chunk(self, collection_id, chunk_id):
384+
# Update a chunk.
385+
386+
update_chunk_data = {
387+
"collection_id": collection_id,
388+
"chunk_id": chunk_id,
389+
"content": "Machine learning is a subfield of artificial intelligence (AI) that involves the development of algorithms that allow computers to learn from and make decisions or predictions based on data.",
390+
"metadata": {"test": "test"},
391+
}
392+
res = update_chunk(**update_chunk_data)
393+
res_dict = vars(res)
394+
assume_chunk_result(update_chunk_data, res_dict)
395+
396+
@pytest.mark.run(order=46)
397+
def test_delete_chunk(self, collection_id):
398+
# List chunks.
399+
400+
chunks = list_chunks(collection_id=collection_id, limit=5)
401+
for index, chunk in enumerate(chunks):
402+
chunk_id = chunk.chunk_id
403+
404+
# Delete a chunk.
405+
406+
delete_chunk(collection_id=collection_id, chunk_id=chunk_id)
407+
408+
# List chunks.
409+
410+
new_chunks = list_chunks(collection_id=collection_id)
411+
chunk_ids = [chunk.chunk_id for chunk in new_chunks]
412+
pytest.assume(chunk_id not in chunk_ids)

0 commit comments

Comments
 (0)