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

@@ -17,6 +17,7 @@ import pytest
import random
from test_common import create_memory, list_memory, delete_memory
@pytest.fixture(scope="function")
def add_memory_func(request, WebApiAuth):
def cleanup():
@@ -33,7 +34,7 @@ def add_memory_func(request, WebApiAuth):
"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 = create_memory(WebApiAuth, payload)
memory_ids.append(res["data"]["id"])

View File

@@ -30,7 +30,7 @@ class TestAuthorization:
(None, 401, "<Unauthorized '401: Unauthorized'>"),
(RAGFlowWebApiAuth(INVALID_API_TOKEN), 401, "<Unauthorized '401: Unauthorized'>"),
],
ids=["empty_auth", "invalid_api_token"]
ids=["empty_auth", "invalid_api_token"],
)
def test_auth_invalid(self, invalid_auth, expected_code, expected_message):
res = create_memory(invalid_auth)
@@ -46,11 +46,11 @@ 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",
}
res = create_memory(WebApiAuth, payload)
assert res["code"] == 0, res
pattern = rf'^{name}|{name}(?:\((\d+)\))?$'
pattern = rf"^{name}|{name}(?:\((\d+)\))?$"
escaped_name = re.escape(res["data"]["name"])
assert re.match(pattern, escaped_name), res
@@ -60,7 +60,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"],
)
@@ -69,7 +69,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",
}
res = create_memory(WebApiAuth, payload)
assert res["message"] == expected_message, res
@@ -77,12 +77,7 @@ class TestMemoryCreate:
@pytest.mark.p2
@pytest.mark.parametrize("name", ["invalid_type_name", "memory_alpha"])
def test_type_invalid(self, WebApiAuth, 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"}
res = create_memory(WebApiAuth, payload)
assert res["message"] == f"Memory type '{ {'something'} }' is not supported.", res
@@ -93,7 +88,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 = create_memory(WebApiAuth, payload)
assert res1["code"] == 0, res1

View File

@@ -20,6 +20,7 @@ from test_common import list_memory, get_memory_config
from configs import INVALID_API_TOKEN
from libs.auth import RAGFlowWebApiAuth
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, WebApiAuth):
res = list_memory(WebApiAuth, None)
res = list_memory(WebApiAuth, None)
assert res["code"] == 0, res
@pytest.mark.p2
@@ -67,8 +69,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, WebApiAuth, params, expected_page_size):
# have added 3 memories in fixture
@@ -112,7 +113,21 @@ class TestMemoryList:
memory_config = get_memory_config(WebApiAuth, memory_list["data"]["memory_list"][0]["id"])
assert memory_config["code"] == 0, memory_config
assert memory_config["data"]["id"] == memory_list["data"]["memory_list"][0]["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 field in memory_config["data"], memory_config

View File

@@ -14,10 +14,11 @@
# limitations under the License.
#
import pytest
from test_common import (list_memory, delete_memory)
from test_common import list_memory, delete_memory
from configs import INVALID_API_TOKEN
from libs.auth import RAGFlowWebApiAuth
class TestAuthorization:
@pytest.mark.p2
@pytest.mark.parametrize(

View File

@@ -31,7 +31,7 @@ class TestAuthorization:
(None, 401, "<Unauthorized '401: Unauthorized'>"),
(RAGFlowWebApiAuth(INVALID_API_TOKEN), 401, "<Unauthorized '401: Unauthorized'>"),
],
ids=["empty_auth", "invalid_api_token"]
ids=["empty_auth", "invalid_api_token"],
)
def test_auth_invalid(self, invalid_auth, expected_code, expected_message):
res = update_memory(invalid_auth, "memory_id")
@@ -40,7 +40,6 @@ class TestAuthorization:
class TestMemoryUpdate:
@pytest.mark.p1
@pytest.mark.parametrize("name", ["updated_memory", "f" * 128])
def test_name(self, WebApiAuth, add_memory_func, name):
@@ -58,7 +57,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, WebApiAuth, add_memory_func, name, expected_message):
memory_ids = add_memory_func
@@ -115,14 +114,7 @@ class TestMemoryUpdate:
assert "Do not set tenant_llm_id or tenant_embd_id directly" in res["message"], 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, WebApiAuth, add_memory_func, permission):
memory_ids = add_memory_func
payload = {"permissions": permission}
@@ -130,7 +122,6 @@ class TestMemoryUpdate:
assert res["code"] == 0, res
assert res["data"]["permissions"] == permission.lower().strip(), res
@pytest.mark.p1
def test_memory_size(self, WebApiAuth, add_memory_func):
memory_ids = add_memory_func