Refactor: reformat all code for lefthook using ruff and gofmt (#16585)

This commit is contained in:
Wang Qi
2026-07-03 12:53:39 +08:00
committed by GitHub
parent 19fcb4a981
commit 6a4b9be426
588 changed files with 11123 additions and 15412 deletions

View File

@@ -28,13 +28,9 @@ def add_empty_raw_type_memory(request, WebApiAuth):
exist_memory_ids = [memory["id"] for memory in memory_list_res["data"]["memory_list"]]
for _memory_id in exist_memory_ids:
delete_memory(WebApiAuth, _memory_id)
request.addfinalizer(cleanup)
payload = {
"name": "test_memory_0",
"memory_type": ["raw"],
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
"llm_id": "glm-4-flash@ZHIPU-AI"
}
payload = {"name": "test_memory_0", "memory_type": ["raw"], "embd_id": "BAAI/bge-small-en-v1.5@Builtin", "llm_id": "glm-4-flash@ZHIPU-AI"}
res = create_memory(WebApiAuth, payload)
memory_id = res["data"]["id"]
request.cls.memory_id = memory_id
@@ -49,12 +45,13 @@ def add_empty_multiple_type_memory(request, WebApiAuth):
exist_memory_ids = [memory["id"] for memory in memory_list_res["data"]["memory_list"]]
for _memory_id in exist_memory_ids:
delete_memory(WebApiAuth, _memory_id)
request.addfinalizer(cleanup)
payload = {
"name": "test_memory_0",
"memory_type": ["raw"] + random.choices(["semantic", "episodic", "procedural"], k=random.randint(1, 3)),
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
"llm_id": "glm-4-flash@ZHIPU-AI"
"llm_id": "glm-4-flash@ZHIPU-AI",
}
res = create_memory(WebApiAuth, payload)
memory_id = res["data"]["id"]
@@ -78,7 +75,7 @@ def add_2_multiple_type_memory(request, WebApiAuth):
"name": f"test_memory_{i}",
"memory_type": ["raw"] + random.choices(["semantic", "episodic", "procedural"], k=random.randint(1, 3)),
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
"llm_id": "glm-4-flash@ZHIPU-AI"
"llm_id": "glm-4-flash@ZHIPU-AI",
}
res = create_memory(WebApiAuth, payload)
memory_ids.append(res["data"]["id"])
@@ -100,7 +97,7 @@ def add_memory_with_multiple_type_message_func(request, WebApiAuth):
"name": "test_memory_0",
"memory_type": ["raw"] + random.choices(["semantic", "episodic", "procedural"], k=random.randint(1, 3)),
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
"llm_id": "glm-4-flash@ZHIPU-AI"
"llm_id": "glm-4-flash@ZHIPU-AI",
}
res = create_memory(WebApiAuth, payload)
memory_id = res["data"]["id"]
@@ -116,7 +113,7 @@ Coriander is a versatile herb with two main edible parts, and its name can refer
1. Leaves and Stems (often called Cilantro or Fresh Coriander): These are the fresh, green, fragrant leaves and tender stems of the plant Coriandrum sativum. They have a bright, citrusy, and sometimes pungent flavor. Cilantro is widely used as a garnish or key ingredient in cuisines like Mexican, Indian, Thai, and Middle Eastern.
2. Seeds (called Coriander Seeds): These are the dried, golden-brown seeds of the same plant. When ground, they become coriander powder. The seeds have a warm, nutty, floral, and slightly citrusy taste, completely different from the fresh leaves. They are a fundamental spice in curries, stews, pickles, and baking.
Key Point of Confusion: The naming differs by region. In North America, "coriander" typically refers to the seeds, while "cilantro" refers to the fresh leaves. In the UK, Europe, and many other parts of the world, "coriander" refers to the fresh herb, and the seeds are called "coriander seeds."
"""
""",
}
add_message(WebApiAuth, message_payload)
request.cls.memory_id = memory_id
@@ -135,12 +132,7 @@ def add_memory_with_5_raw_message_func(request, WebApiAuth):
request.addfinalizer(cleanup)
payload = {
"name": "test_memory_1",
"memory_type": ["raw"],
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
"llm_id": "glm-4-flash@ZHIPU-AI"
}
payload = {"name": "test_memory_1", "memory_type": ["raw"], "embd_id": "BAAI/bge-small-en-v1.5@Builtin", "llm_id": "glm-4-flash@ZHIPU-AI"}
res = create_memory(WebApiAuth, payload)
memory_id = res["data"]["id"]
agent_ids = [uuid.uuid4().hex for _ in range(2)]
@@ -157,11 +149,11 @@ Coriander is a versatile herb with two main edible parts, and its name can refer
1. Leaves and Stems (often called Cilantro or Fresh Coriander): These are the fresh, green, fragrant leaves and tender stems of the plant Coriandrum sativum. They have a bright, citrusy, and sometimes pungent flavor. Cilantro is widely used as a garnish or key ingredient in cuisines like Mexican, Indian, Thai, and Middle Eastern.
2. Seeds (called Coriander Seeds): These are the dried, golden-brown seeds of the same plant. When ground, they become coriander powder. The seeds have a warm, nutty, floral, and slightly citrusy taste, completely different from the fresh leaves. They are a fundamental spice in curries, stews, pickles, and baking.
Key Point of Confusion: The naming differs by region. In North America, "coriander" typically refers to the seeds, while "cilantro" refers to the fresh leaves. In the UK, Europe, and many other parts of the world, "coriander" refers to the fresh herb, and the seeds are called "coriander seeds."
"""
""",
}
add_message(WebApiAuth, message_payload)
request.cls.memory_id = memory_id
request.cls.agent_ids = agent_ids
request.cls.session_ids = session_ids
time.sleep(2) # make sure refresh to index before search
time.sleep(2) # make sure refresh to index before search
return memory_id

View File

@@ -21,6 +21,7 @@ from test_common import list_memory_message, add_message
from configs import INVALID_API_TOKEN
from libs.auth import RAGFlowWebApiAuth
class TestAuthorization:
@pytest.mark.p2
@pytest.mark.parametrize(
@@ -38,7 +39,6 @@ class TestAuthorization:
@pytest.mark.usefixtures("add_empty_raw_type_memory")
class TestAddRawMessage:
@pytest.mark.p1
def test_add_raw_message(self, WebApiAuth):
memory_id = self.memory_id
@@ -59,7 +59,7 @@ Uses: Pineapples are eaten fresh, cooked, grilled, juiced, or canned. They are a
Nutrition: They are a good source of Vitamin C, manganese, and contain an enzyme called bromelain, which aids in digestion and can tenderize meat.
Symbolism: The pineapple is a traditional symbol of hospitality and welcome in many cultures.
Are you asking about the fruit itself, or its use in a specific context?
"""
""",
}
add_res = add_message(WebApiAuth, message_payload)
assert add_res["code"] == 0, add_res
@@ -88,7 +88,6 @@ Are you asking about the fruit itself, or its use in a specific context?
@pytest.mark.usefixtures("add_empty_multiple_type_memory")
class TestAddMultipleTypeMessage:
@pytest.mark.p1
def test_add_multiple_type_message(self, WebApiAuth):
memory_id = self.memory_id
@@ -109,7 +108,7 @@ Uses: Pineapples are eaten fresh, cooked, grilled, juiced, or canned. They are a
Nutrition: They are a good source of Vitamin C, manganese, and contain an enzyme called bromelain, which aids in digestion and can tenderize meat.
Symbolism: The pineapple is a traditional symbol of hospitality and welcome in many cultures.
Are you asking about the fruit itself, or its use in a specific context?
"""
""",
}
add_res = add_message(WebApiAuth, message_payload)
assert add_res["code"] == 0, add_res
@@ -124,7 +123,6 @@ Are you asking about the fruit itself, or its use in a specific context?
@pytest.mark.usefixtures("add_2_multiple_type_memory")
class TestAddToMultipleMemory:
@pytest.mark.p1
def test_add_to_multiple_memory(self, WebApiAuth):
memory_ids = self.memory_ids
@@ -145,7 +143,7 @@ Uses: Pineapples are eaten fresh, cooked, grilled, juiced, or canned. They are a
Nutrition: They are a good source of Vitamin C, manganese, and contain an enzyme called bromelain, which aids in digestion and can tenderize meat.
Symbolism: The pineapple is a traditional symbol of hospitality and welcome in many cultures.
Are you asking about the fruit itself, or its use in a specific context?
"""
""",
}
add_res = add_message(WebApiAuth, message_payload)
assert add_res["code"] == 0, add_res

View File

@@ -38,7 +38,6 @@ class TestAuthorization:
@pytest.mark.usefixtures("add_memory_with_5_raw_message_func")
class TestForgetMessage:
@pytest.mark.p1
def test_forget_message(self, WebApiAuth):
memory_id = self.memory_id

View File

@@ -20,6 +20,7 @@ from test_common import get_message_content, get_recent_message
from configs import INVALID_API_TOKEN
from libs.auth import RAGFlowWebApiAuth
class TestAuthorization:
@pytest.mark.p2
@pytest.mark.parametrize(
@@ -37,7 +38,6 @@ class TestAuthorization:
@pytest.mark.usefixtures("add_memory_with_multiple_type_message_func")
class TestGetMessageContent:
@pytest.mark.p1
def test_get_message_content(self, WebApiAuth):
memory_id = self.memory_id

View File

@@ -38,7 +38,6 @@ class TestAuthorization:
@pytest.mark.usefixtures("add_memory_with_5_raw_message_func")
class TestGetRecentMessage:
@pytest.mark.p1
def test_get_recent_messages(self, WebApiAuth):
memory_id = self.memory_id

View File

@@ -39,7 +39,6 @@ class TestAuthorization:
@pytest.mark.usefixtures("add_memory_with_5_raw_message_func")
class TestMessageList:
@pytest.mark.p2
def test_params_unset(self, WebApiAuth):
memory_id = self.memory_id
@@ -64,8 +63,7 @@ class TestMessageList:
({"page": 3, "page_size": 2}, 1),
({"page": 5, "page_size": 10}, 0),
],
ids=["normal_first_page", "beyond_max_page", "normal_last_partial_page", "normal_middle_page",
"full_data_single_page"],
ids=["normal_first_page", "beyond_max_page", "normal_last_partial_page", "normal_middle_page", "full_data_single_page"],
)
def test_page_size(self, WebApiAuth, params, expected_page_size):
# have added 5 messages in fixture

View File

@@ -18,6 +18,7 @@ from test_common import search_message, list_memory_message
from configs import INVALID_API_TOKEN
from libs.auth import RAGFlowWebApiAuth
class TestAuthorization:
@pytest.mark.p2
@pytest.mark.parametrize(
@@ -35,7 +36,6 @@ class TestAuthorization:
@pytest.mark.usefixtures("add_memory_with_multiple_type_message_func")
class TestSearchMessage:
@pytest.mark.p1
def test_query(self, WebApiAuth):
memory_id = self.memory_id
@@ -71,11 +71,7 @@ class TestSearchMessage:
assert list_res["data"]["messages"]["total_count"] > 0
query = "Coriander is a versatile herb with two main edible parts. What's its name can refer to?"
params = {
"similarity_threshold": 0.1,
"keywords_similarity_weight": 0.6,
"top_n": 4
}
params = {"similarity_threshold": 0.1, "keywords_similarity_weight": 0.6, "top_n": 4}
res = search_message(WebApiAuth, {"memory_id": memory_id, "query": query, **params})
assert res["code"] == 0, res
assert len(res["data"]) > 0

View File

@@ -40,7 +40,6 @@ class TestAuthorization:
@pytest.mark.usefixtures("add_memory_with_5_raw_message_func")
class TestUpdateMessageStatus:
@pytest.mark.p1
def test_update_to_false(self, WebApiAuth):
memory_id = self.memory_id