Home / File/ test_usage.py — langchain Source File

test_usage.py — langchain Source File

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

File python LangChainCore ApiManagement 3 imports 5 functions

Entity Profile

Dependency Diagram

graph LR
  65a4c465_09cd_7d1a_7340_aaf3bfe764ad["test_usage.py"]
  ba56ae45_39a0_5895_3909_d9469cd3e893["operator"]
  65a4c465_09cd_7d1a_7340_aaf3bfe764ad --> ba56ae45_39a0_5895_3909_d9469cd3e893
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  65a4c465_09cd_7d1a_7340_aaf3bfe764ad --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  ce75cbbc_bf05_803c_93a7_022c806f78de["langchain_core.utils.usage"]
  65a4c465_09cd_7d1a_7340_aaf3bfe764ad --> ce75cbbc_bf05_803c_93a7_022c806f78de
  style 65a4c465_09cd_7d1a_7340_aaf3bfe764ad fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import operator

import pytest

from langchain_core.utils.usage import _dict_int_op


def test_dict_int_op_add() -> None:
    left = {"a": 1, "b": 2}
    right = {"b": 3, "c": 4}
    result = _dict_int_op(left, right, operator.add)
    assert result == {"a": 1, "b": 5, "c": 4}


def test_dict_int_op_subtract() -> None:
    left = {"a": 5, "b": 10}
    right = {"a": 2, "b": 3, "c": 1}
    result = _dict_int_op(left, right, lambda x, y: max(x - y, 0))
    assert result == {"a": 3, "b": 7, "c": 0}


def test_dict_int_op_nested() -> None:
    left = {"a": 1, "b": {"c": 2, "d": 3}}
    right = {"a": 2, "b": {"c": 1, "e": 4}}
    result = _dict_int_op(left, right, operator.add)
    assert result == {"a": 3, "b": {"c": 3, "d": 3, "e": 4}}


def test_dict_int_op_max_depth_exceeded() -> None:
    left = {"a": {"b": {"c": 1}}}
    right = {"a": {"b": {"c": 2}}}
    with pytest.raises(
        ValueError, match="max_depth=2 exceeded, unable to combine dicts"
    ):
        _dict_int_op(left, right, operator.add, max_depth=2)


def test_dict_int_op_invalid_types() -> None:
    left = {"a": 1, "b": "string"}
    right = {"a": 2, "b": 3}
    with pytest.raises(
        ValueError,
        match="Only dict and int values are supported",
    ):
        _dict_int_op(left, right, operator.add)

Domain

Subdomains

Dependencies

  • langchain_core.utils.usage
  • operator
  • pytest

Frequently Asked Questions

What does test_usage.py do?
test_usage.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in test_usage.py?
test_usage.py defines 5 function(s): test_dict_int_op_add, test_dict_int_op_invalid_types, test_dict_int_op_max_depth_exceeded, test_dict_int_op_nested, test_dict_int_op_subtract.
What does test_usage.py depend on?
test_usage.py imports 3 module(s): langchain_core.utils.usage, operator, pytest.
Where is test_usage.py in the architecture?
test_usage.py is located at libs/core/tests/unit_tests/utils/test_usage.py (domain: LangChainCore, subdomain: ApiManagement, 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