Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_key_from_envs():
assert get_key_from_envs({"K": "v"}, "K") == "v"
assert get_key_from_envs([{"K": "v"}, {"L": "w"}], "L") == "w"
assert get_key_from_envs({"K": "v"}, "Q") is NO_VALUE
# first match wins
envs = [{"K": "v"}, {"L": "w"}, {"K": "z"}]
assert get_key_from_envs(envs, "K") == "v"
# works with reversed iterator
envs = reversed([{"L": "v"}, {"L": "w"}])
assert get_key_from_envs(envs, "L") == "w"
# works with os.environ
os.environ["DUDE_ABIDES"] = "yeah, man"
assert get_key_from_envs(os.environ, "DUDE_ABIDES") == "yeah, man"
def test_get_key_from_envs():
assert get_key_from_envs({"K": "v"}, "K") == "v"
assert get_key_from_envs([{"K": "v"}, {"L": "w"}], "L") == "w"
assert get_key_from_envs({"K": "v"}, "Q") is NO_VALUE
# first match wins
envs = [{"K": "v"}, {"L": "w"}, {"K": "z"}]
assert get_key_from_envs(envs, "K") == "v"
# works with reversed iterator
envs = reversed([{"L": "v"}, {"L": "w"}])
assert get_key_from_envs(envs, "L") == "w"
# works with os.environ
os.environ["DUDE_ABIDES"] = "yeah, man"
assert get_key_from_envs(os.environ, "DUDE_ABIDES") == "yeah, man"
def test_get_key_from_envs():
assert get_key_from_envs({"K": "v"}, "K") == "v"
assert get_key_from_envs([{"K": "v"}, {"L": "w"}], "L") == "w"
assert get_key_from_envs({"K": "v"}, "Q") is NO_VALUE
# first match wins
envs = [{"K": "v"}, {"L": "w"}, {"K": "z"}]
assert get_key_from_envs(envs, "K") == "v"
# works with reversed iterator
envs = reversed([{"L": "v"}, {"L": "w"}])
assert get_key_from_envs(envs, "L") == "w"
# works with os.environ
os.environ["DUDE_ABIDES"] = "yeah, man"
assert get_key_from_envs(os.environ, "DUDE_ABIDES") == "yeah, man"
def test_get_key_from_envs():
assert get_key_from_envs({"K": "v"}, "K") == "v"
assert get_key_from_envs([{"K": "v"}, {"L": "w"}], "L") == "w"
assert get_key_from_envs({"K": "v"}, "Q") is NO_VALUE
# first match wins
envs = [{"K": "v"}, {"L": "w"}, {"K": "z"}]
assert get_key_from_envs(envs, "K") == "v"
# works with reversed iterator
envs = reversed([{"L": "v"}, {"L": "w"}])
assert get_key_from_envs(envs, "L") == "w"
# works with os.environ
os.environ["DUDE_ABIDES"] = "yeah, man"
assert get_key_from_envs(os.environ, "DUDE_ABIDES") == "yeah, man"
def test_get_key_from_envs():
assert get_key_from_envs({"K": "v"}, "K") == "v"
assert get_key_from_envs([{"K": "v"}, {"L": "w"}], "L") == "w"
assert get_key_from_envs({"K": "v"}, "Q") is NO_VALUE
# first match wins
envs = [{"K": "v"}, {"L": "w"}, {"K": "z"}]
assert get_key_from_envs(envs, "K") == "v"
# works with reversed iterator
envs = reversed([{"L": "v"}, {"L": "w"}])
assert get_key_from_envs(envs, "L") == "w"
# works with os.environ
os.environ["DUDE_ABIDES"] = "yeah, man"
assert get_key_from_envs(os.environ, "DUDE_ABIDES") == "yeah, man"
def test_get_key_from_envs():
assert get_key_from_envs({"K": "v"}, "K") == "v"
assert get_key_from_envs([{"K": "v"}, {"L": "w"}], "L") == "w"
assert get_key_from_envs({"K": "v"}, "Q") is NO_VALUE
# first match wins
envs = [{"K": "v"}, {"L": "w"}, {"K": "z"}]
assert get_key_from_envs(envs, "K") == "v"
# works with reversed iterator
envs = reversed([{"L": "v"}, {"L": "w"}])
assert get_key_from_envs(envs, "L") == "w"
# works with os.environ
os.environ["DUDE_ABIDES"] = "yeah, man"
assert get_key_from_envs(os.environ, "DUDE_ABIDES") == "yeah, man"
def get(self, key, namespace=None):
"""Retrieve value for key."""
if not self.path:
return NO_VALUE
logger.debug("Searching %r for key: %s, namepsace: %s", self, key, namespace)
full_key = generate_uppercase_key(key, namespace)
return get_key_from_envs(self.cfg, full_key)
def get(self, key, namespace=None):
"""Retrieve value for key."""
if not self.path:
return NO_VALUE
# NOTE(willkg): The "main" section is considered the root mainspace.
namespace = namespace or ["main"]
logger.debug("Searching %r for key: %s, namespace: %s", self, key, namespace)
full_key = generate_uppercase_key(key, namespace)
return get_key_from_envs(self.cfg, full_key)