53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
import io
|
|
|
|
from PIL import Image
|
|
|
|
from app.services.image_processor import (
|
|
ImageProcessingTimeout,
|
|
create_variants_with_timeout,
|
|
)
|
|
|
|
|
|
def make_test_image() -> bytes:
|
|
output = io.BytesIO()
|
|
|
|
image = Image.new("RGB", (640, 400), (120, 160, 200))
|
|
image.save(output, format="PNG")
|
|
|
|
return output.getvalue()
|
|
|
|
|
|
def main() -> None:
|
|
image_data = make_test_image()
|
|
|
|
print("Test 1: normal image processing")
|
|
|
|
variants = create_variants_with_timeout(
|
|
image_data,
|
|
timeout_seconds=30,
|
|
)
|
|
|
|
names = sorted(variant.name for variant in variants)
|
|
|
|
assert names == ["crop", "optimized", "thumbnail"], names
|
|
|
|
print(f"PASS: created variants: {names}")
|
|
|
|
print("Test 2: forced processing timeout")
|
|
|
|
try:
|
|
create_variants_with_timeout(
|
|
image_data,
|
|
timeout_seconds=0.001,
|
|
)
|
|
except ImageProcessingTimeout:
|
|
print("PASS: child process was terminated after timeout")
|
|
else:
|
|
raise AssertionError("Expected ImageProcessingTimeout")
|
|
|
|
print("ALL TESTS PASSED")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|