cddb07a176
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
from typing import Any, Literal, Optional, Union
|
|
|
|
import pytest
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class TestModel(BaseModel):
|
|
foo: Literal["bar"] = "bar"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"input_type, expected",
|
|
[
|
|
(str, False),
|
|
(list[str], False),
|
|
(list[dict[str, Any]], False),
|
|
(list[None], False),
|
|
(list[dict[str, None]], False),
|
|
(Any, False),
|
|
(True, False),
|
|
(False, False),
|
|
(Union[str, False], False),
|
|
(Union[str, True], False),
|
|
(None, False),
|
|
(str | None, True),
|
|
(Union[str, None], True),
|
|
(Optional[str], True),
|
|
(str | int | None, True),
|
|
(None | str | int, True),
|
|
(Union[None, str], True),
|
|
(Optional[str], True),
|
|
(Optional[int], True),
|
|
(Optional[str], True),
|
|
(TestModel | None, True),
|
|
(Union[TestModel, None], True),
|
|
(Optional[TestModel], True),
|
|
],
|
|
)
|
|
def test_is_optional(input_type: Any, expected: bool) -> None:
|
|
"""
|
|
Test the is_optional function.
|
|
"""
|
|
from invokeai.app.invocations.baseinvocation import is_optional
|
|
|
|
result = is_optional(input_type)
|
|
assert result == expected, f"Expected {expected} but got {result} for input type {input_type}"
|