"""
{{ display_name }} - Automation tests.

This module contains tests for the data pipeline automation.
"""

import pytest

from torivers_sdk.testing import LocalSandbox
from main import {{ class_name }}


@pytest.fixture
def sandbox():
    """Create a local sandbox for testing."""
    return LocalSandbox()


@pytest.fixture
def automation():
    """Create an automation instance."""
    return {{ class_name }}()


@pytest.mark.asyncio
async def test_pipeline_execution(sandbox, automation):
    """Test complete pipeline execution."""
    result = await sandbox.run(
        automation,
        input_data={
            "data_url": "https://example.com/sample.csv",
        },
    )

    assert result.success
    assert "_blocks" in result.output_data
    blocks = result.output_data["_blocks"]
    assert len(blocks) > 0
    assert blocks[0]["type"] == "json_data"
    data = blocks[0]["data"]
    assert "row_count" in data
    assert "column_count" in data
    assert "statistics" in data


@pytest.mark.asyncio
async def test_pipeline_with_options(sandbox, automation):
    """Test pipeline with custom options."""
    result = await sandbox.run(
        automation,
        input_data={
            "data_url": "https://example.com/data.csv",
            "options": {
                "delimiter": ";",
                "skip_rows": 1,
            },
        },
    )

    assert result.success
    assert "_blocks" in result.output_data


@pytest.mark.asyncio
async def test_output_format(sandbox, automation):
    """Test that output matches expected format."""
    result = await sandbox.run(
        automation,
        input_data={
            "data_url": "https://example.com/sample.csv",
        },
    )

    assert result.success
    assert result.output_data.get("_version") == 1
    blocks = result.output_data["_blocks"]
    assert isinstance(blocks, list)
    assert all("type" in b and "label" in b for b in blocks)
