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

@@ -73,20 +73,20 @@ def list_document(auth, dataset_id):
def get_docs_info(auth, dataset_id, doc_ids=None, doc_id=None):
"""
Get document information by IDs.
Args:
auth: Authorization header
dataset_id: Dataset ID
doc_ids: List of document IDs (use for multiple) - exclusive with doc_id
doc_id: Single document ID (use for one) - exclusive with doc_ids
Raises:
ValueError: If both doc_id and doc_ids are provided
"""
# Validate that id and ids are not used together
if doc_id and doc_ids:
raise ValueError("Cannot use both 'id' and 'ids' parameters at the same time.")
authorization = {"Authorization": auth}
params = {}
if doc_ids:
@@ -96,7 +96,7 @@ def get_docs_info(auth, dataset_id, doc_ids=None, doc_id=None):
elif doc_id:
# Single ID
params["id"] = doc_id
# Use /api/v1 prefix for dataset API
url = f"{HOST_ADDRESS}/api/v1/datasets/{dataset_id}/documents"
res = requests.get(url=url, headers=authorization, params=params)
@@ -113,4 +113,3 @@ def parse_docs(auth, doc_ids):
def parse_file(auth, document_id):
pass

View File

@@ -14,6 +14,7 @@
# limitations under the License.
#
def test_get_email(get_email):
print("\nEmail account:",flush=True)
print(f"{get_email}\n",flush=True)
print("\nEmail account:", flush=True)
print(f"{get_email}\n", flush=True)

View File

@@ -40,15 +40,15 @@ def test_parse_txt_document(get_auth):
break
page_number += 1
filename = 'ragflow_test.txt'
filename = "ragflow_test.txt"
res = upload_file(get_auth, dataset_id, f"../test_sdk_api/test_data/{filename}")
assert res.get("code") == 0, f"{res.get('message')}"
res = list_document(get_auth, dataset_id)
doc_id_list = []
for doc in res['data']['docs']:
doc_id_list.append(doc['id'])
for doc in res["data"]["docs"]:
doc_id_list.append(doc["id"])
res = get_docs_info(get_auth, dataset_id, doc_ids=doc_id_list)
print(doc_id_list)
@@ -59,13 +59,13 @@ def test_parse_txt_document(get_auth):
while True:
res = get_docs_info(get_auth, dataset_id, doc_ids=doc_id_list)
finished_count = 0
for doc_info in res['data']:
if doc_info['progress'] == 1:
for doc_info in res["data"]:
if doc_info["progress"] == 1:
finished_count += 1
if finished_count == doc_count:
break
sleep(1)
print('time cost {:.1f}s'.format(timer() - start_ts))
print("time cost {:.1f}s".format(timer() - start_ts))
# delete dataset
if dataset_list:

View File

@@ -89,7 +89,7 @@ def test_duplicated_name_dataset(get_auth):
if isinstance(data, dict):
data = data.get("kbs", [])
dataset_list = []
pattern = r'^test_create_dataset.*'
pattern = r"^test_create_dataset.*"
for item in data:
dataset_name = item.get("name")
dataset_id = item.get("id")
@@ -106,10 +106,10 @@ def test_duplicated_name_dataset(get_auth):
def test_invalid_name_dataset(get_auth):
# create dataset
res = create_dataset(get_auth, {"name": 0})
assert res['code'] != 0
assert res["code"] != 0
res = create_dataset(get_auth, {"name": ""})
assert res['code'] != 0
assert res["code"] != 0
long_string = ""
@@ -117,7 +117,7 @@ def test_invalid_name_dataset(get_auth):
long_string += random.choice(string.ascii_letters + string.digits)
res = create_dataset(get_auth, {"name": long_string})
assert res['code'] != 0
assert res["code"] != 0
print(res)
@@ -144,13 +144,17 @@ def test_update_different_params_dataset_success(get_auth):
print(f"found {len(dataset_list)} datasets")
dataset_id = dataset_list[0]
res = update_dataset(get_auth, dataset_id, {
"name": "test_update_dataset",
"description": "test",
"permission": "me",
"chunk_method": "presentation",
"language": "spanish",
})
res = update_dataset(
get_auth,
dataset_id,
{
"name": "test_update_dataset",
"description": "test",
"permission": "me",
"chunk_method": "presentation",
"language": "spanish",
},
)
assert res.get("code") == 0, f"{res.get('message')}"
# delete dataset