|
1 | 1 | from io import BytesIO |
2 | 2 | from PIL import Image, ImageDraw, GifImagePlugin |
3 | 3 | from easy_thumbnails import processors |
4 | | -from unittest import TestCase |
| 4 | +from unittest import TestCase, mock |
5 | 5 |
|
6 | 6 | from easy_thumbnails.files import get_thumbnailer |
7 | 7 |
|
@@ -93,18 +93,13 @@ def test_gif_with_mode_p(self): |
93 | 93 | thumbnail = t.get_thumbnail({'size': (500, 50), 'crop': True}) |
94 | 94 | self.assertTrue(thumbnail.image.is_animated) |
95 | 95 |
|
| 96 | + @mock.patch("PIL.GifImagePlugin.LOADING_STRATEGY", GifImagePlugin.LoadingStrategy.RGB_ALWAYS) |
96 | 97 | def test_gif_with_mode_p__gif_plug_loading_strategy_rgb_always(self): |
| 98 | + print("m",GifImagePlugin.LOADING_STRATEGY) |
97 | 99 | image_path = "easy_thumbnails/tests/files/animated_mode_p.gif" |
98 | | - default_loading_strategy = GifImagePlugin.LOADING_STRATEGY |
99 | | - try: |
100 | | - GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_ALWAYS |
101 | | - with open(image_path, "rb") as im: |
102 | | - t = get_thumbnailer(im, image_path) |
103 | | - # Should not fail because of wrong mode and should still be animated. |
104 | | - # https://github.com/SmileyChris/easy-thumbnails/issues/653 |
105 | | - thumbnail = t.get_thumbnail({'size': (500, 50), 'crop': True}) |
106 | | - self.assertTrue(thumbnail.image.is_animated) |
107 | | - except Exception: |
108 | | - GifImagePlugin.LOADING_STRATEGY = default_loading_strategy |
109 | | - raise |
110 | | - GifImagePlugin.LOADING_STRATEGY = default_loading_strategy |
| 100 | + with open(image_path, "rb") as im: |
| 101 | + t = get_thumbnailer(im, image_path) |
| 102 | + # Should not fail because of wrong mode and should still be animated. |
| 103 | + # https://github.com/SmileyChris/easy-thumbnails/issues/653 |
| 104 | + thumbnail = t.get_thumbnail({'size': (500, 50), 'crop': True}) |
| 105 | + self.assertTrue(thumbnail.image.is_animated) |
0 commit comments