Coverage for src/shephex/experiment/status.py: 82%

44 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-03-29 18:45 +0100

1 

2 

3class Status(str): 

4 

5 valid = ["pending", "submitted", "running", "completed", "failed"] 

6 

7 def __init__(self, value: str) -> None: 

8 if value not in self.valid: 

9 raise ValueError(f"Invalid status: {value}") 

10 self.value = value 

11 

12 @classmethod 

13 def pending(cls) -> "Status": 

14 return cls("pending") 

15 

16 @classmethod 

17 def submitted(cls) -> "Status": 

18 return cls("submitted") 

19 

20 @classmethod 

21 def running(cls) -> "Status": 

22 return cls("running") 

23 

24 @classmethod 

25 def completed(cls) -> "Status": 

26 return cls("completed") 

27 

28 @classmethod 

29 def failed(cls) -> "Status": 

30 return cls("failed") 

31 

32 def __eq__(self, other: "Status") -> bool: 

33 if isinstance(other, str): 

34 return self.value == other 

35 return self.value == other.value 

36 

37class Pending(Status): 

38 def __init__(self) -> None: 

39 super().__init__("pending") 

40 

41class Submitted(Status): 

42 def __init__(self) -> None: 

43 super().__init__("submitted") 

44 

45class Running(Status): 

46 def __init__(self) -> None: 

47 super().__init__("running") 

48 

49class Completed(Status): 

50 def __init__(self) -> None: 

51 super().__init__("completed") 

52 

53class Failed(Status): 

54 def __init__(self) -> None: 

55 super().__init__("failed") 

56 

57if __name__ == '__main__': 

58 

59 status = Status.failed() 

60 

61 bools = "pending" in [Pending()] 

62 print(bools) 

63 

64