Skip to content

Commit 30f22e6

Browse files
Copilotxylar
andcommitted
Update Pillow version constraint to support 10.x, 11.x, and 12.x
Co-authored-by: xylar <[email protected]>
1 parent ebb65cc commit 30f22e6

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

dev-spec.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ nco >=4.8.1,!=5.2.6
2020
netcdf4
2121
numpy >=2.0,<3.0
2222
pandas
23-
pillow >=10.0.0,<11.0.0
23+
pillow >=10.0.0,<13.0.0
2424
progressbar2
2525
pyproj
2626
pyremap >=2.0.0,<3.0.0
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# This software is open source software available under the BSD-3 license.
2+
#
3+
# Copyright (c) 2022 Triad National Security, LLC. All rights reserved.
4+
# Copyright (c) 2022 Lawrence Livermore National Security, LLC. All rights
5+
# reserved.
6+
# Copyright (c) 2022 UT-Battelle, LLC. All rights reserved.
7+
#
8+
# Additional copyright and license information can be found in the LICENSE file
9+
# distributed with this code, or at
10+
# https://raw.githubusercontent.com/MPAS-Dev/MPAS-Analysis/main/LICENSE
11+
12+
import os
13+
import tempfile
14+
import unittest
15+
from pathlib import Path
16+
17+
from PIL import Image
18+
19+
20+
# Import the function directly to avoid mpas_analysis.test dependencies
21+
import sys
22+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../..'))
23+
from mpas_analysis.shared.html.image_xml import _generate_thumbnails
24+
25+
26+
class TestThumbnailGeneration(unittest.TestCase):
27+
"""Test thumbnail generation with Pillow"""
28+
29+
def test_generate_thumbnails_horizontal(self):
30+
"""Test thumbnail generation for horizontal images"""
31+
with tempfile.TemporaryDirectory() as tmpdir:
32+
# Create a horizontal test image
33+
test_image = Image.new('RGB', (1200, 600), color='blue')
34+
image_filename = 'test_horizontal.png'
35+
image_path = Path(tmpdir) / image_filename
36+
test_image.save(image_path)
37+
38+
# Generate thumbnails
39+
imageSize, thumbnailSize, orientation = _generate_thumbnails(
40+
image_filename, tmpdir
41+
)
42+
43+
# Verify results
44+
self.assertEqual(imageSize, (1200, 600))
45+
self.assertEqual(orientation, 'horiz')
46+
self.assertEqual(thumbnailSize[1], 120) # height should be 120
47+
48+
# Check thumbnail files exist
49+
thumbnail_dir = Path(tmpdir) / 'thumbnails'
50+
self.assertTrue(thumbnail_dir.exists())
51+
self.assertTrue((thumbnail_dir / 'test_horizontal.jpg').exists())
52+
self.assertTrue((thumbnail_dir / 'fixed_test_horizontal.jpg').exists())
53+
54+
def test_generate_thumbnails_vertical(self):
55+
"""Test thumbnail generation for vertical images"""
56+
with tempfile.TemporaryDirectory() as tmpdir:
57+
# Create a vertical test image
58+
test_image = Image.new('RGB', (400, 800), color='green')
59+
image_filename = 'test_vertical.png'
60+
image_path = Path(tmpdir) / image_filename
61+
test_image.save(image_path)
62+
63+
# Generate thumbnails
64+
imageSize, thumbnailSize, orientation = _generate_thumbnails(
65+
image_filename, tmpdir
66+
)
67+
68+
# Verify results
69+
self.assertEqual(imageSize, (400, 800))
70+
self.assertEqual(orientation, 'vert')
71+
self.assertEqual(thumbnailSize[1], 320) # height should be 320
72+
73+
# Check thumbnail files exist
74+
thumbnail_dir = Path(tmpdir) / 'thumbnails'
75+
self.assertTrue(thumbnail_dir.exists())
76+
self.assertTrue((thumbnail_dir / 'test_vertical.jpg').exists())
77+
self.assertTrue((thumbnail_dir / 'fixed_test_vertical.jpg').exists())
78+
79+
def test_image_lanczos_constant(self):
80+
"""Test that Image.LANCZOS constant is available"""
81+
# This test ensures that Image.LANCZOS is available across
82+
# Pillow versions 10.x, 11.x, and 12.x
83+
self.assertTrue(hasattr(Image, 'LANCZOS'))
84+
self.assertIsNotNone(Image.LANCZOS)
85+
86+
# Test that resize works with LANCZOS
87+
test_image = Image.new('RGB', (100, 100), color='red')
88+
resized = test_image.resize((50, 50), Image.LANCZOS)
89+
self.assertEqual(resized.size, (50, 50))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ dependencies = [
5353
"netcdf4",
5454
"numpy >=2.0,<3.0",
5555
"pandas",
56-
"pillow >=10.0.0,<11.0.0",
56+
"pillow >=10.0.0,<13.0.0",
5757
"progressbar2",
5858
"pyproj",
5959
"python-dateutil",

0 commit comments

Comments
 (0)