2023-05-20 19:43:32 +00:00
|
|
|
from unittest import mock
|
|
|
|
|
2022-09-17 22:49:38 +00:00
|
|
|
from click.testing import CliRunner
|
|
|
|
|
2023-02-20 18:49:47 +00:00
|
|
|
from imaginairy import ImaginePrompt, LazyLoadingImage, surprise_me
|
2023-02-25 20:32:50 +00:00
|
|
|
from imaginairy.cli.edit import edit_cmd
|
|
|
|
from imaginairy.cli.edit_demo import edit_demo_cmd
|
|
|
|
from imaginairy.cli.imagine import imagine_cmd
|
|
|
|
from imaginairy.cli.main import aimg
|
|
|
|
from imaginairy.cli.upscale import upscale_cmd
|
2023-05-20 19:43:32 +00:00
|
|
|
from imaginairy.utils.model_cache import GPUModelCache
|
2022-09-17 22:49:38 +00:00
|
|
|
from tests import TESTS_FOLDER
|
|
|
|
|
|
|
|
|
2023-05-20 19:43:32 +00:00
|
|
|
def test_imagine_cmd(monkeypatch):
|
|
|
|
monkeypatch.setattr(GPUModelCache, "make_gpu_space", mock.MagicMock())
|
2022-09-17 22:49:38 +00:00
|
|
|
runner = CliRunner()
|
|
|
|
result = runner.invoke(
|
|
|
|
imagine_cmd,
|
2022-09-28 00:04:16 +00:00
|
|
|
[
|
|
|
|
"gold coins",
|
|
|
|
"--steps",
|
2023-02-20 18:49:47 +00:00
|
|
|
"2",
|
2022-09-28 00:04:16 +00:00
|
|
|
"--outdir",
|
|
|
|
f"{TESTS_FOLDER}/test_output",
|
|
|
|
"--seed",
|
|
|
|
"703425280",
|
2023-11-16 03:46:56 +00:00
|
|
|
# "--model",
|
|
|
|
# "empty",
|
2023-02-20 18:49:47 +00:00
|
|
|
"--outdir",
|
|
|
|
f"{TESTS_FOLDER}/test_output",
|
2022-09-28 00:04:16 +00:00
|
|
|
],
|
2022-09-17 22:49:38 +00:00
|
|
|
)
|
2023-11-29 06:35:49 +00:00
|
|
|
assert result.exit_code == 0, (result.stdout, result.stderr)
|
2023-02-18 23:40:04 +00:00
|
|
|
|
|
|
|
|
2023-05-20 19:43:32 +00:00
|
|
|
def test_edit_cmd(monkeypatch):
|
|
|
|
monkeypatch.setattr(GPUModelCache, "make_gpu_space", mock.MagicMock())
|
2023-02-18 23:40:04 +00:00
|
|
|
runner = CliRunner()
|
|
|
|
result = runner.invoke(
|
2023-02-25 20:32:50 +00:00
|
|
|
edit_cmd,
|
2023-02-18 23:40:04 +00:00
|
|
|
[
|
|
|
|
f"{TESTS_FOLDER}/data/dog.jpg",
|
|
|
|
"--steps",
|
|
|
|
"1",
|
|
|
|
"-p",
|
|
|
|
"turn the dog into a cat",
|
2023-11-29 06:35:49 +00:00
|
|
|
# "--model",
|
|
|
|
# "empty",
|
2023-02-20 18:49:47 +00:00
|
|
|
"--outdir",
|
|
|
|
f"{TESTS_FOLDER}/test_output",
|
|
|
|
],
|
|
|
|
)
|
2023-11-29 06:35:49 +00:00
|
|
|
assert result.exit_code == 0, (result.stdout, result.stderr)
|
2023-02-20 18:49:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_aimg_shell():
|
|
|
|
runner = CliRunner()
|
|
|
|
result = runner.invoke(
|
|
|
|
aimg,
|
|
|
|
[],
|
|
|
|
)
|
|
|
|
assert "Starting imaginAIry shell" in result.output
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_edit_demo(monkeypatch):
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
|
|
def mock_surprise_me_prompts(*args, **kwargs):
|
|
|
|
return [
|
|
|
|
ImaginePrompt(
|
|
|
|
"",
|
|
|
|
steps=1,
|
|
|
|
width=256,
|
|
|
|
height=256,
|
2023-11-29 06:35:49 +00:00
|
|
|
# model="empty",
|
2023-02-20 18:49:47 +00:00
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
monkeypatch.setattr(surprise_me, "surprise_me_prompts", mock_surprise_me_prompts)
|
2023-05-20 19:43:32 +00:00
|
|
|
monkeypatch.setattr(GPUModelCache, "make_gpu_space", mock.MagicMock())
|
2023-02-20 18:49:47 +00:00
|
|
|
surprise_me.generic_prompts = []
|
|
|
|
result = runner.invoke(
|
2023-02-25 20:32:50 +00:00
|
|
|
edit_demo_cmd,
|
2023-02-20 18:49:47 +00:00
|
|
|
[
|
|
|
|
f"{TESTS_FOLDER}/data/dog.jpg",
|
|
|
|
"--outdir",
|
|
|
|
f"{TESTS_FOLDER}/test_output",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_upscale(monkeypatch):
|
|
|
|
from imaginairy.enhancers import upscale_realesrgan
|
|
|
|
|
|
|
|
def mock_upscale_image(*args, **kwargs):
|
|
|
|
return LazyLoadingImage(filepath=f"{TESTS_FOLDER}/data/dog.jpg")
|
|
|
|
|
|
|
|
monkeypatch.setattr(upscale_realesrgan, "upscale_image", mock_upscale_image)
|
|
|
|
runner = CliRunner()
|
|
|
|
result = runner.invoke(
|
|
|
|
upscale_cmd,
|
|
|
|
[
|
|
|
|
f"{TESTS_FOLDER}/data/dog.jpg",
|
|
|
|
"--outdir",
|
|
|
|
f"{TESTS_FOLDER}/test_output",
|
2023-02-18 23:40:04 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
assert result.exit_code == 0
|