1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Removed PIL compatability layer per deprecation timeline.

refs #19934.
This commit is contained in:
Tim Graham
2014-03-21 10:54:53 -04:00
parent 6d1ae5e27c
commit 4965a77407
15 changed files with 48 additions and 211 deletions

View File

@@ -8,7 +8,6 @@ import tempfile
import unittest
import zlib
from django.core.exceptions import ImproperlyConfigured
from django.core.files import File
from django.core.files.move import file_move_safe
from django.core.files.base import ContentFile
@@ -18,10 +17,11 @@ from django.utils._os import upath
from django.utils import six
try:
from django.utils.image import Image
from django.core.files import images
except ImproperlyConfigured:
from PIL import Image
except ImportError:
Image = None
else:
from django.core.files import images
class FileTests(unittest.TestCase):
@@ -112,7 +112,7 @@ class DimensionClosingBug(unittest.TestCase):
"""
Test that get_image_dimensions() properly closes files (#8817)
"""
@unittest.skipUnless(Image, "Pillow/PIL not installed")
@unittest.skipUnless(Image, "Pillow not installed")
def test_not_closing_of_files(self):
"""
Open files passed into get_image_dimensions() should stay opened.
@@ -123,7 +123,7 @@ class DimensionClosingBug(unittest.TestCase):
finally:
self.assertTrue(not empty_io.closed)
@unittest.skipUnless(Image, "Pillow/PIL not installed")
@unittest.skipUnless(Image, "Pillow not installed")
def test_closing_of_filenames(self):
"""
get_image_dimensions() called with a filename should closed the file.
@@ -163,7 +163,7 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase):
Test that get_image_dimensions() works properly after various calls
using a file handler (#11158)
"""
@unittest.skipUnless(Image, "Pillow/PIL not installed")
@unittest.skipUnless(Image, "Pillow not installed")
def test_multiple_calls(self):
"""
Multiple calls of get_image_dimensions() should return the same size.
@@ -177,7 +177,7 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase):
self.assertEqual(image_pil.size, size_1)
self.assertEqual(size_1, size_2)
@unittest.skipUnless(Image, "Pillow/PIL not installed")
@unittest.skipUnless(Image, "Pillow not installed")
def test_bug_19457(self):
"""
Regression test for #19457

View File

@@ -4,7 +4,6 @@ from __future__ import unicode_literals
import unittest
from django.core.checks import Error
from django.core.exceptions import ImproperlyConfigured
from django.db import connection, models
from .base import IsolatedModelsTestCase
@@ -379,8 +378,8 @@ class ImageFieldTests(IsolatedModelsTestCase):
def test_pillow_installed(self):
try:
import django.utils.image # NOQA
except ImproperlyConfigured:
from PIL import Image # NOQA
except ImportError:
pillow_installed = False
else:
pillow_installed = True

View File

@@ -2,11 +2,9 @@ import os
import tempfile
import warnings
from django.core.exceptions import ImproperlyConfigured
try:
from django.utils.image import Image
except ImproperlyConfigured:
from PIL import Image
except ImportError:
Image = None
from django.core.files.storage import FileSystemStorage
@@ -114,7 +112,7 @@ class VerboseNameField(models.Model):
field9 = models.FileField("verbose field9", upload_to="unused")
field10 = models.FilePathField("verbose field10")
field11 = models.FloatField("verbose field11")
# Don't want to depend on Pillow/PIL in this test
# Don't want to depend on Pillow in this test
#field_image = models.ImageField("verbose field")
field12 = models.IntegerField("verbose field12")
with warnings.catch_warnings(record=True) as w:
@@ -151,7 +149,7 @@ class Document(models.Model):
###############################################################################
# ImageField
# If Pillow/PIL available, do these tests.
# If Pillow available, do these tests.
if Image:
class TestImageFieldFile(ImageFieldFile):
"""

View File

@@ -20,7 +20,7 @@ if Image:
PersonDimensionsFirst, PersonTwoImages, TestImageFieldFile)
from .models import temp_storage_dir
else:
# Pillow/PIL not available, create dummy classes (tests will be skipped anyway)
# Pillow not available, create dummy classes (tests will be skipped anyway)
class Person():
pass
PersonWithHeight = PersonWithHeightAndWidth = PersonDimensionsFirst = Person
@@ -93,7 +93,7 @@ class ImageFieldTestMixin(object):
self.assertEqual(getattr(instance, height_field_name), height)
@skipIf(Image is None, "Pillow/PIL is required to test ImageField")
@skipIf(Image is None, "Pillow is required to test ImageField")
class ImageFieldTests(ImageFieldTestMixin, TestCase):
"""
Tests for ImageField that don't need to be run with each of the
@@ -180,7 +180,7 @@ class ImageFieldTests(ImageFieldTestMixin, TestCase):
self.assertEqual(p.mugshot, loaded_p.mugshot)
@skipIf(Image is None, "Pillow/PIL is required to test ImageField")
@skipIf(Image is None, "Pillow is required to test ImageField")
class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
"""
Tests behavior of an ImageField and its dimensions fields.
@@ -294,7 +294,7 @@ class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
self.assertEqual(p.mugshot.was_opened, True)
@skipIf(Image is None, "Pillow/PIL is required to test ImageField")
@skipIf(Image is None, "Pillow is required to test ImageField")
class ImageFieldNoDimensionsTests(ImageFieldTwoDimensionsTests):
"""
Tests behavior of an ImageField with no dimension fields.
@@ -303,7 +303,7 @@ class ImageFieldNoDimensionsTests(ImageFieldTwoDimensionsTests):
PersonModel = Person
@skipIf(Image is None, "Pillow/PIL is required to test ImageField")
@skipIf(Image is None, "Pillow is required to test ImageField")
class ImageFieldOneDimensionTests(ImageFieldTwoDimensionsTests):
"""
Tests behavior of an ImageField with one dimensions field.
@@ -312,7 +312,7 @@ class ImageFieldOneDimensionTests(ImageFieldTwoDimensionsTests):
PersonModel = PersonWithHeight
@skipIf(Image is None, "Pillow/PIL is required to test ImageField")
@skipIf(Image is None, "Pillow is required to test ImageField")
class ImageFieldDimensionsFirstTests(ImageFieldTwoDimensionsTests):
"""
Tests behavior of an ImageField where the dimensions fields are
@@ -322,7 +322,7 @@ class ImageFieldDimensionsFirstTests(ImageFieldTwoDimensionsTests):
PersonModel = PersonDimensionsFirst
@skipIf(Image is None, "Pillow/PIL is required to test ImageField")
@skipIf(Image is None, "Pillow is required to test ImageField")
class ImageFieldUsingFileTests(ImageFieldTwoDimensionsTests):
"""
Tests behavior of an ImageField when assigning it a File instance
@@ -333,7 +333,7 @@ class ImageFieldUsingFileTests(ImageFieldTwoDimensionsTests):
File = File
@skipIf(Image is None, "Pillow/PIL is required to test ImageField")
@skipIf(Image is None, "Pillow is required to test ImageField")
class TwoImageFieldTests(ImageFieldTestMixin, TestCase):
"""
Tests a model with two ImageFields.

View File

@@ -13,7 +13,7 @@ import os
import tempfile
from django.core import validators
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.core.exceptions import ValidationError
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.utils import six
@@ -154,7 +154,7 @@ class FilePathModel(models.Model):
try:
from django.utils.image import Image # NOQA: detect if Pillow is installed
from PIL import Image # NOQA: detect if Pillow is installed
test_images = True
@@ -193,7 +193,7 @@ try:
def __str__(self):
return self.description
except ImproperlyConfigured:
except ImportError:
test_images = False

View File

@@ -1852,7 +1852,7 @@ class FileAndImageFieldTests(TestCase):
names.sort()
self.assertEqual(names, ['---------', '__init__.py', 'models.py', 'tests.py'])
@skipUnless(test_images, "Pillow/PIL not installed")
@skipUnless(test_images, "Pillow not installed")
def test_image_field(self):
# ImageField and FileField are nearly identical, but they differ slighty when
# it comes to validation. This specifically tests that #6302 is fixed for

View File

@@ -2,7 +2,7 @@
A test spanning all the capabilities of all the serializers.
This class sets up a model for each model field type
(except for image types, because of the Pillow/PIL dependency).
(except for image types, because of the Pillow dependency).
"""
import warnings