allow Exception

This commit is contained in:
CakeCN
2025-09-14 14:12:35 +08:00
parent d6c4f8cfc0
commit d5b16eec52
2 changed files with 40 additions and 39 deletions

View File

@@ -19,8 +19,8 @@ def judge(filepath:str, name: str, course_id: str, lesson_name: str, root_path:s
directory = 'books/code_tests/'+course_id+'/'+name
# 如果目录不存在,报错
if not os.path.exists(directory):
status = FunctionStatus.FAILED
return FunctionResponse("judge", status, f"The name {name} is not found.")
return FunctionResponse("judge", False, f"The name {name} is not found.")
try:
files = os.listdir(directory)
in_files = [file for file in files if file.endswith('.in')]
save_dir = root_path
@@ -52,11 +52,11 @@ def judge(filepath:str, name: str, course_id: str, lesson_name: str, root_path:s
os.remove(os.path.join(save_dir, f"_{name}.out"))
score = int (100 * passed_num / (passed_num + failed_num))
return FunctionResponse("judge", True, f"评测得分为 {score}, 在 {passed_num + failed_num} 个测试用例中通过了 {passed_num}个。最后一个错误样例期望输出:'{exceptoutput}',但你的输出:'{erroroutput}")
except Exception as e:
return FunctionResponse("judge", False, f"评测发生意外错误: {str(e)}")
status = FunctionStatus.SUCCESS
return FunctionResponse("judge", status, f"评测得分为 {score}, 在 {passed_num + failed_num} 个测试用例中通过了 {passed_num}个。最后一个错误样例期望输出:'{exceptoutput}',但你的输出:'{erroroutput}")
def compare_file(path1:str, path2:str):
"""

View File

@@ -2,16 +2,17 @@ from pydantic import BaseModel
from enum import Enum
from typing import Optional
FunctionStatus = Enum("FunctionStatus", ["SUCCESS", "FAILED"])
class FunctionResponse(BaseModel):
name: str
status: FunctionStatus
success: bool
message: str = ""
args: Optional[dict] = None
def __init__(self, name: str, status: FunctionStatus, message: str = "", args: Optional[dict] = None):
super().__init__(name=name, status=status, message=message, args=args)
def __init__(self, name: str, success: bool, message: str = "", args: Optional[dict] = None):
super().__init__(name=name, success=success, message=message, args=args)
def to_dict(self):
return self.model_dump()