1
0
mirror of https://github.com/django/django.git synced 2025-08-09 11:29:13 +00:00

Used skipIf decorator to skip image tests when PIL is not available

This commit is contained in:
Claude Paroz 2012-07-06 11:15:20 +02:00
parent 8fdc56d2a6
commit 86eb606b88
2 changed files with 379 additions and 369 deletions

View File

@ -6,15 +6,20 @@ import shutil
from django.core.files import File from django.core.files import File
from django.core.files.images import ImageFile from django.core.files.images import ImageFile
from django.test import TestCase from django.test import TestCase
from django.utils.unittest import skipIf
from .models import (Image, Person, PersonWithHeight, PersonWithHeightAndWidth, from .models import Image
PersonDimensionsFirst, PersonTwoImages, TestImageFieldFile)
# If PIL available, do these tests.
if Image: if Image:
from .models import (Person, PersonWithHeight, PersonWithHeightAndWidth,
PersonDimensionsFirst, PersonTwoImages, TestImageFieldFile)
from .models import temp_storage_dir from .models import temp_storage_dir
else:
# PIL not available, create dummy classes (tests will be skipped anyway)
class Person():
pass
PersonWithHeight = PersonWithHeightAndWidth = PersonDimensionsFirst = Person
PersonTwoImages = Person
class ImageFieldTestMixin(object): class ImageFieldTestMixin(object):
@ -83,6 +88,7 @@ if Image:
self.assertEqual(getattr(instance, height_field_name), height) self.assertEqual(getattr(instance, height_field_name), height)
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldTests(ImageFieldTestMixin, TestCase): class ImageFieldTests(ImageFieldTestMixin, TestCase):
""" """
Tests for ImageField that don't need to be run with each of the Tests for ImageField that don't need to be run with each of the
@ -169,6 +175,7 @@ if Image:
self.assertEqual(p.mugshot, loaded_p.mugshot) self.assertEqual(p.mugshot, loaded_p.mugshot)
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase): class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
""" """
Tests behavior of an ImageField and its dimensions fields. Tests behavior of an ImageField and its dimensions fields.
@ -282,6 +289,7 @@ if Image:
self.assertEqual(p.mugshot.was_opened, True) self.assertEqual(p.mugshot.was_opened, True)
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldNoDimensionsTests(ImageFieldTwoDimensionsTests): class ImageFieldNoDimensionsTests(ImageFieldTwoDimensionsTests):
""" """
Tests behavior of an ImageField with no dimension fields. Tests behavior of an ImageField with no dimension fields.
@ -290,6 +298,7 @@ if Image:
PersonModel = Person PersonModel = Person
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldOneDimensionTests(ImageFieldTwoDimensionsTests): class ImageFieldOneDimensionTests(ImageFieldTwoDimensionsTests):
""" """
Tests behavior of an ImageField with one dimensions field. Tests behavior of an ImageField with one dimensions field.
@ -298,6 +307,7 @@ if Image:
PersonModel = PersonWithHeight PersonModel = PersonWithHeight
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldDimensionsFirstTests(ImageFieldTwoDimensionsTests): class ImageFieldDimensionsFirstTests(ImageFieldTwoDimensionsTests):
""" """
Tests behavior of an ImageField where the dimensions fields are Tests behavior of an ImageField where the dimensions fields are
@ -307,6 +317,7 @@ if Image:
PersonModel = PersonDimensionsFirst PersonModel = PersonDimensionsFirst
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldUsingFileTests(ImageFieldTwoDimensionsTests): class ImageFieldUsingFileTests(ImageFieldTwoDimensionsTests):
""" """
Tests behavior of an ImageField when assigning it a File instance Tests behavior of an ImageField when assigning it a File instance
@ -317,6 +328,7 @@ if Image:
File = File File = File
@skipIf(Image is None, "PIL is required to test ImageField")
class TwoImageFieldTests(ImageFieldTestMixin, TestCase): class TwoImageFieldTests(ImageFieldTestMixin, TestCase):
""" """
Tests a model with two ImageFields. Tests a model with two ImageFields.

View File

@ -13,8 +13,6 @@ from django.utils import unittest
from .models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, from .models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post,
NullBooleanModel, BooleanModel, Document, RenamedField) NullBooleanModel, BooleanModel, Document, RenamedField)
# If PIL available, do these tests.
if Image:
from .imagefield import (ImageFieldTests, ImageFieldTwoDimensionsTests, from .imagefield import (ImageFieldTests, ImageFieldTwoDimensionsTests,
TwoImageFieldTests, ImageFieldNoDimensionsTests, TwoImageFieldTests, ImageFieldNoDimensionsTests,
ImageFieldOneDimensionTests, ImageFieldDimensionsFirstTests, ImageFieldOneDimensionTests, ImageFieldDimensionsFirstTests,