mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-03 03:59:42 +00:00
core[minor]: Support multiple keys in get_from_dict_or_env (#23086)
Support passing multiple keys for ge_from_dict_or_env
This commit is contained in:
64
libs/core/tests/unit_tests/utils/test_env.py
Normal file
64
libs/core/tests/unit_tests/utils/test_env.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import pytest
|
||||
|
||||
from langchain_core.utils.env import get_from_dict_or_env
|
||||
|
||||
|
||||
def test_get_from_dict_or_env() -> None:
|
||||
assert (
|
||||
get_from_dict_or_env(
|
||||
{
|
||||
"a": "foo",
|
||||
},
|
||||
["a"],
|
||||
"__SOME_KEY_IN_ENV",
|
||||
)
|
||||
== "foo"
|
||||
)
|
||||
|
||||
assert (
|
||||
get_from_dict_or_env(
|
||||
{
|
||||
"a": "foo",
|
||||
},
|
||||
["b", "a"],
|
||||
"__SOME_KEY_IN_ENV",
|
||||
)
|
||||
== "foo"
|
||||
)
|
||||
|
||||
assert (
|
||||
get_from_dict_or_env(
|
||||
{
|
||||
"a": "foo",
|
||||
},
|
||||
"a",
|
||||
"__SOME_KEY_IN_ENV",
|
||||
)
|
||||
== "foo"
|
||||
)
|
||||
|
||||
assert (
|
||||
get_from_dict_or_env(
|
||||
{
|
||||
"a": "foo",
|
||||
},
|
||||
"not exists",
|
||||
"__SOME_KEY_IN_ENV",
|
||||
default="default",
|
||||
)
|
||||
== "default"
|
||||
)
|
||||
|
||||
# Not the most obvious behavior, but
|
||||
# this is how it works right now
|
||||
with pytest.raises(ValueError):
|
||||
assert (
|
||||
get_from_dict_or_env(
|
||||
{
|
||||
"a": "foo",
|
||||
},
|
||||
"not exists",
|
||||
"__SOME_KEY_IN_ENV",
|
||||
)
|
||||
is None
|
||||
)
|
Reference in New Issue
Block a user