def test_python_code_splitter() -> None:
    """Test case for code splitting using python."""
    if "CI" in os.environ:
        return

    code_splitter = CodeHierarchyNodeParser(
        language="python", skeleton=False, chunk_min_characters=0
    )

    text = """\
class Foo:
    def bar() -> None:
        print("bar")

    async def baz():
        print("baz")"""

    text_node = TextNode(
        text=text,
        metadata={
            "module": "example.foo",
        },
    )

    chunks: List[TextNode] = code_splitter.get_nodes_from_documents([text_node])

    # This is the module scope
    assert chunks[0].text == text
    assert chunks[0].metadata["module"] == "example.foo"
    assert chunks[0].metadata["inclusive_scopes"] == []
    assert NodeRelationship.PARENT not in chunks[0].relationships
    assert [c.node_id for c in chunks[0].relationships[NodeRelationship.CHILD]] == [
        chunks[1].id_
    ]
    assert isinstance(chunks[0].relationships[NodeRelationship.SOURCE], RelatedNodeInfo)
    assert (
        cast(RelatedNodeInfo, chunks[0].relationships[NodeRelationship.SOURCE]).node_id
        == text_node.id_
    )
    assert NodeRelationship.PREVIOUS not in chunks[0].relationships
    assert NodeRelationship.NEXT not in chunks[0].relationships

    # This is the class scope
    assert chunks[1].text == text
    assert chunks[1].metadata["module"] == "example.foo"
    assert chunks[1].metadata["inclusive_scopes"] == [
        {"name": "Foo", "type": "class_definition", "signature": "class Foo:"}
    ]
    assert isinstance(chunks[1].relationships[NodeRelationship.PARENT], RelatedNodeInfo)
    assert (
        cast(RelatedNodeInfo, chunks[1].relationships[NodeRelationship.PARENT]).node_id
        == chunks[0].id_
    )
    assert [c.node_id for c in chunks[1].relationships[NodeRelationship.CHILD]] == [
        chunks[2].id_,
        chunks[3].id_,
    ]
    assert isinstance(chunks[1].relationships[NodeRelationship.SOURCE], RelatedNodeInfo)
    assert (
        cast(RelatedNodeInfo, chunks[1].relationships[NodeRelationship.SOURCE]).node_id
        == text_node.id_
    )
    assert NodeRelationship.PREVIOUS not in chunks[1].relationships
    assert NodeRelationship.NEXT not in chunks[1].relationships

    # This is the first method scope
    assert (
        chunks[2].text
        == """\
    def bar() -> None:
        print("bar")"""
    )
    assert chunks[2].metadata["module"] == "example.foo"
    assert chunks[2].metadata["inclusive_scopes"] == [
        {"name": "Foo", "type": "class_definition", "signature": "class Foo:"},
        {
            "name": "bar",
            "type": "function_definition",
            "signature": "def bar() -> None:",
        },
    ]
    assert isinstance(chunks[2].relationships[NodeRelationship.PARENT], RelatedNodeInfo)
    assert (
        cast(RelatedNodeInfo, chunks[2].relationships[NodeRelationship.PARENT]).node_id
        == chunks[1].id_
    )
    assert chunks[2].relationships[NodeRelationship.CHILD] == []
    assert isinstance(chunks[2].relationships[NodeRelationship.SOURCE], RelatedNodeInfo)
    assert (
        cast(RelatedNodeInfo, chunks[2].relationships[NodeRelationship.SOURCE]).node_id
        == text_node.id_
    )
    assert NodeRelationship.PREVIOUS not in chunks[2].relationships
    assert NodeRelationship.NEXT not in chunks[2].relationships

    # This is the second method scope
    assert (
        chunks[3].text
        == """\
    async def baz():
        print("baz")"""
    )
    assert chunks[3].metadata["module"] == "example.foo"
    assert chunks[3].metadata["inclusive_scopes"] == [
        {"name": "Foo", "type": "class_definition", "signature": "class Foo:"},
        {"name": "baz", "type": "function_definition", "signature": "async def baz():"},
    ]
    assert isinstance(chunks[3].relationships[NodeRelationship.PARENT], RelatedNodeInfo)
    assert (
        cast(RelatedNodeInfo, chunks[3].relationships[NodeRelationship.PARENT]).node_id
        == chunks[1].id_
    )
    assert chunks[3].relationships[NodeRelationship.CHILD] == []
    assert isinstance(chunks[3].relationships[NodeRelationship.SOURCE], RelatedNodeInfo)
    assert (
        cast(RelatedNodeInfo, chunks[3].relationships[NodeRelationship.SOURCE]).node_id
        == text_node.id_
    )
    assert NodeRelationship.PREVIOUS not in chunks[3].relationships
    assert NodeRelationship.NEXT not in chunks[3].relationships
Test case for code splitting using python.
llama-index-packs/llama-index-packs-code-hierarchy/tests/test_code_hierarchy_no_skeleton.py