Coverage for o2/models/legacy_approach.py: 61%

33 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-05-16 11:18 +0000

1from enum import Enum 

2from typing import TYPE_CHECKING, Union 

3 

4if TYPE_CHECKING: 

5 pass 

6 

7 

8class LegacyApproachAbbreviation(str, Enum): 

9 """The abbreviations of the legacy combined mode.""" 

10 

11 COMBINED = "CO" 

12 CALENDAR_ONLY = "CA" 

13 RESOURCES_ONLY = "AR" 

14 CALENDAR_FIRST = "CAAR" 

15 RESOURCES_FIRST = "ARCA" 

16 

17 

18class LegacyApproach(str, Enum): 

19 """The status of the legacy combined mode. 

20 

21 See Settings.legacy_combined_mode_status for more information. 

22 """ 

23 

24 COMBINED = "COMBINED" 

25 

26 CALENDAR_ONLY = "CALENDAR_ONLY" 

27 RESOURCES_ONLY = "RESOURCES_ONLY" 

28 

29 CALENDAR_FIRST = "CALENDAR_FIRST" 

30 RESOURCES_FIRST = "RESOURCES_FIRST" 

31 

32 @property 

33 def calendar_is_disabled(self) -> bool: 

34 """Return whether the calendar is disabled in the combined mode.""" 

35 return self == LegacyApproach.RESOURCES_ONLY 

36 

37 @property 

38 def resource_is_disabled(self) -> bool: 

39 """Return whether the resources are disabled in the combined mode.""" 

40 return self == LegacyApproach.CALENDAR_ONLY 

41 

42 @staticmethod 

43 def from_abbreviation(abbreviation: Union[str, LegacyApproachAbbreviation]) -> "LegacyApproach": 

44 """Get the LegacyApproach from its abbreviation.""" 

45 if abbreviation == "CAAR": 

46 return LegacyApproach.CALENDAR_FIRST 

47 if abbreviation == "ARCA": 

48 return LegacyApproach.RESOURCES_FIRST 

49 if abbreviation == "CO": 

50 return LegacyApproach.COMBINED 

51 if abbreviation == "CA": 

52 return LegacyApproach.CALENDAR_ONLY 

53 if abbreviation == "AR": 

54 return LegacyApproach.RESOURCES_ONLY 

55 

56 raise ValueError(f"Unknown abbreviation: {abbreviation}")