status_enum.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from enum import Enum
  2. class TestTaskStatus(Enum):
  3. NOT_STARTED = 0
  4. IN_PROGRESS = 1
  5. COMPLETED = 2
  6. CANCELLED = 3
  7. @property
  8. def description(self):
  9. descriptions = {
  10. self.NOT_STARTED: "未开始",
  11. self.IN_PROGRESS: "进行中",
  12. self.COMPLETED: "已完成",
  13. self.CANCELLED: "已取消"
  14. }
  15. return descriptions.get(self)
  16. class TestTaskConversationsStatus(Enum):
  17. """任务状态枚举类"""
  18. PENDING = 0 # 待执行
  19. RUNNING = 1 # 执行中
  20. SUCCESS = 2 # 执行成功
  21. FAILED = 3 # 执行失败
  22. CANCELLED = 4 # 已取消
  23. @property
  24. def description(self):
  25. descriptions = {
  26. self.PENDING: "待执行",
  27. self.RUNNING: "执行中",
  28. self.SUCCESS: "执行成功",
  29. self.FAILED: "执行失败",
  30. self.CANCELLED: "已取消"
  31. }
  32. return descriptions.get(self)
  33. # 使用示例
  34. def get_test_task_status_desc(status_code):
  35. try:
  36. status = TestTaskStatus(status_code)
  37. return status.description
  38. except ValueError:
  39. return f"未知状态: {status_code}"
  40. # 使用示例
  41. def get_test_task_conversations_status_desc(status_code):
  42. try:
  43. status = TestTaskConversationsStatus(status_code)
  44. return status.description
  45. except ValueError:
  46. return f"未知状态: {status_code}"