Skip to content

Commit

Permalink
add another test for env_config_value
Browse files Browse the repository at this point in the history
  • Loading branch information
cwharris committed May 21, 2024
1 parent 7b60670 commit e4adea6
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tests/test_env_config_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from morpheus.utils.env_config_value import EnvConfigValue
from morpheus.utils.env_config_value import EnvConfigValueSource


class EnvDrivenValue(EnvConfigValue):
_ENV_KEY = "DEFAULT"
_ENV_KEY_OVERRIDE = "OVERRIDE"
Expand All @@ -31,7 +30,6 @@ def test_env_driven_value():
with mock.patch.dict(os.environ, clear=True, values={"DEFAULT": "default.api.com"}):

config = EnvDrivenValue()
assert str(config) == "default.api.com"
assert config.value == "default.api.com"
assert config.source == EnvConfigValueSource.ENV_DEFAULT
assert config.use_env
Expand All @@ -40,21 +38,18 @@ def test_env_driven_value():
config = EnvDrivenValue(use_env=False)

config = EnvDrivenValue("api.com")
assert str(config) == "api.com"
assert config.value == "api.com"
assert config.source == EnvConfigValueSource.CONSTRUCTOR
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

config = EnvDrivenValue("api.com", use_env=False)
assert str(config) == "api.com"
assert config.value == "api.com"
assert config.source == EnvConfigValueSource.CONSTRUCTOR
assert not config.use_env
Expand All @@ -68,7 +63,6 @@ def test_env_driven_value_no_override():
with mock.patch.dict(os.environ, clear=True, values={"DEFAULT": "default.api.com"}):

config = EnvDriverValueNoOverride()
assert str(config) == "default.api.com"
assert config.value == "default.api.com"
assert config.source == EnvConfigValueSource.ENV_DEFAULT
assert config.use_env
Expand All @@ -77,15 +71,13 @@ def test_env_driven_value_no_override():
config = EnvDriverValueNoOverride(use_env=False)

config = EnvDriverValueNoOverride("api.com")
assert str(config) == "api.com"
assert config.value == "api.com"
assert config.source == EnvConfigValueSource.CONSTRUCTOR
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
Expand All @@ -102,15 +94,21 @@ def test_env_driven_value_no_default():
config = EnvDrivenValueNoDefault()

config = EnvDrivenValueNoDefault("api.com")
assert str(config) == "api.com"
assert config.value == "api.com"
assert config.source == EnvConfigValueSource.CONSTRUCTOR
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


class EnvOptionalValue(EnvConfigValue):
_ALLOW_NONE = True


def test_env_optional_value():
EnvOptionalValue()

0 comments on commit e4adea6

Please sign in to comment.