test_string.py — langchain Source File
Architecture documentation for test_string.py, a python file in the langchain codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR ee8d1d01_dc2d_5490_76fd_b7e7c266afd3["test_string.py"] 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] ee8d1d01_dc2d_5490_76fd_b7e7c266afd3 --> 120e2591_3e15_b895_72b6_cb26195e40a6 0b794afa_fd3d_a810_77fd_ed00bf90e394["packaging"] ee8d1d01_dc2d_5490_76fd_b7e7c266afd3 --> 0b794afa_fd3d_a810_77fd_ed00bf90e394 e10bb307_3784_1031_cf6b_680e7c362c93["langchain_core.prompts.string"] ee8d1d01_dc2d_5490_76fd_b7e7c266afd3 --> e10bb307_3784_1031_cf6b_680e7c362c93 1014fe78_cb2c_fde4_a624_ae899aa7ca8e["langchain_core.utils.pydantic"] ee8d1d01_dc2d_5490_76fd_b7e7c266afd3 --> 1014fe78_cb2c_fde4_a624_ae899aa7ca8e style ee8d1d01_dc2d_5490_76fd_b7e7c266afd3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import pytest
from packaging import version
from langchain_core.prompts.string import get_template_variables, mustache_schema
from langchain_core.utils.pydantic import PYDANTIC_VERSION
PYDANTIC_VERSION_AT_LEAST_29 = version.parse("2.9") <= PYDANTIC_VERSION
@pytest.mark.skipif(
not PYDANTIC_VERSION_AT_LEAST_29,
reason=(
"Only test with most recent version of pydantic. "
"Pydantic introduced small fixes to generated JSONSchema on minor versions."
),
)
def test_mustache_schema_parent_child() -> None:
template = "{{x.y}} {{x}}"
expected = {
"$defs": {
"x": {
"properties": {"y": {"default": None, "title": "Y", "type": "string"}},
"title": "x",
"type": "object",
}
},
"properties": {"x": {"$ref": "#/$defs/x", "default": None}},
"title": "PromptInput",
"type": "object",
}
actual = mustache_schema(template).model_json_schema()
assert expected == actual
def test_get_template_variables_mustache_nested() -> None:
template = "Hello {{user.name}}, your role is {{user.role}}"
template_format = "mustache"
# Returns only the top-level key for mustache templates
expected = ["user"]
actual = get_template_variables(template, template_format)
assert actual == expected
Domain
Subdomains
Dependencies
- langchain_core.prompts.string
- langchain_core.utils.pydantic
- packaging
- pytest
Source
Frequently Asked Questions
What does test_string.py do?
test_string.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_string.py?
test_string.py defines 2 function(s): test_get_template_variables_mustache_nested, test_mustache_schema_parent_child.
What does test_string.py depend on?
test_string.py imports 4 module(s): langchain_core.prompts.string, langchain_core.utils.pydantic, packaging, pytest.
Where is test_string.py in the architecture?
test_string.py is located at libs/core/tests/unit_tests/prompts/test_string.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/core/tests/unit_tests/prompts).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free