mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-01 16:15:07 +08:00
Refa(test): improve code formatting and remove debug prints (#12739)
### What problem does this PR solve? - Improving code formatting and consistency - Removing debug print statements ### Type of change - [x] Refactoring
This commit is contained in:
@ -18,6 +18,7 @@ import re
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from utils import wait_for
|
||||||
|
|
||||||
from common import (
|
from common import (
|
||||||
chat_completions,
|
chat_completions,
|
||||||
@ -25,10 +26,10 @@ from common import (
|
|||||||
create_session_with_chat_assistant,
|
create_session_with_chat_assistant,
|
||||||
delete_chat_assistants,
|
delete_chat_assistants,
|
||||||
list_documents,
|
list_documents,
|
||||||
upload_documents,
|
|
||||||
parse_documents,
|
parse_documents,
|
||||||
|
upload_documents,
|
||||||
)
|
)
|
||||||
from utils import wait_for
|
|
||||||
|
|
||||||
@wait_for(200, 1, "Document parsing timeout")
|
@wait_for(200, 1, "Document parsing timeout")
|
||||||
def wait_for_parsing_completion(auth, dataset_id, document_id=None):
|
def wait_for_parsing_completion(auth, dataset_id, document_id=None):
|
||||||
@ -51,7 +52,7 @@ def wait_for_parsing_completion(auth, dataset_id, document_id=None):
|
|||||||
for doc in docs:
|
for doc in docs:
|
||||||
status = doc.get("run", "UNKNOWN")
|
status = doc.get("run", "UNKNOWN")
|
||||||
if status != "DONE":
|
if status != "DONE":
|
||||||
print(f"[DEBUG] Document {doc.get('name', 'unknown')} status: {status}, progress: {doc.get('progress', 0)}%, msg: {doc.get('progress_msg', '')}")
|
# print(f"[DEBUG] Document {doc.get('name', 'unknown')} status: {status}, progress: {doc.get('progress', 0)}%, msg: {doc.get('progress_msg', '')}")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@ -59,7 +60,7 @@ def wait_for_parsing_completion(auth, dataset_id, document_id=None):
|
|||||||
for doc in docs:
|
for doc in docs:
|
||||||
if doc["id"] == document_id:
|
if doc["id"] == document_id:
|
||||||
status = doc.get("run", "UNKNOWN")
|
status = doc.get("run", "UNKNOWN")
|
||||||
print(f"[DEBUG] Document {doc.get('name', 'unknown')} status: {status}, progress: {doc.get('progress', 0)}%, msg: {doc.get('progress_msg', '')}")
|
# print(f"[DEBUG] Document {doc.get('name', 'unknown')} status: {status}, progress: {doc.get('progress', 0)}%, msg: {doc.get('progress_msg', '')}")
|
||||||
if status == "DONE":
|
if status == "DONE":
|
||||||
return True
|
return True
|
||||||
elif status == "FAILED":
|
elif status == "FAILED":
|
||||||
@ -67,6 +68,7 @@ def wait_for_parsing_completion(auth, dataset_id, document_id=None):
|
|||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Test data
|
# Test data
|
||||||
TEST_EXCEL_DATA = [
|
TEST_EXCEL_DATA = [
|
||||||
["employee_id", "name", "department", "salary"],
|
["employee_id", "name", "department", "salary"],
|
||||||
@ -113,7 +115,7 @@ class TestTableParserDatasetChat:
|
|||||||
Creates chat assistant once and reuses it across all test cases.
|
Creates chat assistant once and reuses it across all test cases.
|
||||||
"""
|
"""
|
||||||
# Only setup once (first time)
|
# Only setup once (first time)
|
||||||
if not hasattr(self.__class__, 'chat_id'):
|
if not hasattr(self.__class__, "chat_id"):
|
||||||
self.__class__.dataset_id = add_table_parser_dataset
|
self.__class__.dataset_id = add_table_parser_dataset
|
||||||
self.__class__.auth = HttpApiAuth
|
self.__class__.auth = HttpApiAuth
|
||||||
|
|
||||||
@ -121,14 +123,12 @@ class TestTableParserDatasetChat:
|
|||||||
self._upload_and_parse_excel(HttpApiAuth, add_table_parser_dataset)
|
self._upload_and_parse_excel(HttpApiAuth, add_table_parser_dataset)
|
||||||
|
|
||||||
# Create a single chat assistant and session for all tests
|
# Create a single chat assistant and session for all tests
|
||||||
chat_id, session_id = self._create_chat_assistant_with_session(
|
chat_id, session_id = self._create_chat_assistant_with_session(HttpApiAuth, add_table_parser_dataset)
|
||||||
HttpApiAuth, add_table_parser_dataset
|
|
||||||
)
|
|
||||||
self.__class__.chat_id = chat_id
|
self.__class__.chat_id = chat_id
|
||||||
self.__class__.session_id = session_id
|
self.__class__.session_id = session_id
|
||||||
|
|
||||||
# Store the total number of parametrize cases
|
# Store the total number of parametrize cases
|
||||||
mark = request.node.get_closest_marker('parametrize')
|
mark = request.node.get_closest_marker("parametrize")
|
||||||
if mark:
|
if mark:
|
||||||
# Get the number of test cases from parametrize
|
# Get the number of test cases from parametrize
|
||||||
param_values = mark.args[1]
|
param_values = mark.args[1]
|
||||||
@ -140,7 +140,7 @@ class TestTableParserDatasetChat:
|
|||||||
|
|
||||||
# Teardown: cleanup chat assistant after all tests
|
# Teardown: cleanup chat assistant after all tests
|
||||||
# Use a class-level counter to track tests
|
# Use a class-level counter to track tests
|
||||||
if not hasattr(self.__class__, '_test_counter'):
|
if not hasattr(self.__class__, "_test_counter"):
|
||||||
self.__class__._test_counter = 0
|
self.__class__._test_counter = 0
|
||||||
self.__class__._test_counter += 1
|
self.__class__._test_counter += 1
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ class TestTableParserDatasetChat:
|
|||||||
|
|
||||||
def _teardown_chat_assistant(self):
|
def _teardown_chat_assistant(self):
|
||||||
"""Teardown method to clean up chat assistant."""
|
"""Teardown method to clean up chat assistant."""
|
||||||
if hasattr(self.__class__, 'chat_id') and self.__class__.chat_id:
|
if hasattr(self.__class__, "chat_id") and self.__class__.chat_id:
|
||||||
try:
|
try:
|
||||||
delete_chat_assistants(self.__class__.auth, {"ids": [self.__class__.chat_id]})
|
delete_chat_assistants(self.__class__.auth, {"ids": [self.__class__.chat_id]})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -185,9 +185,6 @@ class TestTableParserDatasetChat:
|
|||||||
# Just verify we got a non-empty answer
|
# Just verify we got a non-empty answer
|
||||||
assert answer and len(answer) > 0, "Expected non-empty answer"
|
assert answer and len(answer) > 0, "Expected non-empty answer"
|
||||||
|
|
||||||
print(f"[Test] Question: {question}")
|
|
||||||
print(f"[Test] Answer: {answer[:100]}...")
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _upload_and_parse_excel(auth, dataset_id):
|
def _upload_and_parse_excel(auth, dataset_id):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user