Skip to content

Commit

Permalink
styles
Browse files Browse the repository at this point in the history
  • Loading branch information
cwharris committed May 20, 2024
1 parent b917f29 commit 16434a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
1 change: 0 additions & 1 deletion morpheus/llm/services/nemo_llm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import asyncio
import logging
import os
import typing
import warnings

Expand Down
12 changes: 8 additions & 4 deletions morpheus/utils/env_config_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ def __init__(self, value: str | None = None, use_env: bool = True):
self._source = EnvConfigValueSource.ENV_OVERRIDE

if value is None:
message = "value must not be None, but provided value was None and no environment-based default or override was found."
message = ("value must not be None, but provided value was None and no environment-based default or "
"override was found.")

if _ENV_KEY is None:
if self.__class__._ENV_KEY is None:
raise ValueError(message)

raise ValueError(f"{message} Try passing a value to the constructor, or setting the `{_ENV_KEY}` environment variable.")

raise ValueError(
f"{message} Try passing a value to the constructor, or setting the `{self.__class__._ENV_KEY}` "
"environment variable."
)

else:
if value is None:
Expand Down
18 changes: 9 additions & 9 deletions tests/test_env_config_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_env_driven_value():
assert str(config) == "default.api.com"
assert config.value == "default.api.com"
assert config.source == EnvConfigValueSource.ENV_DEFAULT
assert config.use_env == True
assert config.use_env

with pytest.raises(ValueError):
config = EnvDrivenValue(use_env=False)
Expand All @@ -43,21 +43,21 @@ def test_env_driven_value():
assert str(config) == "api.com"
assert config.value == "api.com"
assert config.source == EnvConfigValueSource.CONSTRUCTOR
assert config.use_env == True
assert config.use_env

with mock.patch.dict(os.environ, clear=True, values={"OVERRIDE": "override.api.com"}):

config = EnvDrivenValue("api.com")
assert str(config) == "override.api.com"
assert config.value == "override.api.com"
assert config.source == EnvConfigValueSource.ENV_OVERRIDE
assert config.use_env == True
assert config.use_env

config = EnvDrivenValue("api.com", use_env=False)
assert str(config) == "api.com"
assert config.value == "api.com"
assert config.source == EnvConfigValueSource.CONSTRUCTOR
assert config.use_env == False
assert not config.use_env


class EnvDriverValueNoOverride(EnvConfigValue):
Expand All @@ -71,7 +71,7 @@ def test_env_driven_value_no_override():
assert str(config) == "default.api.com"
assert config.value == "default.api.com"
assert config.source == EnvConfigValueSource.ENV_DEFAULT
assert config.use_env == True
assert config.use_env

with pytest.raises(ValueError):
config = EnvDriverValueNoOverride(use_env=False)
Expand All @@ -80,15 +80,15 @@ def test_env_driven_value_no_override():
assert str(config) == "api.com"
assert config.value == "api.com"
assert config.source == EnvConfigValueSource.CONSTRUCTOR
assert config.use_env == True
assert config.use_env

with mock.patch.dict(os.environ, clear=True, values={"OVERRIDE": "override.api.com"}):

config = EnvDriverValueNoOverride("api.com")
assert str(config) == "api.com"
assert config.value == "api.com"
assert config.source == EnvConfigValueSource.CONSTRUCTOR
assert config.use_env == True
assert config.use_env


class EnvDrivenValueNoDefault(EnvConfigValue):
Expand All @@ -105,12 +105,12 @@ def test_env_driven_value_no_default():
assert str(config) == "api.com"
assert config.value == "api.com"
assert config.source == EnvConfigValueSource.CONSTRUCTOR
assert config.use_env == True
assert config.use_env

with mock.patch.dict(os.environ, clear=True, values={"OVERRIDE": "override.api.com"}):

config = EnvDrivenValueNoDefault("api.com")
assert str(config) == "override.api.com"
assert config.value == "override.api.com"
assert config.source == EnvConfigValueSource.ENV_OVERRIDE
assert config.use_env == True
assert config.use_env

0 comments on commit 16434a8

Please sign in to comment.