test_xml_parser.py — langchain Source File
Architecture documentation for test_xml_parser.py, a python file in the langchain codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR a1505d99_fe37_04cb_8c81_2640a51076f6["test_xml_parser.py"] 3888b2bf_bffe_7c16_770f_a406d400119c["importlib"] a1505d99_fe37_04cb_8c81_2640a51076f6 --> 3888b2bf_bffe_7c16_770f_a406d400119c cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] a1505d99_fe37_04cb_8c81_2640a51076f6 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] a1505d99_fe37_04cb_8c81_2640a51076f6 --> 120e2591_3e15_b895_72b6_cb26195e40a6 75137834_4ba7_dc43_7ec5_182c05eceedf["langchain_core.exceptions"] a1505d99_fe37_04cb_8c81_2640a51076f6 --> 75137834_4ba7_dc43_7ec5_182c05eceedf 6ea8ed8c_4ab1_5e30_e53f_6219182045af["langchain_core.output_parsers.xml"] a1505d99_fe37_04cb_8c81_2640a51076f6 --> 6ea8ed8c_4ab1_5e30_e53f_6219182045af style a1505d99_fe37_04cb_8c81_2640a51076f6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Test XMLOutputParser."""
import importlib
from collections.abc import AsyncIterator, Iterable
import pytest
from langchain_core.exceptions import OutputParserException
from langchain_core.output_parsers.xml import XMLOutputParser
DATA = """
<foo>
<bar>
<baz></baz>
<baz>slim.shady</baz>
</bar>
<baz>tag</baz>
</foo>"""
WITH_XML_HEADER = f"""<?xml version="1.0" encoding="UTF-8"?>
{DATA}"""
IN_XML_TAGS_WITH_XML_HEADER = f"""
```xml
{WITH_XML_HEADER}
```
"""
IN_XML_TAGS_WITH_HEADER_AND_TRAILING_JUNK = f"""
Some random text
```xml
{WITH_XML_HEADER}
```
More random text
"""
DEF_RESULT_EXPECTED = {
"foo": [
{"bar": [{"baz": None}, {"baz": "slim.shady"}]},
{"baz": "tag"},
],
}
async def _test_parser(parser: XMLOutputParser, content: str) -> None:
"""Test parser."""
assert parser.parse(content) == DEF_RESULT_EXPECTED
assert await parser.aparse(content) == DEF_RESULT_EXPECTED
assert list(parser.transform(iter(content))) == [
{"foo": [{"bar": [{"baz": None}]}]},
{"foo": [{"bar": [{"baz": "slim.shady"}]}]},
{"foo": [{"baz": "tag"}]},
]
chunks = [chunk async for chunk in parser.atransform(_as_iter(content))]
assert list(chunks) == [
// ... (99 more lines)
Domain
Subdomains
Functions
Dependencies
- collections.abc
- importlib
- langchain_core.exceptions
- langchain_core.output_parsers.xml
- pytest
Source
Frequently Asked Questions
What does test_xml_parser.py do?
test_xml_parser.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in test_xml_parser.py?
test_xml_parser.py defines 7 function(s): _as_iter, _test_parser, test_root_only_xml_output_parser, test_xml_output_parser, test_xml_output_parser_defused, test_xml_output_parser_fail, tests_billion_laughs_attack.
What does test_xml_parser.py depend on?
test_xml_parser.py imports 5 module(s): collections.abc, importlib, langchain_core.exceptions, langchain_core.output_parsers.xml, pytest.
Where is test_xml_parser.py in the architecture?
test_xml_parser.py is located at libs/core/tests/unit_tests/output_parsers/test_xml_parser.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/tests/unit_tests/output_parsers).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free