2023-08-09 21:36:47 +03:00
|
|
|
from os import remove
|
|
|
|
from pathlib import Path
|
2023-08-10 15:31:33 +03:00
|
|
|
from subprocess import run
|
2023-08-09 21:36:47 +03:00
|
|
|
|
|
|
|
from PIL.Image import Image
|
|
|
|
|
|
|
|
from huepaper import generate
|
|
|
|
from huepaper.utils import save_image
|
|
|
|
|
|
|
|
|
|
|
|
def test_generation():
|
2023-08-10 15:19:56 +03:00
|
|
|
image = generate()
|
|
|
|
assert isinstance(image, Image)
|
|
|
|
|
|
|
|
|
2023-08-10 15:22:10 +03:00
|
|
|
def test_saving():
|
|
|
|
image = generate(
|
|
|
|
500,
|
|
|
|
500,
|
|
|
|
hue_max=1.0,
|
|
|
|
lum_min=0.3,
|
|
|
|
lum_max=0.6,
|
|
|
|
sat_min=0.8,
|
|
|
|
sat_max=1.0,
|
|
|
|
lines=0.0,
|
|
|
|
)
|
|
|
|
save_image(image, Path("tests/image.jpg"))
|
|
|
|
assert Path("tests/image.jpg").exists()
|
|
|
|
remove(Path("tests/image.jpg"))
|
|
|
|
|
|
|
|
|
2023-08-10 15:31:33 +03:00
|
|
|
def test_shell():
|
|
|
|
assert (
|
|
|
|
run(
|
|
|
|
[
|
|
|
|
"huepaper",
|
|
|
|
"-hue",
|
|
|
|
"0.3",
|
|
|
|
"-lmin",
|
|
|
|
"0.5",
|
|
|
|
"-lmax",
|
|
|
|
"0.3",
|
|
|
|
"-l",
|
|
|
|
"0.5",
|
|
|
|
"-p",
|
|
|
|
"64x36",
|
|
|
|
"-o",
|
|
|
|
"tests/image.jpg",
|
|
|
|
],
|
|
|
|
check=False,
|
|
|
|
).returncode
|
|
|
|
== 0
|
|
|
|
)
|
|
|
|
remove(Path("tests/image.jpg"))
|
|
|
|
|
|
|
|
|
2023-08-10 15:19:56 +03:00
|
|
|
def test_generation_example_1():
|
|
|
|
image = generate(color="lightgreen")
|
|
|
|
assert isinstance(image, Image)
|
|
|
|
|
|
|
|
|
|
|
|
def test_generation_example_2():
|
|
|
|
image = generate(color="#ff7f50", lines_bright=0.05)
|
|
|
|
assert isinstance(image, Image)
|
|
|
|
|
|
|
|
|
|
|
|
def test_generation_example_3():
|
|
|
|
image = generate(hue_max=1.0, lum_min=0.3, lum_max=0.6, sat_min=0.8, sat_max=1.0)
|
|
|
|
assert isinstance(image, Image)
|
|
|
|
|
|
|
|
|
|
|
|
def test_generation_example_4():
|
|
|
|
image = generate(hue_max=0.3, lum_min=0.5, lum_max=0.5, lines=0.5, pixelate="64x36")
|
|
|
|
assert isinstance(image, Image)
|
|
|
|
|
|
|
|
|
|
|
|
def test_generation_example_5():
|
|
|
|
image = generate(
|
|
|
|
lines=0.3,
|
|
|
|
lines_bright=0.1,
|
|
|
|
lines_dark=0.1,
|
|
|
|
emblem=Path("tests/assets/emblem.png"),
|
|
|
|
)
|
|
|
|
assert isinstance(image, Image)
|