Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cognite/extractorutils/unstable/configuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,15 @@ class LogLevel(Enum):
INFO = "INFO"
DEBUG = "DEBUG"

@classmethod
def _missing_(cls, value: object) -> "LogLevel":
if not isinstance(value, str):
raise ValueError(f"{value} is not a valid log level")
for member in cls:
if member.value == value.upper():
return member
raise ValueError(f"{value} is not a valid log level")


class LogFileHandlerConfig(ConfigModel):
"""
Expand Down
12 changes: 12 additions & 0 deletions tests/test_unstable/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cognite.extractorutils.unstable.configuration.loaders import ConfigFormat, load_io
from cognite.extractorutils.unstable.configuration.models import (
ConnectionConfig,
LogLevel,
TimeIntervalConfig,
_ClientCredentialsConfig,
)
Expand Down Expand Up @@ -212,3 +213,14 @@ def test_from_env() -> None:

# Check that the produces cogniteclient object is valid
assert len(client.assets.list(limit=1)) == 1


def test_setting_log_level_from_any_case() -> None:
log_level = LogLevel("DEBUG")
assert log_level == LogLevel.DEBUG

log_level = LogLevel("debug")
assert log_level == LogLevel.DEBUG

with pytest.raises(ValueError):
LogLevel("not-a-log-level")
Loading