async def test_insert_method_setting():
    """Test that insert_method is respected for blocks."""
    # Create blocks with different insert methods
    system_block = TextMemoryBlock(
        name="system_block",
        priority=1,
    )
    user_block = TextMemoryBlock(
        name="user_block",
        priority=2,
    )

    # Create memory with user insert method
    memory = Memory(
        token_limit=1000,
        token_flush_size=700,
        chat_history_token_ratio=0.9,
        session_id="test_insert_methods",
        insert_method=InsertMethod.USER,
        memory_blocks=[system_block, user_block],
    )

    # Insert a user message
    await memory.aput(ChatMessage(role="user", content="Test message!"))

    # Get messages
    messages = await memory.aget()

    # Should have both system and user messages with appropriate content
    system_msgs = [msg for msg in messages if msg.role == "system"]
    user_msgs = [msg for msg in messages if msg.role == "user"]

    assert len(user_msgs) > 0
    assert len(system_msgs) == 0

    # Create memory with system insert method
    memory = Memory(
        token_limit=1000,
        token_flush_size=700,
        chat_history_token_ratio=0.9,
        session_id="test_insert_methods",
        insert_method=InsertMethod.SYSTEM,
        memory_blocks=[system_block, user_block],
    )

    # Get messages
    messages = await memory.aget()

    # Should have both system and user messages with appropriate content
    system_msgs = [msg for msg in messages if msg.role == "system"]
    user_msgs = [msg for msg in messages if msg.role == "user"]

    assert len(user_msgs) == 0
    assert len(system_msgs) > 0
Test that insert_method is respected for blocks.
llama-index-core/tests/memory/test_memory_blocks_base.py