test_utils.py — langchain Source File
Architecture documentation for test_utils.py, a python file in the langchain codebase. 16 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 76328b48_c466_d255_3e8f_a315858c4c02["test_utils.py"] 0029f612_c503_ebcf_a452_a0fae8c9f2c3["os"] 76328b48_c466_d255_3e8f_a315858c4c02 --> 0029f612_c503_ebcf_a452_a0fae8c9f2c3 b7996424_637b_0b54_6edf_2e18e9c1a8bf["re"] 76328b48_c466_d255_3e8f_a315858c4c02 --> b7996424_637b_0b54_6edf_2e18e9c1a8bf 02625e10_fb78_7ecd_1ee2_105ee470faf5["sys"] 76328b48_c466_d255_3e8f_a315858c4c02 --> 02625e10_fb78_7ecd_1ee2_105ee470faf5 be45a0bb_0276_f8f1_f985_55cddb92c224["contextlib"] 76328b48_c466_d255_3e8f_a315858c4c02 --> be45a0bb_0276_f8f1_f985_55cddb92c224 43a94385_8919_6471_1068_d923b3a3c65f["copy"] 76328b48_c466_d255_3e8f_a315858c4c02 --> 43a94385_8919_6471_1068_d923b3a3c65f feec1ec4_6917_867b_d228_b134d0ff8099["typing"] 76328b48_c466_d255_3e8f_a315858c4c02 --> feec1ec4_6917_867b_d228_b134d0ff8099 23cb242e_1754_041d_200a_553fcb8abe1b["unittest.mock"] 76328b48_c466_d255_3e8f_a315858c4c02 --> 23cb242e_1754_041d_200a_553fcb8abe1b f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"] 76328b48_c466_d255_3e8f_a315858c4c02 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba dd5e7909_a646_84f1_497b_cae69735550e["pydantic"] 76328b48_c466_d255_3e8f_a315858c4c02 --> dd5e7909_a646_84f1_497b_cae69735550e c152ff20_1e21_d466_99bf_a0481a5136a6["pydantic.v1"] 76328b48_c466_d255_3e8f_a315858c4c02 --> c152ff20_1e21_d466_99bf_a0481a5136a6 4075fd38_6e5d_4fc1_617a_55ecfdfd2071["langchain_core"] 76328b48_c466_d255_3e8f_a315858c4c02 --> 4075fd38_6e5d_4fc1_617a_55ecfdfd2071 4382dc25_6fba_324a_49e2_e9742d579385["langchain_core.outputs"] 76328b48_c466_d255_3e8f_a315858c4c02 --> 4382dc25_6fba_324a_49e2_e9742d579385 bd035cf2_5933_bc0f_65e9_0dfe57627ca3["langchain_core.utils"] 76328b48_c466_d255_3e8f_a315858c4c02 --> bd035cf2_5933_bc0f_65e9_0dfe57627ca3 670e42b8_619a_4276_67e0_543963e00f8a["langchain_core.utils._merge"] 76328b48_c466_d255_3e8f_a315858c4c02 --> 670e42b8_619a_4276_67e0_543963e00f8a style 76328b48_c466_d255_3e8f_a315858c4c02 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import os
import re
import sys
from contextlib import AbstractContextManager, nullcontext
from copy import deepcopy
from typing import TYPE_CHECKING, Any
from unittest.mock import patch
import pytest
from pydantic import BaseModel, Field, SecretStr
from pydantic.v1 import BaseModel as PydanticV1BaseModel
from pydantic.v1 import Field as PydanticV1Field
from langchain_core import utils
from langchain_core.outputs import GenerationChunk
from langchain_core.utils import (
check_package_version,
from_env,
get_pydantic_field_names,
guard_import,
)
from langchain_core.utils._merge import merge_dicts, merge_lists, merge_obj
from langchain_core.utils.utils import secret_from_env
if TYPE_CHECKING:
from collections.abc import Callable
@pytest.mark.parametrize(
("package", "check_kwargs", "actual_version", "expected"),
[
("stub", {"gt_version": "0.1"}, "0.1.2", None),
("stub", {"gt_version": "0.1.2"}, "0.1.12", None),
("stub", {"gt_version": "0.1.2"}, "0.1.2", (ValueError, "> 0.1.2")),
("stub", {"gte_version": "0.1"}, "0.1.2", None),
("stub", {"gte_version": "0.1.2"}, "0.1.2", None),
],
)
def test_check_package_version(
package: str,
check_kwargs: dict[str, str | None],
actual_version: str,
expected: tuple[type[Exception], str] | None,
) -> None:
with patch("langchain_core.utils.utils.version", return_value=actual_version):
if expected is None:
check_package_version(package, **check_kwargs)
else:
with pytest.raises(expected[0], match=expected[1]):
check_package_version(package, **check_kwargs)
@pytest.mark.parametrize(
("left", "right", "expected"),
[
# Merge `None` and `1`.
({"a": None}, {"a": 1}, {"a": 1}),
# Merge `1` and `None`.
({"a": 1}, {"a": None}, {"a": 1}),
# Merge `None` and a value.
// ... (432 more lines)
Domain
Subdomains
Functions
- collections()
- test_check_package_version()
- test_from_env_with_default_error_message()
- test_from_env_with_default_value()
- test_from_env_with_env_variable()
- test_from_env_with_error_message()
- test_generation_chunk_addition_type_error()
- test_get_pydantic_field_names_v1_in_2()
- test_get_pydantic_field_names_v2_in_2()
- test_guard_import()
- test_guard_import_failure()
- test_merge_dicts()
- test_merge_dicts_0_3()
- test_merge_lists()
- test_merge_lists_all_none()
- test_merge_lists_multiple_others()
- test_merge_obj()
- test_merge_obj_tuple_raises()
- test_merge_obj_type_mismatch()
- test_merge_obj_unmergeable_values()
- test_secret_from_env_with_custom_error_message()
- test_secret_from_env_with_default_value()
- test_secret_from_env_with_env_variable()
- test_secret_from_env_with_none_default()
- test_secret_from_env_without_default_raises_error()
- test_using_secret_from_env_as_default_factory()
Dependencies
- collections.abc
- contextlib
- copy
- langchain_core
- langchain_core.outputs
- langchain_core.utils
- langchain_core.utils._merge
- langchain_core.utils.utils
- os
- pydantic
- pydantic.v1
- pytest
- re
- sys
- typing
- unittest.mock
Source
Frequently Asked Questions
What does test_utils.py do?
test_utils.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What functions are defined in test_utils.py?
test_utils.py defines 26 function(s): collections, test_check_package_version, test_from_env_with_default_error_message, test_from_env_with_default_value, test_from_env_with_env_variable, test_from_env_with_error_message, test_generation_chunk_addition_type_error, test_get_pydantic_field_names_v1_in_2, test_get_pydantic_field_names_v2_in_2, test_guard_import, and 16 more.
What does test_utils.py depend on?
test_utils.py imports 16 module(s): collections.abc, contextlib, copy, langchain_core, langchain_core.outputs, langchain_core.utils, langchain_core.utils._merge, langchain_core.utils.utils, and 8 more.
Where is test_utils.py in the architecture?
test_utils.py is located at libs/core/tests/unit_tests/utils/test_utils.py (domain: LangChainCore, subdomain: MessageInterface, 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