mirror of https://github.com/hwchase17/langchain
core[minor]: Support multiple keys in get_from_dict_or_env (#23086)
Support passing multiple keys for ge_from_dict_or_envpull/23132/head
parent
226802f0c4
commit
aa6415aa7d
@ -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
|
||||||
|
)
|
Loading…
Reference in New Issue