test_combined_memory.py — langchain Source File
Architecture documentation for test_combined_memory.py, a python file in the langchain codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 16f6ef76_f6f5_7069_fd00_506dc596dcc1["test_combined_memory.py"] 67ec3255_645e_8b6e_1eff_1eb3c648ed95["re"] 16f6ef76_f6f5_7069_fd00_506dc596dcc1 --> 67ec3255_645e_8b6e_1eff_1eb3c648ed95 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] 16f6ef76_f6f5_7069_fd00_506dc596dcc1 --> 120e2591_3e15_b895_72b6_cb26195e40a6 28c42233_7878_c3a0_1c4a_70b88062bf23["langchain_classic.memory"] 16f6ef76_f6f5_7069_fd00_506dc596dcc1 --> 28c42233_7878_c3a0_1c4a_70b88062bf23 style 16f6ef76_f6f5_7069_fd00_506dc596dcc1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Test for CombinedMemory class."""
import re
import pytest
from langchain_classic.memory import CombinedMemory, ConversationBufferMemory
@pytest.fixture
def example_memory() -> list[ConversationBufferMemory]:
example_1 = ConversationBufferMemory(memory_key="foo")
example_2 = ConversationBufferMemory(memory_key="bar")
example_3 = ConversationBufferMemory(memory_key="bar")
return [example_1, example_2, example_3]
def test_basic_functionality(example_memory: list[ConversationBufferMemory]) -> None:
"""Test basic functionality of methods exposed by class."""
combined_memory = CombinedMemory(memories=[example_memory[0], example_memory[1]])
assert combined_memory.memory_variables == ["foo", "bar"]
assert combined_memory.load_memory_variables({}) == {"foo": "", "bar": ""}
combined_memory.save_context(
{"input": "Hello there"},
{"output": "Hello, how can I help you?"},
)
assert combined_memory.load_memory_variables({}) == {
"foo": "Human: Hello there\nAI: Hello, how can I help you?",
"bar": "Human: Hello there\nAI: Hello, how can I help you?",
}
combined_memory.clear()
assert combined_memory.load_memory_variables({}) == {"foo": "", "bar": ""}
def test_repeated_memory_var(example_memory: list[ConversationBufferMemory]) -> None:
"""Test raising error when repeated memory variables found."""
with pytest.raises(
ValueError,
match=re.escape(
"Value error, The same variables {'bar'} are found in "
"multiplememory object, which is not allowed by CombinedMemory."
),
):
CombinedMemory(memories=[example_memory[1], example_memory[2]])
Domain
Subdomains
Dependencies
- langchain_classic.memory
- pytest
- re
Source
Frequently Asked Questions
What does test_combined_memory.py do?
test_combined_memory.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_combined_memory.py?
test_combined_memory.py defines 3 function(s): example_memory, test_basic_functionality, test_repeated_memory_var.
What does test_combined_memory.py depend on?
test_combined_memory.py imports 3 module(s): langchain_classic.memory, pytest, re.
Where is test_combined_memory.py in the architecture?
test_combined_memory.py is located at libs/langchain/tests/unit_tests/memory/test_combined_memory.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/langchain/tests/unit_tests/memory).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free