summaryrefslogtreecommitdiff
path: root/tests/test_schema.py
blob: 15a5f9b1082709d6a84167618aa97ef52d619f63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import annotations

import pytest

from mcp_sd15.errors import InvalidRequestError
from mcp_sd15.schema import (
    ControlMode,
    GuidedImageRequest,
    ImageSize,
    InpaintImageRequest,
    TextToImageRequest,
)


def test_text_request_applies_defaults() -> None:
    request = TextToImageRequest.create("  a castle  ", default_size="landscape_512")
    assert request.positive_prompt == "a castle"
    assert request.negative_prompt == ""
    assert request.size is ImageSize.LANDSCAPE_512
    assert request.size.dimensions == (512, 384)


@pytest.mark.parametrize("prompt", ["", "   ", None, 3])
def test_positive_prompt_is_required(prompt: object) -> None:
    with pytest.raises(InvalidRequestError, match="positive_prompt"):
        TextToImageRequest.create(prompt)  # type: ignore[arg-type]


def test_guided_mode_is_an_enum() -> None:
    request = GuidedImageRequest.create("cat", "openpose_full", "abc")
    assert request.control_mode is ControlMode.OPENPOSE_FULL
    with pytest.raises(InvalidRequestError, match="control_mode"):
        GuidedImageRequest.create("cat", "canny", "abc")


def test_inpaint_requires_both_images() -> None:
    with pytest.raises(InvalidRequestError, match="mask_image"):
        InpaintImageRequest.create("repair", "abc", "")


def test_arbitrary_dimensions_are_not_accepted() -> None:
    with pytest.raises(InvalidRequestError, match="size"):
        TextToImageRequest.create("cat", size="640x480")