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
@@ -16,6 +16,7 @@
import pytest
import random
@pytest.fixture(scope="class")
def add_memory_func(client, request):
def cleanup():
@@ -32,7 +33,7 @@ def add_memory_func(client, request):
"name": f"test_memory_{i}",
"memory_type": ["raw"] + random.choices(["semantic", "episodic", "procedural"], k=random.randint(0, 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 = client.create_memory(**payload)
memory_ids.append(res.id)
@@ -31,7 +31,7 @@ class TestAuthorization:
(None, "<Unauthorized '401: Unauthorized'>"),
(INVALID_API_TOKEN, "<Unauthorized '401: Unauthorized'>"),
],
ids=["empty_auth", "invalid_api_token"]
ids=["empty_auth", "invalid_api_token"],
)
def test_auth_invalid(self, invalid_auth, expected_message):
client = RAGFlow(invalid_auth, HOST_ADDRESS)
@@ -51,10 +51,10 @@ class TestMemoryCreate:
"name": name,
"memory_type": ["raw"] + random.choices(["semantic", "episodic", "procedural"], k=random.randint(0, 3)),
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
"llm_id": "glm-4-flash@ZHIPU-AI"
"llm_id": "glm-4-flash@ZHIPU-AI",
}
memory = client.create_memory(**payload)
pattern = rf'^{name}|{name}(?:\((\d+)\))?$'
pattern = rf"^{name}|{name}(?:\((\d+)\))?$"
escaped_name = re.escape(memory.name)
assert re.match(pattern, escaped_name), str(memory)
@@ -64,7 +64,7 @@ class TestMemoryCreate:
[
("", "Memory name cannot be empty or whitespace."),
(" ", "Memory name cannot be empty or whitespace."),
("a" * 129, f"Memory name '{'a'*129}' exceeds limit of 128."),
("a" * 129, f"Memory name '{'a' * 129}' exceeds limit of 128."),
],
ids=["empty_name", "space_name", "too_long_name"],
)
@@ -73,7 +73,7 @@ class TestMemoryCreate:
"name": name,
"memory_type": ["raw"] + random.choices(["semantic", "episodic", "procedural"], k=random.randint(0, 3)),
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
"llm_id": "glm-4-flash@ZHIPU-AI"
"llm_id": "glm-4-flash@ZHIPU-AI",
}
with pytest.raises(Exception) as exception_info:
client.create_memory(**payload)
@@ -83,12 +83,7 @@ class TestMemoryCreate:
@given(name=valid_names())
@settings(deadline=None)
def test_type_invalid(self, client, name):
payload = {
"name": name,
"memory_type": ["something"],
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
"llm_id": "glm-4-flash@ZHIPU-AI"
}
payload = {"name": name, "memory_type": ["something"], "embd_id": "BAAI/bge-small-en-v1.5@Builtin", "llm_id": "glm-4-flash@ZHIPU-AI"}
with pytest.raises(Exception) as exception_info:
client.create_memory(**payload)
assert str(exception_info.value) == f"Memory type '{ {'something'} }' is not supported.", str(exception_info.value)
@@ -100,7 +95,7 @@ class TestMemoryCreate:
"name": name,
"memory_type": ["raw"] + random.choices(["semantic", "episodic", "procedural"], k=random.randint(0, 3)),
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
"llm_id": "glm-4-flash@ZHIPU-AI"
"llm_id": "glm-4-flash@ZHIPU-AI",
}
res1 = client.create_memory(**payload)
assert res1.name == name, str(res1)
@@ -19,6 +19,7 @@ import pytest
from ragflow_sdk import RAGFlow
from configs import INVALID_API_TOKEN, HOST_ADDRESS
class TestAuthorization:
@pytest.mark.p2
@pytest.mark.parametrize(
@@ -45,11 +46,12 @@ class TestCapability:
assert len(responses) == count, responses
assert all(future.result()["code"] == 0 for future in futures)
@pytest.mark.usefixtures("add_memory_func")
class TestMemoryList:
@pytest.mark.p2
def test_params_unset(self, client):
res = client.list_memory()
res = client.list_memory()
assert len(res["memory_list"]) == 3, str(res)
assert res["total_count"] == 3, str(res)
@@ -69,8 +71,7 @@ class TestMemoryList:
({"page": 2, "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(self, client, params, expected_page_size):
# have added 3 memories in fixture
@@ -110,9 +111,23 @@ class TestMemoryList:
memory_id = memory.id
memory_config = memory.get_config()
assert memory_config.id == memory_id, memory_config
for field in ["name", "avatar", "tenant_id", "owner_name", "memory_type", "storage_type",
"embd_id", "llm_id", "permissions", "description", "memory_size", "forgetting_policy",
"temperature", "system_prompt", "user_prompt"]:
for field in [
"name",
"avatar",
"tenant_id",
"owner_name",
"memory_type",
"storage_type",
"embd_id",
"llm_id",
"permissions",
"description",
"memory_size",
"forgetting_policy",
"temperature",
"system_prompt",
"user_prompt",
]:
assert hasattr(memory, field), memory_config
@pytest.mark.p2
@@ -17,6 +17,7 @@ import pytest
from ragflow_sdk import RAGFlow
from configs import INVALID_API_TOKEN, HOST_ADDRESS
class TestAuthorization:
@pytest.mark.p2
@pytest.mark.parametrize(
@@ -31,7 +31,7 @@ class TestAuthorization:
(None, "<Unauthorized '401: Unauthorized'>"),
(INVALID_API_TOKEN, "<Unauthorized '401: Unauthorized'>"),
],
ids=["empty_auth", "invalid_api_token"]
ids=["empty_auth", "invalid_api_token"],
)
def test_auth_invalid(self, invalid_auth, expected_message):
@@ -41,9 +41,9 @@ class TestAuthorization:
memory.update({"name": "New_Name"})
assert str(exception_info.value) == expected_message, str(exception_info.value)
@pytest.mark.usefixtures("add_memory_func")
class TestMemoryUpdate:
@pytest.mark.p1
@given(name=valid_names())
@example("f" * 128)
@@ -62,7 +62,7 @@ class TestMemoryUpdate:
("", "Memory name cannot be empty or whitespace."),
(" ", "Memory name cannot be empty or whitespace."),
("a" * 129, f"Memory name '{'a' * 129}' exceeds limit of 128."),
]
],
)
def test_name_invalid(self, client, name, expected_message):
memory_ids = self.memory_ids
@@ -112,14 +112,7 @@ class TestMemoryUpdate:
assert res.llm_id == llm_id, str(res)
@pytest.mark.p2
@pytest.mark.parametrize(
"permission",
[
"me",
"team"
],
ids=["me", "team"]
)
@pytest.mark.parametrize("permission", ["me", "team"], ids=["me", "team"])
def test_permission(self, client, permission):
memory_ids = self.memory_ids
update_dict = {"permissions": permission}