summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Lindsley <daniel@toastdriven.com>2013-05-14 19:31:16 -0700
committerDaniel Lindsley <daniel@toastdriven.com>2013-05-14 19:32:04 -0700
commit33793f7c3edd8ff144ff2e9434367267c20af26a (patch)
tree2fc05d98ee3d9c2bb9fd9a208647ad280d52b78c /tests
parentc792c83cad54f064b6ba13e285e95a90e2c61f09 (diff)
Fixed #19934 - Use of Pillow is now preferred over PIL.
This starts the deprecation period for PIL (support to end in 1.8).
Diffstat (limited to 'tests')
-rw-r--r--tests/file_storage/tests.py20
-rw-r--r--tests/model_fields/models.py17
-rw-r--r--tests/model_fields/test_imagefield.py8
-rw-r--r--tests/model_forms/models.py12
-rw-r--r--tests/serializers_regress/models.py2
5 files changed, 23 insertions, 36 deletions
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index 5e6adee894..e4b71dba82 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -29,16 +29,10 @@ from django.utils._os import upath
from django.test.utils import override_settings
from servers.tests import LiveServerBase
-# Try to import PIL in either of the two ways it can end up installed.
-# Checking for the existence of Image is enough for CPython, but
-# for PyPy, you need to check for the underlying modules
try:
- from PIL import Image, _imaging
-except ImportError:
- try:
- import Image, _imaging
- except ImportError:
- Image = None
+ from django.utils.image import Image
+except ImproperlyConfigured:
+ Image = None
class GetStorageClassTests(SimpleTestCase):
@@ -494,7 +488,7 @@ class DimensionClosingBug(unittest.TestCase):
"""
Test that get_image_dimensions() properly closes files (#8817)
"""
- @unittest.skipUnless(Image, "PIL not installed")
+ @unittest.skipUnless(Image, "Pillow/PIL not installed")
def test_not_closing_of_files(self):
"""
Open files passed into get_image_dimensions() should stay opened.
@@ -505,7 +499,7 @@ class DimensionClosingBug(unittest.TestCase):
finally:
self.assertTrue(not empty_io.closed)
- @unittest.skipUnless(Image, "PIL not installed")
+ @unittest.skipUnless(Image, "Pillow/PIL not installed")
def test_closing_of_filenames(self):
"""
get_image_dimensions() called with a filename should closed the file.
@@ -542,7 +536,7 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase):
Test that get_image_dimensions() works properly after various calls
using a file handler (#11158)
"""
- @unittest.skipUnless(Image, "PIL not installed")
+ @unittest.skipUnless(Image, "Pillow/PIL not installed")
def test_multiple_calls(self):
"""
Multiple calls of get_image_dimensions() should return the same size.
@@ -556,7 +550,7 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase):
self.assertEqual(image_pil.size, size_1)
self.assertEqual(size_1, size_2)
- @unittest.skipUnless(Image, "PIL not installed")
+ @unittest.skipUnless(Image, "Pillow/PIL not installed")
def test_bug_19457(self):
"""
Regression test for #19457
diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py
index c3b2f7fccb..2d602d6412 100644
--- a/tests/model_fields/models.py
+++ b/tests/model_fields/models.py
@@ -1,17 +1,12 @@
import os
import tempfile
-# Try to import PIL in either of the two ways it can end up installed.
-# Checking for the existence of Image is enough for CPython, but for PyPy,
-# you need to check for the underlying modules.
+from django.core.exceptions import ImproperlyConfigured
try:
- from PIL import Image, _imaging
-except ImportError:
- try:
- import Image, _imaging
- except ImportError:
- Image = None
+ from django.utils.image import Image
+except ImproperlyConfigured:
+ Image = None
from django.core.files.storage import FileSystemStorage
from django.db import models
@@ -87,7 +82,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 PIL in this test
+ # Don't want to depend on Pillow/PIL in this test
#field_image = models.ImageField("verbose field")
field12 = models.IntegerField("verbose field12")
field13 = models.IPAddressField("verbose field13")
@@ -119,7 +114,7 @@ class Document(models.Model):
###############################################################################
# ImageField
-# If PIL available, do these tests.
+# If Pillow/PIL available, do these tests.
if Image:
class TestImageFieldFile(ImageFieldFile):
"""
diff --git a/tests/model_fields/test_imagefield.py b/tests/model_fields/test_imagefield.py
index df0215db3d..457892ddb8 100644
--- a/tests/model_fields/test_imagefield.py
+++ b/tests/model_fields/test_imagefield.py
@@ -3,20 +3,24 @@ from __future__ import absolute_import
import os
import shutil
+from django.core.exceptions import ImproperlyConfigured
from django.core.files import File
from django.core.files.images import ImageFile
from django.test import TestCase
from django.utils._os import upath
from django.utils.unittest import skipIf
-from .models import Image
+try:
+ from .models import Image
+except ImproperlyConfigured:
+ Image = None
if Image:
from .models import (Person, PersonWithHeight, PersonWithHeightAndWidth,
PersonDimensionsFirst, PersonTwoImages, TestImageFieldFile)
from .models import temp_storage_dir
else:
- # 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
diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py
index 25c780f1c2..a79d9b8c5b 100644
--- a/tests/model_forms/models.py
+++ b/tests/model_forms/models.py
@@ -11,6 +11,7 @@ from __future__ import unicode_literals
import os
import tempfile
+from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.utils import six
@@ -91,14 +92,7 @@ class TextFile(models.Model):
return self.description
try:
- # If PIL is available, try testing ImageFields. Checking for the existence
- # of Image is enough for CPython, but for PyPy, you need to check for the
- # underlying modules If PIL is not available, ImageField tests are omitted.
- # Try to import PIL in either of the two ways it can end up installed.
- try:
- from PIL import Image, _imaging
- except ImportError:
- import Image, _imaging
+ from django.utils.image import Image
test_images = True
@@ -137,7 +131,7 @@ try:
def __str__(self):
return self.description
-except ImportError:
+except ImproperlyConfigured:
test_images = False
@python_2_unicode_compatible
diff --git a/tests/serializers_regress/models.py b/tests/serializers_regress/models.py
index 21fe073122..21a3448a8e 100644
--- a/tests/serializers_regress/models.py
+++ b/tests/serializers_regress/models.py
@@ -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 PIL dependency).
+(except for image types, because of the Pillow/PIL dependency).
"""
from django.db import models