Skip to content

Commit

Permalink
Don't raise an error on unknown enum value (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
iMicknl authored Apr 1, 2022
1 parent 44256c2 commit 77664aa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
22 changes: 22 additions & 0 deletions pyoverkiz/enums/execution.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import logging
from enum import Enum, unique

_LOGGER = logging.getLogger(__name__)


@unique
class ExecutionType(str, Enum):
UNKNOWN = "UNKNOWN"
IMMEDIATE_EXECUTION = "Immediate execution"
DELAYED_EXECUTION = "Delayed execution"
TECHNICAL_EXECUTION = "Technical execution"
PLANNING = "Planning"
RAW_TRIGGER_SERVER = "Raw trigger (Server)"
RAW_TRIGGER_GATEWAY = "Raw trigger (Gateway)"

@classmethod
def _missing_(cls, value): # type: ignore
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
return cls.UNKNOWN


@unique
class ExecutionState(str, Enum):
UNKNOWN = "UNKNOWN"
INITIALIZED = "INITIALIZED"
NOT_TRANSMITTED = "NOT_TRANSMITTED"
TRANSMITTED = "TRANSMITTED"
Expand All @@ -22,9 +32,16 @@ class ExecutionState(str, Enum):
QUEUED_GATEWAY_SIDE = "QUEUED_GATEWAY_SIDE"
QUEUED_SERVER_SIDE = "QUEUED_SERVER_SIDE"

@classmethod
def _missing_(cls, value): # type: ignore
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
return cls.UNKNOWN


@unique
class ExecutionSubType(str, Enum):
UNKNOWN = "UNKNOWN"
_ = "-"
ACTION_GROUP = "ACTION_GROUP"
ACTION_GROUP_SEQUENCE = "ACTION_GROUP_SEQUENCE"
DAWN_TRIGGER = "DAWN_TRIGGER"
Expand All @@ -37,3 +54,8 @@ class ExecutionSubType(str, Enum):
NO_ERROR = "NO_ERROR"
P2P_COMMAND_REGULATION = "P2P_COMMAND_REGULATION"
TIME_TRIGGER = "TIME_TRIGGER"

@classmethod
def _missing_(cls, value): # type: ignore
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
return cls.UNKNOWN
19 changes: 18 additions & 1 deletion tests/test_enums.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from pyoverkiz.enums import EventName, FailureType, GatewaySubType, GatewayType
from pyoverkiz.enums import (
EventName,
ExecutionSubType,
ExecutionType,
FailureType,
GatewaySubType,
GatewayType,
)


class TestGatewayType:
Expand Down Expand Up @@ -30,3 +37,13 @@ def test_missing(self):
class TestFailureType:
def test_missing(self):
assert FailureType(99) == FailureType.UNKNOWN


class TestExecutionType:
def test_missing(self):
assert ExecutionType("test") == ExecutionType.UNKNOWN


class TestExecutionSubType:
def test_missing(self):
assert ExecutionSubType("test") == ExecutionSubType.UNKNOWN

0 comments on commit 77664aa

Please sign in to comment.