File size: 1,389 Bytes
0b2abd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
from PIL import Image
from app import process_image

def test_process_image():
    # Create a large dummy image
    large_img_path = "test_large.png"
    Image.new('RGB', (2000, 2000), color='red').save(large_img_path)
    
    # Process it
    processed_path = process_image(large_img_path)
    
    # Check if a new file was created
    assert processed_path != large_img_path, "Should have returned a new path"
    assert "cropped" in processed_path, "New path should contain 'cropped'"
    
    # Check dimensions
    with Image.open(processed_path) as img:
        assert img.size == (1024, 1024), f"Expected 1024x1024, got {img.size}"
        
    print("Large image test passed!")
    
    # Create a small dummy image
    small_img_path = "test_small.png"
    Image.new('RGB', (800, 800), color='blue').save(small_img_path)
    
    # Process it
    processed_path_small = process_image(small_img_path)
    
    # Check if it returned the same path
    assert processed_path_small == small_img_path, "Should have returned original path"
    
    print("Small image test passed!")
    
    # Cleanup
    if os.path.exists(large_img_path):
        os.remove(large_img_path)
    if os.path.exists(processed_path):
        os.remove(processed_path)
    if os.path.exists(small_img_path):
        os.remove(small_img_path)

if __name__ == "__main__":
    test_process_image()