test_with_config() — langchain Function Reference
Architecture documentation for the test_with_config() function in test_runnable.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD c815e74e_a60f_9f8b_d559_154085048c7a["test_with_config()"] 26df6ad8_0189_51d0_c3c1_6c3248893ff5["test_runnable.py"] c815e74e_a60f_9f8b_d559_154085048c7a -->|defined in| 26df6ad8_0189_51d0_c3c1_6c3248893ff5 593bb72a_4695_6c93_b95c_e277aca006ae["batch()"] c815e74e_a60f_9f8b_d559_154085048c7a -->|calls| 593bb72a_4695_6c93_b95c_e277aca006ae fb618d44_c03b_ea8b_385b_2278dfb173d4["invoke()"] c815e74e_a60f_9f8b_d559_154085048c7a -->|calls| fb618d44_c03b_ea8b_385b_2278dfb173d4 style c815e74e_a60f_9f8b_d559_154085048c7a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/runnables/test_runnable.py lines 1171–1276
def test_with_config(mocker: MockerFixture) -> None:
fake = FakeRunnable()
spy = mocker.spy(fake, "invoke")
assert fake.with_config(tags=["a-tag"]).invoke("hello") == 5
assert spy.call_args_list == [
mocker.call(
"hello",
{"tags": ["a-tag"], "metadata": {}, "configurable": {}},
),
]
spy.reset_mock()
fake_1 = RunnablePassthrough[Any]()
fake_2 = RunnablePassthrough[Any]()
spy_seq_step = mocker.spy(fake_1.__class__, "invoke")
sequence = fake_1.with_config(tags=["a-tag"]) | fake_2.with_config(
tags=["b-tag"], max_concurrency=5
)
assert sequence.invoke("hello") == "hello"
assert len(spy_seq_step.call_args_list) == 2
for i, call in enumerate(spy_seq_step.call_args_list):
assert call.args[1] == "hello"
if i == 0:
assert call.args[2].get("tags") == ["a-tag"]
assert call.args[2].get("max_concurrency") is None
else:
assert call.args[2].get("tags") == ["b-tag"]
assert call.args[2].get("max_concurrency") == 5
mocker.stop(spy_seq_step)
assert [
*fake.with_config(tags=["a-tag"]).stream(
"hello", {"metadata": {"key": "value"}}
)
] == [5]
assert spy.call_args_list == [
mocker.call(
"hello",
{"tags": ["a-tag"], "metadata": {"key": "value"}, "configurable": {}},
),
]
spy.reset_mock()
assert fake.with_config(recursion_limit=5).batch(
["hello", "wooorld"], [{"tags": ["a-tag"]}, {"metadata": {"key": "value"}}]
) == [5, 7]
assert len(spy.call_args_list) == 2
for i, call in enumerate(
sorted(spy.call_args_list, key=lambda x: 0 if x.args[0] == "hello" else 1)
):
assert call.args[0] == ("hello" if i == 0 else "wooorld")
if i == 0:
assert call.args[1].get("recursion_limit") == 5
assert call.args[1].get("tags") == ["a-tag"]
assert call.args[1].get("metadata") == {}
else:
assert call.args[1].get("recursion_limit") == 5
assert call.args[1].get("tags") == []
assert call.args[1].get("metadata") == {"key": "value"}
spy.reset_mock()
assert sorted(
c
for c in fake.with_config(recursion_limit=5).batch_as_completed(
["hello", "wooorld"],
[{"tags": ["a-tag"]}, {"metadata": {"key": "value"}}],
)
) == [(0, 5), (1, 7)]
assert len(spy.call_args_list) == 2
for i, call in enumerate(
sorted(spy.call_args_list, key=lambda x: 0 if x.args[0] == "hello" else 1)
):
assert call.args[0] == ("hello" if i == 0 else "wooorld")
if i == 0:
assert call.args[1].get("recursion_limit") == 5
assert call.args[1].get("tags") == ["a-tag"]
Domain
Subdomains
Source
Frequently Asked Questions
What does test_with_config() do?
test_with_config() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_with_config() defined?
test_with_config() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 1171.
What does test_with_config() call?
test_with_config() calls 2 function(s): batch, invoke.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free