test_middleware_unit_functionality() — langchain Function Reference
Architecture documentation for the test_middleware_unit_functionality() function in test_model_call_limit.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 76816fe8_cb55_de66_856f_43c776440935["test_middleware_unit_functionality()"] 43d91b2d_3fa0_6f03_b3b8_f87c64a4f30a["test_model_call_limit.py"] 76816fe8_cb55_de66_856f_43c776440935 -->|defined in| 43d91b2d_3fa0_6f03_b3b8_f87c64a4f30a style 76816fe8_cb55_de66_856f_43c776440935 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_call_limit.py lines 22–69
def test_middleware_unit_functionality() -> None:
"""Test that the middleware works as expected in isolation."""
# Test with end behavior
middleware = ModelCallLimitMiddleware(thread_limit=2, run_limit=1)
runtime = Runtime()
# Test when limits are not exceeded
state = ModelCallLimitState(messages=[], thread_model_call_count=0, run_model_call_count=0)
result = middleware.before_model(state, runtime)
assert result is None
# Test when thread limit is exceeded
state = ModelCallLimitState(messages=[], thread_model_call_count=2, run_model_call_count=0)
result = middleware.before_model(state, runtime)
assert result is not None
assert result["jump_to"] == "end"
assert "messages" in result
assert len(result["messages"]) == 1
assert "thread limit (2/2)" in result["messages"][0].content
# Test when run limit is exceeded
state = ModelCallLimitState(messages=[], thread_model_call_count=1, run_model_call_count=1)
result = middleware.before_model(state, runtime)
assert result is not None
assert result["jump_to"] == "end"
assert "messages" in result
assert len(result["messages"]) == 1
assert "run limit (1/1)" in result["messages"][0].content
# Test with error behavior
middleware_exception = ModelCallLimitMiddleware(
thread_limit=2, run_limit=1, exit_behavior="error"
)
# Test exception when thread limit exceeded
state = ModelCallLimitState(messages=[], thread_model_call_count=2, run_model_call_count=0)
with pytest.raises(ModelCallLimitExceededError) as exc_info:
middleware_exception.before_model(state, runtime)
assert "thread limit (2/2)" in str(exc_info.value)
# Test exception when run limit exceeded
state = ModelCallLimitState(messages=[], thread_model_call_count=1, run_model_call_count=1)
with pytest.raises(ModelCallLimitExceededError) as exc_info:
middleware_exception.before_model(state, runtime)
assert "run limit (1/1)" in str(exc_info.value)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_middleware_unit_functionality() do?
test_middleware_unit_functionality() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_call_limit.py.
Where is test_middleware_unit_functionality() defined?
test_middleware_unit_functionality() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_call_limit.py at line 22.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free