# 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: detection."""

from pathlib import Path
import pytest  # noqa: F401
from kreuzberg import detect_mime_type_from_bytes, get_extensions_for_mime


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,
    )


def test_detect_mime_bytes_html() -> None:
    """Detect HTML MIME from bytes."""
    content = Path("html/html.html").read_bytes()

    _ = detect_mime_type_from_bytes(content)


def test_detect_mime_bytes_pdf() -> None:
    """Detect PDF MIME type from bytes."""
    content = Path("pdf/fake_memo.pdf").read_bytes()

    _ = detect_mime_type_from_bytes(content)


def test_detect_mime_bytes_png() -> None:
    """Detect PNG MIME type from bytes."""
    content = Path("images/test_hello_world.png").read_bytes()

    _ = detect_mime_type_from_bytes(content)


def test_get_extensions_unknown_mime() -> None:
    """get_extensions unknown MIME."""
    with pytest.raises(Exception):  # noqa: B017
        mime_type = "application/x-totally-unknown"
        get_extensions_for_mime(mime_type)
