Coverage for scheduler/trigger/core.py: 100%

50 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2026-02-11 03:21 +0000

1""" 

2Trigger implementations. 

3 

4Author: Jendrik A. Potyka, Fabian A. Preiss 

5""" 

6 

7import datetime as dt 

8from abc import ABC, abstractmethod 

9from typing import Union 

10 

11 

12class Weekday(ABC): 

13 """ 

14 |Weekday| object with time. 

15 

16 Parameters 

17 ---------- 

18 time : datetime.time 

19 Time on the clock at the specific |Weekday|. 

20 """ 

21 

22 __value: int 

23 __time: dt.time 

24 

25 @abstractmethod 

26 def __init__(self, time: dt.time, value: int) -> None: 

27 """|Weekday| object with time.""" 

28 self.__time = time 

29 self.__value = value 

30 

31 def __repr__(self) -> str: 

32 return f"{self.__class__.__qualname__}(time={self.time!r})" 

33 

34 @property 

35 def time(self) -> dt.time: 

36 """ 

37 Return time of the |Weekday|. 

38 

39 Returns 

40 ------- 

41 datetime.time 

42 Time on the clock at the specific |Weekday|. 

43 """ 

44 return self.__time 

45 

46 @property 

47 def value(self) -> int: 

48 """ 

49 Return value of the given |Weekday|. 

50 

51 Notes 

52 ----- 

53 Enumeration analogous to datetime library (0: Monday, ... 6: Sunday). 

54 

55 Returns 

56 ------- 

57 int 

58 Value 

59 """ 

60 return self.__value 

61 

62 

63# NOTE: pylint missing-class-docstring is just silly here, given functionality and usuage of parent 

64class Monday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101 

65 __doc__ = Weekday.__doc__ 

66 

67 def __init__(self, time: dt.time = dt.time()) -> None: 

68 super().__init__(time, 0) 

69 

70 

71class Tuesday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101 

72 __doc__ = Weekday.__doc__ 

73 

74 def __init__(self, time: dt.time = dt.time()) -> None: 

75 super().__init__(time, 1) 

76 

77 

78class Wednesday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101 

79 __doc__ = Weekday.__doc__ 

80 

81 def __init__(self, time: dt.time = dt.time()) -> None: 

82 super().__init__(time, 2) 

83 

84 

85class Thursday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101 

86 __doc__ = Weekday.__doc__ 

87 

88 def __init__(self, time: dt.time = dt.time()) -> None: 

89 super().__init__(time, 3) 

90 

91 

92class Friday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101 

93 __doc__ = Weekday.__doc__ 

94 

95 def __init__(self, time: dt.time = dt.time()) -> None: 

96 super().__init__(time, 4) 

97 

98 

99class Saturday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101 

100 __doc__ = Weekday.__doc__ 

101 

102 def __init__(self, time: dt.time = dt.time()) -> None: 

103 super().__init__(time, 5) 

104 

105 

106class Sunday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101 

107 __doc__ = Weekday.__doc__ 

108 

109 def __init__(self, time: dt.time = dt.time()) -> None: 

110 super().__init__(time, 6) 

111 

112 

113_Weekday = Union[Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday] 

114 

115_weekday_mapping: dict[int, type[_Weekday]] = { 

116 0: Monday, 

117 1: Tuesday, 

118 2: Wednesday, 

119 3: Thursday, 

120 4: Friday, 

121 5: Saturday, 

122 6: Sunday, 

123} 

124 

125 

126def weekday(value: int, time: dt.time = dt.time()) -> Weekday: 

127 """ 

128 Return |Weekday| from given value with optional time. 

129 

130 Notes 

131 ----- 

132 Enumeration analogous to datetime library (0: Monday, ... 6: Sunday). 

133 

134 Parameters 

135 ---------- 

136 value : int 

137 Integer representation of |Weekday| 

138 time : datetime.time 

139 Time on the clock at the specific weekday. 

140 

141 Returns 

142 ------- 

143 Weekday 

144 |Weekday| object with given time. 

145 """ 

146 weekday_cls: type[_Weekday] = _weekday_mapping[value] 

147 weekday_instance = weekday_cls(time) 

148 return weekday_instance