Home / File/ test_env.py — langchain Source File

test_env.py — langchain Source File

Architecture documentation for test_env.py, a python file in the langchain codebase. 2 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  c39c8c40_f0e0_48c4_f350_1bb6e79fba06["test_env.py"]
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  c39c8c40_f0e0_48c4_f350_1bb6e79fba06 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  2b0178a6_7392_5ad0_fa5a_1b8582a9d85c["langchain_core.utils.env"]
  c39c8c40_f0e0_48c4_f350_1bb6e79fba06 --> 2b0178a6_7392_5ad0_fa5a_1b8582a9d85c
  style c39c8c40_f0e0_48c4_f350_1bb6e79fba06 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

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,
        match="Did not find not exists, "
        "please add an environment variable `__SOME_KEY_IN_ENV` which contains it, "
        "or pass `not exists` as a named parameter",
    ):
        assert (
            get_from_dict_or_env(
                {
                    "a": "foo",
                },
                "not exists",
                "__SOME_KEY_IN_ENV",
            )
            is None
        )

Subdomains

Dependencies

  • langchain_core.utils.env
  • pytest

Frequently Asked Questions

What does test_env.py do?
test_env.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_env.py?
test_env.py defines 1 function(s): test_get_from_dict_or_env.
What does test_env.py depend on?
test_env.py imports 2 module(s): langchain_core.utils.env, pytest.
Where is test_env.py in the architecture?
test_env.py is located at libs/core/tests/unit_tests/utils/test_env.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/tests/unit_tests/utils).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free