imaginAIry/tests/test_schema/test_controlnetinput.py
Bryce 9b95e8b0b6 perf: improve cli startup time
- do not provide automatically imported api functions and objects in `imaginairy` root module
- horrible hack to overcome horrible design choices by easy_install/setuptools

The hack modifies the installed script to remove the __import__ pkg_resources line

If we don't do this then the scripts will be slow to start up because of
pkg_resources.require() which is called by setuptools to ensure the
"correct" version of the package is installed.

before modification example:
```
__requires__ = 'imaginAIry==14.0.0b5'
__import__('pkg_resources').require('imaginAIry==14.0.0b5')
__file__ = '/home/user/projects/imaginairy/imaginairy/bin/aimg'
with open(__file__) as f:
    exec(compile(f.read(), __file__, 'exec'))
```
2023-12-12 20:54:39 -08:00

40 lines
1.3 KiB
Python

import pytest
from pydantic import ValidationError
from imaginairy.schema import ControlInput, LazyLoadingImage
from tests import TESTS_FOLDER
@pytest.fixture(name="lazy_img")
def _lazy_img():
return LazyLoadingImage(filepath=f"{TESTS_FOLDER}/data/red.png")
def test_controlnetinput_basic(lazy_img):
ControlInput(mode="canny", image=lazy_img)
ControlInput(mode="canny", image_raw=lazy_img)
def test_controlnetinput_invalid_mode(lazy_img):
with pytest.raises(ValueError, match=r".*Invalid controlnet mode.*"):
ControlInput(mode="pizza", image=lazy_img)
def test_controlnetinput_both_images(lazy_img):
with pytest.raises(ValueError, match=r".*cannot specify both.*"):
ControlInput(mode="canny", image=lazy_img, image_raw=lazy_img)
def test_controlnetinput_filepath_input(lazy_img):
"""Test that we accept filepaths here."""
c = ControlInput(mode="canny", image=f"{TESTS_FOLDER}/data/red.png")
c.image.convert("RGB")
c = ControlInput(mode="canny", image_raw=f"{TESTS_FOLDER}/data/red.png")
c.image_raw.convert("RGB")
def test_controlnetinput_big(lazy_img):
ControlInput(mode="canny", strength=2)
with pytest.raises(ValidationError, match=r".*float_type.*"):
ControlInput(mode="canny", strength=2**2048)