# This file is auto-generated by alef — DO NOT EDIT.
# alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
# To regenerate: alef generate
# To verify freshness: alef verify --exit-code
# Issues & docs: https://github.com/kreuzberg-dev/alef

"""E2e tests for category: async."""

from pathlib import Path
import pytest  # noqa: F401
from kreuzberg import extract_bytes, ExtractionConfig


def _alef_e2e_text(value: object) -> str:
    return "" if value is None else str(value)


def _alef_e2e_item_texts(item: object) -> tuple[str, ...]:
    raw_items = getattr(item, "items", None)
    items_text = " ".join(str(value) for value in raw_items) if isinstance(raw_items, list) else ""
    return (
        _alef_e2e_text(item),
        _alef_e2e_text(getattr(item, "kind", None)),
        _alef_e2e_text(getattr(item, "name", None)),
        _alef_e2e_text(getattr(item, "source", None)),
        _alef_e2e_text(getattr(item, "alias", None)),
        _alef_e2e_text(getattr(item, "text", None)),
        _alef_e2e_text(getattr(item, "signature", None)),
        items_text,
    )


@pytest.mark.asyncio

async def test_async_extract_bytes() -> None:
    """Async extract_bytes call on PDF document."""
    content = Path("pdf/fake_memo.pdf").read_bytes()
    mime_type = "application/pdf"

    result = await extract_bytes(content, mime_type, None)
    assert result.mime_type.strip() == "application/pdf"  # noqa: S101
    assert len(result.content) >= 50  # noqa: S101


@pytest.mark.asyncio

async def test_async_extract_bytes_empty_mime() -> None:
    """extract_bytes empty MIME async."""
    with pytest.raises(Exception):  # noqa: B017
        content = Path("text/plain.txt").read_bytes()
        mime_type = ""
        config = ExtractionConfig()
        await extract_bytes(content, mime_type, config)


@pytest.mark.asyncio

async def test_async_extract_bytes_invalid_mime() -> None:
    """extract_bytes unsupported MIME async."""
    with pytest.raises(Exception):  # noqa: B017
        content = Path("text/plain.txt").read_bytes()
        mime_type = "application/x-nonexistent"
        config = ExtractionConfig()
        await extract_bytes(content, mime_type, config)
